*/
protected static void findTextRuns(Record[] records, Vector found) {
// Look for a TextHeaderAtom
- for (int i = 0; i < (records.length - 1); i++) {
+ for (int i = 0, slwtIndex=0; i < (records.length - 1); i++) {
if (records[i] instanceof TextHeaderAtom) {
TextRun trun = null;
TextHeaderAtom tha = (TextHeaderAtom) records[i];
// TextSpecInfoAtom - Safe to ignore
} else {
System.err.println("Found a TextHeaderAtom not followed by a TextBytesAtom or TextCharsAtom: Followed by " + records[i + 1].getRecordType());
- continue;
}
if (trun != null) {
Record[] recs = new Record[lst.size()];
lst.toArray(recs);
trun._records = recs;
+ trun.setIndex(slwtIndex);
found.add(trun);
i++;
} else {
// Not a valid one, so skip on to next and look again
}
+ slwtIndex++;
}
}
}
} catch (IOException e){
throw new HSLFException(e);
}
- if(getAnchor().equals(new java.awt.Rectangle())) resizeToFitText();
+ if(getAnchor().equals(new java.awt.Rectangle()) && !"".equals(getText())) resizeToFitText();
}
/**
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
setEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT, align);
}
+
+ public void setHorizontalAlignment(int align){
+ _txtrun.getRichTextRuns()[0].setAlignment(align);
+ }
+ public int getHorizontalAlignment(){
+ return _txtrun.getRichTextRuns()[0].getAlignment();
+ }
+
/**
* Returns the distance (in points) between the bottom of the text frame
* and the bottom of the inscribed rectangle of the shape that contains the text.
TextRun[] runs = sheet.getTextRuns();
if (ota != null) {
int idx = ota.getTextIndex();
- if(idx < runs.length) _txtrun = runs[idx];
+ for (int i = 0; i < runs.length; i++) {
+ if(runs[i].getIndex() == idx){
+ _txtrun = runs[i];
+ }
+ }
if(_txtrun == null) {
logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
}
private SlideShow slideShow;
private Sheet sheet;
private int shapeId;
+ private int slwtIndex; //position in the owning SlideListWithText
/**
* all text run records that follow TextHeaderAtom.
* (there can be misc InteractiveInfo, TxInteractiveInfo and other records)
shapeId = id;
}
+ /**
+ * @return 0-based index of the text run in the SLWT container
+ */
+ protected int getIndex(){
+ return slwtIndex;
+ }
+
+ /**
+ * @param id 0-based index of the text run in the SLWT container
+ */
+ protected void setIndex(int id){
+ slwtIndex = id;
+ }
+
/**
* Returns the array of all hyperlinks in this text run
*
import java.io.*;\r
import java.util.HashSet;\r
import java.util.HashMap;\r
+import java.util.ArrayList;\r
import java.awt.*;\r
\r
/**\r
\r
}\r
\r
+ /**\r
+ * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.\r
+ * ( also fixed followup: getTextRuns() returns no text )\r
+ */\r
+ public void test43781 () throws Exception {\r
+ FileInputStream is = new FileInputStream(new File(cwd, "43781.ppt"));\r
+ SlideShow ppt = new SlideShow(is);\r
+ is.close();\r
+\r
+ assertTrue("No Exceptions while reading file", true);\r
+\r
+ Slide slide = ppt.getSlides()[0];\r
+ TextRun[] tr1 = slide.getTextRuns();\r
+\r
+ ArrayList lst = new ArrayList();\r
+ Shape[] shape = slide.getShapes();\r
+ for (int i = 0; i < shape.length; i++) {\r
+ if( shape[i] instanceof TextBox){\r
+ TextRun textRun = ((TextBox)shape[i]).getTextRun();\r
+ if(textRun != null) lst.add(textRun);\r
+ }\r
+\r
+ }\r
+ TextRun[] tr2 = new TextRun[lst.size()];\r
+ lst.toArray(tr2);\r
+\r
+ assertEquals(tr1.length, tr2.length);\r
+ for (int i = 0; i < tr1.length; i++) {\r
+ assertEquals(tr1[i].getText(), tr2[i].getText());\r
+ }\r
+ }\r
}\r