From: Nick Burch Date: Tue, 26 Sep 2006 11:19:30 +0000 (+0000) Subject: Handle the case where a StyleTextPropAtom has a mask that codes for more properties... X-Git-Tag: REL_3_0_ALPHA3~30 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c41a5148eb8a4aed857cabd69e56a61d21753e5f;p=poi.git Handle the case where a StyleTextPropAtom has a mask that codes for more properties than we have data for (+tests for this) git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@449983 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index 8ab88c69e3..3e99ccbf48 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -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= 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 index 0000000000..976fa94b6a Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt differ diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java index 83e4636a94..6f860d5645 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java @@ -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 + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java index ada75fdfd9..239b75d7a0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java @@ -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()); + } }