You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/18 22:35:28 UTC
svn commit: r1691774 - in /poi/branches/common_sl/src/scratchpad:
src/org/apache/poi/hslf/usermodel/ testcases/org/apache/poi/hslf/usermodel/
Author: kiwiwings
Date: Sat Jul 18 20:35:28 2015
New Revision: 1691774
URL: http://svn.apache.org/r1691774
Log:
Introduce dirty flag for paragraphs and store them to records on save
Modified:
poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java?rev=1691774&r1=1691773&r2=1691774&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java Sat Jul 18 20:35:28 2015
@@ -442,6 +442,20 @@ public final class HSLFSlideShow impleme
* 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);
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java?rev=1691774&r1=1691773&r2=1691774&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java Sat Jul 18 20:35:28 2015
@@ -64,6 +64,8 @@ public final class HSLFTextParagraph imp
private int shapeId;
private StyleTextProp9Atom styleTextProp9Atom;
+
+ private boolean _dirty = false;
/**
* Constructs a Text Run from a Unicode text block.
@@ -265,7 +267,7 @@ public final class HSLFTextParagraph imp
@Override
public void setLeftMargin(Double leftMargin) {
Integer val = (leftMargin == null) ? null : Units.pointsToMaster(leftMargin);
- setPropVal(_paragraphStyle, "text.offset", val);
+ setParagraphTextPropVal("text.offset", val);
}
@Override
@@ -288,7 +290,7 @@ public final class HSLFTextParagraph imp
@Override
public void setIndent(Double indent) {
Integer val = (indent == null) ? null : Units.pointsToMaster(indent);
- setPropVal(_paragraphStyle, "bullet.offset", val);
+ setParagraphTextPropVal("bullet.offset", val);
}
@Override
@@ -327,7 +329,7 @@ public final class HSLFTextParagraph imp
case JUSTIFY_LOW: alignInt = TextAlignmentProp.JUSTIFYLOW; break;
case THAI_DIST: alignInt = TextAlignmentProp.THAIDISTRIBUTED; break;
}
- setPropVal(_paragraphStyle, "alignment", alignInt);
+ setParagraphTextPropVal("alignment", alignInt);
}
@Override
@@ -455,7 +457,7 @@ public final class HSLFTextParagraph imp
*/
public void setBulletChar(Character c) {
Integer val = (c == null) ? null : (int)c.charValue();
- setPropVal(_paragraphStyle, "bullet.char", val);
+ setParagraphTextPropVal("bullet.char", val);
}
/**
@@ -485,7 +487,7 @@ public final class HSLFTextParagraph imp
*/
public void setBulletColor(Color color) {
Integer val = (color == null) ? null : new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
- setPropVal(_paragraphStyle, "bullet.color", val);
+ setParagraphTextPropVal("bullet.color", val);
}
/**
@@ -513,7 +515,7 @@ public final class HSLFTextParagraph imp
FontCollection fc = getSheet().getSlideShow().getFontCollection();
int idx = fc.addFont(typeface);
- setPropVal(_paragraphStyle, "bullet.font", idx);
+ setParagraphTextPropVal("bullet.font", idx);
setFlag(ParagraphFlagsTextProp.BULLET_HARDFONT_IDX, true);
}
@@ -576,7 +578,7 @@ public final class HSLFTextParagraph imp
if (dval != null) {
ival = (dval < 0) ? Units.pointsToMaster(dval) : dval.intValue();
}
- setPropVal(_paragraphStyle, propName, ival);
+ setParagraphTextPropVal(propName, ival);
}
private boolean getFlag(int index) {
@@ -587,6 +589,7 @@ public final class HSLFTextParagraph imp
private void setFlag(int index, boolean value) {
BitMaskTextProp tp = (BitMaskTextProp)_paragraphStyle.addWithName(ParagraphFlagsTextProp.NAME);
tp.setSubValue(value, index);
+ setDirty();
}
/**
@@ -813,6 +816,10 @@ public final class HSLFTextParagraph imp
throw new RuntimeException("failed dummy write", e);
}
}
+
+ for (HSLFTextParagraph p : paragraphs) {
+ p._dirty = false;
+ }
}
/**
@@ -1260,4 +1267,25 @@ public final class HSLFTextParagraph imp
}
return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
}
+
+ /**
+ * Sets the value of the given Paragraph TextProp, add if required
+ * @param propName The name of the Paragraph TextProp
+ * @param val The value to set for the TextProp
+ */
+ public void setParagraphTextPropVal(String propName, Integer val) {
+ setPropVal(_paragraphStyle, propName, val);
+ setDirty();
+ }
+
+ /**
+ * marks this paragraph dirty, so its records will be renewed on save
+ */
+ public void setDirty() {
+ _dirty = true;
+ }
+
+ public boolean isDirty() {
+ return _dirty;
+ }
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java?rev=1691774&r1=1691773&r2=1691774&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java Sat Jul 18 20:35:28 2015
@@ -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 implement
*/
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 implement
* @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 implement
* @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
Modified: poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java?rev=1691774&r1=1691773&r2=1691774&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java (original)
+++ poi/branches/common_sl/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java Sat Jul 18 20:35:28 2015
@@ -525,7 +525,7 @@ public final class TestTextRun {
rt.setFontColor(Color.RED);
}
}
- tx.storeText();
+ // tx.storeText();
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org