aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-01-08 21:35:53 +0000
committerNick Burch <nick@apache.org>2008-01-08 21:35:53 +0000
commitb38da1edcdf086acf753ab3bd8405e6280fd0fe9 (patch)
tree4c784ce975287a27d75710edb4a0b2337904b8ff /src/scratchpad
parent56b73eddb9cdc7ace869e21d6824808329bbc083 (diff)
downloadpoi-b38da1edcdf086acf753ab3bd8405e6280fd0fe9.tar.gz
poi-b38da1edcdf086acf753ab3bd8405e6280fd0fe9.zip
Make the code for adding a new RichTextRun to a TextRun a bit nicer
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610169 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java33
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java52
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java25
3 files changed, 69 insertions, 41 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
index fa9c72bb80..586932e739 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
@@ -20,12 +20,16 @@
package org.apache.poi.hslf.model;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RecordContainer;
+import org.apache.poi.hslf.record.StyleTextPropAtom;
+import org.apache.poi.hslf.record.TextBytesAtom;
+import org.apache.poi.hslf.record.TextCharsAtom;
+import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.util.StringUtil;
@@ -258,12 +262,15 @@ public class TextRun
* Adds the supplied text onto the end of the TextRun,
* creating a new RichTextRun (returned) for it to
* sit in.
+ * In many cases, before calling this, you'll want to add
+ * a newline onto the end of your last RichTextRun
*/
public RichTextRun appendText(String s) {
// We will need a StyleTextProp atom
ensureStyleAtomPresent();
- // First up, append the text
+ // First up, append the text to the
+ // underlying text atom
int oldSize = getRawText().length();
storeText(
getRawText() + s
@@ -272,21 +279,8 @@ public class TextRun
// If either of the previous styles overran
// the text by one, we need to shuffle that
// extra character onto the new ones
- Iterator it = _styleAtom.getParagraphStyles().iterator();
- int pLen = 0;
- while(it.hasNext()) {
- TextPropCollection tpc = (TextPropCollection)it.next();
- pLen += tpc.getCharactersCovered();
- }
- it = _styleAtom.getCharacterStyles().iterator();
- int cLen = 0;
- while(it.hasNext()) {
- TextPropCollection tpc = (TextPropCollection)it.next();
- cLen += tpc.getCharactersCovered();
- }
- int pOverRun = pLen - oldSize;
- int cOverRun = cLen - oldSize;
-
+ int pOverRun = _styleAtom.getParagraphTextLengthCovered() - oldSize;
+ int cOverRun = _styleAtom.getCharacterTextLengthCovered() - oldSize;
if(pOverRun > 0) {
TextPropCollection tpc = (TextPropCollection)
_styleAtom.getParagraphStyles().getLast();
@@ -302,8 +296,7 @@ public class TextRun
);
}
- // Next, add the styles for its
- // paragraph and characters
+ // Next, add the styles for its paragraph and characters
TextPropCollection newPTP =
_styleAtom.addParagraphTextPropCollection(s.length()+pOverRun);
TextPropCollection newCTP =
diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
index 32f8b2bd03..fdaa9eec2c 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
@@ -19,17 +19,19 @@
package org.apache.poi.hslf.record;
-import org.apache.poi.hslf.model.textproperties.*;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogger;
-
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.LinkedList;
-import java.util.Vector;
-import java.util.List;
import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.poi.hslf.model.textproperties.AlignmentTextProp;
+import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.TextProp;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
/**
* A StyleTextPropAtom (type 4001). Holds basic character properties
@@ -88,6 +90,37 @@ public class StyleTextPropAtom extends RecordAtom
* character stylings
*/
public void setCharacterStyles(LinkedList cs) { charStyles = cs; }
+
+ /**
+ * Returns how many characters the paragraph's
+ * TextPropCollections cover.
+ * (May be one or two more than the underlying text does,
+ * due to having extra characters meaning something
+ * special to powerpoint)
+ */
+ public int getParagraphTextLengthCovered() {
+ return getCharactersCovered(paragraphStyles);
+ }
+ /**
+ * Returns how many characters the character's
+ * TextPropCollections cover.
+ * (May be one or two more than the underlying text does,
+ * due to having extra characters meaning something
+ * special to powerpoint)
+ */
+ public int getCharacterTextLengthCovered() {
+ return getCharactersCovered(charStyles);
+ }
+ private int getCharactersCovered(LinkedList styles) {
+ int length = 0;
+ Iterator it = styles.iterator();
+ while(it.hasNext()) {
+ TextPropCollection tpc =
+ (TextPropCollection)it.next();
+ length += tpc.getCharactersCovered();
+ }
+ return length;
+ }
/** All the different kinds of paragraph properties we might handle */
public static TextProp[] paragraphTextPropTypes = new TextProp[] {
@@ -355,8 +388,7 @@ public class StyleTextPropAtom extends RecordAtom
charStyles.add(tpc);
return tpc;
}
-
-
+
/* ************************************************************************ */
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
index d16bf7bc02..fe03755079 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
@@ -20,25 +20,28 @@
package org.apache.poi.hslf.usermodel;
-import org.apache.poi.hslf.model.*;
+import java.awt.Color;
+
+import org.apache.poi.hslf.model.MasterSheet;
import org.apache.poi.hslf.model.Shape;
-import org.apache.poi.hslf.model.textproperties.*;
+import org.apache.poi.hslf.model.Sheet;
+import org.apache.poi.hslf.model.TextRun;
+import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
+import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.TextProp;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.record.ColorSchemeAtom;
-import org.apache.poi.hslf.exceptions.HSLFException;
-
-import java.awt.*;
/**
* Represents a run of text, all with the same style
*
- * TODO: get access to the font/character properties
- *
- * @author Nick Burch
+ * TODO: finish all the getters and setters to the
+ * font/character/paragraph properties (currently only
+ * has some of them)
*/
-
-public class RichTextRun
-{
+public class RichTextRun {
/** The TextRun we belong to */
private TextRun parentRun;
/** The SlideShow we belong to */