]> source.dussan.org Git - poi.git/commitdiff
Properly update the array of Slide's text runs in HSLF when new text shapes are added
authorYegor Kozlov <yegor@apache.org>
Tue, 12 Aug 2008 07:15:26 +0000 (07:15 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 12 Aug 2008 07:15:26 +0000 (07:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@685064 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
src/scratchpad/src/org/apache/poi/hslf/model/Slide.java
src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java
src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java

index 985db6ab9f255e841ae91c7c87a28fc7ba377df7..e290d73df8d2c2739835d6f27bfd121418521ccf 100644 (file)
@@ -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>
index d762f1e5a5173d465e87151ca3c2a5ae1f023742..9a6810660c6b4036d899e9286a8387ef2ea2898d 100644 (file)
@@ -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>
index ccbc03829fae15b0a98725b78edc3f58f5ee2063..c4d542aa0567e2811267316dcc3308deb7855357 100644 (file)
@@ -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 {
 
     }
 
-
 }
index c524f31f70a2811fd1d04827f5651b546a3fd7e2..8acbca5ac93e47f81d9a0de35c6c9cf8e07946a5 100644 (file)
@@ -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;
+        }
+    }
 }
index b48edfc1a1b40bc08a4e575e00fca5bea4004d4d..b30a46e38a7dc317fc481ca92cd106621b12e2c7 100644 (file)
@@ -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;
-
-        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;
-
-            }
-
+    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;
         }
-        return false;
     }
 }
index a9975ab370bd83c9c2b1c856f678d3c6637ce7f9..de78b62656289d4a76a94008b06b08abfabe542c 100755 (executable)
@@ -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(){
index 7b75c3676cd4beb511cadf3823603f73934c1ce4..6463da4c317b1daa993e588bd26d88c17772d4b3 100644 (file)
@@ -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);
+    }
 }