* TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.\r
*/\r
protected EscherTextboxWrapper _txtbox;\r
+ \r
+ /**\r
+ * Is the TextBox missing the text records which actually\r
+ * store the text?\r
+ */\r
+ private boolean _missingTextRecords = false;\r
\r
/**\r
* Create a TextBox object and initialize it from the supplied Record container.\r
public void setSheet(Sheet sheet){\r
_sheet = sheet;\r
\r
- //initialize _txtrun object.\r
- //we can't do it in the constructor because the sheet is not assigned yet\r
+ // Initialize _txtrun object.\r
+ // (We can't do it in the constructor because the sheet\r
+ // is not assigned then, it's only built once we have\r
+ // all the records)\r
if(_txtrun == null) initTextRun();\r
-\r
+ if(_txtrun == null) {\r
+ // No text records found, skip\r
+ _missingTextRecords = true;\r
+ return;\r
+ } else {\r
+ _missingTextRecords = false;\r
+ }\r
+ \r
+ // Supply the sheet to our child RichTextRuns\r
RichTextRun[] rt = _txtrun.getRichTextRuns();\r
for (int i = 0; i < rt.length; i++) {\r
rt[i].supplySlideShow(_sheet.getSlideShow());\r
}\r
\r
private void initTextRun(){\r
-\r
TextHeaderAtom tha = null;\r
TextCharsAtom tca = null;\r
TextBytesAtom tba = null;\r
StyleTextPropAtom sta = null;\r
OutlineTextRefAtom ota = null;\r
+ \r
+ // Find the interesting child records \r
Record[] child = _txtbox.getChildRecords();\r
for (int i = 0; i < child.length; i++) {\r
if (child[i] instanceof TextHeaderAtom) tha = (TextHeaderAtom)child[i];\r
else if (child[i] instanceof TextCharsAtom) tca = (TextCharsAtom)child[i];\r
}\r
\r
- if (ota != null){\r
- //TextHeaderAtom, TextBytesAtom and StyleTextPropAtom are stored outside of EscherContainerRecord\r
+ // Special handling for cases where there's an OutlineTextRefAtom\r
+ if (ota != null) {\r
+ // TextHeaderAtom, TextBytesAtom and StyleTextPropAtom are\r
+ // stored outside of EscherContainerRecord\r
int idx = ota.getTextIndex();\r
Slide sl = (Slide)getSheet();\r
Record[] rec = sl.getSlideAtomsSet().getSlideRecords();\r
}\r
}\r
}\r
- if(tba != null) _txtrun = new TextRun(tha,tba,sta);\r
- else if (tca != null) _txtrun = new TextRun(tha,tca,sta);\r
+ \r
+ // If we found the records we needed, create a TextRun\r
+ if(tba != null) {\r
+ // Bytes based Text Run\r
+ _txtrun = new TextRun(tha,tba,sta);\r
+ } else if (tca != null) {\r
+ // Characters (unicode) based Text Run\r
+ _txtrun = new TextRun(tha,tca,sta);\r
+ } else {\r
+ // Empty text box\r
+ System.err.println("Warning - no text records found for TextBox");\r
+ }\r
}\r
}\r
*/\r
public class TestShapes extends TestCase {\r
private SlideShow ppt;\r
+ private SlideShow pptB;\r
\r
protected void setUp() throws Exception {\r
String dirname = System.getProperty("HSLF.testdata.path");\r
String filename = dirname + "/empty.ppt";\r
ppt = new SlideShow(new HSLFSlideShow(filename));\r
+ \r
+ String filenameB = dirname + "/empty_textbox.ppt";\r
+ pptB = new SlideShow(new HSLFSlideShow(filenameB));\r
}\r
\r
public void testGraphics() throws Exception {\r
assertEquals("Arial", rt.getFontName());\r
assertEquals(Color.red, txtbox.getFontColor());\r
}\r
+ \r
+ /**\r
+ * Test with an empty text box\r
+ */\r
+ public void testEmptyTextBox() throws Exception {\r
+ assertEquals(2, pptB.getSlides().length);\r
+ Slide s1 = pptB.getSlides()[0];\r
+ Slide s2 = pptB.getSlides()[1];\r
+ \r
+ // Check we can get the shapes count\r
+ assertEquals(2, s1.getShapes().length);\r
+ assertEquals(2, s2.getShapes().length);\r
+ }\r
\r
/**\r
* If you iterate over text shapes in a slide and collect them in a set\r