]> source.dussan.org Git - poi.git/commitdiff
Fixed several test drivers or the implementation
authorAndreas Beeker <kiwiwings@apache.org>
Thu, 28 May 2015 23:32:26 +0000 (23:32 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Thu, 28 May 2015 23:32:26 +0000 (23:32 +0000)
renamed font functions in HSLFTextRun

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1682356 13f79535-47bb-0310-9956-ffa450edef68

34 files changed:
src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
src/examples/src/org/apache/poi/hslf/examples/TableDemo.java
src/java/org/apache/poi/util/HexDump.java
src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java
src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
src/scratchpad/testcases/org/apache/poi/hslf/model/AllHSLFModelTests.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java [deleted file]
src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java [deleted file]
src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java [deleted file]
src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextSpecInfoAtom.java
src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/AllHSLFUserModelTests.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList2.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNumberedList3.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java [new file with mode: 0644]

index 3397278737eef2c2ecba562d2613e5b6504989e6..494c7f9c3209daedc21b2fff7cc9b10286fc0670 100644 (file)
@@ -153,7 +153,7 @@ public final class ApacheconEU08 {
                 cell.setText(txt1[i][j]);
                 HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
                 rt.setFontSize(10);
-                rt.setFontName("Arial");
+                rt.setFontFamily("Arial");
                 rt.setBold(true);
                 if(i == 0){
                     rt.setFontSize(32);
@@ -232,7 +232,7 @@ public final class ApacheconEU08 {
 
         HSLFTextBox box3 = new HSLFTextBox();
         HSLFTextRun rt3 = box3.getTextParagraphs().get(0).getTextRuns().get(0);
-        rt3.setFontName("Courier New");
+        rt3.setFontFamily("Courier New");
         rt3.setFontSize(8);
         box3.setText(
                 "SlideShow ppt = new SlideShow();\u000b" +
@@ -341,7 +341,7 @@ public final class ApacheconEU08 {
 
         HSLFTextBox box3 = new HSLFTextBox();
         HSLFTextRun rt3 = box3.getTextParagraphs().get(0).getTextRuns().get(0);
-        rt3.setFontName("Courier New");
+        rt3.setFontFamily("Courier New");
         rt3.setFontSize(8);
         box3.setText(
                 "//bar chart data. The first value is the bar color, the second is the width\u000b" +
index bb2e813865c949af0bd1e01ef2e0a50d291e3aa2..abc40750cc359034fbbb6c456fa78c48469d577b 100644 (file)
@@ -54,7 +54,7 @@ public final class TableDemo {
             for (int j = 0; j < txt1[i].length; j++) {
                 TableCell cell = table1.getCell(i, j);
                 HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
-                rt.setFontName("Arial");
+                rt.setFontFamily("Arial");
                 rt.setFontSize(10);
                 if(i == 0){
                     cell.getFill().setForegroundColor(new Color(227, 227, 227));
@@ -94,7 +94,7 @@ public final class TableDemo {
                 TableCell cell = table2.getCell(i, j);
                 HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
                 rt.setFontSize(10);
-                rt.setFontName("Arial");
+                rt.setFontFamily("Arial");
                 if(i == 0){
                     cell.getFill().setForegroundColor(new Color(0, 51, 102));
                     rt.setFontColor(Color.white);
index 979ca1c9c5e62ed2dfd7e4ed867a88cb78fe2b73..3c086ba606c28245cee83ae7c3645a356b5757f0 100644 (file)
@@ -170,49 +170,41 @@ public class HexDump {
      * @return output string
      */
 
-    public static String dump(final byte [] data, final long offset,
-                            final int index) {
-        StringBuffer buffer;
-        if ((index < 0) || (index >= data.length))
+    public static String dump(final byte [] data, final long offset, final int index) {
+        if ((index < 0) || (index > data.length))
         {
             throw new ArrayIndexOutOfBoundsException(
                 "illegal index: " + index + " into array of length "
                 + data.length);
         }
-        long         display_offset = offset + index;
-        buffer         = new StringBuffer(74);
+        long  display_offset = offset + index;
+        StringBuilder buffer = new StringBuilder(74);
 
-        for (int j = index; j < data.length; j += 16)
-        {
+        for (int j = index; j <= data.length; j += 16) {
             int chars_read = data.length - j;
 
-            if (chars_read > 16)
-            {
+            if (chars_read > 16) {
                 chars_read = 16;
             }
+            
             buffer.append(dump(display_offset)).append(' ');
-            for (int k = 0; k < 16; k++)
-            {
-                if (k < chars_read)
-                {
-                    buffer.append(dump(data[ k + j ]));
-                }
-                else
-                {
-                    buffer.append("  ");
-                }
+            for (int k = 0; k < 16; k++) {
+                String hexDmp = (k < chars_read) ? dump(data[ k + j ]) : "  ";
+                buffer.append(hexDmp);
                 buffer.append(' ');
             }
-            for (int k = 0; k < chars_read; k++)
-            {
-                if ((data[ k + j ] >= ' ') && (data[ k + j ] < 127))
-                {
-                    buffer.append(( char ) data[ k + j ]);
-                }
-                else
-                {
-                    buffer.append('.');
+            for (int k = 0; k < chars_read; k++) {
+                byte dataB = data[ k + j ];
+                char charB = (char)(dataB & 0xFF);
+                switch (charB) {
+                case 127: case 128: case 129: case 141: case 142: case 143: case 144: case 157: case 158:
+                    charB = '.';
+                    break;
+                default:
+                    if (charB < ' ') charB = '.';
+                    break;
                 }
+                buffer.append(charB);
             }
             buffer.append(EOL);
             display_offset += chars_read;
index 526ccc7dc126ce64e3aee443e1bc48398eb3aa48..7ae20c6696c47d33bcce5f3ccf6db1931dc46fbd 100644 (file)
@@ -257,7 +257,7 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
 
         HSLFTextRun rt = txt.getTextParagraphs().get(0).getTextRuns().get(0);
         rt.setFontSize(_font.getSize());
-        rt.setFontName(_font.getFamily());
+        rt.setFontFamily(_font.getFamily());
 
         if (getColor() != null) rt.setFontColor(getColor());
         if (_font.isBold()) rt.setBold(true);
index 38535ecf09e761f1d861ddb78aaa655ef129cf59..09f21d1bafebb6eb6489738953e0bc24f50b76f4 100644 (file)
@@ -247,14 +247,14 @@ public final class PPDrawing extends RecordAtom {
         */
        public void writeOut(OutputStream out) throws IOException {
                // Ensure the escher layer reflects the text changes
-               for(int i=0; i<textboxWrappers.length; i++) {
-                       textboxWrappers[i].writeOut(null);
+               for (EscherTextboxWrapper w : textboxWrappers) {
+                       w.writeOut(null);
                }
 
                // Find the new size of the escher children;
                int newSize = 0;
-               for(int i=0; i<childRecords.length; i++) {
-                       newSize += childRecords[i].getRecordSize();
+               for(EscherRecord er : childRecords) {
+                       newSize += er.getRecordSize();
                }
 
                // Update the size (header bytes 5-8)
index a3624678a04d01dac4ade2ca54a7addd4bdef88b..6782def529b17c3dd2b9145e8ef5523990e15118 100644 (file)
 
 package org.apache.poi.hslf.record;
 
-import org.apache.poi.util.LittleEndian;
-
-import java.io.OutputStream;
-import java.io.IOException;
+import java.io.*;
 import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
 
 /**
  * The special info runs contained in this text.
@@ -42,6 +43,15 @@ public final class TextSpecInfoAtom extends RecordAtom {
      */
     private byte[] _data;
 
+    /**
+     * Constructs an empty atom, with a default run of size 1 
+     */
+    public TextSpecInfoAtom() {
+        _header = new byte[8];
+        LittleEndian.putUInt(_header, 4, _type);
+        reset(1);
+    }
+    
     /**
      * Constructs the link related atom record from its
      *  source data.
@@ -50,7 +60,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
      * @param start the start offset into the byte array.
      * @param len the length of the slice in the byte array.
      */
-    protected TextSpecInfoAtom(byte[] source, int start, int len) {
+    public TextSpecInfoAtom(byte[] source, int start, int len) {
         // Get the header.
         _header = new byte[8];
         System.arraycopy(source,start,_header,0,8);
@@ -92,18 +102,49 @@ public final class TextSpecInfoAtom extends RecordAtom {
      * @param size  the site of parent text
      */
     public void reset(int size){
-        _data = new byte[10];
-        // 01 00 00 00
-        LittleEndian.putInt(_data, 0, size);
-        // 01 00 00 00
-        LittleEndian.putInt(_data, 4, 1); //mask
-        // 00 00
-        LittleEndian.putShort(_data, 8, (short)0); //langId
+        TextSpecInfoRun sir = new TextSpecInfoRun(size);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        try {
+            sir.writeOut(bos);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        _data = bos.toByteArray();
 
         // Update the size (header bytes 5-8)
         LittleEndian.putInt(_header, 4, _data.length);
     }
 
+    /**
+     * Adapts the size by enlarging the last {@link TextSpecInfoRun}
+     * or chopping the runs to the given length
+     *
+     * @param size
+     */
+    public void setParentSize(int size) {
+        assert(size > 0);
+        int covered = 0;
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        TextSpecInfoRun runs[] = getTextSpecInfoRuns();
+        assert(runs.length > 0);
+        for (int i=0; i<runs.length && covered < size; i++) {
+            TextSpecInfoRun run = runs[i];
+            if (covered + run.getLength() > size || i == runs.length-1) {
+                run.setLength(size-covered);
+            }
+            covered += run.getLength();
+            try {
+                run.writeOut(bos);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        _data = bos.toByteArray();
+
+        // Update the size (header bytes 5-8)
+        LittleEndian.putInt(_header, 4, _data.length);
+    }
+    
     /**
      * Get the number of characters covered by this records
      *
@@ -111,92 +152,17 @@ public final class TextSpecInfoAtom extends RecordAtom {
      */
     public int getCharactersCovered(){
         int covered = 0;
-        TextSpecInfoRun[] runs = getTextSpecInfoRuns();
-        for (int i = 0; i < runs.length; i++) covered += runs[i].len;
+        for (TextSpecInfoRun r : getTextSpecInfoRuns()) covered += r.length;
         return covered;
     }
 
     public TextSpecInfoRun[] getTextSpecInfoRuns(){
-        ArrayList<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
-        int pos = 0;
-        int[] bits = {1, 0, 2};
-        while(pos < _data.length) {
-            TextSpecInfoRun run = new TextSpecInfoRun();
-            run.len = LittleEndian.getInt(_data, pos); pos += 4;
-            run.mask = LittleEndian.getInt(_data, pos); pos += 4;
-            for (int i = 0; i < bits.length; i++) {
-                if((run.mask & 1 << bits[i]) != 0){
-                    switch (bits[i]){
-                        case 0:
-                            run.spellInfo = LittleEndian.getShort(_data, pos); pos += 2;
-                            break;
-                        case 1:
-                            run.langId = LittleEndian.getShort(_data, pos); pos += 2;
-                            break;
-                        case 2:
-                            run.altLangId = LittleEndian.getShort(_data, pos); pos += 2;
-                            break;
-                    }
-                }
-            }
-            lst.add(run);
+        LittleEndianByteArrayInputStream bis = new LittleEndianByteArrayInputStream(_data);
+        List<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
+        while (bis.available() > 0) {
+            lst.add(new TextSpecInfoRun(bis));
         }
         return lst.toArray(new TextSpecInfoRun[lst.size()]);
     }
 
-    public static class TextSpecInfoRun {
-        //Length of special info run.
-        protected int len;
-
-        //Special info mask of this run;
-        protected int mask;
-
-        // info fields as indicated by the mask.
-        // -1 means the bit is not set
-        protected short spellInfo = -1;
-        protected short langId = -1;
-        protected short altLangId = -1;
-
-        /**
-         * Spelling status of this text. See Spell Info table below.
-         *
-         * <p>Spell Info Types:</p>
-         * <li>0    Unchecked
-         * <li>1    Previously incorrect, needs rechecking
-         * <li>2    Correct
-         * <li>3    Incorrect
-         *
-         * @return Spelling status of this text
-         */
-        public short getSpellInfo(){
-            return spellInfo;
-        }
-
-        /**
-         * Windows LANGID for this text.
-         *
-         * @return Windows LANGID for this text.
-         */
-        public short getLangId(){
-            return spellInfo;
-        }
-
-        /**
-         * Alternate Windows LANGID of this text;
-         * must be a valid non-East Asian LANGID if the text has an East Asian language,
-         * otherwise may be an East Asian LANGID or language neutral (zero).
-         *
-         * @return  Alternate Windows LANGID of this text
-         */
-        public short getAltLangId(){
-            return altLangId;
-        }
-
-        /**
-         * @return Length of special info run.
-         */
-        public int length(){
-            return len;
-        }
-    }
 }
diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java
new file mode 100644 (file)
index 0000000..0e2f730
--- /dev/null
@@ -0,0 +1,346 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hslf.record;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+import org.apache.poi.util.*;\r
+\r
+public class TextSpecInfoRun {\r
+    /**\r
+     * A enum that specifies the spelling status of a run of text.\r
+     */\r
+    public enum SpellInfoEnum {\r
+        /** the text is spelled incorrectly. */\r
+        error(new BitField(1)),\r
+        /** the text needs rechecking. */\r
+        clean(new BitField(2)),\r
+        /** the text has a grammar error. */\r
+        grammar(new BitField(4)),\r
+        /** the text is spelled correct */\r
+        correct(new BitField(0));\r
+        \r
+        final BitField bitField;\r
+        \r
+        SpellInfoEnum(BitField bitField) {\r
+            this.bitField = bitField;\r
+        }\r
+    }\r
+    \r
+    /** A bit that specifies whether the spellInfo field exists. */\r
+    private static final BitField spellFld    = new BitField(0X00000001);\r
+    /** A bit that specifies whether the lid field exists. */\r
+    private static final BitField langFld     = new BitField(0X00000002);\r
+    /** A bit that specifies whether the altLid field exists. */\r
+    private static final BitField altLangFld  = new BitField(0X00000004);\r
+    // unused1, unused2 - Undefined and MUST be ignored.\r
+    /** A bit that specifies whether the pp10runid, reserved3, and grammarError fields exist. */\r
+    private static final BitField pp10extFld  = new BitField(0X00000020);\r
+    /** A bit that specifies whether the bidi field exists. */\r
+    private static final BitField bidiFld     = new BitField(0X00000040);\r
+    // unused3 - Undefined and MUST be ignored.\r
+    // reserved1 - MUST be zero and MUST be ignored.\r
+    /** A bit that specifies whether the smartTags field exists. */\r
+    private static final BitField smartTagFld = new BitField(0X00000200);\r
+    // reserved2 - MUST be zero and MUST be ignored. \r
+\r
+    /**\r
+     * An optional unsigned integer that specifies an identifier for a character\r
+     * run that contains StyleTextProp11 data. It MUST exist if and only if pp10ext is TRUE.\r
+     **/\r
+    private static final BitField pp10runidFld = new BitField(0X0000000F);\r
+    // reserved3 - An optional unsigned integer that MUST be zero, and MUST be ignored. It\r
+    // MUST exist if and only if fPp10ext is TRUE.\r
+    /**\r
+     * An optional bit that specifies a grammar error. It MUST exist if and\r
+     * only if fPp10ext is TRUE.\r
+     **/\r
+    private static final BitField grammarErrorFld = new BitField(0X80000000);\r
+    \r
+    //Length of special info run.\r
+    protected int length;\r
+\r
+    //Special info mask of this run;\r
+    protected int mask;\r
+\r
+    // info fields as indicated by the mask.\r
+    // -1 means the bit is not set\r
+\r
+    /**\r
+     * An optional SpellingFlags structure that specifies the spelling status of this\r
+     * text. It MUST exist if and only if spell is TRUE.\r
+     * The spellInfo.grammar sub-field MUST be zero.\r
+     * <br>\r
+     * error (1 bit): A bit that specifies whether the text is spelled incorrectly.<br>\r
+     * clean (1 bit): A bit that specifies whether the text needs rechecking.<br>\r
+     * grammar (1 bit): A bit that specifies whether the text has a grammar error.<br>\r
+     * reserved (13 bits): MUST be zero and MUST be ignored.\r
+     */\r
+    protected short spellInfo = -1;\r
+    \r
+    /**\r
+     * An optional TxLCID that specifies the language identifier of this text.\r
+     * It MUST exist if and only if lang is TRUE.\r
+     * <br>\r
+     * 0x0000 = No language.<br>\r
+     * 0x0013 = Any Dutch language is preferred over non-Dutch languages when proofing the text.<br>\r
+     * 0x0400 = No proofing is performed on the text.<br>\r
+     * &gt; 0x0400 = A valid LCID as specified by [MS-LCID].\r
+     */\r
+    protected short langId = -1;\r
+    \r
+    /**\r
+     * An optional TxLCID that specifies the alternate language identifier of this text.\r
+     * It MUST exist if and only if altLang is TRUE.\r
+     */\r
+    protected short altLangId = -1;\r
+    \r
+    /**\r
+     * An optional signed integer that specifies whether the text contains bidirectional\r
+     * characters. It MUST exist if and only if fBidi is TRUE.\r
+     * 0x0000 = Contains no bidirectional characters,\r
+     * 0x0001 = Contains bidirectional characters.\r
+     */\r
+    protected short bidi = -1;\r
+    \r
+    protected int pp10extMask = -1;\r
+    protected byte[] smartTagsBytes = null;\r
+\r
+    /**\r
+     * Inits a TextSpecInfoRun with default values\r
+     *\r
+     * @param len the length of the one and only run\r
+     */\r
+    public TextSpecInfoRun(int len) {\r
+        setLength(len);\r
+        setLangId((short)0);\r
+    }\r
+    \r
+    public TextSpecInfoRun(LittleEndianByteArrayInputStream source) {\r
+        length = source.readInt();\r
+        mask = source.readInt();\r
+        if (spellFld.isSet(mask)) {\r
+            spellInfo = source.readShort();\r
+        }\r
+        if (langFld.isSet(mask)) {\r
+            langId = source.readShort();\r
+        }\r
+        if (altLangFld.isSet(mask)) {\r
+            altLangId = source.readShort();\r
+        }\r
+        if (bidiFld.isSet(mask)) {\r
+            bidi = source.readShort();\r
+        }\r
+        if (pp10extFld.isSet(mask)) {\r
+            pp10extMask = source.readInt();\r
+        }\r
+        if (smartTagFld.isSet(mask)) {\r
+            // An unsigned integer specifies the count of items in rgSmartTagIndex.\r
+            int count = source.readInt();\r
+            smartTagsBytes = new byte[4+count*4];\r
+            LittleEndian.putInt(smartTagsBytes, 0, count);\r
+            // An array of SmartTagIndex that specifies the indices.\r
+            // The count of items in the array is specified by count.\r
+            source.readFully(smartTagsBytes, 4, count*4);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Write the contents of the record back, so it can be written\r
+     * to disk\r
+     *\r
+     * @param out the output stream to write to.\r
+     * @throws java.io.IOException if an error occurs.\r
+     */\r
+    public void writeOut(OutputStream out) throws IOException {\r
+        final byte buf[] = new byte[4];\r
+        LittleEndian.putInt(buf, 0, length);\r
+        out.write(buf);\r
+        LittleEndian.putInt(buf, 0, mask);\r
+        out.write(buf);\r
+        Object flds[] = {\r
+            spellFld, spellInfo, "spell info",\r
+            langFld, langId, "lang id",\r
+            altLangFld, altLangId, "alt lang id",\r
+            bidiFld, bidi, "bidi",\r
+            pp10extFld, pp10extMask, "pp10 extension field",\r
+            smartTagFld, smartTagsBytes, "smart tags"\r
+        };\r
+        \r
+        for (int i=0; i<flds.length; i+=3) {\r
+            BitField fld = (BitField)flds[i+0];\r
+            Object valO = flds[i+1];\r
+            if (!fld.isSet(mask)) continue;\r
+            boolean valid;\r
+            if (valO instanceof byte[]) {\r
+                byte bufB[] = (byte[])valO;\r
+                valid = bufB.length > 0;\r
+                out.write(bufB);\r
+            } else if (valO instanceof Integer) {\r
+                int valI = ((Integer)valO);\r
+                valid = (valI != -1);\r
+                LittleEndian.putInt(buf, 0, valI);\r
+                out.write(buf);\r
+            } else if (valO instanceof Short) {\r
+                short valS = ((Short)valO);\r
+                valid = (valS != -1);\r
+                LittleEndian.putShort(buf, 0, valS);\r
+                out.write(buf, 0, 2);\r
+            } else {\r
+                valid = false;\r
+            }\r
+            if (!valid) {\r
+                throw new IOException(flds[i+2]+" is activated, but its value is invalid");\r
+            }\r
+        }\r
+    }        \r
+    \r
+    /**\r
+     * @return Spelling status of this text. null if not defined.\r
+     */\r
+    public SpellInfoEnum getSpellInfo(){\r
+        if (spellInfo == -1) return null;\r
+        for (SpellInfoEnum si : new SpellInfoEnum[]{SpellInfoEnum.clean,SpellInfoEnum.error,SpellInfoEnum.grammar}) {\r
+            if (si.bitField.isSet(spellInfo)) return si;\r
+        }\r
+        return SpellInfoEnum.correct;\r
+    }\r
+\r
+    /**\r
+     * @param spellInfo Spelling status of this text. null if not defined.\r
+     */\r
+    public void setSpellInfo(SpellInfoEnum spellInfo) {\r
+        this.spellInfo = (spellInfo == null)\r
+            ? -1\r
+            : (short)spellInfo.bitField.set(0);\r
+        mask = spellFld.setBoolean(mask, spellInfo != null);\r
+    }\r
+    \r
+    /**\r
+     * Windows LANGID for this text.\r
+     *\r
+     * @return Windows LANGID for this text, -1 if it's not set\r
+     */\r
+    public short getLangId(){\r
+        return langId;\r
+    }\r
+\r
+    /**\r
+     * @param langId Windows LANGID for this text, -1 to unset\r
+     */\r
+    public void setLangId(short langId) {\r
+        this.langId = langId;\r
+        mask = langFld.setBoolean(mask, langId != -1);\r
+    }\r
+    \r
+    /**\r
+     * Alternate Windows LANGID of this text;\r
+     * must be a valid non-East Asian LANGID if the text has an East Asian language,\r
+     * otherwise may be an East Asian LANGID or language neutral (zero).\r
+     *\r
+     * @return  Alternate Windows LANGID of this text, -1 if it's not set\r
+     */\r
+    public short getAltLangId(){\r
+        return altLangId;\r
+    }\r
+\r
+    public void setAltLangId(short altLangId) {\r
+        this.altLangId = altLangId;\r
+        mask = altLangFld.setBoolean(mask, altLangId != -1);\r
+    }\r
+\r
+    /**\r
+     * @return Length of special info run.\r
+     */\r
+    public int getLength() {\r
+        return length;\r
+    }\r
+\r
+    /**\r
+     * @param length Length of special info run.\r
+     */\r
+    public void setLength(int length) {\r
+        this.length = length;\r
+    }\r
+\r
+    /**\r
+     * @return the bidirectional characters flag. false = not bidi, true = is bidi, null = not set\r
+     */\r
+    public Boolean getBidi() {\r
+        return (bidi == -1 ? null : bidi != 0);\r
+    }\r
+\r
+    /**\r
+     * @param bidi the bidirectional characters flag. false = not bidi, true = is bidi, null = not set\r
+     */\r
+    public void setBidi(Boolean bidi) {\r
+        this.bidi = (bidi == null) ? -1 : (short)(bidi ? 1 : 0);\r
+        mask = bidiFld.setBoolean(mask, bidi != null);\r
+    }\r
+\r
+    /**\r
+     * @return the unparsed smart tags\r
+     */\r
+    public byte[] getSmartTagsBytes() {\r
+        return smartTagsBytes;\r
+    }\r
+\r
+    /**\r
+     * @param smartTagsBytes the unparsed smart tags, null to unset\r
+     */\r
+    public void setSmartTagsBytes(byte[] smartTagsBytes) {\r
+        this.smartTagsBytes = smartTagsBytes;\r
+        mask = smartTagFld.setBoolean(mask, smartTagsBytes != null);\r
+    }\r
+    \r
+    /**\r
+     * @return an identifier for a character run that contains StyleTextProp11 data.\r
+     */\r
+    public int getPP10RunId() {\r
+        return (pp10extMask == -1 || !pp10extFld.isSet(mask)) ? -1 : pp10runidFld.getValue(pp10extMask);\r
+        \r
+    }\r
+    \r
+    /**\r
+     * @param pp10RunId an identifier for a character run that contains StyleTextProp11 data, -1 to unset\r
+     */\r
+    public void setPP10RunId(int pp10RunId) {\r
+        if (pp10RunId == -1) {\r
+            pp10extMask = (getGrammarError() == null) ? -1 : pp10runidFld.clear(pp10extMask);\r
+        } else {\r
+            pp10extMask = pp10runidFld.setValue(pp10extMask, pp10RunId);\r
+        }\r
+        // if both parameters are invalid, remove the extension mask\r
+        mask = pp10extFld.setBoolean(mask, pp10extMask != -1);\r
+    }\r
+    \r
+    public Boolean getGrammarError() {\r
+        return (pp10extMask == -1 || !pp10extFld.isSet(mask)) ? null : grammarErrorFld.isSet(pp10extMask);\r
+    }\r
+    \r
+    public void getGrammarError(Boolean grammarError) {\r
+        if (grammarError == null) {\r
+            pp10extMask = (getPP10RunId() == -1) ? -1 : grammarErrorFld.clear(pp10extMask);\r
+        } else {\r
+            pp10extMask = grammarErrorFld.set(pp10extMask);\r
+        }\r
+        // if both parameters are invalid, remove the extension mask\r
+        mask = pp10extFld.setBoolean(mask, pp10extMask != -1);\r
+    }\r
+}\r
index ddc6e130685362346a87e663e49c26948733b389..547e095efbe17cb14fcc99a13fe2033d6ad5937f 100644 (file)
@@ -127,7 +127,36 @@ public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> {
      */
     @Override
     public List<HSLFShape> getShapes() {
-        return getShapeList();
+        PPDrawing ppdrawing = getPPDrawing();
+
+        EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
+        EscherContainerRecord spgr = null;
+
+        for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
+            EscherRecord rec = it.next();
+            if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
+                spgr = (EscherContainerRecord) rec;
+                break;
+            }
+        }
+        if (spgr == null) {
+            throw new IllegalStateException("spgr not found");
+        }
+
+        List<HSLFShape> shapeList = new ArrayList<HSLFShape>();
+        Iterator<EscherRecord> it = spgr.getChildIterator();
+        if (it.hasNext()) {
+            // skip first item
+            it.next();
+        }
+        for (; it.hasNext();) {
+            EscherContainerRecord sp = (EscherContainerRecord) it.next();
+            HSLFShape sh = HSLFShapeFactory.createShape(sp, null);
+            sh.setSheet(this);
+            shapeList.add(sh);
+        }
+
+        return shapeList;
     }
 
     /**
@@ -347,48 +376,10 @@ public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> {
     }
 
     public Iterator<HSLFShape> iterator() {
-        return getShapeList().iterator();
+        return getShapes().iterator();
     }
 
 
-    /**
-     * Returns all shapes contained in this Sheet
-     *
-     * @return all shapes contained in this Sheet (Slide or Notes)
-     */
-    protected List<HSLFShape> getShapeList() {
-        PPDrawing ppdrawing = getPPDrawing();
-
-        EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
-        EscherContainerRecord spgr = null;
-
-        for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
-            EscherRecord rec = it.next();
-            if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
-                spgr = (EscherContainerRecord) rec;
-                break;
-            }
-        }
-        if (spgr == null) {
-            throw new IllegalStateException("spgr not found");
-        }
-
-        List<HSLFShape> shapeList = new ArrayList<HSLFShape>();
-        Iterator<EscherRecord> it = spgr.getChildIterator();
-        if (it.hasNext()) {
-            // skip first item
-            it.next();
-        }
-        for (; it.hasNext();) {
-            EscherContainerRecord sp = (EscherContainerRecord) it.next();
-            HSLFShape sh = HSLFShapeFactory.createShape(sp, null);
-            sh.setSheet(this);
-            shapeList.add(sh);
-        }
-
-        return shapeList;
-    }
-
     /**
      * @return whether shapes on the master sheet should be shown. By default master graphics is turned off.
      * Sheets that support the notion of master (slide, slideLayout) should override it and
index eb8eb485128e17fccc0805ac9ee09739a6f8231f..5cc313e91f0f40999bdeb7a26fe33b9f92102d68 100644 (file)
@@ -571,10 +571,6 @@ public final class HSLFSlideShow implements SlideShow {
                                                        + _slides.size() + ")");
                }
 
-               _slides.get(newSlideNumber).setSlideNumber(oldSlideNumber);
-               _slides.get(oldSlideNumber).setSlideNumber(newSlideNumber);
-               Collections.swap(_slides, oldSlideNumber-1, newSlideNumber-1);
-               
                // The order of slides is defined by the order of slide atom sets in the
                // SlideListWithText container.
                SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
@@ -584,11 +580,16 @@ public final class HSLFSlideShow implements SlideShow {
                sas[oldSlideNumber - 1] = sas[newSlideNumber - 1];
                sas[newSlideNumber - 1] = tmp;
 
+               Collections.swap(_slides, oldSlideNumber - 1, newSlideNumber - 1);
+               _slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber);
+               _slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber);
+               
                ArrayList<Record> lst = new ArrayList<Record>();
                for (SlideAtomsSet s : sas) {
                        lst.add(s.getSlidePersistAtom());
                        lst.addAll(Arrays.asList(s.getSlideRecords()));
                }
+               
                Record[] r = lst.toArray(new Record[lst.size()]);
                slwt.setChildRecord(r);
        }
@@ -628,7 +629,7 @@ public final class HSLFSlideShow implements SlideShow {
             records.add(s.getSlidePersistAtom());
             records.addAll(Arrays.asList(s.getSlideRecords()));
                }
-               if (sa.size() == 0) {
+               if (sa.isEmpty()) {
                        _documentRecord.removeSlideListWithText(slwt);
                } else {
                        slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()]));
index 4b1e3767a7181c53e282e56fd367d2cc5e99b746..ca6ddf6e800593a895ae18679e68129adc1d42e1 100644 (file)
@@ -241,8 +241,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
             hardAttribute = maskProp != null && maskProp.getValue() == 0;\r
         }\r
         if (prop == null && !hardAttribute){\r
-            HSLFSheet sheet = _parentShape.getSheet();\r
-            int txtype = _parentShape.getRunType();\r
+            HSLFSheet sheet = getSheet();\r
+            int txtype = getRunType();\r
             HSLFMasterSheet master = sheet.getMasterSheet();\r
             if (master != null)\r
                 prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);\r
@@ -600,7 +600,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
 \r
         if (prop == null) {\r
             if (_sheet != null) {\r
-                int txtype = getParentShape().getRunType();\r
+                int txtype = getRunType();\r
                 HSLFMasterSheet master = _sheet.getMasterSheet();\r
                 if (master != null) {\r
                     prop = (BitMaskTextProp) master.getStyleAttribute(txtype, getIndentLevel(), ParagraphFlagsTextProp.NAME, false);\r
@@ -789,10 +789,11 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         * If TextSpecInfoAtom is present, we must update the text size in it,\r
         * otherwise the ppt will be corrupted\r
         */\r
-       TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_txtbox.findFirstOfType(RecordTypes.TextSpecInfoAtom.typeID);\r
-       int len = rawText.length() + 1;\r
-       if(specAtom != null && len != specAtom.getCharactersCovered()) {\r
-           specAtom.reset(len);\r
+       for (Record r : paragraphs.get(0)._records) {\r
+           if (r instanceof TextSpecInfoAtom) {\r
+               ((TextSpecInfoAtom)r).setParentSize(rawText.length()+1);\r
+               break;\r
+           }\r
        }\r
    }\r
 \r
@@ -870,6 +871,12 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
        return appendText(paragraphs, text, false);\r
    }\r
 \r
+   public static String getText(List<HSLFTextParagraph> paragraphs) {\r
+       assert(!paragraphs.isEmpty());\r
+       String rawText = getRawText(paragraphs);\r
+       return toExternalString(rawText, paragraphs.get(0).getRunType());\r
+   }\r
+   \r
    public static String getRawText(List<HSLFTextParagraph> paragraphs) {\r
        StringBuilder sb = new StringBuilder();\r
        for (HSLFTextParagraph p : paragraphs) {\r
@@ -1151,7 +1158,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         wrapper.appendChildRecord(tha);\r
 \r
         TextBytesAtom tba = new TextBytesAtom();\r
-        tba.setText("\r".getBytes());\r
+        tba.setText("".getBytes());\r
         wrapper.appendChildRecord(tba);\r
 \r
         StyleTextPropAtom sta = new StyleTextPropAtom(1);\r
@@ -1162,16 +1169,10 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         HSLFTextParagraph htp = new HSLFTextParagraph(tha, tba, null, sta);\r
         htp.setParagraphStyle(paraStyle);\r
         htp._records = new Record[0];\r
-//        htp.setBullet(false);\r
-//        htp.setLineSpacing(100);\r
-//        htp.setLeftMargin(0);\r
-//        htp.setIndent(0);\r
-        // set wrap flags\r
 \r
         HSLFTextRun htr = new HSLFTextRun(htp);\r
         htr.setCharacterStyle(charStyle);\r
-        htr.setText("\r");\r
-//        htr.setFontColor(Color.black);\r
+        htr.setText("");\r
         htp.addTextRun(htr);\r
 \r
         return Arrays.asList(htp);\r
index 91f327c10b3459b2a9de13324a79544c7ecdf2ce..0fb443b604d2af6713aa3b6e3da3c27d7619339c 100644 (file)
@@ -39,7 +39,7 @@ public final class HSLFTextRun implements TextRun {
        /** The TextRun we belong to */
        private HSLFTextParagraph parentParagraph;
        private String _runText = "";
-       private String _fontname;
+       private String _fontFamily;
        
        /**
         * Our paragraph and character style.
@@ -68,9 +68,9 @@ public final class HSLFTextRun implements TextRun {
         * Supply the SlideShow we belong to
         */
        public void updateSheet() {
-               if (_fontname != null) {
-                       setFontName(_fontname);
-                       _fontname = null;
+               if (_fontFamily != null) {
+                       setFontFamily(_fontFamily);
+                       _fontFamily = null;
                }
        }
 
@@ -149,7 +149,7 @@ public final class HSLFTextRun implements TextRun {
 
                if (prop == null){
                        HSLFSheet sheet = parentParagraph.getSheet();
-                       int txtype = parentParagraph.getParentShape().getRunType();
+                       int txtype = parentParagraph.getRunType();
                        HSLFMasterSheet master = sheet.getMasterSheet();
                        if (master != null)
                                prop = master.getStyleAttribute(txtype, parentParagraph.getIndentLevel(), propName, true);
@@ -306,16 +306,16 @@ public final class HSLFTextRun implements TextRun {
        /**
         * Sets the font name to use
         */
-       public void setFontName(String fontName) {
+       public void setFontFamily(String fontFamily) {
            HSLFSheet sheet = parentParagraph.getSheet();
            HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow();
                if (sheet == null || slideShow == null) {
                        //we can't set font since slideshow is not assigned yet
-                       _fontname = fontName;
+                       _fontFamily = fontFamily;
                        return;
                }
                // Get the index for this font (adding if needed)
-               int fontIdx = slideShow.getFontCollection().addFont(fontName);
+               int fontIdx = slideShow.getFontCollection().addFont(fontFamily);
                setCharTextPropVal("font.index", fontIdx);
        }
 
@@ -327,7 +327,7 @@ public final class HSLFTextRun implements TextRun {
         HSLFSheet sheet = parentParagraph.getSheet();
         HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow();
                if (sheet == null || slideShow == null) {
-                       return _fontname;
+                       return _fontFamily;
                }
                int fontIdx = getCharTextPropVal("font.index");
                if(fontIdx == -1) { return null; }
index f43f168ee71269ce39c6f6427fd371ea075a4d50..ca9e6c9a2f72a98b331b049d6111063de1ea5d14 100644 (file)
@@ -17,7 +17,6 @@
 
 package org.apache.poi.hslf.model;
 
-import org.apache.poi.hslf.usermodel.TestTextRun;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
@@ -36,7 +35,6 @@ import org.junit.runners.Suite;
     TestOleEmbedding.class,
     TestPPFont.class,
     TestPPGraphics2D.class,
-    TestPicture.class,
     TestSetBoldItalic.class,
     TestShapes.class,
     TestSheet.class,
@@ -44,9 +42,7 @@ import org.junit.runners.Suite;
     TestSlideMaster.class,
     TestSlides.class,
     TestTable.class,
-    TestTextRun.class,
-    TestTextRunReWrite.class,
-    TestTextShape.class
+    TestTextRunReWrite.class
 })
 public class AllHSLFModelTests {
 }
index 4fb06ddcf3d67c57b1e1a0b99b518cedc15554fa..cd5c3f797618d23cfe8c293d23a1c27e5628ff2b 100644 (file)
@@ -40,7 +40,7 @@ public final class TestPPGraphics2D {
     private HSLFSlideShow ppt;
 
     @Before
-    protected void setUp() throws Exception {
+    public void setUp() throws Exception {
                ppt = new HSLFSlideShow(_slTests.openResourceAsStream("empty.ppt"));
     }
 
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
deleted file mode 100644 (file)
index ff4e1c5..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.imageio.ImageIO;
-
-import org.apache.poi.POIDataSamples;
-import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.util.JvmBugs;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * Test Picture shape.
- *
- * @author Yegor Kozlov
- */
-public final class TestPicture {
-    private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
-
-    /**
-     * Test that the reference count of a blip is incremented every time the picture is inserted.
-     * This is important when the same image appears multiple times in a slide show.
-     *
-     */
-    @Test
-    public void multiplePictures() throws Exception {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-
-        HSLFSlide s = ppt.createSlide();
-        HSLFSlide s2 = ppt.createSlide();
-        HSLFSlide s3 = ppt.createSlide();
-
-        int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), HSLFPictureShape.JPEG);
-        HSLFPictureShape pict = new HSLFPictureShape(idx);
-        HSLFPictureShape pict2 = new HSLFPictureShape(idx);
-        HSLFPictureShape pict3 = new HSLFPictureShape(idx);
-
-        pict.setAnchor(new Rectangle(10,10,100,100));
-        s.addShape(pict);
-        EscherBSERecord bse1 = pict.getEscherBSERecord();
-        assertEquals(1, bse1.getRef());
-
-        pict2.setAnchor(new Rectangle(10,10,100,100));
-        s2.addShape(pict2);
-        EscherBSERecord bse2 = pict.getEscherBSERecord();
-        assertSame(bse1, bse2);
-        assertEquals(2, bse1.getRef());
-
-        pict3.setAnchor(new Rectangle(10,10,100,100));
-        s3.addShape(pict3);
-        EscherBSERecord bse3 = pict.getEscherBSERecord();
-        assertSame(bse2, bse3);
-        assertEquals(3, bse1.getRef());
-    }
-
-    /**
-     * Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER
-     * was not found. The correct behaviour is to return null.
-     */
-    @Test
-    public void bug46122() {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-        HSLFSlide slide = ppt.createSlide();
-
-        HSLFPictureShape pict = new HSLFPictureShape(-1); //index to non-existing picture data
-        pict.setSheet(slide);
-        HSLFPictureData data = pict.getPictureData();
-        assertNull(data);
-
-        BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
-        Graphics2D graphics = img.createGraphics();
-        pict.draw(graphics);
-    }
-
-    @Test
-    public void macImages() throws Exception {
-        HSLFSlideShowImpl hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("53446.ppt"));
-
-        HSLFPictureData[] pictures = hss.getPictures();
-        assertEquals(15, pictures.length);
-
-        int[][] expectedSizes = {
-                null,           // WMF
-                { 427, 428 },   // PNG
-                { 371, 370 },   // PNG
-                { 288, 183 },   // PNG
-                { 285, 97 },    // PNG
-                { 288, 168 },   // PNG
-                null,           // WMF
-                null,           // WMF
-                { 199, 259 },   // PNG
-                { 432, 244 },   // PNG
-                { 261, 258 },   // PNG
-                null,           // WMF
-                null,           // WMF
-                null,           // WMF
-                null            // EMF
-        };
-
-        for (int i = 0; i < pictures.length; i++) {
-            BufferedImage image = ImageIO.read(new ByteArrayInputStream(pictures[i].getData()));
-
-            if (pictures[i].getType() != HSLFPictureShape.WMF && pictures[i].getType() != HSLFPictureShape.EMF) {
-                assertNotNull(image);
-
-                int[] dimensions = expectedSizes[i];
-                assertEquals(dimensions[0], image.getWidth());
-                assertEquals(dimensions[1], image.getHeight());
-            }
-        }
-    }
-
-    @Test
-    @Ignore("Just for visual validation - antialiasing is different on various systems")
-    public void bug54541() throws Exception {
-//        InputStream xis = _slTests.openResourceAsStream("54542_cropped_bitmap.pptx");
-//        XMLSlideShow xss = new XMLSlideShow(xis);
-//        xis.close();
-//        
-//        Dimension xpg = xss.getPageSize();
-//        for(XSLFSlide slide : xss.getSlides()) {
-//            BufferedImage img = new BufferedImage(xpg.width, xpg.height, BufferedImage.TYPE_INT_RGB);
-//            Graphics2D graphics = img.createGraphics();
-//            fixFonts(graphics);
-//            slide.draw(graphics);
-//            ImageIO.write(img, "PNG", new File("testx.png"));
-//        }
-//
-//        System.out.println("########################");
-        
-        InputStream is = _slTests.openResourceAsStream("54541_cropped_bitmap.ppt");
-        HSLFSlideShow ss = new HSLFSlideShow(is);
-        is.close();
-        
-        Dimension pg = ss.getPageSize();
-        int i=1;
-        for(HSLFSlide slide : ss.getSlides()) {
-            BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_RGB);
-            Graphics2D graphics = img.createGraphics();
-            fixFonts(graphics);
-            slide.draw(graphics);
-            ImageIO.write(img, "PNG", new File("test"+(i++)+".png"));
-        }
-    }
-    
-    @SuppressWarnings("unchecked")
-    private void fixFonts(Graphics2D graphics) {
-        if (!JvmBugs.hasLineBreakMeasurerBug()) return;
-        Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(TextPainter.KEY_FONTMAP);
-        if (fontMap == null) fontMap = new HashMap<String,String>();
-        fontMap.put("Calibri", "Lucida Sans");
-        fontMap.put("Cambria", "Lucida Bright");
-        graphics.setRenderingHint(TextPainter.KEY_FONTMAP, fontMap);        
-    }
-}
index c807c201160c6e0bdddcbbb402d8c2cadf91e7a2..4fde26896573ad975ede5149448dc5e73c08f611 100644 (file)
@@ -21,7 +21,6 @@ import static org.junit.Assert.*;
 
 import java.awt.*;
 import java.awt.geom.Rectangle2D;
-import java.awt.geom.Rectangle2D.Double;
 import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
@@ -29,11 +28,8 @@ import java.util.List;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.ddf.*;
 import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.sl.usermodel.ShapeType;
 import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
-import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
-import org.apache.poi.sl.usermodel.TextParagraph.FontAlign;
-import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -138,6 +134,7 @@ public final class TestShapes {
         }
     }
 
+    @SuppressWarnings("unused")
     @Test
     public void testParagraphs() throws Exception {
         HSLFSlideShow ppt = new HSLFSlideShow();
@@ -196,7 +193,7 @@ public final class TestShapes {
         HSLFTextBox txtbox = new HSLFTextBox();
         rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
         txtbox.setText(val);
-        rt.setFontName("Arial");
+        rt.setFontFamily("Arial");
         rt.setFontSize(42);
         rt.setBold(true);
         rt.setItalic(true);
index 330c832486a0dcbc07378c1cbed05991a8223ec5..a5e9084b9e88a2a64408f4a8bc59ddf42f2ca533 100644 (file)
@@ -82,10 +82,13 @@ public final class TestSheet {
         assertTrue(sheet._getSheetNumber() != 0);
         assertTrue(sheet._getSheetRefId() != 0);
 
-        List<HSLFTextParagraph> txt = sheet.getTextParagraphs();
-        assertTrue("no text runs", txt != null && !txt.isEmpty());
-        for (HSLFTextParagraph t : txt) {
-            assertNotNull(t.getSheet());
+        List<List<HSLFTextParagraph>> txt = sheet.getTextParagraphs();
+        // assertTrue("no text runs", txt != null && !txt.isEmpty());
+        // backgrounds.ppt has no texts
+        for (List<HSLFTextParagraph> t : txt) {
+            for (HSLFTextParagraph tp : t) {
+                assertNotNull(tp.getSheet());
+            }
         }
 
         List<HSLFShape> shape = sheet.getShapes();
index e6b24ce1b9c18385d145a4410128f8122729cc53..cd46ef98ec4974e7ee8d2e8277abed7337adbece 100644 (file)
@@ -113,10 +113,9 @@ public final class TestSlideMaster {
         HSLFMasterSheet masterSheet = slide.getMasterSheet();
         assertTrue(masterSheet instanceof HSLFTitleMaster);
 
-        List<HSLFTextParagraph> txt = slide.getTextParagraphs();
-        for (int i = 0; i < txt.size(); i++) {
-            HSLFTextRun rt = txt.get(i).getTextRuns().get(0);
-            switch(txt.get(i).getRunType()){
+        for (List<HSLFTextParagraph> txt : slide.getTextParagraphs()) {
+            HSLFTextRun rt = txt.get(0).getTextRuns().get(0);
+            switch(txt.get(0).getRunType()){
                 case TextHeaderAtom.CENTER_TITLE_TYPE:
                     assertEquals("Arial", rt.getFontFamily());
                     assertEquals(32, rt.getFontSize(), 0);
@@ -141,20 +140,22 @@ public final class TestSlideMaster {
         HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
         List<HSLFSlide> slide = ppt.getSlides();
         assertEquals(3, slide.size());
-        for (HSLFTextParagraph trun : slide.get(0).getTextParagraphs()) {
-            if (trun.getRunType() == TextHeaderAtom.TITLE_TYPE){
-                HSLFTextRun rt = trun.getTextRuns().get(0);
+        for (List<HSLFTextParagraph> tparas : slide.get(0).getTextParagraphs()) {
+            HSLFTextParagraph tpara = tparas.get(0);
+            if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
+                HSLFTextRun rt = tpara.getTextRuns().get(0);
                 assertEquals(40, rt.getFontSize(), 0);
                 assertEquals(true, rt.isUnderlined());
                 assertEquals("Arial", rt.getFontFamily());
-            } else if (trun.getRunType() == TextHeaderAtom.BODY_TYPE){
-                HSLFTextRun rt = trun.getTextRuns().get(0);
-                assertEquals(0, trun.getIndentLevel());
+            } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
+                HSLFTextRun rt = tpara.getTextRuns().get(0);
+                assertEquals(0, tpara.getIndentLevel());
                 assertEquals(32, rt.getFontSize(), 0);
                 assertEquals("Arial", rt.getFontFamily());
 
-                rt = trun.getTextRuns().get(1);
-                assertEquals(1, trun.getIndentLevel());
+                tpara = tparas.get(1);
+                rt = tpara.getTextRuns().get(0);
+                assertEquals(1, tpara.getIndentLevel());
                 assertEquals(28, rt.getFontSize(), 0);
                 assertEquals("Arial", rt.getFontFamily());
 
@@ -162,16 +163,17 @@ public final class TestSlideMaster {
         }
 
         ;
-        for (HSLFTextParagraph trun : slide.get(1).getTextParagraphs()) {
-            if (trun.getRunType() == TextHeaderAtom.TITLE_TYPE){
-                HSLFTextRun rt = trun.getTextRuns().get(0);
+        for (List<HSLFTextParagraph> tparas : slide.get(1).getTextParagraphs()) {
+            HSLFTextParagraph tpara = tparas.get(0);
+            if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
+                HSLFTextRun rt = tpara.getTextRuns().get(0);
                 assertEquals(48, rt.getFontSize(), 0);
                 assertEquals(true, rt.isItalic());
                 assertEquals("Georgia", rt.getFontFamily());
-            } else if (trun.getRunType() == TextHeaderAtom.BODY_TYPE){
+            } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
                 HSLFTextRun rt;
-                rt = trun.getTextRuns().get(0);
-                assertEquals(0, trun.getIndentLevel());
+                rt = tpara.getTextRuns().get(0);
+                assertEquals(0, tpara.getIndentLevel());
                 assertEquals(32, rt.getFontSize(), 0);
                 assertEquals("Courier New", rt.getFontFamily());
             }
@@ -222,16 +224,17 @@ public final class TestSlideMaster {
         HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
         HSLFSlide slide = ppt.getSlides().get(0);
         
-        for (HSLFTextParagraph trun : slide.getTextParagraphs()) {
-            if (trun.getRunType() == TextHeaderAtom.TITLE_TYPE){
-                HSLFTextRun rt = trun.getTextRuns().get(0);
+        for (List<HSLFTextParagraph> tparas : slide.getTextParagraphs()) {
+            HSLFTextParagraph tpara = tparas.get(0);
+            if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
+                HSLFTextRun rt = tpara.getTextRuns().get(0);
                 assertEquals(40, rt.getFontSize(), 0);
                 assertEquals(true, rt.isUnderlined());
                 assertEquals("Arial", rt.getFontFamily());
-            } else if (trun.getRunType() == TextHeaderAtom.BODY_TYPE){
+            } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
                 int indents[] = { 32, 28, 24 };
-                for (HSLFTextRun rt : trun.getTextRuns()) {
-                    int indent = trun.getIndentLevel();
+                for (HSLFTextRun rt : tpara.getTextRuns()) {
+                    int indent = tpara.getIndentLevel();
                     assertEquals(indents[indent], rt.getFontSize(), 0);
                 }
             }
index 8601f95ea5543c27aff5ba883d6c673d86e48a5e..85070a3d51b50f307a7556e014849ff1f4390c07 100644 (file)
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.List;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.usermodel.*;
@@ -58,34 +59,37 @@ public final class TestTextRunReWrite {
 
     @Test
        public void testWritesOutTheSameNonRich() throws Exception {
-       // Grab the first text run on the first sheet
-       HSLFTextParagraph tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
-       HSLFTextParagraph tr2 = ss.getSlides().get(0).getTextParagraphs().get(1);
-
        // Ensure the text lengths are as we'd expect to start with
-       assertEquals(1, ss.getSlides().length);
-       assertEquals(2, ss.getSlides().get(0).getTextParagraphs().length);
-       assertEquals(30, tr1.getRawText().length());
-       assertEquals(179, tr2.getRawText().length());
-
-       assertEquals(1, tr1.getTextRuns().length);
-       assertEquals(30, tr1.getTextRuns().get(0).getLength());
-       assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
-       assertEquals(31, tr1.getTextRuns().get(0)._getRawCharacterStyle().getCharactersCovered());
-       assertEquals(31, tr1.getTextRuns().get(0)._getRawParagraphStyle().getCharactersCovered());
+       assertEquals(1, ss.getSlides().size());
+       assertEquals(2, ss.getSlides().get(0).getTextParagraphs().size());
+
+        // Grab the first text run on the first sheet
+        List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
+        List<HSLFTextParagraph> tr2 = ss.getSlides().get(0).getTextParagraphs().get(1);
+       
+       
+       assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
+       assertEquals(179, HSLFTextParagraph.getRawText(tr2).length());
+
+       assertEquals(1, tr1.size());
+       assertEquals(30, HSLFTextParagraph.getText(tr1).length());
+       assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
+       assertEquals(31, tr1.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
+       assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
 
        // Set the text to be as it is now
-       tr1.setText( tr1.getRawText() );
+       HSLFTextParagraph.setText(tr1, HSLFTextParagraph.getRawText(tr1));
+       tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
 
        // Check the text lengths are still right
-       assertEquals(30, tr1.getRawText().length());
-       assertEquals(179, tr2.getRawText().length());
+       assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
+       assertEquals(179, HSLFTextParagraph.getRawText(tr2).length());
 
-       assertEquals(1, tr1.getTextRuns().length);
-       assertEquals(30, tr1.getTextRuns().get(0).getLength());
-       assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
-       assertEquals(31, tr1.getTextRuns().get(0)._getRawCharacterStyle().getCharactersCovered());
-       assertEquals(31, tr1.getTextRuns().get(0)._getRawParagraphStyle().getCharactersCovered());
+        assertEquals(1, tr1.size());
+        assertEquals(30, HSLFTextParagraph.getText(tr1).length());
+        assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
+        assertEquals(31, tr1.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
+        assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
 
 
                // Write the slideshow out to a byte array
@@ -117,33 +121,32 @@ public final class TestTextRunReWrite {
     @Test
     public void testWritesOutTheSameRich() throws Exception {
        // Grab the first text run on the first sheet
-       HSLFTextParagraph tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
+       List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
 
        // Get the first rich text run
-       HSLFTextRun rtr1 = tr1.getTextRuns().get(0);
+       HSLFTextRun rtr1 = tr1.get(0).getTextRuns().get(0);
 
 
        // Check that the text sizes are as expected
-       assertEquals(1, tr1.getTextRuns().length);
-       assertEquals(30, tr1.getRawText().length());
-       assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
+       assertEquals(1, tr1.get(0).getTextRuns().size());
+        assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
        assertEquals(30, rtr1.getLength());
        assertEquals(30, rtr1.getRawText().length());
-       assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
-       assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
+       assertEquals(31, rtr1.getCharacterStyle().getCharactersCovered());
+       assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
 
        // Set the text to be as it is now
        rtr1.setText( rtr1.getRawText() );
-       rtr1 = tr1.getTextRuns().get(0);
+       rtr1 = tr1.get(0).getTextRuns().get(0);
 
        // Check that the text sizes are still as expected
-       assertEquals(1, tr1.getTextRuns().length);
-       assertEquals(30, tr1.getRawText().length());
-       assertEquals(30, tr1.getTextRuns().get(0).getRawText().length());
+       assertEquals(1, tr1.get(0).getTextRuns().size());
+       assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
+       assertEquals(30, tr1.get(0).getTextRuns().get(0).getRawText().length());
        assertEquals(30, rtr1.getLength());
        assertEquals(30, rtr1.getRawText().length());
-       assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
-       assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
+       assertEquals(31, rtr1.getCharacterStyle().getCharactersCovered());
+       assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
 
 
                // Write the slideshow out to a byte array
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java
deleted file mode 100644 (file)
index f57d154..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.sl.usermodel.ShapeType;
-import org.junit.Test;
-
-/**
- * Verify behavior of <code>TextShape</code> and its sub-classes
- *
- * @author Yegor Kozlov
- */
-public final class TestTextShape {
-    private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
-
-    @Test
-    public void createAutoShape(){
-        HSLFTextShape shape = new HSLFAutoShape(ShapeType.TRAPEZOID);
-        assertNull(shape.getTextParagraphs());
-        assertNull(shape.getText());
-        assertNull(shape.getEscherTextboxWrapper());
-
-        HSLFTextParagraph run = shape.createTextRun();
-        assertNotNull(run);
-        assertNotNull(shape.getTextParagraphs());
-        assertNotNull(shape.getEscherTextboxWrapper());
-        assertEquals("", shape.getText());
-        assertSame(run, shape.createTextRun());
-        assertEquals(-1, run.getIndex());
-    }
-
-    @Test
-    public void createTextBox(){
-        HSLFTextShape shape = new HSLFTextBox();
-        HSLFTextParagraph run = shape.getTextParagraphs();
-        assertNotNull(run);
-        assertNotNull(shape.getText());
-        assertNotNull(shape.getEscherTextboxWrapper());
-
-        assertSame(run, shape.createTextRun());
-        assertNotNull(shape.getTextParagraphs());
-        assertNotNull(shape.getEscherTextboxWrapper());
-        assertEquals("", shape.getText());
-
-    }
-
-    /**
-     * Verify we can get text from TextShape in the following cases:
-     *  - placeholders
-     *  - normal TextBox object
-     *  - text in auto-shapes
-     */
-    @Test
-    public void read() throws IOException {
-        HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text_shapes.ppt"));
-
-        List<String> lst1 = new ArrayList<String>();
-        HSLFSlide slide = ppt.getSlides()[0];
-        HSLFShape[] shape = slide.getShapes();
-        for (int i = 0; i < shape.length; i++) {
-            assertTrue("Expected TextShape but found " + shape[i].getClass().getName(), shape[i] instanceof HSLFTextShape);
-            HSLFTextShape tx = (HSLFTextShape)shape[i];
-            HSLFTextParagraph run = tx.getTextParagraphs();
-            assertNotNull(run);
-            int runType = run.getRunType();
-
-            ShapeType type = shape[i].getShapeType();
-            switch (type){
-                case TEXT_BOX:
-                    assertEquals("Text in a TextBox", run.getRawText());
-                    break;
-                case RECT:
-                    if(runType == TextHeaderAtom.OTHER_TYPE)
-                        assertEquals("Rectangle", run.getRawText());
-                    else if(runType == TextHeaderAtom.TITLE_TYPE)
-                        assertEquals("Title Placeholder", run.getRawText());
-                    break;
-                case OCTAGON:
-                    assertEquals("Octagon", run.getRawText());
-                    break;
-                case ELLIPSE:
-                    assertEquals("Ellipse", run.getRawText());
-                    break;
-                case ROUND_RECT:
-                    assertEquals("RoundRectangle", run.getRawText());
-                    break;
-                default:
-                    fail("Unexpected shape: " + shape[i].getShapeName());
-
-            }
-            lst1.add(run.getRawText());
-        }
-
-        List<String> lst2 = new ArrayList<String>();
-        HSLFTextParagraph[] run = slide.getTextParagraphs();
-        for (int i = 0; i < run.length; i++) {
-            lst2.add(run[i].getRawText());
-        }
-
-        assertTrue(lst1.containsAll(lst2));
-    }
-
-    @Test
-    public void readWrite() throws IOException {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-        HSLFSlide slide =  ppt.createSlide();
-
-        HSLFTextShape shape1 = new HSLFTextBox();
-        HSLFTextParagraph run1 = shape1.createTextRun();
-        run1.setText("Hello, World!");
-        slide.addShape(shape1);
-
-        shape1.moveTo(100, 100);
-
-        HSLFTextShape shape2 = new HSLFAutoShape(ShapeType.RIGHT_ARROW);
-        HSLFTextParagraph run2 = shape2.createTextRun();
-        run2.setText("Testing TextShape");
-        slide.addShape(shape2);
-        shape2.moveTo(300, 300);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        ppt.write(out);
-        out.close();
-
-        ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
-        slide = ppt.getSlides()[0];
-        HSLFShape[] shape = slide.getShapes();
-
-        assertTrue(shape[0] instanceof HSLFTextShape);
-        shape1 = (HSLFTextShape)shape[0];
-        assertEquals(ShapeType.TEXT_BOX, shape1.getShapeType());
-        assertEquals("Hello, World!", shape1.getTextParagraphs().getRawText());
-
-        assertTrue(shape[1] instanceof HSLFTextShape);
-        shape1 = (HSLFTextShape)shape[1];
-        assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType());
-        assertEquals("Testing TextShape", shape1.getTextParagraphs().getRawText());
-    }
-
-    @Test
-    public void margins() throws IOException {
-        HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text-margins.ppt"));
-
-        HSLFSlide slide = ppt.getSlides()[0];
-
-        Map<String,HSLFTextShape> map = new HashMap<String,HSLFTextShape>();
-        HSLFShape[] shape = slide.getShapes();
-        for (int i = 0; i < shape.length; i++) {
-            if(shape[i] instanceof HSLFTextShape){
-                HSLFTextShape tx = (HSLFTextShape)shape[i];
-                map.put(tx.getText(), tx);
-            }
-        }
-
-        HSLFTextShape tx;
-
-        tx = map.get("TEST1");
-        assertEquals(0.1, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.1, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.39, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.05, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-
-        tx = map.get("TEST2");
-        assertEquals(0.1, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.1, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.05, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.39, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-
-        tx = map.get("TEST3");
-        assertEquals(0.39, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.1, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.05, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.05, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-
-        tx = map.get("TEST4");
-        assertEquals(0.1, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.39, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.05, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-        assertEquals(0.05, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
-    }
-
-    @Test
-    public void bug52599() throws IOException {
-        HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52599.ppt"));
-
-        HSLFSlide slide = ppt.getSlides()[0];
-        HSLFShape[] sh = slide.getShapes();
-        assertEquals(3, sh.length);
-
-        HSLFTextShape sh0 = (HSLFTextShape)sh[0];
-        assertEquals(null, sh0.getText());
-        assertEquals(null, sh0.getTextParagraphs());
-
-        HSLFTextShape sh1 = (HSLFTextShape)sh[1];
-        assertEquals(null, sh1.getText());
-        assertEquals(null, sh1.getTextParagraphs());
-
-        HSLFTextShape sh2 = (HSLFTextShape)sh[2];
-        assertEquals("this box should be shown just once", sh2.getText());
-        assertEquals(-1, sh2.getTextParagraphs().getIndex());
-    }
-}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java
deleted file mode 100644 (file)
index f11d299..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextCharsAtom;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.hssf.usermodel.DummyGraphics2d;
-import org.junit.Test;
-
-
-public class TextPainterTest {
-    @Test
-    public void testTextPainter() {
-        HSLFTextShape shape = new Polygon();
-        TextPainter painter = new TextPainter(shape);
-        painter.getAttributedString(new HSLFTextParagraph(null, new TextCharsAtom(), null));
-        painter.paint(new DummyGraphics2d());
-        painter.getTextElements((float)1.0, null);
-    }
-
-    @Test
-    public void testTextPainterWithText() {
-        HSLFTextShape shape = new Polygon();
-        TextPainter painter = new TextPainter(shape);
-        TextCharsAtom tca = new TextCharsAtom();
-        tca.setText("some text to read");
-        HSLFTextParagraph txrun = new HSLFTextParagraph(new TextHeaderAtom(), tca, new StyleTextPropAtom(10));
-        HSLFSlide sheet = new HSLFSlide(1, 1, 1);
-        sheet.setSlideShow(new HSLFSlideShow());
-        txrun.setSheet(sheet);
-
-        painter.getAttributedString(txrun, new DummyGraphics2d());
-        painter.paint(new DummyGraphics2d());
-        painter.getTextElements((float)1.0, null);
-    }
-}
index 6a407365a07eb859e452a3edc6b68bbfd043e4d8..593f116cab45cd80847c86056760952dc75906bb 100644 (file)
@@ -42,14 +42,14 @@ public final class TestTextSpecInfoAtom extends TestCase {
 
     public void testRead() {
         TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
-        TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
+        TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
         assertEquals(5, run.length);
 
-        assertEquals(10, run[0].length());
-        assertEquals(1, run[1].length());
-        assertEquals(70, run[2].length());
-        assertEquals(9, run[3].length());
-        assertEquals(32, run[4].length());
+        assertEquals(10, run[0].getLength());
+        assertEquals(1, run[1].getLength());
+        assertEquals(70, run[2].getLength());
+        assertEquals(9, run[3].getLength());
+        assertEquals(32, run[4].getLength());
 
     }
 
@@ -66,10 +66,10 @@ public final class TestTextSpecInfoAtom extends TestCase {
         TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
         spec.reset(32);  //length of the parent text
 
-        TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
+        TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
         assertEquals(1, run.length);
 
-        assertEquals(32, run[0].length());
+        assertEquals(32, run[0].getLength());
 
         //serialize and read again
         ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -77,9 +77,9 @@ public final class TestTextSpecInfoAtom extends TestCase {
 
         byte[] result = out.toByteArray();
         TextSpecInfoAtom spec2 = new TextSpecInfoAtom(result, 0, result.length);
-        TextSpecInfoAtom.TextSpecInfoRun[] run2 = spec2.getTextSpecInfoRuns();
+        TextSpecInfoRun[] run2 = spec2.getTextSpecInfoRuns();
         assertEquals(1, run2.length);
 
-        assertEquals(32, run2[0].length());
+        assertEquals(32, run2[0].getLength());
     }
 }
index 6a66b234db040dbf2e3855f962b5ab859f470d18..cd4b54d19cdf1a26a56ca7d567379b879f10de64 100644 (file)
@@ -84,13 +84,13 @@ public final class TestTxMasterStyleAtom extends TestCase {
         TextProp prop;
 
         //paragraph styles
-        props = txmaster.getParagraphStyles()[0];
+        props = txmaster.getParagraphStyles().get(0);
 
         prop = props.findByName("alignment");
         assertEquals(1, prop.getValue()); //title has center alignment
 
         //character styles
-        props = txmaster.getCharacterStyles()[0];
+        props = txmaster.getCharacterStyles().get(0);
 
         prop = props.findByName("font.color");
         assertEquals(0x3000000, prop.getValue());
@@ -110,27 +110,27 @@ public final class TestTxMasterStyleAtom extends TestCase {
         TextPropCollection props;
         TextProp prop;
 
-        TextPropCollection[] prstyles = txmaster.getParagraphStyles();
-        TextPropCollection[] chstyles = txmaster.getCharacterStyles();
+        List<TextPropCollection> prstyles = txmaster.getParagraphStyles();
+        List<TextPropCollection> chstyles = txmaster.getCharacterStyles();
         assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
-                "must contain styles for 5 indentation levels", 5, prstyles.length);
+                "must contain styles for 5 indentation levels", 5, prstyles.size());
         assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
-                "must contain styles for 5 indentation levels", 5, chstyles.length);
+                "must contain styles for 5 indentation levels", 5, chstyles.size());
 
         //paragraph styles
-        props = prstyles[0];
+        props = prstyles.get(0);
 
         prop = props.findByName("alignment");
         assertEquals(0, prop.getValue());
 
 
-        for (int i = 0; i < prstyles.length; i++) {
-            assertNotNull("text.offset is null for indentation level " + i, prstyles[i].findByName("text.offset"));
-            assertNotNull("bullet.offset is null for indentation level " + i, prstyles[i].findByName("bullet.offset"));
+        for (int i = 0; i < prstyles.size(); i++) {
+            assertNotNull("text.offset is null for indentation level " + i, prstyles.get(i).findByName("text.offset"));
+            assertNotNull("bullet.offset is null for indentation level " + i, prstyles.get(i).findByName("bullet.offset"));
         }
 
         //character styles
-        props = chstyles[0];
+        props = chstyles.get(0);
 
         prop = props.findByName("font.color");
         assertEquals(0x1000000, prop.getValue());
@@ -150,13 +150,13 @@ public final class TestTxMasterStyleAtom extends TestCase {
         TextProp prop;
 
         //paragraph styles
-        props = txmaster.getParagraphStyles()[0];
+        props = txmaster.getParagraphStyles().get(0);
 
         prop = props.findByName("alignment");
         assertEquals(0, prop.getValue());
 
         //character styles
-        props = txmaster.getCharacterStyles()[0];
+        props = txmaster.getCharacterStyles().get(0);
 
         prop = props.findByName("font.color");
         assertEquals(0x1000000, prop.getValue());
@@ -176,13 +176,13 @@ public final class TestTxMasterStyleAtom extends TestCase {
         TextProp prop;
 
         //paragraph styles
-        props = txmaster.getParagraphStyles()[0];
+        props = txmaster.getParagraphStyles().get(0);
 
         prop = props.findByName("alignment");
         assertEquals(0, prop.getValue()); //title has center alignment
 
         //character styles
-        props = txmaster.getCharacterStyles()[0];
+        props = txmaster.getCharacterStyles().get(0);
 
         prop = props.findByName("font.color");
         assertEquals(0x1000000, prop.getValue());
index bc6b6cd972d34f9ff9ceedd21dbb5bcbe718d819..0354d9b46cc75131a90873d5d6b7e216e4b166d5 100644 (file)
@@ -37,7 +37,10 @@ import org.junit.runners.Suite;
     TestSheetText.class,
     TestSlideOrdering.class,
     TestSoundData.class,
-    TestFontRendering.class
+    TestFontRendering.class,
+    TestPicture.class,
+    TestTextRun.class,
+    TestTextShape.class
 })
 public class AllHSLFUserModelTests {
 }
index 53079a3ac2fd635aa65d23de30660ff9b4e702e2..9695a9d053912ede94602ba1176b94fff76e1877 100644 (file)
 
 package org.apache.poi.hslf.usermodel;
 
-import java.util.List;
+import static org.junit.Assert.*;
 
-import junit.framework.TestCase;
+import java.util.List;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.model.textproperties.TextPFException9;
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.EscherTextboxWrapper;
-import org.apache.poi.hslf.record.StyleTextProp9Atom;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
-import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.record.*;
+import org.junit.Test;
 
 
 /**
@@ -37,22 +35,21 @@ import org.apache.poi.POIDataSamples;
  * 
  * @author Alex Nikiforov [mailto:anikif@gmail.com]
  */
-public final class TestNumberedList extends TestCase {
+public final class TestNumberedList {
     private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
 
-       protected void setUp() throws Exception {
-       }
-
-       public void testNumberedList() throws Exception {
+    @Test
+    public void testNumberedList() throws Exception {
                HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers.ppt"));
                assertTrue("No Exceptions while reading file", true);
 
-               final HSLFSlide[] slides = ppt.getSlides();
-               assertEquals(2, slides.length);
-               checkSlide0(slides[0]);
-               checkSlide1(slides[1]);
+               final List<HSLFSlide> slides = ppt.getSlides();
+               assertEquals(2, slides.size());
+               checkSlide0(slides.get(0));
+               checkSlide1(slides.get(1));
        }
-       private void checkSlide0(final HSLFSlide s) {
+
+    private void checkSlide0(final HSLFSlide s) {
                final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
                assertNotNull(numberedListArray);
                assertEquals(1, numberedListArray.length);//Just one text box here
@@ -68,27 +65,33 @@ public final class TestNumberedList extends TestCase {
                assertNull(autoNumbers[1].getAutoNumberScheme());
                assertTrue(TextAutoNumberSchemeEnum.ANM_AlphaLcParenRight == autoNumbers[2].getAutoNumberScheme());
                        
-               HSLFTextParagraph[] textRuns = s.getTextParagraphs();
-               assertEquals(2, textRuns.length);
+               List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
+               assertEquals(2, textParass.size());
 
-               HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
-               assertEquals("titTe", textRun.getRawText());
-               assertEquals(1, textRuns[0].getTextRuns().length);
-               assertFalse(textRun.isBullet());
+               List<HSLFTextParagraph> textParas = textParass.get(0);
+               assertEquals("titTe", HSLFTextParagraph.getRawText(textParas));
+               assertEquals(1, textParas.size());
+               assertFalse(textParas.get(0).isBullet());
 
-               assertEquals("This is a text placeholder that \rfollows the design pattern\rJust a test\rWithout any paragraph\rSecond paragraph first line c) ;\rSecond paragraph second line d) . \r", textRuns[1].getRawText());
+               String expected =
+               "This is a text placeholder that \r" +
+               "follows the design pattern\r" +
+               "Just a test\rWithout any paragraph\r" +
+               "Second paragraph first line c) ;\r" +
+               "Second paragraph second line d) . \r";
+               assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
                
                final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
-               assertEquals(textRuns.length, styleAtoms.length);
+               assertEquals(textParass.size(), styleAtoms.length);
                final EscherTextboxWrapper wrapper =  styleAtoms[1];
                final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
                final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
-               final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
-               assertEquals(60, props[0].getCharactersCovered());
-               assertEquals(34, props[1].getCharactersCovered());
-               assertEquals(68, props[2].getCharactersCovered());
+               assertEquals(60, textProps.get(0).getCharactersCovered());
+               assertEquals(34, textProps.get(1).getCharactersCovered());
+               assertEquals(68, textProps.get(2).getCharactersCovered());
        }
-       private void checkSlide1(final HSLFSlide s) {
+
+    private void checkSlide1(final HSLFSlide s) {
                final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
                assertNotNull(numberedListArray);
                assertEquals(1, numberedListArray.length);//Just one text box here
@@ -104,25 +107,30 @@ public final class TestNumberedList extends TestCase {
                assertNull(autoNumbers[1].getAutoNumberScheme());
                assertTrue(TextAutoNumberSchemeEnum.ANM_AlphaUcPeriod == autoNumbers[2].getAutoNumberScheme());
 
-               final HSLFTextParagraph[] textRuns = s.getTextParagraphs();
-               assertEquals(2, textRuns.length);
+               final List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
+               assertEquals(2, textParass.size());
 
-               HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
-               assertEquals("Second Slide Title", textRun.getRawText());
-               assertEquals(1, textRuns[0].getTextRuns().length);
-               assertFalse(textRun.isBullet());
+               List<HSLFTextParagraph> textParas = textParass.get(0);
+               assertEquals("Second Slide Title", HSLFTextParagraph.getRawText(textParas));
+               assertEquals(1, textParas.size());
+               assertFalse(textParas.get(0).isBullet());
 
-               assertEquals("This is a text placeholder that \rfollows the design pattern\rJust a test\rWithout any paragraph\rSecond paragraph first line c) ;\rSecond paragraph second line d) . \r", textRuns[1].getRawText());
+               String expected =
+               "This is a text placeholder that \r" +
+               "follows the design pattern\r" +
+               "Just a test\rWithout any paragraph\r" +
+               "Second paragraph first line c) ;\r" +
+               "Second paragraph second line d) . \r";                 
+               assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
                
                final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
-               assertEquals(textRuns.length, styleAtoms.length);
+               assertEquals(textParass.size(), styleAtoms.length);
                final EscherTextboxWrapper wrapper =  styleAtoms[1];
                final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
                final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
                
-               final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
-               assertEquals(33, props[0].getCharactersCovered());
-               assertEquals(61, props[1].getCharactersCovered());
-               assertEquals(68, props[2].getCharactersCovered());
+               assertEquals(33, textProps.get(0).getCharactersCovered());
+               assertEquals(61, textProps.get(1).getCharactersCovered());
+               assertEquals(68, textProps.get(2).getCharactersCovered());
        }
 }
index c0457f4d8c8fe0ba2d67dddd53bf1389787453cc..9a096c18ed52c925df67da225d364e1001ad7938 100644 (file)
 
 package org.apache.poi.hslf.usermodel;
 
-import java.util.List;
+import static org.junit.Assert.*;
 
-import junit.framework.TestCase;
+import java.util.List;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.model.textproperties.TextPFException9;
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.EscherTextboxWrapper;
-import org.apache.poi.hslf.record.StyleTextProp9Atom;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
-import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.record.*;
+import org.junit.Test;
 
 
 /**
@@ -40,20 +38,18 @@ import org.apache.poi.POIDataSamples;
  * 
  * @author Alex Nikiforov [mailto:anikif@gmail.com]
  */
-public final class TestNumberedList2 extends TestCase {
+public final class TestNumberedList2 {
     private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
 
-       protected void setUp() throws Exception {
-       }
-
+    @Test
        public void testNumberedList() throws Exception {
                HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers2.ppt"));
                assertTrue("No Exceptions while reading file", true);
 
-               final HSLFSlide[] slides = ppt.getSlides();
-               assertEquals(2, slides.length);
-               checkSlide0(slides[0]);
-               checkSlide1(slides[1]);
+               final List<HSLFSlide> slides = ppt.getSlides();
+               assertEquals(2, slides.size());
+               checkSlide0(slides.get(0));
+               checkSlide1(slides.get(1));
        }
        private void checkSlide0(final HSLFSlide s) {
                final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
@@ -73,18 +69,22 @@ public final class TestNumberedList2 extends TestCase {
                assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox1[0].getAutoNumberScheme());
 
                
-               HSLFTextParagraph[] textRuns = s.getTextParagraphs();
-               assertEquals(2, textRuns.length);
+               List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
+               assertEquals(2, textParass.size());
 
-               HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
-               assertEquals("List Item One\rList Item Two\rList Item Three", textRun.getRawText());
-               assertEquals(1, textRuns[0].getTextRuns().length);
-               assertTrue(textRun.isBullet());
+               List<HSLFTextParagraph> textParas = textParass.get(0);
+               assertEquals("List Item One\rList Item Two\rList Item Three", HSLFTextParagraph.getRawText(textParas));
+               assertEquals(3, textParas.size());
+               assertTrue(textParas.get(0).isBullet());
 
-               assertEquals("A numbered list may start at any number \rThis would be used as a continuation list on another page\rThis list should start with #6", textRuns[1].getRawText());
+               String expected =
+               "A numbered list may start at any number \r" +
+               "This would be used as a continuation list on another page\r" +
+            "This list should start with #6";
+               assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
                
                final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
-               assertEquals(textRuns.length, styleAtoms.length);
+               assertEquals(textParass.size(), styleAtoms.length);
                checkSingleRunWrapper(44, styleAtoms[0]);
                checkSingleRunWrapper(130, styleAtoms[1]);
        }
@@ -99,19 +99,21 @@ public final class TestNumberedList2 extends TestCase {
                assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox[0].getAutoNumberStartNumber());//Default value = 1 will be used 
                assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox[0].getAutoNumberScheme());
                        
-               HSLFTextParagraph[] textRuns = s.getTextParagraphs();
-               assertEquals(3, textRuns.length);
+               List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
+               assertEquals(3, textParass.size());
 
-               HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
-               assertEquals("Bulleted list\rMore bullets", textRun.getRawText());
-               assertEquals(1, textRuns[0].getTextRuns().length);
-               assertTrue(textRun.isBullet());
+               List<HSLFTextParagraph> textParas = textParass.get(0);
+               assertEquals("Bulleted list\rMore bullets", HSLFTextParagraph.getRawText(textParas));
+               assertEquals(2, textParas.size());
+               assertTrue(textParas.get(0).isBullet());
 
-               assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", textRuns[1].getRawText());
-               assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", textRuns[2].getRawText());
+               String expected = "Numbered list between two bulleted lists\rSecond numbered list item";
+               assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(1)));
+               expected = "Second bulleted list \u2013 should appear after numbered list\rMore bullets";
+               assertEquals(expected, HSLFTextParagraph.getRawText(textParass.get(2)));
                
                final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
-               assertEquals(textRuns.length, styleAtoms.length);
+               assertEquals(textParass.size(), styleAtoms.length);
                checkSingleRunWrapper(27, styleAtoms[0]);
                checkSingleRunWrapper(67, styleAtoms[1]);
                checkSingleRunWrapper(70, styleAtoms[2]);
@@ -120,7 +122,6 @@ public final class TestNumberedList2 extends TestCase {
                final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
                final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
                assertEquals(1, textProps.size());
-               final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
-               assertEquals(exceptedLength, props[0].getCharactersCovered());
+               assertEquals(exceptedLength, textProps.get(0).getCharactersCovered());
        }
 }
index eabbc4d58fd54278a777636a626db77fbbc31d85..ab358f65a0af31a3a38cee646dfae233267b1b91 100644 (file)
 
 package org.apache.poi.hslf.usermodel;
 
-import java.util.List;
+import static org.junit.Assert.*;
 
-import junit.framework.TestCase;
+import java.util.List;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.model.textproperties.TextPFException9;
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.EscherTextboxWrapper;
-import org.apache.poi.hslf.record.StyleTextProp9Atom;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
-import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.record.*;
+import org.junit.Test;
 
 
 /**
@@ -40,19 +38,17 @@ import org.apache.poi.POIDataSamples;
  * 
  * @author Alex Nikiforov [mailto:anikif@gmail.com]
  */
-public final class TestNumberedList3 extends TestCase {
+public final class TestNumberedList3 {
     private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
 
-       protected void setUp() throws Exception {
-       }
-
-       public void testNumberedList() throws Exception {
+    @Test
+    public void testNumberedList() throws Exception {
                HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers3.ppt"));
                assertTrue("No Exceptions while reading file", true);
 
-               final HSLFSlide[] slides = ppt.getSlides();
-               assertEquals(1, slides.length);
-               final HSLFSlide slide = slides[0];
+               final List<HSLFSlide> slides = ppt.getSlides();
+               assertEquals(1, slides.size());
+               final HSLFSlide slide = slides.get(0);
                checkSlide(slide);
        }
        private void checkSlide(final HSLFSlide s) {
@@ -66,35 +62,32 @@ public final class TestNumberedList3 extends TestCase {
                assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());//Default value = 1 will be used 
                assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
                
-               final HSLFTextParagraph[] textRuns = s.getTextParagraphs();
-               assertEquals(3, textRuns.length);
-               assertEquals("Bulleted list\rMore bullets\rNo bullets here", textRuns[0].getRawText());
-               assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", textRuns[1].getRawText());
-               assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", textRuns[2].getRawText());
-               assertEquals(2, textRuns[0].getTextRuns().length);
-               assertEquals(1, textRuns[1].getTextRuns().length);
-               assertEquals(1, textRuns[2].getTextRuns().length);
-               assertNull(textRuns[0].getStyleTextProp9Atom());
-               assertNotNull(textRuns[1].getStyleTextProp9Atom());
-               assertNull(textRuns[2].getStyleTextProp9Atom());
-               final TextPFException9[] autoNumbers = textRuns[1].getStyleTextProp9Atom().getAutoNumberTypes();
+               final List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
+               assertEquals(3, textParass.size());
+               assertEquals("Bulleted list\rMore bullets\rNo bullets here", HSLFTextParagraph.getRawText(textParass.get(0)));
+               assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", HSLFTextParagraph.getRawText(textParass.get(1)));
+               assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", HSLFTextParagraph.getRawText(textParass.get(2)));
+               assertEquals(3, textParass.get(0).size());
+               assertEquals(2, textParass.get(1).size());
+               assertEquals(2, textParass.get(2).size());
+               assertNull(textParass.get(0).get(0).getStyleTextProp9Atom());
+               assertNotNull(textParass.get(1).get(0).getStyleTextProp9Atom());
+               assertNull(textParass.get(2).get(0).getStyleTextProp9Atom());
+               final TextPFException9[] autoNumbers = textParass.get(1).get(0).getStyleTextProp9Atom().getAutoNumberTypes();
                assertEquals(1, autoNumbers.length);
                assertEquals(Short.valueOf((short)1), autoNumbers[0].getfBulletHasAutoNumber());
                assertEquals(Short.valueOf((short)1), autoNumbers[0].getAutoNumberStartNumber());//Default value = 1 will be used 
                assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
                
-               final List<TextPropCollection> textProps = textRuns[1].getStyleTextPropAtom().getCharacterStyles();
+               final List<TextPropCollection> textProps = textParass.get(1).get(0).getStyleTextPropAtom().getCharacterStyles();
                assertEquals(1, textProps.size());
                final TextPropCollection textProp = textProps.get(0);
                assertEquals(67, textProp.getCharactersCovered());
                
-               
-               HSLFTextRun textRun = textRuns[0].getTextRuns()[0];
-               assertTrue(textRun.isBullet());
-
+               assertTrue(textParass.get(0).get(0).isBullet());
                
                final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
-               assertEquals(textRuns.length, styleAtoms.length);
+               assertEquals(textParass.size(), styleAtoms.length);
                checkSingleRunWrapper(43, styleAtoms[0]);
                checkSingleRunWrapper(67, styleAtoms[1]);
        }
@@ -102,7 +95,6 @@ public final class TestNumberedList3 extends TestCase {
                final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
                final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
                assertEquals(1, textProps.size());
-               final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
-               assertEquals(exceptedLength, props[0].getCharactersCovered());
+               assertEquals(exceptedLength, textProps.get(0).getCharactersCovered());
        }
 }
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java
new file mode 100644 (file)
index 0000000..2410d6c
--- /dev/null
@@ -0,0 +1,187 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.usermodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.ddf.EscherBSERecord;
+import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.util.JvmBugs;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test Picture shape.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestPicture {
+    private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+
+    /**
+     * Test that the reference count of a blip is incremented every time the picture is inserted.
+     * This is important when the same image appears multiple times in a slide show.
+     *
+     */
+    @Test
+    public void multiplePictures() throws Exception {
+        HSLFSlideShow ppt = new HSLFSlideShow();
+
+        HSLFSlide s = ppt.createSlide();
+        HSLFSlide s2 = ppt.createSlide();
+        HSLFSlide s3 = ppt.createSlide();
+
+        int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), HSLFPictureShape.JPEG);
+        HSLFPictureShape pict = new HSLFPictureShape(idx);
+        HSLFPictureShape pict2 = new HSLFPictureShape(idx);
+        HSLFPictureShape pict3 = new HSLFPictureShape(idx);
+
+        pict.setAnchor(new Rectangle(10,10,100,100));
+        s.addShape(pict);
+        EscherBSERecord bse1 = pict.getEscherBSERecord();
+        assertEquals(1, bse1.getRef());
+
+        pict2.setAnchor(new Rectangle(10,10,100,100));
+        s2.addShape(pict2);
+        EscherBSERecord bse2 = pict.getEscherBSERecord();
+        assertSame(bse1, bse2);
+        assertEquals(2, bse1.getRef());
+
+        pict3.setAnchor(new Rectangle(10,10,100,100));
+        s3.addShape(pict3);
+        EscherBSERecord bse3 = pict.getEscherBSERecord();
+        assertSame(bse2, bse3);
+        assertEquals(3, bse1.getRef());
+    }
+
+    /**
+     * Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER
+     * was not found. The correct behaviour is to return null.
+     */
+    @Test
+    public void bug46122() {
+        HSLFSlideShow ppt = new HSLFSlideShow();
+        HSLFSlide slide = ppt.createSlide();
+
+        HSLFPictureShape pict = new HSLFPictureShape(-1); //index to non-existing picture data
+        pict.setSheet(slide);
+        HSLFPictureData data = pict.getPictureData();
+        assertNull(data);
+
+        BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
+        Graphics2D graphics = img.createGraphics();
+        pict.draw(graphics);
+    }
+
+    @Test
+    public void macImages() throws Exception {
+        HSLFSlideShowImpl hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("53446.ppt"));
+
+        HSLFPictureData[] pictures = hss.getPictures();
+        assertEquals(15, pictures.length);
+
+        int[][] expectedSizes = {
+                null,           // WMF
+                { 427, 428 },   // PNG
+                { 371, 370 },   // PNG
+                { 288, 183 },   // PNG
+                { 285, 97 },    // PNG
+                { 288, 168 },   // PNG
+                null,           // WMF
+                null,           // WMF
+                { 199, 259 },   // PNG
+                { 432, 244 },   // PNG
+                { 261, 258 },   // PNG
+                null,           // WMF
+                null,           // WMF
+                null,           // WMF
+                null            // EMF
+        };
+
+        for (int i = 0; i < pictures.length; i++) {
+            BufferedImage image = ImageIO.read(new ByteArrayInputStream(pictures[i].getData()));
+
+            if (pictures[i].getType() != HSLFPictureShape.WMF && pictures[i].getType() != HSLFPictureShape.EMF) {
+                assertNotNull(image);
+
+                int[] dimensions = expectedSizes[i];
+                assertEquals(dimensions[0], image.getWidth());
+                assertEquals(dimensions[1], image.getHeight());
+            }
+        }
+    }
+
+    @Test
+    @Ignore("Just for visual validation - antialiasing is different on various systems")
+    public void bug54541() throws Exception {
+//        InputStream xis = _slTests.openResourceAsStream("54542_cropped_bitmap.pptx");
+//        XMLSlideShow xss = new XMLSlideShow(xis);
+//        xis.close();
+//        
+//        Dimension xpg = xss.getPageSize();
+//        for(XSLFSlide slide : xss.getSlides()) {
+//            BufferedImage img = new BufferedImage(xpg.width, xpg.height, BufferedImage.TYPE_INT_RGB);
+//            Graphics2D graphics = img.createGraphics();
+//            fixFonts(graphics);
+//            slide.draw(graphics);
+//            ImageIO.write(img, "PNG", new File("testx.png"));
+//        }
+//
+//        System.out.println("########################");
+        
+        InputStream is = _slTests.openResourceAsStream("54541_cropped_bitmap.ppt");
+        HSLFSlideShow ss = new HSLFSlideShow(is);
+        is.close();
+        
+        Dimension pg = ss.getPageSize();
+        int i=1;
+        for(HSLFSlide slide : ss.getSlides()) {
+            BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_RGB);
+            Graphics2D graphics = img.createGraphics();
+            fixFonts(graphics);
+            slide.draw(graphics);
+            ImageIO.write(img, "PNG", new File("test"+(i++)+".png"));
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void fixFonts(Graphics2D graphics) {
+        if (!JvmBugs.hasLineBreakMeasurerBug()) return;
+        Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(TextPainter.KEY_FONTMAP);
+        if (fontMap == null) fontMap = new HashMap<String,String>();
+        fontMap.put("Calibri", "Lucida Sans");
+        fontMap.put("Cambria", "Lucida Bright");
+        graphics.setRenderingHint(TextPainter.KEY_FONTMAP, fontMap);        
+    }
+}
index 270e01caa3a2dca94ff6316018402caff6d623ae..c8a3d3761d76dff84fc4e1516b88e838297103ff 100644 (file)
 package org.apache.poi.hslf.usermodel;
 
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 
-import junit.framework.TestCase;
-
-import org.apache.poi.hslf.*;
-import org.apache.poi.hslf.model.*;
 import org.apache.poi.POIDataSamples;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Tests that SlideShow can re-order slides properly
  *
  * @author Nick Burch (nick at torchbox dot com)
  */
-public final class TestReOrderingSlides extends TestCase {
+public final class TestReOrderingSlides {
        // A SlideShow with one slide
        private HSLFSlideShowImpl hss_one;
        private HSLFSlideShow ss_one;
@@ -48,6 +48,7 @@ public final class TestReOrderingSlides extends TestCase {
        /**
         * Create/open the slideshows
         */
+       @Before
        public void setUp() throws Exception {
         POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
 
@@ -64,10 +65,11 @@ public final class TestReOrderingSlides extends TestCase {
        /**
         * Test that we can "re-order" a slideshow with only 1 slide on it
         */
+       @Test
        public void testReOrder1() throws Exception {
                // Has one slide
-               assertEquals(1, ss_one.getSlides().length);
-               HSLFSlide s1 = ss_one.getSlides()[0];
+               assertEquals(1, ss_one.getSlides().size());
+               HSLFSlide s1 = ss_one.getSlides().get(0);
 
                // Check slide 1 is as expected
                assertEquals(256, s1._getSheetNumber());
@@ -86,10 +88,10 @@ public final class TestReOrderingSlides extends TestCase {
                HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
 
                // Check it still has 1 slide
-               assertEquals(1, ss_read.getSlides().length);
+               assertEquals(1, ss_read.getSlides().size());
 
                // And check it's as expected
-               s1 = ss_read.getSlides()[0];
+               s1 = ss_read.getSlides().get(0);
                assertEquals(256, s1._getSheetNumber());
                assertEquals(3, s1._getSheetRefId());
                assertEquals(1, s1.getSlideNumber());
@@ -99,11 +101,12 @@ public final class TestReOrderingSlides extends TestCase {
         * Test doing a dummy re-order on a slideshow with
         *  two slides in it
         */
+    @Test
        public void testReOrder2() throws Exception {
                // Has two slides
-               assertEquals(2, ss_two.getSlides().length);
-               HSLFSlide s1 = ss_two.getSlides()[0];
-               HSLFSlide s2 = ss_two.getSlides()[1];
+               assertEquals(2, ss_two.getSlides().size());
+               HSLFSlide s1 = ss_two.getSlides().get(0);
+               HSLFSlide s2 = ss_two.getSlides().get(1);
 
                // Check slide 1 is as expected
                assertEquals(256, s1._getSheetNumber());
@@ -126,11 +129,11 @@ public final class TestReOrderingSlides extends TestCase {
                HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
 
                // Check it still has 2 slides
-               assertEquals(2, ss_read.getSlides().length);
+               assertEquals(2, ss_read.getSlides().size());
 
                // And check it's as expected
-               s1 = ss_read.getSlides()[0];
-               s2 = ss_read.getSlides()[1];
+               s1 = ss_read.getSlides().get(0);
+               s2 = ss_read.getSlides().get(1);
                assertEquals(256, s1._getSheetNumber());
                assertEquals(4, s1._getSheetRefId());
                assertEquals(1, s1.getSlideNumber());
@@ -142,11 +145,12 @@ public final class TestReOrderingSlides extends TestCase {
        /**
         * Test re-ordering slides in a slideshow with 2 slides on it
         */
+    @Test
        public void testReOrder2swap() throws Exception {
                // Has two slides
-               assertEquals(2, ss_two.getSlides().length);
-               HSLFSlide s1 = ss_two.getSlides()[0];
-               HSLFSlide s2 = ss_two.getSlides()[1];
+               assertEquals(2, ss_two.getSlides().size());
+               HSLFSlide s1 = ss_two.getSlides().get(0);
+               HSLFSlide s2 = ss_two.getSlides().get(1);
 
                // Check slide 1 is as expected
                assertEquals(256, s1._getSheetNumber());
@@ -169,11 +173,11 @@ public final class TestReOrderingSlides extends TestCase {
                HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
 
                // Check it still has 2 slides
-               assertEquals(2, ss_read.getSlides().length);
+               assertEquals(2, ss_read.getSlides().size());
 
                // And check it's as expected
-               s1 = ss_read.getSlides()[0];
-               s2 = ss_read.getSlides()[1];
+               s1 = ss_read.getSlides().get(0);
+               s2 = ss_read.getSlides().get(1);
                assertEquals(257, s1._getSheetNumber());
                assertEquals(6, s1._getSheetRefId());
                assertEquals(1, s1.getSlideNumber());
@@ -186,12 +190,13 @@ public final class TestReOrderingSlides extends TestCase {
         * Test doing a dummy re-order on a slideshow with
         *  three slides in it
         */
+    @Test
        public void testReOrder3() throws Exception {
                // Has three slides
-               assertEquals(3, ss_three.getSlides().length);
-               HSLFSlide s1 = ss_three.getSlides()[0];
-               HSLFSlide s2 = ss_three.getSlides()[1];
-               HSLFSlide s3 = ss_three.getSlides()[2];
+               assertEquals(3, ss_three.getSlides().size());
+               HSLFSlide s1 = ss_three.getSlides().get(0);
+               HSLFSlide s2 = ss_three.getSlides().get(1);
+               HSLFSlide s3 = ss_three.getSlides().get(2);
 
                // Check slide 1 is as expected
                assertEquals(256, s1._getSheetNumber());
@@ -218,12 +223,12 @@ public final class TestReOrderingSlides extends TestCase {
                HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
 
                // Check it still has 3 slides
-               assertEquals(3, ss_read.getSlides().length);
+               assertEquals(3, ss_read.getSlides().size());
 
                // And check it's as expected
-               s1 = ss_read.getSlides()[0];
-               s2 = ss_read.getSlides()[1];
-               s3 = ss_read.getSlides()[2];
+               s1 = ss_read.getSlides().get(0);
+               s2 = ss_read.getSlides().get(1);
+               s3 = ss_read.getSlides().get(2);
 
                assertEquals(256, s1._getSheetNumber());
                assertEquals(3, s1._getSheetRefId());
@@ -239,12 +244,13 @@ public final class TestReOrderingSlides extends TestCase {
        /**
         * Test re-ordering slides in a slideshow with 3 slides on it
         */
+    @Test
        public void testReOrder3swap() throws Exception {
                // Has three slides
-               assertEquals(3, ss_three.getSlides().length);
-               HSLFSlide s1 = ss_three.getSlides()[0];
-               HSLFSlide s2 = ss_three.getSlides()[1];
-               HSLFSlide s3 = ss_three.getSlides()[2];
+               assertEquals(3, ss_three.getSlides().size());
+               HSLFSlide s1 = ss_three.getSlides().get(0);
+               HSLFSlide s2 = ss_three.getSlides().get(1);
+               HSLFSlide s3 = ss_three.getSlides().get(2);
 
                // Check slide 1 is as expected
                assertEquals(256, s1._getSheetNumber());
@@ -263,6 +269,18 @@ public final class TestReOrderingSlides extends TestCase {
                // (1 -> 2, 2 -> 3)
                ss_three.reorderSlide(3, 1);
 
+               // refresh the slides
+               s1 = ss_three.getSlides().get(0);
+        s2 = ss_three.getSlides().get(1);
+        s3 = ss_three.getSlides().get(2);
+               
+               assertEquals(1, s1.getSlideNumber());
+        assertEquals(2, s2.getSlideNumber());
+        assertEquals(3, s3.getSlideNumber());
+        
+        assertEquals("Slide 3", ((HSLFTextShape)s1.getShapes().get(0)).getText());
+        assertEquals("Slide 1", ((HSLFTextShape)s3.getShapes().get(0)).getText());
+
                // Write out, and read back in
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                hss_three.write(baos);
@@ -272,16 +290,16 @@ public final class TestReOrderingSlides extends TestCase {
                HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
 
                // Check it still has 3 slides
-               assertEquals(3, ss_read.getSlides().length);
+               assertEquals(3, ss_read.getSlides().size());
 
                // And check it's as expected
-               HSLFSlide _s1 = ss_read.getSlides()[0];
-               HSLFSlide _s2 = ss_read.getSlides()[1];
-               HSLFSlide _s3 = ss_read.getSlides()[2];
+               HSLFSlide _s1 = ss_read.getSlides().get(0);
+               HSLFSlide _s2 = ss_read.getSlides().get(1);
+               HSLFSlide _s3 = ss_read.getSlides().get(2);
 
         // 1 --> 3
-        assertEquals(s1._getSheetNumber(), _s3._getSheetNumber());
-               assertEquals(s1._getSheetRefId(), _s3._getSheetRefId());
+        assertEquals(s1._getSheetNumber(), _s1._getSheetNumber());
+               assertEquals(s1._getSheetRefId(), _s1._getSheetRefId());
                assertEquals(1, s1.getSlideNumber());
 
         // 2nd slide is not updated
@@ -290,8 +308,8 @@ public final class TestReOrderingSlides extends TestCase {
                assertEquals(2, s2.getSlideNumber());
 
         // 3 --> 1
-        assertEquals(s3._getSheetNumber(), _s1._getSheetNumber());
-        assertEquals(s3._getSheetRefId(), _s1._getSheetRefId());
+        assertEquals(s3._getSheetNumber(), _s3._getSheetNumber());
+        assertEquals(s3._getSheetRefId(), _s3._getSheetRefId());
                assertEquals(3, s3.getSlideNumber());
        }
 }
index 4acda5beb9529818ac69df4b011c76cbf2fbd60e..cbaa02ec7e926fd3ed001624449bd792e9795aff 100644 (file)
 
 package org.apache.poi.hslf.usermodel;
 
+import static org.junit.Assert.assertEquals;
 
-import junit.framework.TestCase;
-
-import org.apache.poi.hslf.*;
-import org.apache.poi.hslf.record.ParentAwareRecord;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordContainer;
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.record.*;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Tests that the record setup done by SlideShow
@@ -33,17 +31,20 @@ import org.apache.poi.POIDataSamples;
  *
  * @author Nick Burch (nick at torchbox dot com)
  */
-public final class TestRecordSetup extends TestCase {
+public final class TestRecordSetup {
        // SlideShow primed on the test data
-       private HSLFSlideShow ss;
+       @SuppressWarnings("unused")
+    private HSLFSlideShow ss;
        private HSLFSlideShowImpl hss;
 
-       public TestRecordSetup() throws Exception {
+       @Before
+       public void init() throws Exception {
         POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
                hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
                ss = new HSLFSlideShow(hss);
        }
 
+       @Test
        public void testHandleParentAwareRecords() {
                Record[] records = hss.getRecords();
                for(int i=0; i<records.length; i++) {
index fca03441e915b983f1ca64ff9c24c57ef0fc0481..0468955eeb03465c42a1c9bcb1e67e975e9be354 100644 (file)
 
 package org.apache.poi.hslf.usermodel;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
+import static org.junit.Assert.*;
+import static org.apache.poi.POITestCase.assertContains;
+
+import java.io.*;
+import java.util.List;
 
 import org.apache.poi.POIDataSamples;
-import org.apache.poi.POITestCase;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.SlideListWithText;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.util.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Test that the friendly getters and setters on RichTextRun
  *  behave as expected.
  * (model.TestTextRun tests the other functionality)
  */
-public final class TestRichTextRun extends POITestCase {
-   private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
-
-   // SlideShow primed on the test data
-   private HSLFSlideShow ss;
-   private HSLFSlideShow ssRichA;
-   private HSLFSlideShow ssRichB;
-   private HSLFSlideShow ssRichC;
-   private HSLFSlideShow ssChinese;
-   private HSLFSlideShowImpl hss;
-   private HSLFSlideShowImpl hssRichA;
-   private HSLFSlideShowImpl hssRichB;
-   private HSLFSlideShowImpl hssRichC;
-   private HSLFSlideShowImpl hssChinese;
-   private static String filenameC;
-
-   protected void setUp() throws Exception {
-      // Basic (non rich) test file
-      hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
-      ss = new HSLFSlideShow(hss);
-
-               // Rich test file A
-               hssRichA = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
-               ssRichA = new HSLFSlideShow(hssRichA);
-
-               // Rich test file B
-               hssRichB = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page_With_Fonts_and_Alignments.ppt"));
-               ssRichB = new HSLFSlideShow(hssRichB);
-
-               // Rich test file C - has paragraph styles that run out before
-               //   the character ones do
-               filenameC = "ParagraphStylesShorterThanCharStyles.ppt";
+public final class TestRichTextRun {
+    private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+
+    // SlideShow primed on the test data
+    private HSLFSlideShow ss;
+    private HSLFSlideShow ssRichA;
+    private HSLFSlideShow ssRichB;
+    private HSLFSlideShow ssRichC;
+    private HSLFSlideShow ssChinese;
+    private HSLFSlideShowImpl hss;
+    private HSLFSlideShowImpl hssRichA;
+    private HSLFSlideShowImpl hssRichB;
+    private HSLFSlideShowImpl hssRichC;
+    private HSLFSlideShowImpl hssChinese;
+    private static String filenameC;
+
+    @Before
+    public void setUp() throws Exception {
+        // Basic (non rich) test file
+        hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+        ss = new HSLFSlideShow(hss);
+
+        // Rich test file A
+        hssRichA = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
+        ssRichA = new HSLFSlideShow(hssRichA);
+        
+        // Rich test file B
+        hssRichB = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page_With_Fonts_and_Alignments.ppt"));
+        ssRichB = new HSLFSlideShow(hssRichB);
+        
+        // Rich test file C - has paragraph styles that run out before
+        //   the character ones do
+        filenameC = "ParagraphStylesShorterThanCharStyles.ppt";
         hssRichC = new HSLFSlideShowImpl(_slTests.openResourceAsStream(filenameC));
-               ssRichC = new HSLFSlideShow(hssRichC);
-               
-               // Rich test file with Chinese + English text in it
-      hssChinese = new HSLFSlideShowImpl(_slTests.openResourceAsStream("54880_chinese.ppt"));
-      ssChinese = new HSLFSlideShow(hssChinese);
-       }
+        ssRichC = new HSLFSlideShow(hssRichC);
+        
+        // Rich test file with Chinese + English text in it
+        hssChinese = new HSLFSlideShowImpl(_slTests.openResourceAsStream("54880_chinese.ppt"));
+        ssChinese = new HSLFSlideShow(hssChinese);
+    }
 
        /**
         * Test the stuff about getting/setting bold
         *  on a non rich text run
         */
+    @Test
        public void testBoldNonRich() {
-               HSLFSlide slideOne = ss.getSlides()[0];
-               HSLFTextParagraph[] textRuns = slideOne.getTextParagraphs();
-               HSLFTextRun rtr = textRuns[0].getTextRuns()[0];
+               HSLFSlide slideOne = ss.getSlides().get(0);
+               List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+               List<HSLFTextParagraph> textParas = textParass.get(0);
+               HSLFTextRun rtr = textParas.get(0).getTextRuns().get(0);
 
-               assertNull(rtr._getRawCharacterStyle());
-               assertNull(rtr._getRawParagraphStyle());
+               assertNotNull(rtr.getCharacterStyle());
+               assertNotNull(textParas.get(0).getParagraphStyle());
                assertFalse(rtr.isBold());
 
                // Now set it to not bold
                rtr.setBold(false);
-               //setting bold=false doesn't change the internal state
-               assertNull(rtr._getRawCharacterStyle());
-               assertNull(rtr._getRawParagraphStyle());
+               // in Pre 3.12: setting bold=false doesn't change the internal state
+               // now: also allow explicitly disable styles and there aren't any non rich text runs anymore
+               assertNotNull(rtr.getCharacterStyle());
+               assertNotNull(textParas.get(0).getParagraphStyle());
 
                assertFalse(rtr.isBold());
 
                // And now make it bold
                rtr.setBold(true);
-               assertNotNull(rtr._getRawCharacterStyle());
-               assertNotNull(rtr._getRawParagraphStyle());
+               assertNotNull(rtr.getCharacterStyle());
+        assertNotNull(textParas.get(0).getParagraphStyle());
                assertTrue(rtr.isBold());
        }
 
@@ -104,115 +111,116 @@ public final class TestRichTextRun extends POITestCase {
         * Test the stuff about getting/setting bold
         *  on a rich text run
         */
+    @Test
        public void testBoldRich() {
-               HSLFSlide slideOneR = ssRichA.getSlides()[0];
-               HSLFTextParagraph[] textRunsR = slideOneR.getTextParagraphs();
-               HSLFTextRun[] rtrs = textRunsR[1].getTextRuns();
-               assertEquals(3, rtrs.length);
+               HSLFSlide slideOneR = ssRichA.getSlides().get(0);
+               List<List<HSLFTextParagraph>> textParass = slideOneR.getTextParagraphs();
+               List<HSLFTextParagraph> textParas = textParass.get(1);
+               assertEquals(3, textParas.size());
 
-               assertTrue(rtrs[0].isBold());
-               assertFalse(rtrs[1].isBold());
-               assertFalse(rtrs[2].isBold());
+               assertTrue(textParas.get(0).getTextRuns().get(0).isBold());
+               assertFalse(textParas.get(1).getTextRuns().get(0).isBold());
+               assertFalse(textParas.get(2).getTextRuns().get(0).isBold());
 
-               rtrs[0].setBold(true);
-               rtrs[1].setBold(true);
+               textParas.get(0).getTextRuns().get(0).setBold(true);
+               textParas.get(1).getTextRuns().get(0).setBold(true);
 
-               assertTrue(rtrs[0].isBold());
-               assertTrue(rtrs[1].isBold());
+               assertTrue(textParas.get(0).getTextRuns().get(0).isBold());
+               assertTrue(textParas.get(1).getTextRuns().get(0).isBold());
 
-               rtrs[0].setBold(false);
-               rtrs[1].setBold(false);
+               textParas.get(0).getTextRuns().get(0).setBold(false);
+               textParas.get(1).getTextRuns().get(0).setBold(false);
 
-               assertFalse(rtrs[0].isBold());
-               assertFalse(rtrs[1].isBold());
+               assertFalse(textParas.get(0).getTextRuns().get(0).isBold());
+               assertFalse(textParas.get(1).getTextRuns().get(0).isBold());
        }
 
        /**
         * Tests getting and setting the font size on rich and non
         *  rich text runs
         */
+    @Test
        public void testFontSize() {
 
-               HSLFSlide slideOne = ss.getSlides()[0];
-               HSLFTextParagraph[] textRuns = slideOne.getTextParagraphs();
-               HSLFTextRun rtr = textRuns[0].getTextRuns()[0];
+               HSLFSlide slideOne = ss.getSlides().get(0);
+               List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+               HSLFTextRun rtr = textParass.get(0).get(0).getTextRuns().get(0);
 
-               HSLFSlide slideOneR = ssRichB.getSlides()[0];
-               HSLFTextParagraph[] textRunsR = slideOneR.getTextParagraphs();
-               HSLFTextRun rtrRa = textRunsR[0].getTextRuns()[0];
-               HSLFTextRun rtrRb = textRunsR[1].getTextRuns()[0];
-               HSLFTextRun rtrRc = textRunsR[1].getTextRuns()[3];
+               HSLFSlide slideOneR = ssRichB.getSlides().get(0);
+               List<List<HSLFTextParagraph>> textParassR = slideOneR.getTextParagraphs();
+               HSLFTextRun rtrRa = textParassR.get(0).get(0).getTextRuns().get(0);
+               HSLFTextRun rtrRb = textParassR.get(1).get(0).getTextRuns().get(0);
+               HSLFTextRun rtrRc = textParassR.get(1).get(3).getTextRuns().get(0);
 
                String defaultFont = "Arial";
 
                // Start off with rich one
                // First run has defaults
-               assertEquals(44, rtrRa.getFontSize());
-               assertEquals(defaultFont, rtrRa.getFontName());
+               assertEquals(44, rtrRa.getFontSize(), 0);
+               assertEquals(defaultFont, rtrRa.getFontFamily());
 
                // Second is size 20, default font
-               assertEquals(20, rtrRb.getFontSize());
-               assertEquals(defaultFont, rtrRb.getFontName());
+               assertEquals(20, rtrRb.getFontSize(), 0);
+               assertEquals(defaultFont, rtrRb.getFontFamily());
                // Third is size 24, alt font
-               assertEquals(24, rtrRc.getFontSize());
-               assertEquals("Times New Roman", rtrRc.getFontName());
+               assertEquals(24, rtrRc.getFontSize(), 0);
+               assertEquals("Times New Roman", rtrRc.getFontFamily());
 
                // Change 2nd to different size and font
                assertEquals(2, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR
                rtrRb.setFontSize(18);
-               rtrRb.setFontName("Courier");
+               rtrRb.setFontFamily("Courier");
                assertEquals(3, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR + Courier
-               assertEquals(18, rtrRb.getFontSize());
-               assertEquals("Courier", rtrRb.getFontName());
+               assertEquals(18, rtrRb.getFontSize(), 0);
+               assertEquals("Courier", rtrRb.getFontFamily());
 
 
                // Now do non rich one
-               assertEquals(44, rtr.getFontSize());
-               assertEquals(defaultFont, rtr.getFontName());
+               assertEquals(44, rtr.getFontSize(), 0);
+               assertEquals(defaultFont, rtr.getFontFamily());
                assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
-               assertNull(rtr._getRawCharacterStyle());
-               assertNull(rtr._getRawParagraphStyle());
+               assertNotNull(rtr.getCharacterStyle());
+               assertNotNull(rtr.getTextParagraph().getParagraphStyle());
 
                // Change Font size
                rtr.setFontSize(99);
-               assertEquals(99, rtr.getFontSize());
-               assertEquals(defaultFont, rtr.getFontName());
-               assertNotNull(rtr._getRawCharacterStyle());
-               assertNotNull(rtr._getRawParagraphStyle());
+               assertEquals(99, rtr.getFontSize(), 0);
+               assertEquals(defaultFont, rtr.getFontFamily());
+               assertNotNull(rtr.getCharacterStyle());
+               assertNotNull(rtr.getTextParagraph().getParagraphStyle());
                assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
 
                // Change Font size and name
                rtr.setFontSize(25);
-               rtr.setFontName("Times New Roman");
-               assertEquals(25, rtr.getFontSize());
-               assertEquals("Times New Roman", rtr.getFontName());
-               assertNotNull(rtr._getRawCharacterStyle());
-               assertNotNull(rtr._getRawParagraphStyle());
+               rtr.setFontFamily("Times New Roman");
+               assertEquals(25, rtr.getFontSize(), 0);
+               assertEquals("Times New Roman", rtr.getFontFamily());
+               assertNotNull(rtr.getCharacterStyle());
+               assertNotNull(rtr.getTextParagraph().getParagraphStyle());
                assertEquals(2, ss.getFontCollection().getChildRecords().length);
        }
 
+    @Test
        public void testChangeWriteRead() throws Exception {
-               HSLFSlideShowImpl[] h = new HSLFSlideShowImpl[] { hss, hssRichA, hssRichB };
-               HSLFSlide[] s = new HSLFSlide[] { ss.getSlides()[0], ssRichA.getSlides()[0], ssRichB.getSlides()[0] };
-
-               for(int i=0; i<h.length; i++) {
+               for(HSLFSlideShow h : new HSLFSlideShow[] { ss, ssRichA, ssRichB }) {
                        // Change
-                       HSLFSlide slideOne = s[i];
-                       HSLFTextParagraph[] textRuns = slideOne.getTextParagraphs();
-                       HSLFTextRun rtr = textRuns[0].getTextRuns()[0];
-
+                       HSLFSlide slideOne = h.getSlides().get(0);
+                       List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+                       HSLFTextRun rtr = textParass.get(0).get(0).getTextRuns().get(0);
+                       
                        rtr.setBold(true);
                        rtr.setFontSize(18);
-                       rtr.setFontName("Courier");
+                       rtr.setFontFamily("Courier");
+            HSLFTextParagraph.storeText(textParass.get(0));
 
                        // Check it took those
-                       assertEquals(true, rtr.isBold());
-                       assertEquals(18, rtr.getFontSize());
-                       assertEquals("Courier", rtr.getFontName());
+                       assertTrue(rtr.isBold());
+                       assertEquals(18., rtr.getFontSize(), 0);
+                       assertEquals("Courier", rtr.getFontFamily());
 
                        // Write out and back in
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                       h[i].write(baos);
+                       h.write(baos);
                        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
 
                        HSLFSlideShowImpl readHSLF = new HSLFSlideShowImpl(bais);
@@ -221,23 +229,23 @@ public final class TestRichTextRun extends POITestCase {
                        // Tweak existing one again, to ensure really worked
                        rtr.setBold(false);
                        rtr.setFontSize(17);
-                       rtr.setFontName("CourierZZ");
+                       rtr.setFontFamily("CourierZZ");
 
                        // Check it took those changes
-                       assertEquals(false, rtr.isBold());
-                       assertEquals(17, rtr.getFontSize());
-                       assertEquals("CourierZZ", rtr.getFontName());
+                       assertFalse(rtr.isBold());
+                       assertEquals(17., rtr.getFontSize(), 0);
+                       assertEquals("CourierZZ", rtr.getFontFamily());
 
 
                        // Now, look at the one we changed, wrote out, and read back in
                        // Ensure it does contain our original modifications
-                       HSLFSlide slideOneRR = readS.getSlides()[0];
-                       HSLFTextParagraph[] textRunsRR = slideOneRR.getTextParagraphs();
-                       HSLFTextRun rtrRRa = textRunsRR[0].getTextRuns()[0];
+                       HSLFSlide slideOneRR = readS.getSlides().get(0);
+                       List<List<HSLFTextParagraph>> textParassRR = slideOneRR.getTextParagraphs();
+                       HSLFTextRun rtrRRa = textParassRR.get(0).get(0).getTextRuns().get(0);
 
-                       assertEquals(true, rtrRRa.isBold());
-                       assertEquals(18, rtrRRa.getFontSize());
-                       assertEquals("Courier", rtrRRa.getFontName());
+                       assertTrue(rtrRRa.isBold());
+                       assertEquals(18., rtrRRa.getFontSize(), 0);
+                       assertEquals("Courier", rtrRRa.getFontFamily());
                }
        }
 
@@ -245,16 +253,17 @@ public final class TestRichTextRun extends POITestCase {
         * Test that we can do the right things when the paragraph styles
         *  run out before the character styles do
         */
+    @Test
        public void testParagraphStylesShorterTheCharStyles() {
                // Check we have the right number of sheets
-               HSLFSlide[] slides = ssRichC.getSlides();
-               assertEquals(14, slides.length);
+               List<HSLFSlide> slides = ssRichC.getSlides();
+               assertEquals(14, slides.size());
 
                // Check the number of text runs on interesting sheets
-               HSLFSlide slideThreeC = ssRichC.getSlides()[2];
-               HSLFSlide slideSevenC = ssRichC.getSlides()[6];
-               assertEquals(3, slideThreeC.getTextParagraphs().length);
-               assertEquals(5, slideSevenC.getTextParagraphs().length);
+               HSLFSlide slideThreeC = ssRichC.getSlides().get(2);
+               HSLFSlide slideSevenC = ssRichC.getSlides().get(6);
+               assertEquals(4, slideThreeC.getTextParagraphs().size());
+               assertEquals(5, slideSevenC.getTextParagraphs().size());
 
                // On slide three, we should have:
                // TR:
@@ -266,32 +275,20 @@ public final class TestRichTextRun extends POITestCase {
                //   Illustrative Example
                //   .
 
-               HSLFTextParagraph[] s3tr = slideThreeC.getTextParagraphs();
-               HSLFTextRun[] s3rtr0 = s3tr[0].getTextRuns();
-               HSLFTextRun[] s3rtr1 = s3tr[1].getTextRuns();
-               HSLFTextRun[] s3rtr2 = s3tr[2].getTextRuns();
-
-               assertEquals(2, s3rtr0.length);
-               assertEquals(1, s3rtr1.length);
-               assertEquals(2, s3rtr2.length);
-
-               assertEquals("You are an important supplier of various items that I need", s3rtr0[0].getRawText());
-               assertEquals("", s3rtr0[1].getRawText());
-               assertEquals("Source: Internal focus groups", s3rtr1[0].getRawText());
-               assertEquals("Illustrative Example", s3rtr2[0].getRawText());
-               assertEquals("", s3rtr2[1].getRawText());
-
-               assertTrue(s3rtr0[0]._isParagraphStyleShared());
-               assertTrue(s3rtr0[1]._isParagraphStyleShared());
-               assertFalse(s3rtr1[0]._isParagraphStyleShared());
-               assertTrue(s3rtr2[0]._isParagraphStyleShared());
-               assertTrue(s3rtr2[1]._isParagraphStyleShared());
-
-               assertFalse(s3rtr0[0]._isCharacterStyleShared());
-               assertFalse(s3rtr0[1]._isCharacterStyleShared());
-               assertFalse(s3rtr1[0]._isCharacterStyleShared());
-               assertFalse(s3rtr2[0]._isCharacterStyleShared());
-               assertFalse(s3rtr2[1]._isCharacterStyleShared());
+        List<List<HSLFTextParagraph>> s3tr = slideThreeC.getTextParagraphs();
+               List<HSLFTextRun> s3rtr0 = s3tr.get(0).get(0).getTextRuns();
+               List<HSLFTextRun> s3rtr1 = s3tr.get(2).get(0).getTextRuns();
+               List<HSLFTextRun> s3rtr2 = s3tr.get(3).get(0).getTextRuns();
+
+               assertEquals(2, s3rtr0.size());
+               assertEquals(1, s3rtr1.size());
+               assertEquals(2, s3rtr2.size());
+
+               assertEquals("You are an important supplier of various items that I need", s3rtr0.get(0).getRawText());
+               assertEquals("", s3rtr0.get(1).getRawText());
+               assertEquals("Source: Internal focus groups", s3rtr1.get(0).getRawText());
+               assertEquals("Illustrative Example", s3rtr2.get(0).getRawText());
+               assertEquals("", s3rtr2.get(1).getRawText());
 
                // On slide seven, we have:
                // TR:
@@ -300,26 +297,14 @@ public final class TestRichTextRun extends POITestCase {
                //  <ps>(text a)</ps><ps>(text a)(text b)</ps>
                // TR:
                //  (text)
-               HSLFTextParagraph[] s7tr = slideSevenC.getTextParagraphs();
-               HSLFTextRun[] s7rtr0 = s7tr[0].getTextRuns();
-               HSLFTextRun[] s7rtr1 = s7tr[1].getTextRuns();
-               HSLFTextRun[] s7rtr2 = s7tr[2].getTextRuns();
-
-               assertEquals(1, s7rtr0.length);
-               assertEquals(3, s7rtr1.length);
-               assertEquals(1, s7rtr2.length);
-
-               assertFalse(s7rtr0[0]._isParagraphStyleShared());
-               assertFalse(s7rtr1[0]._isParagraphStyleShared());
-               assertTrue(s7rtr1[1]._isParagraphStyleShared());
-               assertTrue(s7rtr1[2]._isParagraphStyleShared());
-               assertFalse(s7rtr2[0]._isParagraphStyleShared());
-
-               assertFalse(s7rtr0[0]._isCharacterStyleShared());
-               assertTrue(s7rtr1[0]._isCharacterStyleShared());
-               assertTrue(s7rtr1[1]._isCharacterStyleShared());
-               assertFalse(s7rtr1[2]._isCharacterStyleShared());
-               assertFalse(s7rtr2[0]._isCharacterStyleShared());
+               List<List<HSLFTextParagraph>> s7tr = slideSevenC.getTextParagraphs();
+               List<HSLFTextParagraph> s7rtr0 = s7tr.get(0);
+               List<HSLFTextParagraph> s7rtr1 = s7tr.get(1);
+               List<HSLFTextParagraph> s7rtr2 = s7tr.get(2);
+
+               assertEquals(1, s7rtr0.size());
+               assertEquals(8, s7rtr1.size());
+               assertEquals(1, s7rtr2.size());
        }
 
        /**
@@ -327,39 +312,44 @@ public final class TestRichTextRun extends POITestCase {
         *  run out before the character styles do, when we tweak something
         *  and write back out.
         */
-       public void testParagraphStylesShorterTheCharStylesWrite() throws Exception {
+    @Test
+       @SuppressWarnings("unused")
+    public void testParagraphStylesShorterTheCharStylesWrite() throws Exception {
                assertMatchesSLTWC(ssRichC);
                assertMatchesFileC(ssRichC);
 
-               HSLFSlide slideSevenC = ssRichC.getSlides()[6];
-               HSLFTextParagraph[] s7tr = slideSevenC.getTextParagraphs();
-               HSLFTextRun[] s7rtr0 = s7tr[0].getTextRuns();
-               HSLFTextRun[] s7rtr1 = s7tr[1].getTextRuns();
-               HSLFTextRun[] s7rtr2 = s7tr[2].getTextRuns();
+               HSLFSlide slideSevenC = ssRichC.getSlides().get(6);
+               List<List<HSLFTextParagraph>> s7tr = slideSevenC.getTextParagraphs();
+               List<HSLFTextRun> s7rtr0 = s7tr.get(0).get(0).getTextRuns();
+               List<HSLFTextRun> s7rtr1 = s7tr.get(1).get(0).getTextRuns();
+               List<HSLFTextRun> s7rtr2 = s7tr.get(2).get(0).getTextRuns();
 
                String oldText;
 
                // Reset the text on the last run
                // Need to ensure it's a run that really has styles!
-               oldText = s7rtr2[0].getRawText();
-               s7rtr2[0].setText( oldText );
-               assertEquals(oldText, s7rtr2[0].getRawText());
-               assertEquals(oldText, s7tr[2].getRawText());
-               assertEquals(oldText.length() + 1, s7rtr2[0]._getRawCharacterStyle().getCharactersCovered());
-               assertEquals(oldText.length() + 1, s7rtr2[0]._getRawParagraphStyle().getCharactersCovered());
+               oldText = s7rtr2.get(0).getRawText();
+               s7rtr2.get(0).setText( oldText );
+               HSLFTextParagraph.storeText(s7tr.get(2));
+               assertEquals(oldText, s7rtr2.get(0).getRawText());
+               assertEquals(oldText, HSLFTextParagraph.getRawText(s7tr.get(2)));
+               assertEquals(oldText.length() + 1, s7rtr2.get(0).getCharacterStyle().getCharactersCovered());
+               assertEquals(oldText.length() + 1, s7rtr2.get(0).getTextParagraph().getParagraphStyle().getCharactersCovered());
                assertMatchesSLTWC(ssRichC);
                assertMatchesFileC(ssRichC);
 
                // Reset the text on a shared paragraph
-               oldText = s7rtr1[2].getRawText();
-               s7rtr1[2].setText( oldText );
-               assertEquals(oldText, s7rtr1[2].getRawText());
-               assertEquals(oldText.length() + 1, s7rtr1[2]._getRawCharacterStyle().getCharactersCovered());
+               oldText = s7rtr1.get(0).getRawText();
+               s7rtr1.get(0).setText( oldText );
+        HSLFTextParagraph.storeText(s7tr.get(1));
+               assertEquals(oldText, s7rtr1.get(0).getRawText());
+               assertEquals(oldText.length(), s7rtr1.get(0).getCharacterStyle().getCharactersCovered());
                assertMatchesSLTWC(ssRichC);
                assertMatchesFileC(ssRichC);
 
                // Reset the text on a shared paragraph+character
-               s7rtr1[1].setText( s7rtr1[1].getRawText() );
+               s7rtr1.get(0).setText( s7rtr1.get(0).getRawText() );
+               HSLFTextParagraph.storeText(s7tr.get(1));
                assertMatchesSLTWC(ssRichC);
                assertMatchesFileC(ssRichC);
        }
@@ -391,17 +381,11 @@ public final class TestRichTextRun extends POITestCase {
 
                        byte[] r_rb = writeRecord(ref_r);
                        byte[] s_rb = writeRecord(s_r);
-                       assertEquals(r_rb.length, s_rb.length);
-                       for(int j=0; j<r_rb.length; j++) {
-                               assertEquals(r_rb[j],s_rb[j]);
-                       }
+                       assertArrayEquals(r_rb, s_rb);
                }
 
                // Check the bytes are the same
-               assertEquals(raw_slwt.length, s_slwt.length);
-               for(int i=0; i<raw_slwt.length; i++) {
-                       assertEquals(raw_slwt[i], s_slwt[i]);
-               }
+               assertArrayEquals(raw_slwt, s_slwt);
        }
 
        /**
@@ -409,35 +393,35 @@ public final class TestRichTextRun extends POITestCase {
         *  of slideshow c
         */
        private static void assertMatchesFileC(HSLFSlideShow s) throws Exception {
-               if (true) { // TODO - test is disabled, pending fix of bug #39800
-                       // System.err.println("Skipping test, as would be marked as failed due to bug #39800"); //
-                       return;
-               }
-if(false) {
                // Grab the bytes of the file
-               FileInputStream fin = new FileInputStream(filenameC);
-               ByteArrayOutputStream fb = new ByteArrayOutputStream();
-               byte[] b = new byte[4096];
-               int read = 0;
-               while(read != -1) {
-                       read = fin.read(b);
-                       if(read > 0) {
-                               fb.write(b, 0, read);
-                       }
-               }
-               byte[] raw_file = fb.toByteArray();
+           NPOIFSFileSystem fs = new NPOIFSFileSystem(_slTests.getFile(filenameC));
+           ByteArrayOutputStream baos = new ByteArrayOutputStream();
+           InputStream is = fs.createDocumentInputStream("PowerPoint Document");
+           IOUtils.copy(is, baos);
+           is.close();
+           fs.close();
+           byte[] raw_file = baos.toByteArray();
 
                // Now write out the slideshow
-               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+               baos.reset();
                s.write(baos);
+               fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
+               baos.reset();
+               is = fs.createDocumentInputStream("PowerPoint Document");
+        IOUtils.copy(is, baos);
+        is.close();
+        fs.close();            
                byte[] raw_ss = baos.toByteArray();
+               
+               FileOutputStream fos = new FileOutputStream("PowerPoint Document.new.stream");
+               fos.write(raw_ss);
+               fos.close();
 
+               // different paragraph mask, because of sanitizing
+               raw_ss[169030] = 0x0a;
+               
                // Ensure they're the same
-               assertEquals(raw_file.length, raw_ss.length);
-               for(int i=0; i<raw_file.length; i++) {
-                       assertEquals(raw_file[i], raw_ss[i]);
-               }
-}
+               assertArrayEquals(raw_file, raw_ss);
        }
 
        private byte[] writeRecord(Record r) throws Exception {
@@ -446,15 +430,13 @@ if(false) {
                return baos.toByteArray();
        }
 
+    @Test
        public void testIndentationLevel() throws Exception {
                HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
-               HSLFSlide[] sl = ppt.getSlides();
-               for (int i = 0; i < sl.length; i++) {
-                       HSLFTextParagraph[] txt = sl[i].getTextParagraphs();
-                       for (int j = 0; j < txt.length; j++) {
-                               HSLFTextRun[] rt = txt[j].getTextRuns();
-                               for (int k = 0; k < rt.length; k++) {
-                                       int indent = rt[k].getIndentLevel();
+               for (HSLFSlide sl : ppt.getSlides()) {
+                       for (List<HSLFTextParagraph> txt : sl.getTextParagraphs()) {
+                               for (HSLFTextParagraph p : txt) {
+                                       int indent = p.getIndentLevel();
                                        assertTrue(indent >= 0 && indent <= 4 );
                                }
 
@@ -462,78 +444,84 @@ if(false) {
                }
        }
 
+    @Test
        public void testReadParagraphStyles() throws Exception {
                HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt"));
                assertTrue("No Exceptions while reading file", true);
 
-               HSLFTextRun rt;
-               HSLFTextParagraph[] txt;
-               HSLFSlide[] slide = ppt.getSlides();
-               assertEquals(2, slide.length);
+               HSLFTextParagraph rt;
+               List<List<HSLFTextParagraph>> txt;
+               List<HSLFSlide> slide = ppt.getSlides();
+               assertEquals(2, slide.size());
 
-               txt = slide[0].getTextParagraphs();
-               assertEquals(2, txt.length);
+               txt = slide.get(0).getTextParagraphs();
+               assertEquals(2, txt.size());
 
-               assertEquals("Title text", txt[0].getRawText());
-               assertEquals(1, txt[0].getTextRuns().length);
-               rt = txt[0].getTextRuns()[0];
+               assertEquals("Title text", HSLFTextParagraph.getRawText(txt.get(0)));
+               assertEquals(1, txt.get(0).size());
+               rt = txt.get(0).get(0);
                assertFalse(rt.isBullet());
 
-               assertEquals(
-                               "This is a text placeholder that \r" +
-                               "follows the design pattern\r" +
-                               "Defined in the slide master\r" +
-                               "and has bullets by default", txt[1].getRawText());
-               assertEquals(1, txt[1].getTextRuns().length);
-               rt = txt[1].getTextRuns()[0];
+               String expected =
+               "This is a text placeholder that \r" +
+            "follows the design pattern\r" +
+            "Defined in the slide master\r" +
+            "and has bullets by default";
+               assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(1)));
+               assertEquals(4, txt.get(1).size());
+               rt = txt.get(1).get(0);
                assertEquals('\u2022', rt.getBulletChar());
                assertTrue(rt.isBullet());
 
 
-               txt = slide[1].getTextParagraphs();
-               assertEquals(2, txt.length);
+               txt = slide.get(1).getTextParagraphs();
+               assertEquals(2, txt.size());
 
-               assertEquals(
-                               "I\u2019m a text box\r" +
-                               "With bullets\r" +
-                               "That follow the design pattern\r" +
-                               "From the slide master", txt[0].getRawText());
-               assertEquals(1, txt[0].getTextRuns().length);
-               rt = txt[0].getTextRuns()[0];
+               expected =
+               "I\u2019m a text box\r" +
+            "With bullets\r" +
+            "That follow the design pattern\r" +
+            "From the slide master";
+               assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(0)));
+               assertEquals(4, txt.get(0).size());
+               rt = txt.get(0).get(0);
                assertTrue(rt.isBullet());
                assertEquals('\u2022', rt.getBulletChar());
 
-               assertEquals(
-                               "I\u2019m a text box with user-defined\r" +
-                               "bullet character", txt[1].getRawText());
-               assertEquals(1, txt[1].getTextRuns().length);
-               rt = txt[1].getTextRuns()[0];
+               expected =
+            "I\u2019m a text box with user-defined\r" +
+            "bullet character";
+        assertEquals(expected, HSLFTextParagraph.getRawText(txt.get(1)));
+               assertEquals(2, txt.get(1).size());
+               rt = txt.get(1).get(0);
                assertTrue(rt.isBullet());
                assertEquals('\u263A', rt.getBulletChar());
        }
 
+    @Test
        public void testSetParagraphStyles() throws Exception {
                HSLFSlideShow ppt = new HSLFSlideShow();
 
                HSLFSlide slide = ppt.createSlide();
 
                HSLFTextBox shape = new HSLFTextBox();
-               HSLFTextRun rt = shape.getTextParagraphs().getTextRuns()[0];
                shape.setText(
                                "Hello, World!\r" +
                                "This should be\r" +
                                "Multiline text");
-               rt.setFontSize(42);
+        HSLFTextParagraph rt = shape.getTextParagraphs().get(0);
+        HSLFTextRun tr = rt.getTextRuns().get(0);
+               tr.setFontSize(42);
                rt.setBullet(true);
-               rt.setTextOffset(50);
-               rt.setBulletOffset(0);
+               rt.setLeftMargin(50);
+               rt.setIndent(0);
                rt.setBulletChar('\u263A');
                slide.addShape(shape);
 
-               assertEquals(42, rt.getFontSize());
+               assertEquals(42.0, tr.getFontSize(), 0);
                assertEquals(true, rt.isBullet());
-               assertEquals(50, rt.getTextOffset());
-               assertEquals(0, rt.getBulletOffset());
+               assertEquals(50.0, rt.getLeftMargin(), 0);
+               assertEquals(0, rt.getIndent(), 0);
                assertEquals('\u263A', rt.getBulletChar());
 
                shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300));
@@ -545,57 +533,67 @@ if(false) {
                out.close();
 
                ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
-               slide = ppt.getSlides()[0];
-               shape = (HSLFTextBox)slide.getShapes()[0];
-               rt = shape.getTextParagraphs().getTextRuns()[0];
-               assertEquals(42, rt.getFontSize());
+               slide = ppt.getSlides().get(0);
+               shape = (HSLFTextBox)slide.getShapes().get(0);
+               rt = shape.getTextParagraphs().get(0);
+               tr = rt.getTextRuns().get(0);
+               assertEquals(42.0, tr.getFontSize(), 0);
                assertEquals(true, rt.isBullet());
-               assertEquals(50, rt.getTextOffset());
-               assertEquals(0, rt.getBulletOffset());
+               assertEquals(50.0, rt.getLeftMargin(), 0);
+               assertEquals(0, rt.getIndent(), 0);
                assertEquals('\u263A', rt.getBulletChar());
        }
 
+    @Test
        public void testAddText() throws Exception {
                HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt"));
                assertTrue("No Exceptions while reading file", true);
 
-               HSLFTextRun rt;
-               HSLFTextParagraph[] txt;
-               HSLFSlide[] slides = ppt.getSlides();
+               HSLFTextParagraph rt;
+               HSLFTextRun tr;
+               List<List<HSLFTextParagraph>> txt;
+               List<HSLFSlide> slides = ppt.getSlides();
 
-               assertEquals(2, slides.length);
-               txt = slides[0].getTextParagraphs();
-               assertEquals(2, txt.length);
+               assertEquals(2, slides.size());
+               txt = slides.get(0).getTextParagraphs();
+               assertEquals(2, txt.size());
 
-               assertEquals("Title text", txt[0].getRawText());
-               assertEquals(1, txt[0].getTextRuns().length);
-               rt = txt[0].getTextRuns()[0];
+               assertEquals("Title text", HSLFTextParagraph.getRawText(txt.get(0)));
+               assertEquals(1, txt.get(0).size());
+               rt = txt.get(0).get(0);
                assertFalse(rt.isBullet());
 
                // Add some new text
-               txt[0].appendText("Foo! I'm new!");
-               assertEquals(2, txt[0].getTextRuns().length);
-
-               rt = txt[0].getTextRuns()[0];
-               assertFalse(rt.isBold());
-               assertEquals("Title text", rt.getRawText());
-               rt = txt[0].getTextRuns()[1];
-               assertFalse(rt.isBold());
-               assertEquals("Foo! I'm new!", rt.getRawText());
-               rt.setBold(true);
-
-               // And some more
-               txt[0].appendText("Me too!");
-               assertEquals(3, txt[0].getTextRuns().length);
-               rt = txt[0].getTextRuns()[0];
-               assertFalse(rt.isBold());
-               assertEquals("Title text", rt.getRawText());
-               rt = txt[0].getTextRuns()[1];
-               assertTrue(rt.isBold());
-               assertEquals("Foo! I'm new!", rt.getRawText());
-               rt = txt[0].getTextRuns()[2];
-               assertFalse(rt.isBold());
-               assertEquals("Me too!", rt.getRawText());
+               HSLFTextParagraph.appendText(txt.get(0), "Foo! I'm new!", true);
+               assertEquals(2, txt.get(0).size());
+
+               rt = txt.get(0).get(0);
+               tr = rt.getTextRuns().get(0);
+               assertFalse(tr.isBold());
+               assertEquals("Title text\r", tr.getRawText());
+               rt = txt.get(0).get(1);
+               tr = rt.getTextRuns().get(0);
+               assertFalse(tr.isBold());
+               assertEquals("Foo! I'm new!", tr.getRawText());
+               tr.setBold(true);
+               HSLFTextParagraph.storeText(txt.get(0));
+
+               // And some more, attributes will be copied from previous run
+               HSLFTextParagraph.appendText(txt.get(0), "Me too!", true);
+               HSLFTextParagraph.storeText(txt.get(0));
+               assertEquals(3, txt.get(0).size());
+               rt = txt.get(0).get(0);
+               tr = rt.getTextRuns().get(0);
+               assertFalse(tr.isBold());
+               assertEquals("Title text\r", tr.getRawText());
+               rt = txt.get(0).get(1);
+               tr = rt.getTextRuns().get(0);
+               assertTrue(tr.isBold());
+               assertEquals("Foo! I'm new!\r", tr.getRawText());
+               rt = txt.get(0).get(2);
+               tr = rt.getTextRuns().get(0);
+               assertTrue(tr.isBold());
+               assertEquals("Me too!", tr.getRawText());
 
                // Save and re-open
                ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -605,55 +603,59 @@ if(false) {
                ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
                slides = ppt.getSlides();
 
-               assertEquals(2, slides.length);
-
-               txt = slides[0].getTextParagraphs();
-               assertEquals(2, txt.length);
-               assertEquals(3, txt[0].getTextRuns().length);
-               rt = txt[0].getTextRuns()[0];
-               assertFalse(rt.isBold());
-               assertEquals("Title text", rt.getRawText());
-               rt = txt[0].getTextRuns()[1];
-               assertTrue(rt.isBold());
-               assertEquals("Foo! I'm new!", rt.getRawText());
-               rt = txt[0].getTextRuns()[2];
-               assertFalse(rt.isBold());
-               assertEquals("Me too!", rt.getRawText());
+               assertEquals(2, slides.size());
+
+               txt = slides.get(0).getTextParagraphs();
+               assertEquals(2, txt.size());
+               assertEquals(3, txt.get(0).size());
+               rt = txt.get(0).get(0);
+               tr = rt.getTextRuns().get(0);
+               assertFalse(tr.isBold());
+               assertEquals("Title text\r", tr.getRawText());
+               rt = txt.get(0).get(1);
+               tr = rt.getTextRuns().get(0);
+               assertTrue(tr.isBold());
+               assertEquals("Foo! I'm new!\r", tr.getRawText());
+               rt = txt.get(0).get(2);
+               tr = rt.getTextRuns().get(0);
+               assertTrue(tr.isBold());
+               assertEquals("Me too!", tr.getRawText());
 
 //             FileOutputStream fout = new FileOutputStream("/tmp/foo.ppt");
 //             ppt.write(fout);
        }
        
+    @Test
        public void testChineseParagraphs() throws Exception {
-      HSLFTextRun[] rts;
+      List<HSLFTextRun> rts;
       HSLFTextRun rt;
-      HSLFTextParagraph[] txt;
-      HSLFSlide[] slides = ssChinese.getSlides();
+      List<List<HSLFTextParagraph>> txt;
+      List<HSLFSlide> slides = ssChinese.getSlides();
 
       // One slide
-      assertEquals(1, slides.length);
+      assertEquals(1, slides.size());
       
       // One block of text within that
-      txt = slides[0].getTextParagraphs();
-      assertEquals(1, txt.length);
+      txt = slides.get(0).getTextParagraphs();
+      assertEquals(1, txt.size());
       
       // One rich block of text in that - text is all the same style
       // TODO Is this completely correct?
-      rts = txt[0].getTextRuns();
-      assertEquals(1, rts.length);
-      rt = rts[0];
+      rts = txt.get(0).get(0).getTextRuns();
+      assertEquals(1, rts.size());
+      rt = rts.get(0);
       
       // Check we can get the english text out of that
       String text = rt.getRawText();
       assertContains(text, "Single byte");
       // And the chinese
-      assertContains(text, "\uff8a\uff9d\uff76\uff78");
+      assertContains(txt.get(0).get(3).getTextRuns().get(0).getRawText(), "\uff8a\uff9d\uff76\uff78");
       
       // It isn't bold or italic
       assertFalse(rt.isBold());
       assertFalse(rt.isItalic());
       
       // Font is Calibri
-      assertEquals("Calibri", rt.getFontName());
+      assertEquals("Calibri", rt.getFontFamily());
        }
 }
index 000166b754b122d23f08989c9ebd05b3333c190a..9c8f3e18cfe4ff474d47f8c141dc0d14c624544e 100644 (file)
 
 package org.apache.poi.hslf.usermodel;
 
+import static org.junit.Assert.assertEquals;
 
-import junit.framework.TestCase;
+import java.util.List;
 
-import org.apache.poi.hslf.*;
-import org.apache.poi.hslf.model.*;
 import org.apache.poi.POIDataSamples;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Tests that SlideShow returns Sheets which have the right text in them
  *
  * @author Nick Burch (nick at torchbox dot com)
  */
-public final class TestSheetText extends TestCase {
+public final class TestSheetText {
        // SlideShow primed on the test data
        private HSLFSlideShow ss;
 
-       public TestSheetText() throws Exception {
+       @Before
+       public void init() throws Exception {
         POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
                HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
                ss = new HSLFSlideShow(hss);
        }
 
+       @Test
        public void testSheetOne() {
-               HSLFSheet slideOne = ss.getSlides()[0];
+               HSLFSheet slideOne = ss.getSlides().get(0);
 
-               String[] expectText = new String[] {"This is a test title","This is a test subtitle\nThis is on page 1"};
-               assertEquals(expectText.length, slideOne.getTextParagraphs().length);
-               for(int i=0; i<expectText.length; i++) {
-                       assertEquals(expectText[i], slideOne.getTextParagraphs()[i].getRawText());
+               String[] expectText = new String[] {"This is a test title","This is a test subtitle\rThis is on page 1"};
+               assertEquals(expectText.length, slideOne.getTextParagraphs().size());
+               int i = 0;
+               for(List<HSLFTextParagraph> textParas : slideOne.getTextParagraphs()) {
+                       assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas));
                }
        }
 
        public void testSheetTwo() {
-               HSLFSheet slideTwo = ss.getSlides()[1];
-               String[] expectText = new String[] {"This is the title on page 2","This is page two\nIt has several blocks of text\nNone of them have formatting"};
-               assertEquals(expectText.length, slideTwo.getTextParagraphs().length);
-               for(int i=0; i<expectText.length; i++) {
-                       assertEquals(expectText[i], slideTwo.getTextParagraphs()[i].getRawText());
-               }
+               HSLFSheet slideTwo = ss.getSlides().get(1);
+               String[] expectText = new String[] {"This is the title on page 2","This is page two\rIt has several blocks of text\rNone of them have formatting"};
+               assertEquals(expectText.length, slideTwo.getTextParagraphs().size());
+        int i = 0;
+        for(List<HSLFTextParagraph> textParas : slideTwo.getTextParagraphs()) {
+            assertEquals(expectText[i++], HSLFTextParagraph.getRawText(textParas));
+        }
        }
 
        /**
@@ -69,11 +74,11 @@ public final class TestSheetText extends TestCase {
                HSLFSlideShow sss = new HSLFSlideShow(hss);
 
                // Should come out with 10 slides, no notes
-               assertEquals(10, sss.getSlides().length);
-               assertEquals(0, sss.getNotes().length);
+               assertEquals(10, sss.getSlides().size());
+               assertEquals(0, sss.getNotes().size());
 
                // Check text on first slide
-               HSLFSlide s = sss.getSlides()[0];
+               HSLFSlide s = sss.getSlides().get(0);
                String exp =
                        "Realizing the Development Dividend:\n" +
                        "Community Capacity Building and CDM.\n" +
@@ -83,7 +88,7 @@ public final class TestSheetText extends TestCase {
                        "COP 11 \u2013 MOP 1\n" + // special long hyphen
                        "December 5, 2005\n";
 
-               assertEquals(1, s.getTextParagraphs().length);
-               assertEquals(exp, s.getTextParagraphs()[0].getRawText());
+               assertEquals(1, s.getTextParagraphs().size());
+               assertEquals(exp, HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
        }
 }
index 0aaa8acb77a4d79a32dd9e99f920ffe2d308b898..e1a6a6009fa463a759cda3b596a2fa9242edda3d 100644 (file)
 
 package org.apache.poi.hslf.usermodel;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
 
-import org.apache.poi.hslf.*;
-import org.apache.poi.hslf.model.*;
 import org.apache.poi.POIDataSamples;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Tests that SlideShow returns Sheets in the right order
  *
  * @author Nick Burch (nick at torchbox dot com)
  */
-public final class TestSlideOrdering extends TestCase {
+public final class TestSlideOrdering {
     private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
 
        // Simple slideshow, record order matches slide order
@@ -36,7 +38,8 @@ public final class TestSlideOrdering extends TestCase {
        // Complex slideshow, record order doesn't match slide order
        private HSLFSlideShow ssB;
 
-       public TestSlideOrdering() throws Exception {
+       @Before
+       public void init() throws Exception {
                HSLFSlideShowImpl hssA = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
                ssA = new HSLFSlideShow(hssA);
 
@@ -47,33 +50,29 @@ public final class TestSlideOrdering extends TestCase {
        /**
         * Test the simple case - record order matches slide order
         */
+       @Test
        public void testSimpleCase() {
-               assertEquals(2, ssA.getSlides().length);
+               assertEquals(2, ssA.getSlides().size());
 
-               HSLFSlide s1 = ssA.getSlides()[0];
-               HSLFSlide s2 = ssA.getSlides()[1];
+               HSLFSlide s1 = ssA.getSlides().get(0);
+               HSLFSlide s2 = ssA.getSlides().get(1);
 
                String[] firstTRs = new String[] { "This is a test title", "This is the title on page 2" };
 
-               assertEquals(firstTRs[0], s1.getTextParagraphs()[0].getRawText());
-               assertEquals(firstTRs[1], s2.getTextParagraphs()[0].getRawText());
+               assertEquals(firstTRs[0], HSLFTextParagraph.getRawText(s1.getTextParagraphs().get(0)));
+               assertEquals(firstTRs[1], HSLFTextParagraph.getRawText(s2.getTextParagraphs().get(0)));
        }
 
        /**
         * Test the complex case - record order differs from slide order
         */
+    @Test
        public void testComplexCase() {
-               assertEquals(3, ssB.getSlides().length);
-
-               HSLFSlide s1 = ssB.getSlides()[0];
-               HSLFSlide s2 = ssB.getSlides()[1];
-               HSLFSlide s3 = ssB.getSlides()[2];
-
-               String[] firstTRs = new String[] { "Slide 1", "Slide 2", "Slide 3" };
-
-               assertEquals(firstTRs[0], s1.getTextParagraphs()[0].getRawText());
-               assertEquals(firstTRs[1], s2.getTextParagraphs()[0].getRawText());
-               assertEquals(firstTRs[2], s3.getTextParagraphs()[0].getRawText());
+               assertEquals(3, ssB.getSlides().size());
+               int i=1;
+               for (HSLFSlide s : ssB.getSlides()) {
+                   assertEquals("Slide "+(i++), HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
+               }
        }
 
        /**
@@ -88,15 +87,16 @@ public final class TestSlideOrdering extends TestCase {
         POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
 
         HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream(filename));
-               HSLFSlide[] slide = ppt.getSlides();
+               List<HSLFSlide> slide = ppt.getSlides();
 
-               assertEquals(titles.length, slide.length);
-               for (int i = 0; i < slide.length; i++) {
-                       String title = slide[i].getTitle();
+               assertEquals(titles.length, slide.size());
+               for (int i = 0; i < slide.size(); i++) {
+                       String title = slide.get(i).getTitle();
                        assertEquals("Wrong slide title in " + filename, titles[i], title);
                }
        }
 
+    @Test
        public void testTitles() throws Exception {
                assertSlideOrdering("basic_test_ppt_file.ppt", new String[] {
                                "This is a test title", "This is the title on page 2" });
index 60676b643c45c57dc56f1ddb7b0609abb937f583..3b1313e4eaa158f109209d97c38af560a675e706 100644 (file)
@@ -19,15 +19,11 @@ package org.apache.poi.hslf.usermodel;
 
 import static org.junit.Assert.*;
 
-import java.awt.Color;
-import java.io.*;
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.model.Table;
-import org.apache.poi.hslf.model.textproperties.TextPropCollection;
 import org.apache.poi.hslf.record.*;
-import org.apache.poi.hslf.usermodel.*;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -59,28 +55,28 @@ public final class TestTextRun {
        @Test
        public void testGetText() {
                HSLFSlide slideOne = ss.getSlides().get(0);
-               List<HSLFTextParagraph> textParas = slideOne.getTextParagraphs();
+               List<List<HSLFTextParagraph>> textParas = slideOne.getTextParagraphs();
 
                assertEquals(2, textParas.size());
 
                // Get text works with \n
-               assertEquals("This is a test title", textParas.get(0).getTextRuns().get(0).getRawText());
-               assertEquals("This is a test subtitle\nThis is on page 1", textParas.get(1).getTextRuns().get(0).getRawText());
+               assertEquals("This is a test title", HSLFTextParagraph.getText(textParas.get(0)));
+               assertEquals("This is a test subtitle\nThis is on page 1", HSLFTextParagraph.getText(textParas.get(1)));
 
                // Raw text has \r instead
-               assertEquals("This is a test title", textParas.get(0).getTextRuns().get(0).getRawText());
-               assertEquals("This is a test subtitle\rThis is on page 1", textParas.get(1).getTextRuns().get(0).getRawText());
+               assertEquals("This is a test title", HSLFTextParagraph.getRawText(textParas.get(0)));
+               assertEquals("This is a test subtitle\rThis is on page 1", HSLFTextParagraph.getRawText(textParas.get(1)));
 
 
                // Now check on a rich text run
                HSLFSlide slideOneR = ssRich.getSlides().get(0);
-               List<HSLFTextParagraph> textRunsR = slideOneR.getTextParagraphs();
+               textParas = slideOneR.getTextParagraphs();
 
-               assertEquals(2, textRunsR.size());
-               assertEquals("This is a title, it\u2019s in black", textRunsR.get(0).getTextRuns().get(0).getRawText());
-               assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", textRunsR.get(1).getTextRuns().get(0).getRawText());
-               assertEquals("This is a title, it\u2019s in black", textRunsR.get(0).getTextRuns().get(0).getRawText());
-               assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", textRunsR.get(1).getTextRuns().get(0).getRawText());
+               assertEquals(2, textParas.size());
+               assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getText(textParas.get(0)));
+               assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", HSLFTextParagraph.getText(textParas.get(1)));
+               assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getRawText(textParas.get(0)));
+               assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", HSLFTextParagraph.getRawText(textParas.get(1)));
        }
 
        /**
@@ -89,8 +85,8 @@ public final class TestTextRun {
        @Test
        public void testSetText() {
                HSLFSlide slideOne = ss.getSlides().get(0);
-               List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
-               HSLFTextParagraph run = textRuns.get(0);
+               List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
+               HSLFTextParagraph run = textRuns.get(0).get(0);
                HSLFTextRun tr =  run.getTextRuns().get(0);
 
                // Check current text
@@ -110,10 +106,11 @@ public final class TestTextRun {
         * Test to ensure that changing non rich text between bytes and
         *  chars works correctly
         */
-       @Test
+       @SuppressWarnings("unused")
+    @Test
        public void testAdvancedSetText() {
                HSLFSlide slideOne = ss.getSlides().get(0);
-               List<HSLFTextParagraph> paras = slideOne.getTextParagraphs();
+               List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0);
                HSLFTextParagraph para = paras.get(0);
                
         TextHeaderAtom tha = null;
@@ -192,21 +189,21 @@ public final class TestTextRun {
        @Test
        public void testGetRichTextNonRich() {
                HSLFSlide slideOne = ss.getSlides().get(0);
-               List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
+               List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
 
-               assertEquals(2, textRuns.size());
+               assertEquals(2, textParass.size());
 
-               HSLFTextParagraph trA = textRuns.get(0);
-               HSLFTextParagraph trB = textRuns.get(1);
+               List<HSLFTextParagraph> trA = textParass.get(0);
+               List<HSLFTextParagraph> trB = textParass.get(1);
 
-               assertEquals(1, trA.getTextRuns().size());
-               assertEquals(1, trB.getTextRuns().size());
+               assertEquals(1, trA.size());
+               assertEquals(1, trB.size());
 
-               HSLFTextRun rtrA = trA.getTextRuns().get(0);
-               HSLFTextRun rtrB = trB.getTextRuns().get(0);
+               HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
+               HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
 
-               assertEquals(HSLFTextParagraph.getRawText(textRuns.subList(0, 0)), rtrA.getRawText());
-               assertEquals(HSLFTextParagraph.getRawText(textRuns.subList(1, 1)), rtrB.getRawText());
+               assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
+               assertEquals(HSLFTextParagraph.getRawText(trB), rtrB.getRawText());
 
 //             assertNull(rtrA._getRawCharacterStyle());
 //             assertNull(rtrA._getRawParagraphStyle());
@@ -220,45 +217,36 @@ public final class TestTextRun {
        @Test
        public void testGetRichText() {
                HSLFSlide slideOne = ssRich.getSlides().get(0);
-               List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
+               List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
 
-               assertEquals(2, textRuns.size());
+               assertEquals(2, textParass.size());
 
-               HSLFTextParagraph trA = textRuns.get(0);
-               HSLFTextParagraph trB = textRuns.get(1);
+               List<HSLFTextParagraph> trA = textParass.get(0);
+               List<HSLFTextParagraph> trB = textParass.get(1);
 
-               assertEquals(1, trA.getTextRuns().size());
-               assertEquals(3, trB.getTextRuns().size());
+               assertEquals(1, trA.size());
+               assertEquals(3, trB.size());
 
-               HSLFTextRun rtrA = trA.getTextRuns().get(0);
-               HSLFTextRun rtrB = trB.getTextRuns().get(0);
-               HSLFTextRun rtrC = trB.getTextRuns().get(1);
-               HSLFTextRun rtrD = trB.getTextRuns().get(2);
+               HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
+               HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+               HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+               HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
 
-               assertEquals(HSLFTextParagraph.getRawText(textRuns.subList(0, 0)), rtrA.getRawText());
+               assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
 
-               String trBstr = HSLFTextParagraph.getRawText(textRuns.subList(1, 1));
+               String trBstr = HSLFTextParagraph.getRawText(trB);
                assertEquals(trBstr.substring(0, 30), rtrB.getRawText());
                assertEquals(trBstr.substring(30,58), rtrC.getRawText());
                assertEquals(trBstr.substring(58,82), rtrD.getRawText());
 
-//             assertNull(rtrA._getRawCharacterStyle());
-//             assertNull(rtrA._getRawParagraphStyle());
-//             assertNotNull(rtrB._getRawCharacterStyle());
-//             assertNotNull(rtrB._getRawParagraphStyle());
-//             assertNotNull(rtrC._getRawCharacterStyle());
-//             assertNotNull(rtrC._getRawParagraphStyle());
-//             assertNotNull(rtrD._getRawCharacterStyle());
-//             assertNotNull(rtrD._getRawParagraphStyle());
-
                // Same paragraph styles
-//             assertEquals(rtrB._getRawParagraphStyle(), rtrC._getRawParagraphStyle());
-//             assertEquals(rtrB._getRawParagraphStyle(), rtrD._getRawParagraphStyle());
+               assertEquals(trB.get(0).getParagraphStyle(), trB.get(1).getParagraphStyle());
+               assertEquals(trB.get(0).getParagraphStyle(), trB.get(2).getParagraphStyle());
 
                // Different char styles
-//             assertFalse( rtrB._getRawCharacterStyle().equals( rtrC._getRawCharacterStyle() ));
-//             assertFalse( rtrB._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
-//             assertFalse( rtrC._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
+               assertNotEquals(rtrB.getCharacterStyle(), rtrC.getCharacterStyle());
+        assertNotEquals(rtrB.getCharacterStyle(), rtrD.getCharacterStyle());
+        assertNotEquals(rtrC.getCharacterStyle(), rtrD.getCharacterStyle());
        }
 
        /**
@@ -268,22 +256,18 @@ public final class TestTextRun {
        @Test
        public void testSetTextWhereNotRich() {
                HSLFSlide slideOne = ss.getSlides().get(0);
-               List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
-               HSLFTextParagraph trB = textRuns.get(1);
-//             assertEquals(1, trB.getTextRuns().length);
+               List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+               List<HSLFTextParagraph> trB = textParass.get(0);
+               assertEquals(1, trB.size());
 
-               HSLFTextRun rtrB = trB.getTextRuns().get(0);
-//             assertEquals(trB.getRawText(), rtrB.getRawText());
-//             assertNull(rtrB._getRawCharacterStyle());
-//             assertNull(rtrB._getRawParagraphStyle());
+               HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+               assertEquals(HSLFTextParagraph.getText(trB), rtrB.getRawText());
 
                // Change text via normal
-//             trB.setText("Test Foo Test");
-               rtrB = trB.getTextRuns().get(0);
-//             assertEquals("Test Foo Test", trB.getRawText());
-//             assertEquals("Test Foo Test", rtrB.getRawText());
-//             assertNull(rtrB._getRawCharacterStyle());
-//             assertNull(rtrB._getRawParagraphStyle());
+               HSLFTextParagraph.setText(trB, "Test Foo Test");
+               rtrB = trB.get(0).getTextRuns().get(0);
+               assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
+               assertEquals("Test Foo Test", rtrB.getRawText());
        }
 
        /**
@@ -293,13 +277,13 @@ public final class TestTextRun {
        @Test
        public void testSetTextWhereRich() {
                HSLFSlide slideOne = ssRich.getSlides().get(0);
-               List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
-               HSLFTextParagraph trB = textRuns.get(1);
-               assertEquals(3, trB.getTextRuns().size());
+               List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+               List<HSLFTextParagraph> trB = textParass.get(1);
+               assertEquals(3, trB.size());
 
-               HSLFTextRun rtrB = trB.getTextRuns().get(0);
-               HSLFTextRun rtrC = trB.getTextRuns().get(1);
-               HSLFTextRun rtrD = trB.getTextRuns().get(2);
+               HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+               HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+               HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
 //             TextPropCollection tpBP = rtrB._getRawParagraphStyle();
 //             TextPropCollection tpBC = rtrB._getRawCharacterStyle();
 //             TextPropCollection tpCP = rtrC._getRawParagraphStyle();
@@ -342,8 +326,8 @@ public final class TestTextRun {
        @Test
        public void testChangeTextInRichTextRunNonRich() {
                HSLFSlide slideOne = ss.getSlides().get(0);
-               List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
-               HSLFTextParagraph trB = textRuns.get(1);
+               List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
+               List<HSLFTextParagraph> trB = textRuns.get(1);
 //             assertEquals(1, trB.getTextRuns().length);
 //
 //             HSLFTextRun rtrB = trB.getTextRuns().get(0);
@@ -368,15 +352,15 @@ public final class TestTextRun {
        @Test
        public void testChangeTextInRichTextRun() {
                HSLFSlide slideOne = ssRich.getSlides().get(0);
-               List<HSLFTextParagraph> textRuns = slideOne.getTextParagraphs();
-               HSLFTextParagraph trB = textRuns.get(1);
-               assertEquals(3, trB.getTextRuns().size());
+               List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+               List<HSLFTextParagraph> trB = textParass.get(1);
+               assertEquals(3, trB.size());
 
                // We start with 3 text runs, each with their own set of styles,
                //  but all sharing the same paragraph styles
-               HSLFTextRun rtrB = trB.getTextRuns().get(0);
-               HSLFTextRun rtrC = trB.getTextRuns().get(1);
-               HSLFTextRun rtrD = trB.getTextRuns().get(2);
+               HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+               HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+               HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
 //             TextPropCollection tpBP = rtrB._getRawParagraphStyle();
 //             TextPropCollection tpBC = rtrB._getRawCharacterStyle();
 //             TextPropCollection tpCP = rtrC._getRawParagraphStyle();
@@ -400,8 +384,8 @@ public final class TestTextRun {
 //             assertFalse(tpCC.equals(tpDC));
 
                // Check text in the rich runs
-               assertEquals("This is the subtitle, in bold\n", rtrB.getRawText());
-               assertEquals("This bit is blue and italic\n", rtrC.getRawText());
+               assertEquals("This is the subtitle, in bold\r", rtrB.getRawText());
+               assertEquals("This bit is blue and italic\r", rtrC.getRawText());
                assertEquals("This bit is red (normal)", rtrD.getRawText());
 
                String newBText = "New Subtitle, will still be bold\n";
@@ -452,23 +436,24 @@ public final class TestTextRun {
 
                HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug-41015.ppt"));
                HSLFSlide sl = ppt.getSlides().get(0);
-               List<HSLFTextParagraph> txt = sl.getTextParagraphs();
-               assertEquals(2, txt.size());
-
-               rt = txt.get(0).getTextRuns();
+        List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
+               assertEquals(2, textParass.size());
+               
+               List<HSLFTextParagraph> textParas = textParass.get(0);
+               rt = textParass.get(0).get(0).getTextRuns();
                assertEquals(1, rt.size());
-               assertEquals(0, txt.get(0).getIndentLevel());
+               assertEquals(0, textParass.get(0).get(0).getIndentLevel());
                assertEquals("sdfsdfsdf", rt.get(0).getRawText());
 
-               rt = txt.get(1).getTextRuns();
-               assertEquals(2, rt.size());
-               assertEquals(0, txt.get(0).getIndentLevel());
-               assertEquals("Sdfsdfsdf\n" +
-                               "Dfgdfg\n" +
-                               "Dfgdfgdfg\n", rt.get(0).getRawText());
-               assertEquals(1, txt.get(1).getIndentLevel());
-               assertEquals("Sdfsdfs\n" +
-                               "Sdfsdf\n", rt.get(1).getRawText());
+               textParas = textParass.get(1);
+               String texts[] = {"Sdfsdfsdf\r","Dfgdfg\r","Dfgdfgdfg\r","Sdfsdfs\r","Sdfsdf\r"};
+               int indents[] = {0,0,0,1,1};
+               int i=0;
+               for (HSLFTextParagraph p : textParas) {
+                   assertEquals(texts[i], p.getTextRuns().get(0).getRawText());
+                   assertEquals(indents[i], p.getIndentLevel());
+                   i++;
+               }
        }
 
        /**
@@ -479,7 +464,7 @@ public final class TestTextRun {
                HSLFSlideShow ppt = new HSLFSlideShow();
                HSLFSlide slide = ppt.createSlide();
 
-               assertNull(slide.getTextParagraphs());
+               assertEquals(0, slide.getTextParagraphs().size());
 
                HSLFTextBox shape1 = new HSLFTextBox();
 //             HSLFTextParagraph run1 = shape1.getTextParagraphs();
@@ -565,17 +550,14 @@ public final class TestTextRun {
        public void test52244() throws IOException {
         HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52244.ppt"));
         HSLFSlide slide = ppt.getSlides().get(0);
-        List<HSLFTextParagraph> runs = slide.getTextParagraphs();
-
-        assertEquals("Arial", runs.get(0).getTextRuns().get(0).getFontFamily());
-        assertEquals(36, runs.get(0).getTextRuns().get(0).getFontSize(), 0);
-
-        assertEquals("Arial", runs.get(1).getTextRuns().get(0).getFontFamily());
-        assertEquals(24, runs.get(1).getTextRuns().get(0).getFontSize(), 0);
-
-        assertEquals("Arial", runs.get(2).getTextRuns().get(0).getFontFamily());
-        assertEquals(32, runs.get(2).getTextRuns().get(0).getFontSize(), 0);
 
+        int sizes[] = { 36, 24, 12, 32, 12, 12 };
+        
+        int i=0;
+        for (List<HSLFTextParagraph> textParas : slide.getTextParagraphs()) {
+            assertEquals("Arial", textParas.get(0).getTextRuns().get(0).getFontFamily());
+            assertEquals(sizes[i++], (int)textParas.get(0).getTextRuns().get(0).getFontSize());
+        }
     }
 
 }
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java
new file mode 100644 (file)
index 0000000..07a1a68
--- /dev/null
@@ -0,0 +1,213 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.usermodel;
+
+import static org.junit.Assert.*;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.sl.usermodel.ShapeType;
+import org.junit.Test;
+
+/**
+ * Verify behavior of <code>TextShape</code> and its sub-classes
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestTextShape {
+    private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+
+    @Test
+    public void createAutoShape(){
+        HSLFTextShape shape = new HSLFAutoShape(ShapeType.TRAPEZOID);
+        assertNull(shape.getEscherTextboxWrapper());
+        assertNotNull(shape.getTextParagraphs());
+        assertNotNull(shape.getEscherTextboxWrapper());
+        assertEquals("", shape.getText());
+        assertEquals(-1, shape.getTextParagraphs().get(0).getIndex());
+    }
+
+    @Test
+    public void createTextBox(){
+        HSLFTextShape shape = new HSLFTextBox();
+        List<HSLFTextParagraph> paras = shape.getTextParagraphs();
+        assertNotNull(paras);
+        assertNotNull(shape.getText());
+        assertNotNull(shape.getEscherTextboxWrapper());
+
+        assertNotNull(shape.getTextParagraphs());
+        assertNotNull(shape.getEscherTextboxWrapper());
+        assertEquals("", shape.getText());
+
+    }
+
+    /**
+     * Verify we can get text from TextShape in the following cases:
+     *  - placeholders
+     *  - normal TextBox object
+     *  - text in auto-shapes
+     */
+    @Test
+    public void read() throws IOException {
+        HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text_shapes.ppt"));
+
+        List<String> lst1 = new ArrayList<String>();
+        HSLFSlide slide = ppt.getSlides().get(0);
+        for (HSLFShape shape : slide.getShapes()) {
+            assertTrue("Expected TextShape but found " + shape.getClass().getName(), shape instanceof HSLFTextShape);
+            HSLFTextShape tx = (HSLFTextShape)shape;
+            List<HSLFTextParagraph> paras = tx.getTextParagraphs();
+            assertNotNull(paras);
+            int runType = paras.get(0).getRunType();
+
+            ShapeType type = shape.getShapeType();
+            String rawText = HSLFTextParagraph.getRawText(paras);
+            switch (type){
+                case TEXT_BOX:
+                    assertEquals("Text in a TextBox", rawText);
+                    break;
+                case RECT:
+                    if(runType == TextHeaderAtom.OTHER_TYPE)
+                        assertEquals("Rectangle", rawText);
+                    else if(runType == TextHeaderAtom.TITLE_TYPE)
+                        assertEquals("Title Placeholder", rawText);
+                    break;
+                case OCTAGON:
+                    assertEquals("Octagon", rawText);
+                    break;
+                case ELLIPSE:
+                    assertEquals("Ellipse", rawText);
+                    break;
+                case ROUND_RECT:
+                    assertEquals("RoundRectangle", rawText);
+                    break;
+                default:
+                    fail("Unexpected shape: " + shape.getShapeName());
+
+            }
+            lst1.add(rawText);
+        }
+
+        List<String> lst2 = new ArrayList<String>();
+        for (List<HSLFTextParagraph> paras : slide.getTextParagraphs()) {
+            lst2.add(HSLFTextParagraph.getRawText(paras));
+        }
+
+        assertTrue(lst1.containsAll(lst2));
+    }
+
+    @Test
+    public void readWrite() throws IOException {
+        HSLFSlideShow ppt = new HSLFSlideShow();
+        HSLFSlide slide =  ppt.createSlide();
+
+        HSLFTextShape shape1 = new HSLFTextBox();
+        shape1.setText("Hello, World!");
+        slide.addShape(shape1);
+
+        shape1.moveTo(100, 100);
+
+        HSLFTextShape shape2 = new HSLFAutoShape(ShapeType.RIGHT_ARROW);
+        shape2.setText("Testing TextShape");
+        slide.addShape(shape2);
+        shape2.moveTo(300, 300);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ppt.write(out);
+        out.close();
+
+        ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
+        slide = ppt.getSlides().get(0);
+        List<HSLFShape> shape = slide.getShapes();
+
+        assertTrue(shape.get(0) instanceof HSLFTextShape);
+        shape1 = (HSLFTextShape)shape.get(0);
+        assertEquals(ShapeType.TEXT_BOX, shape1.getShapeType());
+        assertEquals("Hello, World!", shape1.getText());
+
+        assertTrue(shape.get(1) instanceof HSLFTextShape);
+        shape1 = (HSLFTextShape)shape.get(1);
+        assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType());
+        assertEquals("Testing TextShape", shape1.getText());
+    }
+
+    @Test
+    public void margins() throws IOException {
+        HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text-margins.ppt"));
+
+        HSLFSlide slide = ppt.getSlides().get(0);
+
+        Map<String,HSLFTextShape> map = new HashMap<String,HSLFTextShape>();
+        for (HSLFShape shape : slide.getShapes()) {
+            if(shape instanceof HSLFTextShape){
+                HSLFTextShape tx = (HSLFTextShape)shape;
+                map.put(tx.getText(), tx);
+            }
+        }
+
+        HSLFTextShape tx;
+
+        tx = map.get("TEST1");
+        assertEquals(0.1, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.1, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.39, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.05, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+
+        tx = map.get("TEST2");
+        assertEquals(0.1, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.1, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.05, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.39, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+
+        tx = map.get("TEST3");
+        assertEquals(0.39, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.1, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.05, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.05, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+
+        tx = map.get("TEST4");
+        assertEquals(0.1, tx.getLeftInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.39, tx.getRightInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.05, tx.getTopInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+        assertEquals(0.05, tx.getBottomInset()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
+    }
+
+    @Test
+    public void bug52599() throws IOException {
+        HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52599.ppt"));
+
+        HSLFSlide slide = ppt.getSlides().get(0);
+        List<HSLFShape> sh = slide.getShapes();
+        assertEquals(3, sh.size());
+
+        HSLFTextShape sh0 = (HSLFTextShape)sh.get(0);
+        assertNotNull(sh0.getTextParagraphs());
+        assertEquals("", sh0.getText());
+
+        HSLFTextShape sh1 = (HSLFTextShape)sh.get(1);
+        assertNotNull(sh1.getTextParagraphs());
+        assertEquals("", sh1.getText());
+
+        HSLFTextShape sh2 = (HSLFTextShape)sh.get(2);
+        assertEquals("this box should be shown just once", sh2.getText());
+        assertEquals(-1, sh2.getTextParagraphs().get(0).getIndex());
+    }
+}