You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/08/12 09:15:27 UTC

svn commit: r685064 - in /poi/trunk/src: documentation/content/xdocs/ scratchpad/src/org/apache/poi/hslf/model/ scratchpad/testcases/org/apache/poi/hslf/model/

Author: yegor
Date: Tue Aug 12 00:15:26 2008
New Revision: 685064

URL: http://svn.apache.org/viewvc?rev=685064&view=rev
Log:
Properly update the array of Slide's text runs in HSLF when new text shapes are added

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

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=685064&r1=685063&r2=685064&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Tue Aug 12 00:15:26 2008
@@ -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>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=685064&r1=685063&r2=685064&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Aug 12 00:15:26 2008
@@ -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>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java?rev=685064&r1=685063&r2=685064&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java Tue Aug 12 00:15:26 2008
@@ -364,6 +364,16 @@
     }
 
     /**
+     * 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
      *
      * @param type  type of text, See {@link org.apache.poi.hslf.record.TextHeaderAtom}
@@ -440,5 +450,4 @@
 
     }
 
-
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java?rev=685064&r1=685063&r2=685064&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java Tue Aug 12 00:15:26 2008
@@ -460,4 +460,16 @@
             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;
+        }
+    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java?rev=685064&r1=685063&r2=685064&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java Tue Aug 12 00:15:26 2008
@@ -129,33 +129,15 @@
         }
     }
 
-    /**
-     * 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;
     }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java?rev=685064&r1=685063&r2=685064&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java Tue Aug 12 00:15:26 2008
@@ -199,6 +199,10 @@
             }
             if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();
         }
+        if(_txtrun != null) {
+            _txtrun.setShapeId(getShapeId());
+            sh.onAddTextShape(this);
+        }
     }
 
     protected EscherTextboxWrapper getEscherTextboxWrapper(){

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java?rev=685064&r1=685063&r2=685064&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java Tue Aug 12 00:15:26 2008
@@ -445,4 +445,55 @@
 		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);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org