]> source.dussan.org Git - poi.git/commitdiff
Introduce dirty flag for paragraphs and store them to records on save
authorAndreas Beeker <kiwiwings@apache.org>
Sat, 18 Jul 2015 20:35:28 +0000 (20:35 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sat, 18 Jul 2015 20:35:28 +0000 (20:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1691774 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java

index 5cc313e91f0f40999bdeb7a26fe33b9f92102d68..ec7de6635ce196c51e6c4a602b48b0c9471f81b7 100644 (file)
@@ -442,6 +442,20 @@ public final class HSLFSlideShow implements SlideShow {
         *             OutputStream
         */
        public void write(OutputStream out) throws IOException {
+           // check for text paragraph modifications
+           for (HSLFSlide sl : getSlides()) {
+               for (HSLFShape sh : sl.getShapes()) {
+                   if (!(sh instanceof HSLFTextShape)) continue;
+                   HSLFTextShape hts = (HSLFTextShape)sh;
+                boolean isDirty = false;
+                for (HSLFTextParagraph p : hts.getTextParagraphs()) {
+                    isDirty |= p.isDirty();
+                }
+                   if (isDirty) hts.storeText();
+               }
+           }
+           
+           
                _hslfSlideShow.write(out);
        }
 
index 386447328b4516d7247da45747b70c9c60f78ce8..b07a8f8b67c7924a1511c4d1b081d5337618b5ef 100644 (file)
@@ -64,6 +64,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
     private int shapeId;\r
 \r
     private StyleTextProp9Atom styleTextProp9Atom;\r
+    \r
+    private boolean _dirty = false;\r
 \r
     /**\r
     * Constructs a Text Run from a Unicode text block.\r
@@ -265,7 +267,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
     @Override\r
     public void setLeftMargin(Double leftMargin) {\r
         Integer val = (leftMargin == null) ? null : Units.pointsToMaster(leftMargin);\r
-        setPropVal(_paragraphStyle, "text.offset", val);\r
+        setParagraphTextPropVal("text.offset", val);\r
     }\r
 \r
     @Override\r
@@ -288,7 +290,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
     @Override\r
     public void setIndent(Double indent) {\r
         Integer val = (indent == null) ? null : Units.pointsToMaster(indent);\r
-        setPropVal(_paragraphStyle, "bullet.offset", val);\r
+        setParagraphTextPropVal("bullet.offset", val);\r
     }\r
 \r
     @Override\r
@@ -327,7 +329,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
             case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break;\r
             case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break;\r
         }\r
-        setPropVal(_paragraphStyle, "alignment", alignInt);\r
+        setParagraphTextPropVal("alignment", alignInt);\r
     }\r
 \r
     @Override\r
@@ -455,7 +457,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
      */\r
     public void setBulletChar(Character c) {\r
         Integer val = (c == null) ? null : (int)c.charValue();\r
-        setPropVal(_paragraphStyle, "bullet.char", val);\r
+        setParagraphTextPropVal("bullet.char", val);\r
     }\r
 \r
     /**\r
@@ -485,7 +487,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
      */\r
     public void setBulletColor(Color color) {\r
         Integer val = (color == null) ? null : new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();\r
-        setPropVal(_paragraphStyle, "bullet.color", val);\r
+        setParagraphTextPropVal("bullet.color", val);\r
     }\r
 \r
     /**\r
@@ -513,7 +515,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         FontCollection fc = getSheet().getSlideShow().getFontCollection();\r
         int idx = fc.addFont(typeface);\r
 \r
-        setPropVal(_paragraphStyle, "bullet.font", idx);\r
+        setParagraphTextPropVal("bullet.font", idx);\r
         setFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX, true);\r
     }\r
 \r
@@ -576,7 +578,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         if (dval != null) {\r
             ival = (dval < 0) ? Units.pointsToMaster(dval) : dval.intValue();\r
         }\r
-        setPropVal(_paragraphStyle, propName, ival);\r
+        setParagraphTextPropVal(propName, ival);\r
     }\r
     \r
     private boolean getFlag(int index) {\r
@@ -587,6 +589,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
     private void setFlag(int index, boolean value) {\r
         BitMaskTextProp tp = (BitMaskTextProp)_paragraphStyle.addWithName(ParagraphFlagsTextProp.NAME);\r
         tp.setSubValue(value, index);\r
+        setDirty();\r
     }\r
 \r
     /**\r
@@ -813,6 +816,10 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
                 throw new RuntimeException("failed dummy write", e);\r
             }\r
         }\r
+        \r
+        for (HSLFTextParagraph p : paragraphs) {\r
+            p._dirty = false;\r
+        }\r
     }\r
 \r
     /**\r
@@ -1260,4 +1267,25 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         }\r
         return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());\r
     }\r
+\r
+    /**\r
+     * Sets the value of the given Paragraph TextProp, add if required\r
+     * @param propName The name of the Paragraph TextProp\r
+     * @param val The value to set for the TextProp\r
+     */\r
+    public void setParagraphTextPropVal(String propName, Integer val) {\r
+        setPropVal(_paragraphStyle, propName, val);\r
+        setDirty();\r
+    }\r
+    \r
+    /**\r
+     * marks this paragraph dirty, so its records will be renewed on save\r
+     */\r
+    public void setDirty() {\r
+        _dirty = true;\r
+    }\r
+    \r
+    public boolean isDirty() {\r
+        return _dirty;\r
+    }\r
 }\r
index d12bfe3de85445fce554af22f09875aed0a1cf46..8728eabb6b4b786489fe161a5b628e69ecf14743 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.poi.hslf.usermodel;
 
 import static org.apache.poi.hslf.usermodel.HSLFTextParagraph.getPropVal;
-import static org.apache.poi.hslf.usermodel.HSLFTextParagraph.setPropVal;
 
 import java.awt.Color;
 
@@ -133,7 +132,10 @@ public final class HSLFTextRun implements TextRun {
         */
        private void setCharFlagsTextPropVal(int index, boolean value) {
            // TODO: check if paragraph/chars can be handled the same ...
-               if (getFlag(index) != value) setFlag(index, value);
+               if (getFlag(index) != value) {
+                   setFlag(index, value);
+                   parentParagraph.setDirty();
+               }
        }
 
        /**
@@ -142,7 +144,8 @@ public final class HSLFTextRun implements TextRun {
         * @param val The value to set for the TextProp
         */
        public void setCharTextPropVal(String propName, Integer val) {
-           setPropVal(characterStyle, propName, val);
+           HSLFTextParagraph.setPropVal(characterStyle, propName, val);
+           parentParagraph.setDirty();
        }
 
 
@@ -248,7 +251,7 @@ public final class HSLFTextRun implements TextRun {
         * @param val the percentage of the font size. If the value is positive, it is superscript, otherwise it is subscript
         */
        public void setSuperscript(int val) {
-           setPropVal(characterStyle, "superscript", val);
+           setCharTextPropVal("superscript", val);
        }
 
     @Override
index c2f7ac9d08f805acfd7ef423ebe82889f17b0817..aa0c307f936c34e9da7c9bb80be289ace677b643 100644 (file)
@@ -525,7 +525,7 @@ public final class TestTextRun {
                         rt.setFontColor(Color.RED);
                     }
                 }
-                tx.storeText();
+                // tx.storeText();
             }
         }
         ByteArrayOutputStream out = new ByteArrayOutputStream();