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);
// 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) {
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;
* @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
};
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
};
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());
}
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
+ }
}
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());
+ }
}