]> source.dussan.org Git - poi.git/commitdiff
Handle the case where a StyleTextPropAtom has a mask that codes for more properties...
authorNick Burch <nick@apache.org>
Tue, 26 Sep 2006 11:19:30 +0000 (11:19 +0000)
committerNick Burch <nick@apache.org>
Tue, 26 Sep 2006 11:19:30 +0000 (11:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@449983 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java

index 8ab88c69e377d8e54201d08016e4ef29e84f45ab..3e99ccbf48db6f1e0a846ae04f386206e0a2246c 100644 (file)
@@ -266,6 +266,7 @@ public class StyleTextPropAtom extends RecordAtom
                        pos += 4;
 
                        // Now make sense of those properties
+                       // (Assuming we actually have some)
                        TextPropCollection thisCollection = new TextPropCollection(textLen, no_val);
                        int chSize = thisCollection.buildTextPropList(
                                        charFlags, characterTextPropTypes, rawContents, pos);
@@ -411,8 +412,15 @@ public class StyleTextPropAtom extends RecordAtom
                        // For each possible entry, see if we match the mask
                        // If we do, decode that, save it, and shuffle on
                        for(int i=0; i<potentialProperties.length; i++) {
+                               // Check there's still data left to read
+                               if(dataOffset+bytesPassed >= data.length) {
+                                       // Out of data, can't be any more properties to go
+                                       return bytesPassed;
+                               }
+                               
+                               // Check if this property is found in the mask
                                if((containsField & potentialProperties[i].getMask()) != 0) {
-                                       // Bingo, contained
+                                       // Bingo, data contains this property
                                        TextProp prop = (TextProp)potentialProperties[i].clone();
                                        int val = 0;
                                        if(prop.getSize() == 2) {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt
new file mode 100644 (file)
index 0000000..976fa94
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt differ
index 83e4636a94e7663163da5e074e10d93357f281e1..6f860d5645c1c71ac699effac4e91892b9071685 100644 (file)
@@ -19,7 +19,9 @@
 
 package org.apache.poi.hslf.record;
 
+import org.apache.poi.hslf.HSLFSlideShow;
 import org.apache.poi.hslf.record.StyleTextPropAtom.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
 
 import junit.framework.TestCase;
 import java.io.ByteArrayOutputStream;
@@ -31,7 +33,7 @@ import java.util.LinkedList;
  * @author Nick Burch (nick at torchbox dot com)
  */
 public class TestStyleTextPropAtom extends TestCase {
-       // From a real file: a paragraph with 4 different styles
+       /** From a real file: a paragraph with 4 different styles */
        private byte[] data_a = new byte[] { 
          0, 0, 0xA1-256, 0x0F, 0x2A, 0, 0, 0,
       0x36, 00, 00, 00, // paragraph is 54 long 
@@ -48,12 +50,14 @@ public class TestStyleTextPropAtom extends TestCase {
        };
        private int data_a_text_len = 54;
 
-       // From a real file: 4 paragraphs with text in 4 different styles:
-       // left aligned+bold (30)
-       // centre aligned+italic+blue (28)
-       // right aligned+red (25)
-       // left aligned+underlined+larger font size (96)
-       // left aligned+underlined+larger font size+red (1)
+       /** 
+        * From a real file: 4 paragraphs with text in 4 different styles:
+        * left aligned+bold (30)
+        * centre aligned+italic+blue (28)
+        * right aligned+red (25)
+        * left aligned+underlined+larger font size (96)
+        * left aligned+underlined+larger font size+red (1)
+        */
        private byte[] data_b = new byte[] { 
                0, 0, 0xA1-256, 0x0F, 0x80-256, 0, 0, 0, 
                0x1E, 00, 00, 00,     // paragraph is 30 long 
@@ -104,12 +108,32 @@ public class TestStyleTextPropAtom extends TestCase {
        };
        private int data_b_text_len = 0xB3;
        
+       /**
+        * From a real file. Has a mask with more bits
+        *  set than it actually has data for. Shouldn't do,
+        *  but some real files do :(
+        */
+       private byte[] data_c = new byte[] {
+               0, 0, -95, 15, 62, 0, 0, 0,
+               123, 0, 0, 0, 0, 0, 48, 8, 
+               10, 0, 1, 0, 0, 0, 0, 0, 
+               1, 0, 2, 0, 1, 0, 0, 0, 
+               0, 0, 48, 0, 10, 0, 1, 0, 
+               0, 0, 0, 0, 2, 0, 123, 0, 
+               0, 0, 0, 0, 3, 0, 1, 0, 
+               28, 0, 1, 0, 0, 0, 0, 0, 
+               3, 0, 1, 0, 24, 0
+       };
+       private int data_c_text_len = 123;
 
+       
     public void testRecordType() throws Exception {
                StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
                StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+               StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
                assertEquals(4001l, stpa.getRecordType());
                assertEquals(4001l, stpb.getRecordType());
+               assertEquals(4001l, stpc.getRecordType());
        }
 
 
@@ -663,4 +687,15 @@ public class TestStyleTextPropAtom extends TestCase {
                        assertEquals(data_b[i],b[i]);
                }
        }
+       
+       
+       public void testNotEnoughDataProp() throws Exception {
+               // We don't have enough data in the record to cover
+               //  all the properties the mask says we have
+               // Make sure we just do the best we can
+               StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
+               stpc.setParentTextSize(data_c_text_len);
+               
+               // If we get here, we didn't break
+       }
 }
index ada75fdfd9c9243fa244a33df3779927cf5adcd0..239b75d7a0cfc1a7a9b4b64fe6564f2b1ba503bf 100644 (file)
@@ -58,4 +58,34 @@ public class TestSheetText extends TestCase {
                        assertEquals(expectText[i], slideTwo.getTextRuns()[i].getText());
                }
        }
+       
+       /**
+        * Check we can still get the text from a file where the
+        *  TextProps don't have enough data.
+        * (Make sure we don't screw up / throw an exception etc)
+        */
+       public void testWithShortTextPropData() throws Exception {
+               String dirname = System.getProperty("HSLF.testdata.path");
+               String filename = dirname + "/iisd_report.ppt";
+               HSLFSlideShow hss = new HSLFSlideShow(filename);
+               SlideShow sss = new SlideShow(hss);
+               
+               // Should come out with 10 slides, no notes
+               assertEquals(10, sss.getSlides().length);
+               assertEquals(0, sss.getNotes().length);
+               
+               // Check text on first slide
+               Slide s = sss.getSlides()[0];
+               String exp = 
+                       "Realizing the Development Dividend:\n" +
+                       "Community Capacity Building and CDM.\n" +
+                       "Can they co-exist?\n\n" +
+                       "Gay Harley\n" +
+                       "Clean Development Alliance\n" +
+                       "COP 11 – MOP 1\n" +
+                       "December 5, 2005\n";
+
+               assertEquals(1, s.getTextRuns().length);
+               assertEquals(exp, s.getTextRuns()[0].getText());
+       }
 }