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;
* 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
// 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();
);
}
- // 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 =
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
* 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[] {
charStyles.add(tpc);
return tpc;
}
-
-
+
/* ************************************************************************ */
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 */