]> source.dussan.org Git - poi.git/commitdiff
propagate parent to parent-aware records decoded from Escher, also ensure that TextSh...
authorYegor Kozlov <yegor@apache.org>
Sat, 3 Apr 2010 14:44:39 +0000 (14:44 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 3 Apr 2010 14:44:39 +0000 (14:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@930525 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java
src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java

index 50bc1cd624d14f40329572ea503b399ba50c38d6..846614c880d6c2462e67543bc372d064bf539396 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">48916 - Propagate parent to parent-aware records decoded from Escher</action>
            <action dev="POI-DEVELOPERS" type="fix">48485 - Add extra paper size constans to PrintSetup, such as A3, B4 and B5</action>
            <action dev="POI-DEVELOPERS" type="fix">Make poifs.filesystem.DirectoryNode preserve the original ordering of its files, which HSMF needs to be able to correctly match up chunks</action>
            <action dev="POI-DEVELOPERS" type="add">Support evaluation of indirect defined names in INDIRECT</action>
index f42eb8429c53c048b300bc407d703e4d77c8ab14..e5246653958fe1cbf7702029cb027f1a136289b8 100644 (file)
@@ -126,6 +126,9 @@ public abstract class Sheet {
         EscherTextboxWrapper[] wrappers = ppdrawing.getTextboxWrappers();
         for (int i = 0; i < wrappers.length; i++) {
             int s1 = runsV.size();
+
+            // propagate parents to parent-aware records
+            RecordContainer.handleParentAwareRecords(wrappers[i]);
             findTextRuns(wrappers[i].getChildRecords(), runsV);
             int s2 = runsV.size();
             if (s2 != s1){
index a72e4658b7a2bca539d799751c8513584f45a641..5ebbb27fbabf77adfb8ad667ef4a5168a0707dcc 100644 (file)
@@ -140,4 +140,8 @@ public final class SlideMaster extends MasterSheet {
             _runs = tmp;
         }
     }
+
+    public TxMasterStyleAtom[] getTxMasterStyleAtoms(){
+        return _txmaster;
+    }
 }
index 5724e270fa9ba610ade86f8a7d6ab431e2232b1e..b1ae68f0591763c201f961834f87d0df0ff37821 100644 (file)
@@ -527,6 +527,14 @@ public abstract class TextShape extends SimpleShape {
                 }
             }
         }
+        // ensure the same references child records of TextRun
+        if(_txtrun != null) for (int i = 0; i < child.length; i++) {
+            for (Record r : _txtrun.getRecords()) {
+                if (child[i].getRecordType() == r.getRecordType()) {
+                    child[i] = r;
+                }
+            }
+        }
     }
 
     public void draw(Graphics2D graphics){
index 509c891ce7394fb715f1d8d965654a1a69ea1fcb..be732d44ca1c2522cbfed0cf95841f7f5190f1ed 100644 (file)
@@ -341,4 +341,23 @@ public abstract class RecordContainer extends Record
                        out.write(toWrite);
                }
        }
+
+    /**
+     * Find the records that are parent-aware, and tell them who their parent is
+     */
+    public static void handleParentAwareRecords(RecordContainer br) {
+        // Loop over child records, looking for interesting ones
+        for (Record record : br.getChildRecords()) {
+            // Tell parent aware records of their parent
+            if (record instanceof ParentAwareRecord) {
+                ((ParentAwareRecord) record).setParentRecord(br);
+            }
+            // Walk on down for the case of container records
+            if (record instanceof RecordContainer) {
+                handleParentAwareRecords((RecordContainer)record);
+            }
+        }
+    }
+
+
 }
index 8214f0d36c52bc2613dfdb4b2d88d9273dc728a2..94183638491218c92a3ac5919b13d4185e305da9 100644 (file)
@@ -91,13 +91,15 @@ public final class SlideShow {
         * @param hslfSlideShow the HSLFSlideShow to base on
         */
        public SlideShow(HSLFSlideShow hslfSlideShow) {
-       // Get useful things from our base slideshow
-       _hslfSlideShow = hslfSlideShow;
+           // Get useful things from our base slideshow
+           _hslfSlideShow = hslfSlideShow;
                _records = _hslfSlideShow.getRecords();
 
-               // Handle Parent-aware Reocrds
-               for (int i = 0; i < _records.length; i++) {
-                       handleParentAwareRecords(_records[i]);
+               // Handle Parent-aware Records
+               for (Record record : _records) {
+                       if(record instanceof RecordContainer){
+                RecordContainer.handleParentAwareRecords((RecordContainer)record);
+            }
                }
 
                // Find the versions of the core records we'll want to use
@@ -121,30 +123,6 @@ public final class SlideShow {
                this(new HSLFSlideShow(inputStream));
        }
 
-       /**
-        * Find the records that are parent-aware, and tell them who their parent is
-        */
-       private void handleParentAwareRecords(Record baseRecord) {
-               // Only need to do something if this is a container record
-               if (baseRecord instanceof RecordContainer) {
-                       RecordContainer br = (RecordContainer) baseRecord;
-                       Record[] childRecords = br.getChildRecords();
-
-                       // Loop over child records, looking for interesting ones
-                       for (int i = 0; i < childRecords.length; i++) {
-                               Record record = childRecords[i];
-                               // Tell parent aware records of their parent
-                               if (record instanceof ParentAwareRecord) {
-                                       ((ParentAwareRecord) record).setParentRecord(br);
-                               }
-                               // Walk on down for the case of container records
-                               if (record instanceof RecordContainer) {
-                                       handleParentAwareRecords(record);
-                               }
-                       }
-               }
-       }
-
        /**
         * Use the PersistPtrHolder entries to figure out what is the "most recent"
         * version of all the core records (Document, Notes, Slide etc), and save a
index be399fefa691743db6676428561b3ccd571b23e1..471ee5bb50abe1cb2e1df37d88eccdfdcf5b880f 100644 (file)
 package org.apache.poi.hslf.model;
 
 
+import java.awt.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.Record;
 import org.apache.poi.hslf.record.TextBytesAtom;
 import org.apache.poi.hslf.record.TextCharsAtom;
 import org.apache.poi.hslf.record.TextHeaderAtom;
@@ -490,4 +494,41 @@ public final class TestTextRun extends TestCase {
                assertNotNull(runs);
                assertEquals(4, runs.length);
        }
+
+    public void test48916() throws IOException {
+        SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
+        for(Slide slide : ppt.getSlides()){
+            for(Shape sh : slide.getShapes()){
+                if(sh instanceof TextShape){
+                    TextShape tx = (TextShape)sh;
+                    TextRun run = tx.getTextRun();
+                    //verify that records cached in  TextRun and EscherTextboxWrapper are the same
+                    Record[] runChildren = run.getRecords();
+                    Record[] txboxChildren = tx.getEscherTextboxWrapper().getChildRecords();
+                    assertEquals(runChildren.length, txboxChildren.length);
+                    for(int i=0; i < txboxChildren.length; i++){
+                        assertSame(txboxChildren[i], runChildren[i]);
+                    }
+                    //caused NPE prior to fix of Bugzilla #48916 
+                    run.getRichTextRuns()[0].setBold(true);
+                    run.getRichTextRuns()[0].setFontColor(Color.RED);
+                }
+            }
+        }
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ppt.write(out);
+        ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+        for(Slide slide : ppt.getSlides()){
+            for(Shape sh : slide.getShapes()){
+                if(sh instanceof TextShape){
+                    TextShape tx = (TextShape)sh;
+                    TextRun run = tx.getTextRun();
+                    RichTextRun rt = run.getRichTextRuns()[0];
+                    assertTrue(rt.isBold());
+                    assertEquals(rt.getFontColor(), Color.RED);
+                }
+            }
+        }
+
+    }
 }