aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-07-18 20:35:28 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-07-18 20:35:28 +0000
commit9b09cb683ab24180411f033a8ba9ed2d6073ebca (patch)
treea55aae080adc4c96d0f167a5ba74d798eedf1e2e /src/scratchpad
parentf7b8e88bda206d65bd03617bbff18c75af618111 (diff)
downloadpoi-9b09cb683ab24180411f033a8ba9ed2d6073ebca.tar.gz
poi-9b09cb683ab24180411f033a8ba9ed2d6073ebca.zip
Introduce dirty flag for paragraphs and store them to records on save
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1691774 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java14
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java42
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java11
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java2
4 files changed, 57 insertions, 12 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
index 5cc313e91f..ec7de6635c 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
@@ -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);
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
index 386447328b..b07a8f8b67 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
@@ -64,6 +64,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
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 implements TextParagraph<HSLFTextRun> {
@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 implements TextParagraph<HSLFTextRun> {
@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 implements TextParagraph<HSLFTextRun> {
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 implements TextParagraph<HSLFTextRun> {
*/
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 implements TextParagraph<HSLFTextRun> {
*/
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 implements TextParagraph<HSLFTextRun> {
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 implements TextParagraph<HSLFTextRun> {
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 implements TextParagraph<HSLFTextRun> {
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 implements TextParagraph<HSLFTextRun> {
throw new RuntimeException("failed dummy write", e);
}
}
+
+ for (HSLFTextParagraph p : paragraphs) {
+ p._dirty = false;
+ }
}
/**
@@ -1260,4 +1267,25 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
}
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;
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
index d12bfe3de8..8728eabb6b 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
@@ -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
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java
index c2f7ac9d08..aa0c307f93 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextRun.java
@@ -525,7 +525,7 @@ public final class TestTextRun {
rt.setFontColor(Color.RED);
}
}
- tx.storeText();
+ // tx.storeText();
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();