From ccc494626e8d948a0becf8df2a8f5a3fdb5be116 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 26 Sep 2006 15:53:21 +0000 Subject: [PATCH] Fix for NPE in bug #40036. The TextBox will still be fairly useless though git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@450097 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hslf/model/TextBox.java | 45 ++++++++++++++---- .../apache/poi/hslf/data/empty_textbox.ppt | Bin 0 -> 11776 bytes .../org/apache/poi/hslf/model/TestShapes.java | 17 +++++++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/data/empty_textbox.ppt diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java index 755dd4d98..44cee7c0e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java @@ -84,6 +84,12 @@ public class TextBox extends SimpleShape { * TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc. */ protected EscherTextboxWrapper _txtbox; + + /** + * Is the TextBox missing the text records which actually + * store the text? + */ + private boolean _missingTextRecords = false; /** * Create a TextBox object and initialize it from the supplied Record container. @@ -544,10 +550,20 @@ public class TextBox extends SimpleShape { public void setSheet(Sheet sheet){ _sheet = sheet; - //initialize _txtrun object. - //we can't do it in the constructor because the sheet is not assigned yet + // Initialize _txtrun object. + // (We can't do it in the constructor because the sheet + // is not assigned then, it's only built once we have + // all the records) if(_txtrun == null) initTextRun(); - + if(_txtrun == null) { + // No text records found, skip + _missingTextRecords = true; + return; + } else { + _missingTextRecords = false; + } + + // Supply the sheet to our child RichTextRuns RichTextRun[] rt = _txtrun.getRichTextRuns(); for (int i = 0; i < rt.length; i++) { rt[i].supplySlideShow(_sheet.getSlideShow()); @@ -555,12 +571,13 @@ public class TextBox extends SimpleShape { } private void initTextRun(){ - TextHeaderAtom tha = null; TextCharsAtom tca = null; TextBytesAtom tba = null; StyleTextPropAtom sta = null; OutlineTextRefAtom ota = null; + + // Find the interesting child records Record[] child = _txtbox.getChildRecords(); for (int i = 0; i < child.length; i++) { if (child[i] instanceof TextHeaderAtom) tha = (TextHeaderAtom)child[i]; @@ -570,8 +587,10 @@ public class TextBox extends SimpleShape { else if (child[i] instanceof TextCharsAtom) tca = (TextCharsAtom)child[i]; } - if (ota != null){ - //TextHeaderAtom, TextBytesAtom and StyleTextPropAtom are stored outside of EscherContainerRecord + // Special handling for cases where there's an OutlineTextRefAtom + if (ota != null) { + // TextHeaderAtom, TextBytesAtom and StyleTextPropAtom are + // stored outside of EscherContainerRecord int idx = ota.getTextIndex(); Slide sl = (Slide)getSheet(); Record[] rec = sl.getSlideAtomsSet().getSlideRecords(); @@ -591,7 +610,17 @@ public class TextBox extends SimpleShape { } } } - if(tba != null) _txtrun = new TextRun(tha,tba,sta); - else if (tca != null) _txtrun = new TextRun(tha,tca,sta); + + // If we found the records we needed, create a TextRun + if(tba != null) { + // Bytes based Text Run + _txtrun = new TextRun(tha,tba,sta); + } else if (tca != null) { + // Characters (unicode) based Text Run + _txtrun = new TextRun(tha,tca,sta); + } else { + // Empty text box + System.err.println("Warning - no text records found for TextBox"); + } } } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/empty_textbox.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/empty_textbox.ppt new file mode 100644 index 0000000000000000000000000000000000000000..403b2861e28b0402924b5b17d9a046ce1411a037 GIT binary patch literal 11776 zcmeHN4UAOP6+Z91S#}n7dBe`GAX<2(L}`n-y2fZUFxG|ITFZvTM2*#1cW2m%yE|lN z5J8P&O)XVe*FdmqTLo+zq|#z*+W6B-BL38_5v?|u5T%jU-_+4s{6nVSckaC1+1VZ3 zO%NgBPR_gk=kK0#&%N)>&gUlW+4#WJe@aQ3D~=qP^{K&x`j^7_P z^$KZGI$hGLvVRBk;-H=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