poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r610169 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hslf: model/TextRun.java record/StyleTextPropAtom.java usermodel/RichTextRun.java
Date Tue, 08 Jan 2008 21:35:54 GMT
Author: nick
Date: Tue Jan  8 13:35:53 2008
New Revision: 610169

URL: http://svn.apache.org/viewvc?rev=610169&view=rev
Log:
Make the code for adding a new RichTextRun to a TextRun a bit nicer

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java?rev=610169&r1=610168&r2=610169&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java Tue Jan  8 13:35:53
2008
@@ -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 @@
 	 * 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 @@
 		// 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 @@
 			);
 		}
 		
-		// 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 =

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?rev=610169&r1=610168&r2=610169&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java Tue Jan
 8 13:35:53 2008
@@ -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 @@
 	 *  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 @@
 		charStyles.add(tpc);
 		return tpc;
 	}
-
-
+	
 /* ************************************************************************ */
 
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java?rev=610169&r1=610168&r2=610169&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java Tue Jan  8
13:35:53 2008
@@ -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 */



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message