Properly update the array of Slide's text runs in HSLF when new text shapes are added
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@685064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d92587222d
commit
2e33f41e90
@ -37,6 +37,7 @@
|
||||
|
||||
<!-- Don't forget to update status.xml too! -->
|
||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
||||
<action dev="POI-DEVELOPERS" type="fix">Properly update the array of Slide's text runs in HSLF when new text shapes are added</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45590 - Fix for Header/footer extraction for .ppt files saved in Office 2007</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">Big improvement in how HWPF handles unicode text, and more sanity checking of text ranges within HWPF</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Include headers and footers int he extracted text from HWPF's WordExtractor</action>
|
||||
|
@ -34,6 +34,7 @@
|
||||
<!-- Don't forget to update changes.xml too! -->
|
||||
<changes>
|
||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
||||
<action dev="POI-DEVELOPERS" type="fix">Properly update the array of Slide's text runs in HSLF when new text shapes are added</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45590 - Fix for Header/footer extraction for .ppt files saved in Office 2007</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">Big improvement in how HWPF handles unicode text, and more sanity checking of text ranges within HWPF</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Include headers and footers int he extracted text from HWPF's WordExtractor</action>
|
||||
|
@ -363,6 +363,16 @@ public abstract class Sheet {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should call this method and update the array of text runs
|
||||
* when a text shape is added
|
||||
*
|
||||
* @param shape
|
||||
*/
|
||||
protected void onAddTextShape(TextShape shape) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return placeholder by text type
|
||||
*
|
||||
@ -440,5 +450,4 @@ public abstract class Sheet {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -460,4 +460,16 @@ public class Slide extends Sheet
|
||||
return new HeadersFooters(hdd, this, newRecord, ppt2007);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onAddTextShape(TextShape shape) {
|
||||
TextRun run = shape.getTextRun();
|
||||
|
||||
if(_runs == null) _runs = new TextRun[]{run};
|
||||
else {
|
||||
TextRun[] tmp = new TextRun[_runs.length + 1];
|
||||
System.arraycopy(_runs, 0, tmp, 0, _runs.length);
|
||||
tmp[tmp.length-1] = run;
|
||||
_runs = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,33 +129,15 @@ public class SlideMaster extends MasterSheet {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shape is a placeholder.
|
||||
* (placeholders aren't normal shapes, they are visible only in the Edit Master mode)
|
||||
*
|
||||
*
|
||||
* @return true if the shape is a placeholder
|
||||
*/
|
||||
public static boolean isPlaceholder(Shape shape){
|
||||
if(!(shape instanceof TextShape)) return false;
|
||||
protected void onAddTextShape(TextShape shape) {
|
||||
TextRun run = shape.getTextRun();
|
||||
|
||||
TextShape tx = (TextShape)shape;
|
||||
TextRun run = tx.getTextRun();
|
||||
if(run == null) return false;
|
||||
|
||||
Record[] records = run._records;
|
||||
for (int i = 0; i < records.length; i++) {
|
||||
int type = (int)records[i].getRecordType();
|
||||
if (type == RecordTypes.OEPlaceholderAtom.typeID ||
|
||||
type == RecordTypes.SlideNumberMCAtom.typeID ||
|
||||
type == RecordTypes.DateTimeMCAtom.typeID ||
|
||||
type == RecordTypes.GenericDateMCAtom.typeID ||
|
||||
type == RecordTypes.FooterMCAtom.typeID ){
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
if(_runs == null) _runs = new TextRun[]{run};
|
||||
else {
|
||||
TextRun[] tmp = new TextRun[_runs.length + 1];
|
||||
System.arraycopy(_runs, 0, tmp, 0, _runs.length);
|
||||
tmp[tmp.length-1] = run;
|
||||
_runs = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -199,6 +199,10 @@ public abstract class TextShape extends SimpleShape {
|
||||
}
|
||||
if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();
|
||||
}
|
||||
if(_txtrun != null) {
|
||||
_txtrun.setShapeId(getShapeId());
|
||||
sh.onAddTextShape(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected EscherTextboxWrapper getEscherTextboxWrapper(){
|
||||
|
@ -445,4 +445,55 @@ public class TestTextRun extends TestCase {
|
||||
assertEquals("Sdfsdfs\n" +
|
||||
"Sdfsdf\n", rt[1].getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation of TextRun objects.
|
||||
*/
|
||||
public void testAddTextRun() throws Exception{
|
||||
SlideShow ppt = new SlideShow();
|
||||
Slide slide = ppt.createSlide();
|
||||
|
||||
assertNull(slide.getTextRuns());
|
||||
|
||||
TextBox shape1 = new TextBox();
|
||||
TextRun run1 = shape1.getTextRun();
|
||||
assertSame(run1, shape1.createTextRun());
|
||||
run1.setText("Text 1");
|
||||
slide.addShape(shape1);
|
||||
|
||||
//The array of Slide's text runs must be updated when new text shapes are added.
|
||||
TextRun[] runs = slide.getTextRuns();
|
||||
assertNotNull(runs);
|
||||
assertSame(run1, runs[0]);
|
||||
|
||||
TextBox shape2 = new TextBox();
|
||||
TextRun run2 = shape2.getTextRun();
|
||||
assertSame(run2, shape2.createTextRun());
|
||||
run2.setText("Text 2");
|
||||
slide.addShape(shape2);
|
||||
|
||||
runs = slide.getTextRuns();
|
||||
assertEquals(2, runs.length);
|
||||
|
||||
assertSame(run1, runs[0]);
|
||||
assertSame(run2, runs[1]);
|
||||
|
||||
//as getShapes()
|
||||
Shape[] sh = slide.getShapes();
|
||||
assertEquals(2, sh.length);
|
||||
assertTrue(sh[0] instanceof TextBox);
|
||||
TextBox box1 = (TextBox)sh[0];
|
||||
assertSame(run1, box1.getTextRun());
|
||||
TextBox box2 = (TextBox)sh[1];
|
||||
assertSame(run2, box2.getTextRun());
|
||||
|
||||
//test Table - a complex group of shapes containing text objects
|
||||
Slide slide2 = ppt.createSlide();
|
||||
assertNull(slide2.getTextRuns());
|
||||
Table table = new Table(2, 2);
|
||||
slide2.addShape(table);
|
||||
runs = slide2.getTextRuns();
|
||||
assertNotNull(runs);
|
||||
assertEquals(4, runs.length);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user