poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r692907 [3/4] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/documentation/content/xdocs/hpbf/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/formula/ src/java/org/apache/poi/hssf/record/formula/...
Date Sun, 07 Sep 2008 17:34:38 GMT
Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java Sun Sep  7 10:34:36 2008
@@ -34,6 +34,7 @@
 	private int charactersCovered;
 	private short reservedField;
 	private LinkedList textPropList;
+    private int maskSpecial = 0;
 
 	/** Fetch the number of characters this styling applies to */
 	public int getCharactersCovered() { return charactersCovered; }
@@ -94,21 +95,28 @@
 		// If we do, decode that, save it, and shuffle on
 		for(int i=0; i<potentialProperties.length; i++) {
 			// Check there's still data left to read
-			if(dataOffset+bytesPassed >= data.length) {
-				// Out of data, can't be any more properties to go
-				return bytesPassed;
-			}
-			
+
 			// Check if this property is found in the mask
 			if((containsField & potentialProperties[i].getMask()) != 0) {
+                if(dataOffset+bytesPassed >= data.length) {
+                    // Out of data, can't be any more properties to go
+                    // remember the mask and return
+                    maskSpecial |= potentialProperties[i].getMask();
+                    return bytesPassed;
+                }
+
 				// Bingo, data contains this property
 				TextProp prop = (TextProp)potentialProperties[i].clone();
 				int val = 0;
 				if(prop.getSize() == 2) {
 					val = LittleEndian.getShort(data,dataOffset+bytesPassed);
-				} else {
+				} else if(prop.getSize() == 4){
 					val = LittleEndian.getInt(data,dataOffset+bytesPassed);
-				}
+				} else if (prop.getSize() == 0){
+                    //remember "special" bits.
+                    maskSpecial |= potentialProperties[i].getMask();
+                    continue;
+                }
 				prop.setValue(val);
 				bytesPassed += prop.getSize();
 				textPropList.add(prop);
@@ -161,15 +169,18 @@
 		}
 
 		// Then the mask field
-		int mask = 0;
+		int mask = maskSpecial;
 		for(int i=0; i<textPropList.size(); i++) {
 			TextProp textProp = (TextProp)textPropList.get(i);
             //sometimes header indicates that the bitmask is present but its value is 0
-            if (textProp instanceof BitMaskTextProp)
-                mask |= (textProp.getWriteMask() == 0 ? 1 : textProp.getWriteMask());
-            else
+
+            if (textProp instanceof BitMaskTextProp) {
+                if(mask == 0) mask |=  textProp.getWriteMask();
+            }
+            else {
                 mask |= textProp.getWriteMask();
-		}
+            }
+        }
 		StyleTextPropAtom.writeLittleEndian(mask,o);
 
 		// Then the contents of all the properties
@@ -178,7 +189,7 @@
 			int val = textProp.getValue();
 			if(textProp.getSize() == 2) {
 				StyleTextPropAtom.writeLittleEndian((short)val,o);
-			} else {
+			} else if(textProp.getSize() == 4){
 				StyleTextPropAtom.writeLittleEndian(val,o);
 			}
 		}

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java Sun Sep  7 10:34:36 2008
@@ -63,14 +63,16 @@
 	 * TODO: Figure out if we should always set both
 	 */
 	public void setLinkURL(String url) {
-		linkDetailsA.setText(url);
-
-		// linkDetailsB isn't present in all PPT versions
 		if(linkDetailsB != null) {
 			linkDetailsB.setText(url);
 		}
 	}
-	
+    public void setLinkTitle(String title) {
+        if(linkDetailsA != null) {
+            linkDetailsA.setText(title);
+        }
+    }
+
 	/**
 	 * Get the link details (field A)
 	 */

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java Sun Sep  7 10:34:36 2008
@@ -124,47 +124,54 @@
 
 	/** All the different kinds of paragraph properties we might handle */
 	public static TextProp[] paragraphTextPropTypes = new TextProp[] {
-				new ParagraphFlagsTextProp(),
+                new TextProp(0, 0x1, "hasBullet"),
+                new TextProp(0, 0x2, "hasBulletFont"),
+                new TextProp(0, 0x4, "hasBulletColor"),
+                new TextProp(0, 0x8, "hasBulletSize"),
+                new ParagraphFlagsTextProp(),
                 new TextProp(2, 0x80, "bullet.char"),
 				new TextProp(2, 0x10, "bullet.font"),
                 new TextProp(2, 0x40, "bullet.size"),
 				new TextProp(4, 0x20, "bullet.color"),
                 new AlignmentTextProp(),
                 new TextProp(2, 0x100, "text.offset"),
-				new TextProp(2, 0x200, "para_unknown_2"),
                 new TextProp(2, 0x400, "bullet.offset"),
-				new TextProp(2, 0x1000, "linespacing"),
-				new TextProp(2, 0x2000, "spacebefore"),
-				new TextProp(2, 0x4000, "spaceafter"),
-				new TextProp(2, 0x8000, "para_unknown_4"),
-				new TextProp(2, 0x10000, "para_unknown_5"),
-				new TextProp(2, 0xA0000, "para_unknown_6"),
-				new TextProp(2, 0x200000, "para_unknown_7")
+                new TextProp(2, 0x1000, "linespacing"),
+                new TextProp(2, 0x2000, "spacebefore"),
+                new TextProp(2, 0x4000, "spaceafter"),
+                new TextProp(2, 0x8000, "defaultTabSize"),
+				new TextProp(2, 0x100000, "tabStops"),
+				new TextProp(2, 0x10000, "fontAlign"),
+				new TextProp(2, 0xA0000, "wrapFlags"),
+				new TextProp(2, 0x200000, "textDirection")
 	};
 	/** All the different kinds of character properties we might handle */
 	public static TextProp[] characterTextPropTypes = new TextProp[] {
-				new CharFlagsTextProp(),
+                new TextProp(0, 0x1, "bold"),
+                new TextProp(0, 0x2, "italic"),
+                new TextProp(0, 0x4, "underline"),
+                new TextProp(0, 0x8, "unused1"),
+                new TextProp(0, 0x10, "shadow"),
+                new TextProp(0, 0x20, "fehint"),
+                new TextProp(0, 0x40, "unused2"),
+                new TextProp(0, 0x80, "kumi"),
+                new TextProp(0, 0x100, "unused3"),
+                new TextProp(0, 0x200, "emboss"),
+                new CharFlagsTextProp(),
 				new TextProp(2, 0x10000, "font.index"),
-                new TextProp(2, 0x200000, "asian_or_complex"),
-                new TextProp(2, 0x400000, "char_unknown_2"),
-                new TextProp(2, 0x800000, "symbol"),
+                new TextProp(0, 0x100000, "pp10ext"),
+                new TextProp(2, 0x200000, "asian.font.index"),
+                new TextProp(2, 0x400000, "ansi.font.index"),
+                new TextProp(2, 0x800000, "symbol.font.index"),
 				new TextProp(2, 0x20000, "font.size"),
 				new TextProp(4, 0x40000, "font.color"),
-				new TextProp(2, 0x80000, "superscript"),
-				new TextProp(2, 0x100000, "char_unknown_1"),
-				new TextProp(2, 0x1000000, "char_unknown_3"),
-				new TextProp(2, 0x2000000, "char_unknown_4"),
-				new TextProp(2, 0x4000000, "char_unknown_5"),
-				new TextProp(2, 0x8000000, "char_unknown_6"),
-				new TextProp(2, 0x10000000, "char_unknown_7"),
-				new TextProp(2, 0x20000000, "char_unknown_8"),
-				new TextProp(2, 0x40000000, "char_unknown_9"),
-				new TextProp(2, 0x80000000, "char_unknown_10"),
-	};
+                new TextProp(2, 0x80000, "superscript"),
+
+    };
 
 	/* *************** record code follows ********************** */
 
-	/** 
+	/**
 	 * For the Text Style Properties (StyleTextProp) Atom
 	 */
 	public StyleTextPropAtom(byte[] source, int start, int len) {
@@ -192,7 +199,7 @@
 	}
 
 
-	/** 
+	/**
 	 * A new set of text style properties for some text without any.
 	 */
 	public StyleTextPropAtom(int parentTextSize) {
@@ -209,11 +216,11 @@
 		paragraphStyles = new LinkedList();
 		charStyles = new LinkedList();
 
-		TextPropCollection defaultParagraphTextProps = 
+		TextPropCollection defaultParagraphTextProps =
 			new TextPropCollection(parentTextSize, (short)0);
 		paragraphStyles.add(defaultParagraphTextProps);
 
-		TextPropCollection defaultCharacterTextProps = 
+		TextPropCollection defaultCharacterTextProps =
 			new TextPropCollection(parentTextSize);
 		charStyles.add(defaultCharacterTextProps);
 
@@ -269,8 +276,7 @@
 			textHandled += textLen;
 			pos += 4;
 
-			// Fetch the 2 byte value that is safe to ignore as 0
-			short paraIgn = LittleEndian.getShort(rawContents,pos);
+			short indent = LittleEndian.getShort(rawContents,pos);
 			pos += 2;
 
 			// Grab the 4 byte value that tells us what properties follow
@@ -278,7 +284,7 @@
 			pos += 4;
 
 			// Now make sense of those properties
-			TextPropCollection thisCollection = new TextPropCollection(textLen, paraIgn);
+			TextPropCollection thisCollection = new TextPropCollection(textLen, indent);
 			int plSize = thisCollection.buildTextPropList(
 					paraFlags, paragraphTextPropTypes, rawContents, pos);
 			pos += plSize;

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Sun Sep  7 10:34:36 2008
@@ -920,7 +920,7 @@
      * @return 0-based index of the control
      */
     public int addControl(String name, String progId) {
-        ExObjList lst = _documentRecord.getExObjList();
+        ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
         if (lst == null) {
             lst = new ExObjList();
             _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
@@ -943,4 +943,31 @@
 
         return objectId;
     }
+
+    /**
+     * Add a hyperlink to this presentation
+     *
+     * @return 0-based index of the hyperlink
+     */
+    public int addHyperlink(Hyperlink link) {
+        ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
+        if (lst == null) {
+            lst = new ExObjList();
+            _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
+        }
+        ExObjListAtom objAtom = lst.getExObjListAtom();
+        //increment the object ID seed
+        int objectId = (int) objAtom.getObjectIDSeed() + 1;
+        objAtom.setObjectIDSeed(objectId);
+
+        ExHyperlink ctrl = new ExHyperlink();
+        ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom();
+        obj.setNumber(objectId);
+        ctrl.setLinkURL(link.getAddress());
+        ctrl.setLinkTitle(link.getTitle());
+        lst.addChildAfter(ctrl, objAtom);
+        link.setId(objectId);
+
+        return objectId;
+    }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java Sun Sep  7 10:34:36 2008
@@ -760,12 +760,8 @@
 		r.setIndexNumberFmtRecord( (short) 0 );
 		LinkedDataFormulaField formula = new LinkedDataFormulaField();
 		Stack tokens = new Stack();
-		Area3DPtg p = new Area3DPtg();
-		p.setExternSheetIndex( (short) 0 );
-		p.setFirstColumn( (short) 1 );
-		p.setLastColumn( (short) 1 );
-		p.setFirstRow( (short) 0 );
-		p.setLastRow( (short) 31 );
+		Area3DPtg p = new Area3DPtg(0, 31, 1, 1,
+		        false, false, false, false, 0);
 		tokens.add( p );
 		formula.setFormulaTokens( tokens );
 		r.setFormulaOfLink( formula );
@@ -781,12 +777,8 @@
 		r.setIndexNumberFmtRecord( (short) 0 );
 		LinkedDataFormulaField formula = new LinkedDataFormulaField();
 		Stack tokens = new Stack();
-		Area3DPtg p = new Area3DPtg();
-		p.setExternSheetIndex( (short) 0 );
-		p.setFirstColumn( (short) 0 );
-		p.setLastColumn( (short) 0 );
-		p.setFirstRow( (short) 0 );
-		p.setLastRow( (short) 31 );
+		Area3DPtg p = new Area3DPtg(0, 31, 0, 0,
+				false, false, false, false, 0);
 		tokens.add( p );
 		formula.setFormulaTokens( tokens );
 		r.setFormulaOfLink( formula );

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java Sun Sep  7 10:34:36 2008
@@ -31,6 +31,7 @@
 import junit.framework.TestCase;
 import java.io.ByteArrayOutputStream;
 import java.util.LinkedList;
+import java.util.Arrays;
 
 /**
  * Tests that StyleTextPropAtom works properly
@@ -38,9 +39,9 @@
  * @author Nick Burch (nick at torchbox dot com)
  */
 public class TestStyleTextPropAtom extends TestCase {
-	/** From a real file: a paragraph with 4 different styles */
-	private byte[] data_a = new byte[] { 
-	  0, 0, 0xA1-256, 0x0F, 0x2A, 0, 0, 0,
+    /** From a real file: a paragraph with 4 different styles */
+    private byte[] data_a = new byte[] {
+      0, 0, 0xA1-256, 0x0F, 0x2A, 0, 0, 0,
       0x36, 00, 00, 00, // paragraph is 54 long 
       00, 00,           // (paragraph reserved field)
       00, 00, 00, 00,   // it doesn't have any styles
@@ -52,84 +53,84 @@
       0x10, 00, 00, 00, // third char run is 16 long
       00, 00, 0x04, 00, // font.color only
       0xFF-256, 0x33, 00, 0xFE-256 // red
-	};
-	private int data_a_text_len = 0x36-1;
+    };
+    private int data_a_text_len = 0x36-1;
+
+    /**
+     * From a real file: 4 paragraphs with text in 4 different styles:
+     * left aligned+bold (30)
+     * centre aligned+italic+blue (28)
+     * right aligned+red (25)
+     * left aligned+underlined+larger font size (96)
+     * left aligned+underlined+larger font size+red (1)
+     */
+    private byte[] data_b = new byte[] {
+        0, 0, 0xA1-256, 0x0F, 0x80-256, 0, 0, 0,
+        0x1E, 00, 00, 00,     // paragraph is 30 long
+        00, 00,               // paragraph reserved field
+        00, 0x18, 00, 00,     // mask is 0x1800
+        00, 00,               // left aligned
+        0x50, 00,             // line spacing 80
+        0x1C, 00, 00, 00,     // paragprah is 28 long
+        00, 00,               // paragraph reserved field
+        00, 0x10, 00, 00,     // mask is 0x1000
+        0x50, 00,             // line spacing 80
+        0x19, 00, 00, 00,     // paragraph is 25 long
+        00, 00,               // paragraph reserved field
+        00, 0x18, 00, 00,     // mask is 0x1800
+        02, 00,               // right aligned
+        0x50, 00,             // line spacing 80
+        0x61, 00, 00, 00,     // paragraph is 97 long
+        00, 00,               // paragraph reserved field
+        00, 0x18, 00, 00,     // mask is 0x1800
+        00, 00,               // left aligned
+        0x50, 00,             // line spacing 80
+
+        0x1E, 00, 00, 00,     // character run is 30 long
+        01, 00, 02, 00,       // mask is 0x020001
+        01, 00,               // char flags 0x0001 = bold
+        0x14, 00,             // font size 20
+        0x1C, 00, 00, 00,     // character run is 28 long
+        02, 00, 06, 00,       // mask is 0x060002
+        02, 00,               // char flags 0x0002 = italic
+        0x14, 00,             // font size 20
+        00, 00, 00, 05,       // colour blue
+        0x19, 00, 00, 00,     // character run is 25 long
+        00, 00, 06, 00,       // char flags 0x060000
+        0x14, 00,             // font size 20
+        0xFF-256, 0x33, 00, 0xFE-256, // colour red
+        0x60, 00, 00, 00,     // character run is 96 long
+        04, 00, 03, 00,       // mask is 0x030004
+        04, 00,               // char flags 0x0004 = underlined
+        01, 00,               // font index is 1
+        0x18, 00,             // font size 24
+
+        01, 00, 00, 00,       // character run is 1 long
+        04, 00, 07, 00,       // mask is 0x070004
+        04, 00,               // char flags 0x0004 = underlined
+        01, 00,               // font index is 1
+        0x18, 00,             // font size 24
+        0xFF-256, 0x33, 00, 0xFE-256 // colour red
+    };
+    private int data_b_text_len = 0xB3;
 
-	/** 
-	 * From a real file: 4 paragraphs with text in 4 different styles:
-	 * left aligned+bold (30)
-	 * centre aligned+italic+blue (28)
-	 * right aligned+red (25)
-	 * left aligned+underlined+larger font size (96)
-	 * left aligned+underlined+larger font size+red (1)
-	 */
-	private byte[] data_b = new byte[] { 
-		0, 0, 0xA1-256, 0x0F, 0x80-256, 0, 0, 0, 
-		0x1E, 00, 00, 00,     // paragraph is 30 long 
-		00, 00,               // paragraph reserved field
-		00, 0x18, 00, 00,     // mask is 0x1800
-		00, 00,               // left aligned
-		0x50, 00,             // line spacing 80
-		0x1C, 00, 00, 00,     // paragprah is 28 long 
-		00, 00,               // paragraph reserved field
-		00, 0x10, 00, 00,     // mask is 0x1000
-		0x50, 00,             // line spacing 80
-		0x19, 00, 00, 00,     // paragraph is 25 long
-	    00, 00,               // paragraph reserved field
-	    00, 0x18, 00, 00,     // mask is 0x1800 
-	    02, 00,               // right aligned
-	    0x50, 00,             // line spacing 80
-	    0x61, 00, 00, 00,     // paragraph is 97 long
-	    00, 00,               // paragraph reserved field
-	    00, 0x18, 00, 00,     // mask is 0x1800
-	    00, 00,               // left aligned
-	    0x50, 00,             // line spacing 80
-	    
-	    0x1E, 00, 00, 00,     // character run is 30 long
-	    01, 00, 02, 00,       // mask is 0x020001
-	    01, 00,               // char flags 0x0001 = bold
-	    0x14, 00,             // font size 20
-	    0x1C, 00, 00, 00,     // character run is 28 long
-	    02, 00, 06, 00,       // mask is 0x060002
-	    02, 00,               // char flags 0x0002 = italic
-	    0x14, 00,             // font size 20
-	    00, 00, 00, 05,       // colour blue
-	    0x19, 00, 00, 00,     // character run is 25 long
-	    00, 00, 06, 00,       // char flags 0x060000
-	    0x14, 00,             // font size 20
-	    0xFF-256, 0x33, 00, 0xFE-256, // colour red
-	    0x60, 00, 00, 00,     // character run is 96 long
-	    04, 00, 03, 00,       // mask is 0x030004
-	    04, 00,               // char flags 0x0004 = underlined
-	    01, 00,               // font index is 1
-	    0x18, 00,             // font size 24
-	    
-	    01, 00, 00, 00,       // character run is 1 long
-	    04, 00, 07, 00,       // mask is 0x070004
-	    04, 00,               // char flags 0x0004 = underlined
-	    01, 00,               // font index is 1 
-	    0x18, 00,             // font size 24
-	    0xFF-256, 0x33, 00, 0xFE-256 // colour red
-	};
-	private int data_b_text_len = 0xB3;
-	
-	/**
-	 * From a real file. Has a mask with more bits
-	 *  set than it actually has data for. Shouldn't do,
-	 *  but some real files do :(
-	 */
-	private byte[] data_c = new byte[] {
-		0, 0, -95, 15, 62, 0, 0, 0,
-		123, 0, 0, 0, 0, 0, 48, 8, 
-		10, 0, 1, 0, 0, 0, 0, 0, 
-		1, 0, 2, 0, 1, 0, 0, 0, 
-		0, 0, 48, 0, 10, 0, 1, 0, 
-		0, 0, 0, 0, 2, 0, 123, 0, 
-		0, 0, 0, 0, 3, 0, 1, 0, 
-		28, 0, 1, 0, 0, 0, 0, 0, 
-		3, 0, 1, 0, 24, 0
-	};
-	private int data_c_text_len = 123-1;
+    /**
+     * From a real file. Has a mask with more bits
+     *  set than it actually has data for. Shouldn't do,
+     *  but some real files do :(
+     */
+    private byte[] data_c = new byte[] {
+        0, 0, -95, 15, 62, 0, 0, 0,
+        123, 0, 0, 0, 0, 0, 48, 8,
+        10, 0, 1, 0, 0, 0, 0, 0,
+        1, 0, 2, 0, 1, 0, 0, 0,
+        0, 0, 48, 0, 10, 0, 1, 0,
+        0, 0, 0, 0, 2, 0, 123, 0,
+        0, 0, 0, 0, 3, 0, 1, 0,
+        28, 0, 1, 0, 0, 0, 0, 0,
+        3, 0, 1, 0, 24, 0
+    };
+    private int data_c_text_len = 123-1;
 
     /**
      * From a real file supplied for Bug 40143 by tales@great.ufc.br
@@ -143,576 +144,563 @@
     private int data_d_text_len = 0xA0-1;
 
     public void testRecordType() throws Exception {
-		StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
-		assertEquals(4001l, stpa.getRecordType());
-		assertEquals(4001l, stpb.getRecordType());
-		assertEquals(4001l, stpc.getRecordType());
-	}
-
-
-	public void testCharacterStyleCounts() throws Exception {
-		StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-
-		// Set for the appropriate text sizes
-		stpa.setParentTextSize(data_a_text_len);
-		stpb.setParentTextSize(data_b_text_len);
-
-		// In case A, there is a single styling of the characters
-		assertEquals(3, stpa.getCharacterStyles().size());
-		// In case B, there are 5 different stylings
-		assertEquals(5, stpb.getCharacterStyles().size());
-	}
-
-	public void testParagraphStyleCounts() throws Exception {
-		StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-
-		// Set for the appropriate text sizes
-		stpa.setParentTextSize(data_a_text_len);
-		stpb.setParentTextSize(data_b_text_len);
-
-		// In case A, all has the same spacing and alignment
-		assertEquals(1, stpa.getParagraphStyles().size());
-		// In case B, all 4 sets have different alignments
-		assertEquals(4, stpb.getParagraphStyles().size());
-	}
-
-
-	public void testCharacterStyleLengths() throws Exception {
-		StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-
-		// Set for the appropriate text sizes
-		stpa.setParentTextSize(data_a_text_len);
-		stpb.setParentTextSize(data_b_text_len);
-
-		// 54 chars, 21 + 17 + 16
-		LinkedList a_ch_l = stpa.getCharacterStyles();
-		TextPropCollection a_ch_1 = (TextPropCollection)a_ch_l.get(0);
-		TextPropCollection a_ch_2 = (TextPropCollection)a_ch_l.get(1);
-		TextPropCollection a_ch_3 = (TextPropCollection)a_ch_l.get(2);
-		assertEquals(21, a_ch_1.getCharactersCovered());
-		assertEquals(17, a_ch_2.getCharactersCovered());
-		assertEquals(16, a_ch_3.getCharactersCovered());
-
-		// 179 chars, 30 + 28 + 25
-		LinkedList b_ch_l = stpb.getCharacterStyles();
-		TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
-		TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
-		TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
-		TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
-		assertEquals(30, b_ch_1.getCharactersCovered());
-		assertEquals(28, b_ch_2.getCharactersCovered());
-		assertEquals(25, b_ch_3.getCharactersCovered());
-		assertEquals(96, b_ch_4.getCharactersCovered());
-	}
-
-
-	public void testCharacterPropOrdering() throws Exception {
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		stpb.setParentTextSize(data_b_text_len);
-
-		LinkedList b_ch_l = stpb.getCharacterStyles();
-		TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
-		TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
-		TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
-		TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
-		
-		// In first set, we get a CharFlagsTextProp and a font.size
-		assertEquals(2,b_ch_1.getTextPropList().size());
-		TextProp tp_1_1 = (TextProp)b_ch_1.getTextPropList().get(0);
-		TextProp tp_1_2 = (TextProp)b_ch_1.getTextPropList().get(1);
-		assertEquals(true, tp_1_1 instanceof CharFlagsTextProp);
-		assertEquals(true, tp_1_2 instanceof TextProp);
-		assertEquals("font.size", tp_1_2.getName());
-		assertEquals(20, tp_1_2.getValue());
-		
-		// In second set, we get a CharFlagsTextProp and a font.size and a font.color
-		assertEquals(3,b_ch_2.getTextPropList().size());
-		TextProp tp_2_1 = (TextProp)b_ch_2.getTextPropList().get(0);
-		TextProp tp_2_2 = (TextProp)b_ch_2.getTextPropList().get(1);
-		TextProp tp_2_3 = (TextProp)b_ch_2.getTextPropList().get(2);
-		assertEquals(true, tp_2_1 instanceof CharFlagsTextProp);
-		assertEquals(true, tp_2_2 instanceof TextProp);
-		assertEquals(true, tp_2_3 instanceof TextProp);
-		assertEquals("font.size", tp_2_2.getName());
-		assertEquals("font.color", tp_2_3.getName());
-		assertEquals(20, tp_2_2.getValue());
-		
-		// In third set, it's just a font.size and a font.color
-		assertEquals(2,b_ch_3.getTextPropList().size());
-		TextProp tp_3_1 = (TextProp)b_ch_3.getTextPropList().get(0);
-		TextProp tp_3_2 = (TextProp)b_ch_3.getTextPropList().get(1);
-		assertEquals(true, tp_3_1 instanceof TextProp);
-		assertEquals(true, tp_3_2 instanceof TextProp);
-		assertEquals("font.size", tp_3_1.getName());
-		assertEquals("font.color", tp_3_2.getName());
-		assertEquals(20, tp_3_1.getValue());
-		
-		// In fourth set, we get a CharFlagsTextProp and a font.index and a font.size
-		assertEquals(3,b_ch_4.getTextPropList().size());
-		TextProp tp_4_1 = (TextProp)b_ch_4.getTextPropList().get(0);
-		TextProp tp_4_2 = (TextProp)b_ch_4.getTextPropList().get(1);
-		TextProp tp_4_3 = (TextProp)b_ch_4.getTextPropList().get(2);
-		assertEquals(true, tp_4_1 instanceof CharFlagsTextProp);
-		assertEquals(true, tp_4_2 instanceof TextProp);
-		assertEquals(true, tp_4_3 instanceof TextProp);
-		assertEquals("font.index", tp_4_2.getName());
-		assertEquals("font.size", tp_4_3.getName());
-		assertEquals(24, tp_4_3.getValue());
-	}
-
-	public void testParagraphProps() throws Exception {
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		stpb.setParentTextSize(data_b_text_len);
-		
-		LinkedList b_p_l = stpb.getParagraphStyles();
-		TextPropCollection b_p_1 = (TextPropCollection)b_p_l.get(0);
-		TextPropCollection b_p_2 = (TextPropCollection)b_p_l.get(1);
-		TextPropCollection b_p_3 = (TextPropCollection)b_p_l.get(2);
-		TextPropCollection b_p_4 = (TextPropCollection)b_p_l.get(3);
-		
-		// 1st is left aligned + normal line spacing
-		assertEquals(2,b_p_1.getTextPropList().size());
-		TextProp tp_1_1 = (TextProp)b_p_1.getTextPropList().get(0);
-		TextProp tp_1_2 = (TextProp)b_p_1.getTextPropList().get(1);
-		assertEquals(true, tp_1_1 instanceof TextProp);
-		assertEquals(true, tp_1_2 instanceof TextProp);
-		assertEquals("alignment", tp_1_1.getName());
-		assertEquals("linespacing", tp_1_2.getName());
-		assertEquals(0, tp_1_1.getValue());
-		assertEquals(80, tp_1_2.getValue());
-		
-		// 2nd is centre aligned (default) + normal line spacing
-		assertEquals(1,b_p_2.getTextPropList().size());
-		TextProp tp_2_1 = (TextProp)b_p_2.getTextPropList().get(0);
-		assertEquals(true, tp_2_1 instanceof TextProp);
-		assertEquals(true, tp_1_2 instanceof TextProp);
-		assertEquals("linespacing", tp_2_1.getName());
-		assertEquals(80, tp_2_1.getValue());
-		
-		// 3rd is right aligned + normal line spacing
-		assertEquals(2,b_p_3.getTextPropList().size());
-		TextProp tp_3_1 = (TextProp)b_p_3.getTextPropList().get(0);
-		TextProp tp_3_2 = (TextProp)b_p_3.getTextPropList().get(1);
-		assertEquals(true, tp_3_1 instanceof TextProp);
-		assertEquals(true, tp_3_2 instanceof TextProp);
-		assertEquals("alignment", tp_3_1.getName());
-		assertEquals("linespacing", tp_3_2.getName());
-		assertEquals(2, tp_3_1.getValue());
-		assertEquals(80, tp_3_2.getValue());
-		
-		// 4st is left aligned + normal line spacing (despite differing font)
-		assertEquals(2,b_p_4.getTextPropList().size());
-		TextProp tp_4_1 = (TextProp)b_p_4.getTextPropList().get(0);
-		TextProp tp_4_2 = (TextProp)b_p_4.getTextPropList().get(1);
-		assertEquals(true, tp_4_1 instanceof TextProp);
-		assertEquals(true, tp_4_2 instanceof TextProp);
-		assertEquals("alignment", tp_4_1.getName());
-		assertEquals("linespacing", tp_4_2.getName());
-		assertEquals(0, tp_4_1.getValue());
-		assertEquals(80, tp_4_2.getValue());
-	}
-
-	public void testCharacterProps() throws Exception {
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		stpb.setParentTextSize(data_b_text_len);
-
-		LinkedList b_ch_l = stpb.getCharacterStyles();
-		TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
-		TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
-		TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
-		TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
-
-		// 1st is bold
-		CharFlagsTextProp cf_1_1 = (CharFlagsTextProp)b_ch_1.getTextPropList().get(0);
-		assertEquals(true,cf_1_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
-		assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
-		
-		// 2nd is italic
-		CharFlagsTextProp cf_2_1 = (CharFlagsTextProp)b_ch_2.getTextPropList().get(0);
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
-		assertEquals(true,cf_2_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
-		assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
-
-		// 3rd is normal, so lacks a CharFlagsTextProp
-		assertFalse(b_ch_3.getTextPropList().get(0) instanceof CharFlagsTextProp);
-		
-		// 4th is underlined
-		CharFlagsTextProp cf_4_1 = (CharFlagsTextProp)b_ch_4.getTextPropList().get(0);
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
-		assertEquals(true,cf_4_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
-		
-		// The value for this should be 4
-		assertEquals(0x0004, cf_4_1.getValue());
-		
-		// Now make the 4th bold, italic and not underlined
-		cf_4_1.setSubValue(true, CharFlagsTextProp.BOLD_IDX);
-		cf_4_1.setSubValue(true, CharFlagsTextProp.ITALIC_IDX);
-		cf_4_1.setSubValue(false, CharFlagsTextProp.UNDERLINE_IDX);
-		
-		assertEquals(true,cf_4_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
-		assertEquals(true,cf_4_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
-		assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
-		
-		// The value should now be 3
-		assertEquals(0x0003, cf_4_1.getValue());
-	}
-	
-	public void testFindAddTextProp() {
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		stpb.setParentTextSize(data_b_text_len);
-
-		LinkedList b_p_l = stpb.getParagraphStyles();
-		TextPropCollection b_p_1 = (TextPropCollection)b_p_l.get(0);
-		TextPropCollection b_p_2 = (TextPropCollection)b_p_l.get(1);
-		TextPropCollection b_p_3 = (TextPropCollection)b_p_l.get(2);
-		TextPropCollection b_p_4 = (TextPropCollection)b_p_l.get(3);
-		
-		LinkedList b_ch_l = stpb.getCharacterStyles();
-		TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
-		TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
-		TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
-		TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
-
-		// CharFlagsTextProp: 3 doesn't have, 4 does
-		assertNull(b_ch_3.findByName("char_flags"));
-		assertNotNull(b_ch_4.findByName("char_flags"));
-		
-		// Now add in on 3, should go to front
-		assertEquals(2, b_ch_3.getTextPropList().size());
-		TextProp new_cftp = b_ch_3.addWithName("char_flags");
-		assertEquals(3, b_ch_3.getTextPropList().size());
-		assertEquals(new_cftp, b_ch_3.getTextPropList().get(0));
-		
-		// alignment: 1 does have, 2 doesn't
-		assertNotNull(b_p_1.findByName("alignment"));
-		assertNull(b_p_2.findByName("alignment"));
-		
-		// Now add in on 2, should go to the front
-		assertEquals(1, b_p_2.getTextPropList().size());
-		TextProp new_al = b_p_2.addWithName("alignment");
-		assertEquals(2, b_p_2.getTextPropList().size());
-		assertEquals(new_al, b_p_2.getTextPropList().get(0));
-		
-		// This should go at the end
-		TextProp new_sa = b_p_2.addWithName("spaceafter");
-		assertEquals(3, b_p_2.getTextPropList().size());
-		assertEquals(new_sa, b_p_2.getTextPropList().get(2));
-		
-		// Check we get an error with a made up one
-		try {
-			b_p_2.addWithName("madeUpOne");
-			fail();
-		} catch(IllegalArgumentException e) {
-			// Good, as expected
-		}
-	}
-	
-	/**
-	 * Try to recreate an existing StyleTextPropAtom (a) from the empty
-	 *  constructor, and setting the required properties
-	 */
-	public void testCreateAFromScatch() throws Exception {
-		// Start with an empty one
-		StyleTextPropAtom stpa = new StyleTextPropAtom(54);
-		
-		// Don't need to touch the paragraph styles
-		// Add two more character styles
-		LinkedList cs = stpa.getCharacterStyles();
-		
-		// First char style is boring, and 21 long
-		TextPropCollection tpca = (TextPropCollection)cs.get(0);
-		tpca.updateTextSize(21);
-		
-		// Second char style is coloured, 00 00 00 05, and 17 long
-		TextPropCollection tpcb = stpa.addCharacterTextPropCollection(17);
-		TextProp tpb = tpcb.addWithName("font.color");
-		tpb.setValue(0x05000000);
-		
-		// Third char style is coloured, FF 33 00 FE, and 16 long
-		TextPropCollection tpcc = stpa.addCharacterTextPropCollection(16);
-		TextProp tpc = tpcc.addWithName("font.color");
-		tpc.setValue(0xFE0033FF);
-		
-		// Should now be the same as data_a
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		stpa.writeOut(baos);
-		byte[] b = baos.toByteArray();
-
-		assertEquals(data_a.length, b.length);
-		for(int i=0; i<data_a.length; i++) {
-			assertEquals(data_a[i],b[i]);
-		}
-	}
-
-	/**
-	 * Try to recreate an existing StyleTextPropAtom (b) from the empty
-	 *  constructor, and setting the required properties
-	 */
-	public void testCreateBFromScatch() throws Exception {
-		// Start with an empty one
-		StyleTextPropAtom stpa = new StyleTextPropAtom(data_b_text_len);
-		
-		
-		// Need 4 paragraph styles
-		LinkedList ps = stpa.getParagraphStyles();
-		
-		// First is 30 long, left aligned, normal spacing
-		TextPropCollection tppa = (TextPropCollection)ps.get(0);
-		tppa.updateTextSize(30);
-		
-		TextProp tp = tppa.addWithName("alignment");
-		tp.setValue(0);
-		tp = tppa.addWithName("linespacing");
-		tp.setValue(80);
-
-		// Second is 28 long, centre aligned and normal spacing
-		TextPropCollection tppb = stpa.addParagraphTextPropCollection(28);
-		
-		tp = tppb.addWithName("linespacing");
-		tp.setValue(80);
-		
-		// Third is 25 long, right aligned and normal spacing
-		TextPropCollection tppc = stpa.addParagraphTextPropCollection(25);
-		
-		tp = tppc.addWithName("alignment");
-		tp.setValue(2);
-		tp = tppc.addWithName("linespacing");
-		tp.setValue(80);
-		
-		// Forth is left aligned + normal line spacing (despite differing font)
-		TextPropCollection tppd = stpa.addParagraphTextPropCollection(97);
-		
-		tp = tppd.addWithName("alignment");
-		tp.setValue(0);
-		tp = tppd.addWithName("linespacing");
-		tp.setValue(80);
-		
-		
-		// Now do 4 character styles
-		LinkedList cs = stpa.getCharacterStyles();
-		
-		// First is 30 long, bold and font size
-		TextPropCollection tpca = (TextPropCollection)cs.get(0);
-		tpca.updateTextSize(30);
-		
-		tp = tpca.addWithName("font.size");
-		tp.setValue(20);
-		CharFlagsTextProp cftp = (CharFlagsTextProp)
-			tpca.addWithName("char_flags");
-		assertEquals(0, cftp.getValue());
-		cftp.setSubValue(true, CharFlagsTextProp.BOLD_IDX);
-		assertEquals(1, cftp.getValue());
-		
-		// Second is 28 long, blue and italic
-		TextPropCollection tpcb = stpa.addCharacterTextPropCollection(28);
-		
-		tp = tpcb.addWithName("font.size");
-		tp.setValue(20);
-		tp = tpcb.addWithName("font.color");
-		tp.setValue(0x05000000);
-		cftp = (CharFlagsTextProp)tpcb.addWithName("char_flags");
-		cftp.setSubValue(true, CharFlagsTextProp.ITALIC_IDX);
-		assertEquals(2, cftp.getValue());
-		
-		// Third is 25 long and red
-		TextPropCollection tpcc = stpa.addCharacterTextPropCollection(25);
-		
-		tp = tpcc.addWithName("font.size");
-		tp.setValue(20);
-		tp = tpcc.addWithName("font.color");
-		tp.setValue(0xfe0033ff);
-		
-		// Fourth is 96 long, underlined and different+bigger font 
-		TextPropCollection tpcd = stpa.addCharacterTextPropCollection(96);
-		
-		tp = tpcd.addWithName("font.size");
-		tp.setValue(24);
-		tp = tpcd.addWithName("font.index");
-		tp.setValue(1);
-		cftp = (CharFlagsTextProp)tpcd.addWithName("char_flags");
-		cftp.setSubValue(true, CharFlagsTextProp.UNDERLINE_IDX);
-		assertEquals(4, cftp.getValue());
-		
-		// Fifth is 1 long, underlined and different+bigger font + red
-		TextPropCollection tpce = stpa.addCharacterTextPropCollection(1);
-		
-		tp = tpce.addWithName("font.size");
-		tp.setValue(24);
-		tp = tpce.addWithName("font.index");
-		tp.setValue(1);
-		tp = tpce.addWithName("font.color");
-		tp.setValue(0xfe0033ff);
-		cftp = (CharFlagsTextProp)tpce.addWithName("char_flags");
-		cftp.setSubValue(true, CharFlagsTextProp.UNDERLINE_IDX);
-		assertEquals(4, cftp.getValue());
-		
-		
-		// Check it's as expected
-		assertEquals(4, stpa.getParagraphStyles().size());
-		assertEquals(5, stpa.getCharacterStyles().size());
-		
-		// Compare in detail to b
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		stpb.setParentTextSize(data_b_text_len);
-		LinkedList psb = stpb.getParagraphStyles();
-		LinkedList csb = stpb.getCharacterStyles();
-		
-		assertEquals(psb.size(), ps.size());
-		assertEquals(csb.size(), cs.size());
-		
-		// Ensure Paragraph Character styles match
-		for(int z=0; z<2; z++) {
-			LinkedList lla = cs; 
-			LinkedList llb = csb;
-			int upto = 5;
-			if(z == 1) {
-				lla = ps;
-				llb = psb;
-				upto = 4;
-			}
-			
-			for(int i=0; i<upto; i++) {
-				TextPropCollection ca = (TextPropCollection)lla.get(i);
-				TextPropCollection cb = (TextPropCollection)llb.get(i);
-				
-				assertEquals(ca.getCharactersCovered(), cb.getCharactersCovered());
-				assertEquals(ca.getTextPropList().size(), cb.getTextPropList().size());
-				
-				for(int j=0; j<ca.getTextPropList().size(); j++) {
-					TextProp tpa = (TextProp)ca.getTextPropList().get(j);
-					TextProp tpb = (TextProp)cb.getTextPropList().get(j);
-					//System.out.println("TP " + i + " " + j + " " + tpa.getName() + "\t" + tpa.getValue() );
-					assertEquals(tpa.getName(), tpb.getName());
-					assertEquals(tpa.getMask(), tpb.getMask());
-					assertEquals(tpa.getWriteMask(), tpb.getWriteMask());
-					assertEquals(tpa.getValue(), tpb.getValue());
-				}
-				
-				ByteArrayOutputStream ba = new ByteArrayOutputStream();
-				ByteArrayOutputStream bb = new ByteArrayOutputStream();
-				
-				ca.writeOut(ba);
-				cb.writeOut(bb);
-				byte[] cab = ba.toByteArray(); 
-				byte[] cbb = bb.toByteArray();
-				
-				assertEquals(cbb.length, cab.length);
-				for(int j=0; j<cab.length; j++) {
-					//System.out.println("On tp " + z + " " + i + " " + j + "\t" + cab[j] + "\t" + cbb[j]);
-					assertEquals(cbb[j], cab[j]);
-				}
-			}
-		}
-		
-
-		
-		// Check byte level with b
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		stpa.writeOut(baos);
-		byte[] b = baos.toByteArray();
-
-		assertEquals(data_b.length, b.length);
-		for(int i=0; i<data_b.length; i++) {
-			System.out.println(i + "\t" + b[i] + "\t" + data_b[i] + "\t" + Integer.toHexString(b[i]) );
-			assertEquals(data_b[i],b[i]);
-		}
-	}
-
-	public void testWriteA() throws Exception {
-		StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		stpa.writeOut(baos);
-		byte[] b = baos.toByteArray();
-
-		assertEquals(data_a.length, b.length);
-		for(int i=0; i<data_a.length; i++) {
-			assertEquals(data_a[i],b[i]);
-		}
-	}
-
-	public void testLoadWriteA() throws Exception {
-		StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
-		stpa.setParentTextSize(data_a_text_len);
-
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		stpa.writeOut(baos);
-		byte[] b = baos.toByteArray();
-
-		assertEquals(data_a.length, b.length);
-		for(int i=0; i<data_a.length; i++) {
-			assertEquals(data_a[i],b[i]);
-		}
-	}
-
-
-	public void testWriteB() throws Exception {
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		stpb.writeOut(baos);
-		byte[] b = baos.toByteArray();
-
-		assertEquals(data_b.length, b.length);
-		for(int i=0; i<data_b.length; i++) {
-			assertEquals(data_b[i],b[i]);
-		}
-	}
-
-	public void testLoadWriteB() throws Exception {
-		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
-		stpb.setParentTextSize(data_b_text_len);
-
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		stpb.writeOut(baos);
-		byte[] b = baos.toByteArray();
-
-		assertEquals(data_b.length, b.length);
-		for(int i=0; i<data_b.length; i++) {
-			//System.out.println(i + "\t" + b[i] + "\t" + data_b[i] + "\t" + Integer.toHexString(b[i]) );
-			assertEquals(data_b[i],b[i]);
-		}
-	}
-	
-	
-	public void testNotEnoughDataProp() throws Exception {
-		// We don't have enough data in the record to cover
-		//  all the properties the mask says we have
-		// Make sure we just do the best we can
-		StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
-		stpc.setParentTextSize(data_c_text_len);
-		
-		// If we get here, we didn't break
-	}
+        StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+        StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
+        assertEquals(4001l, stpa.getRecordType());
+        assertEquals(4001l, stpb.getRecordType());
+        assertEquals(4001l, stpc.getRecordType());
+    }
+
+
+    public void testCharacterStyleCounts() throws Exception {
+        StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+
+        // Set for the appropriate text sizes
+        stpa.setParentTextSize(data_a_text_len);
+        stpb.setParentTextSize(data_b_text_len);
+
+        // In case A, there is a single styling of the characters
+        assertEquals(3, stpa.getCharacterStyles().size());
+        // In case B, there are 5 different stylings
+        assertEquals(5, stpb.getCharacterStyles().size());
+    }
+
+    public void testParagraphStyleCounts() throws Exception {
+        StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+
+        // Set for the appropriate text sizes
+        stpa.setParentTextSize(data_a_text_len);
+        stpb.setParentTextSize(data_b_text_len);
+
+        // In case A, all has the same spacing and alignment
+        assertEquals(1, stpa.getParagraphStyles().size());
+        // In case B, all 4 sets have different alignments
+        assertEquals(4, stpb.getParagraphStyles().size());
+    }
+
+
+    public void testCharacterStyleLengths() throws Exception {
+        StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+
+        // Set for the appropriate text sizes
+        stpa.setParentTextSize(data_a_text_len);
+        stpb.setParentTextSize(data_b_text_len);
+
+        // 54 chars, 21 + 17 + 16
+        LinkedList a_ch_l = stpa.getCharacterStyles();
+        TextPropCollection a_ch_1 = (TextPropCollection)a_ch_l.get(0);
+        TextPropCollection a_ch_2 = (TextPropCollection)a_ch_l.get(1);
+        TextPropCollection a_ch_3 = (TextPropCollection)a_ch_l.get(2);
+        assertEquals(21, a_ch_1.getCharactersCovered());
+        assertEquals(17, a_ch_2.getCharactersCovered());
+        assertEquals(16, a_ch_3.getCharactersCovered());
+
+        // 179 chars, 30 + 28 + 25
+        LinkedList b_ch_l = stpb.getCharacterStyles();
+        TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
+        TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
+        TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
+        TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
+        assertEquals(30, b_ch_1.getCharactersCovered());
+        assertEquals(28, b_ch_2.getCharactersCovered());
+        assertEquals(25, b_ch_3.getCharactersCovered());
+        assertEquals(96, b_ch_4.getCharactersCovered());
+    }
+
+
+    public void testCharacterPropOrdering() throws Exception {
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+        stpb.setParentTextSize(data_b_text_len);
+
+        LinkedList b_ch_l = stpb.getCharacterStyles();
+        TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
+        TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
+        TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
+        TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
+
+        // In first set, we get a CharFlagsTextProp and a font.size
+        assertEquals(2,b_ch_1.getTextPropList().size());
+        TextProp tp_1_1 = (TextProp)b_ch_1.getTextPropList().get(0);
+        TextProp tp_1_2 = (TextProp)b_ch_1.getTextPropList().get(1);
+        assertEquals(true, tp_1_1 instanceof CharFlagsTextProp);
+        assertEquals(true, tp_1_2 instanceof TextProp);
+        assertEquals("font.size", tp_1_2.getName());
+        assertEquals(20, tp_1_2.getValue());
+
+        // In second set, we get a CharFlagsTextProp and a font.size and a font.color
+        assertEquals(3,b_ch_2.getTextPropList().size());
+        TextProp tp_2_1 = (TextProp)b_ch_2.getTextPropList().get(0);
+        TextProp tp_2_2 = (TextProp)b_ch_2.getTextPropList().get(1);
+        TextProp tp_2_3 = (TextProp)b_ch_2.getTextPropList().get(2);
+        assertEquals(true, tp_2_1 instanceof CharFlagsTextProp);
+        assertEquals(true, tp_2_2 instanceof TextProp);
+        assertEquals(true, tp_2_3 instanceof TextProp);
+        assertEquals("font.size", tp_2_2.getName());
+        assertEquals("font.color", tp_2_3.getName());
+        assertEquals(20, tp_2_2.getValue());
+
+        // In third set, it's just a font.size and a font.color
+        assertEquals(2,b_ch_3.getTextPropList().size());
+        TextProp tp_3_1 = (TextProp)b_ch_3.getTextPropList().get(0);
+        TextProp tp_3_2 = (TextProp)b_ch_3.getTextPropList().get(1);
+        assertEquals(true, tp_3_1 instanceof TextProp);
+        assertEquals(true, tp_3_2 instanceof TextProp);
+        assertEquals("font.size", tp_3_1.getName());
+        assertEquals("font.color", tp_3_2.getName());
+        assertEquals(20, tp_3_1.getValue());
+
+        // In fourth set, we get a CharFlagsTextProp and a font.index and a font.size
+        assertEquals(3,b_ch_4.getTextPropList().size());
+        TextProp tp_4_1 = (TextProp)b_ch_4.getTextPropList().get(0);
+        TextProp tp_4_2 = (TextProp)b_ch_4.getTextPropList().get(1);
+        TextProp tp_4_3 = (TextProp)b_ch_4.getTextPropList().get(2);
+        assertEquals(true, tp_4_1 instanceof CharFlagsTextProp);
+        assertEquals(true, tp_4_2 instanceof TextProp);
+        assertEquals(true, tp_4_3 instanceof TextProp);
+        assertEquals("font.index", tp_4_2.getName());
+        assertEquals("font.size", tp_4_3.getName());
+        assertEquals(24, tp_4_3.getValue());
+    }
+
+    public void testParagraphProps() throws Exception {
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+        stpb.setParentTextSize(data_b_text_len);
+
+        LinkedList b_p_l = stpb.getParagraphStyles();
+        TextPropCollection b_p_1 = (TextPropCollection)b_p_l.get(0);
+        TextPropCollection b_p_2 = (TextPropCollection)b_p_l.get(1);
+        TextPropCollection b_p_3 = (TextPropCollection)b_p_l.get(2);
+        TextPropCollection b_p_4 = (TextPropCollection)b_p_l.get(3);
+
+        // 1st is left aligned + normal line spacing
+        assertEquals(2,b_p_1.getTextPropList().size());
+        TextProp tp_1_1 = (TextProp)b_p_1.getTextPropList().get(0);
+        TextProp tp_1_2 = (TextProp)b_p_1.getTextPropList().get(1);
+        assertEquals(true, tp_1_1 instanceof TextProp);
+        assertEquals(true, tp_1_2 instanceof TextProp);
+        assertEquals("alignment", tp_1_1.getName());
+        assertEquals("linespacing", tp_1_2.getName());
+        assertEquals(0, tp_1_1.getValue());
+        assertEquals(80, tp_1_2.getValue());
+
+        // 2nd is centre aligned (default) + normal line spacing
+        assertEquals(1,b_p_2.getTextPropList().size());
+        TextProp tp_2_1 = (TextProp)b_p_2.getTextPropList().get(0);
+        assertEquals(true, tp_2_1 instanceof TextProp);
+        assertEquals(true, tp_1_2 instanceof TextProp);
+        assertEquals("linespacing", tp_2_1.getName());
+        assertEquals(80, tp_2_1.getValue());
+
+        // 3rd is right aligned + normal line spacing
+        assertEquals(2,b_p_3.getTextPropList().size());
+        TextProp tp_3_1 = (TextProp)b_p_3.getTextPropList().get(0);
+        TextProp tp_3_2 = (TextProp)b_p_3.getTextPropList().get(1);
+        assertEquals(true, tp_3_1 instanceof TextProp);
+        assertEquals(true, tp_3_2 instanceof TextProp);
+        assertEquals("alignment", tp_3_1.getName());
+        assertEquals("linespacing", tp_3_2.getName());
+        assertEquals(2, tp_3_1.getValue());
+        assertEquals(80, tp_3_2.getValue());
+
+        // 4st is left aligned + normal line spacing (despite differing font)
+        assertEquals(2,b_p_4.getTextPropList().size());
+        TextProp tp_4_1 = (TextProp)b_p_4.getTextPropList().get(0);
+        TextProp tp_4_2 = (TextProp)b_p_4.getTextPropList().get(1);
+        assertEquals(true, tp_4_1 instanceof TextProp);
+        assertEquals(true, tp_4_2 instanceof TextProp);
+        assertEquals("alignment", tp_4_1.getName());
+        assertEquals("linespacing", tp_4_2.getName());
+        assertEquals(0, tp_4_1.getValue());
+        assertEquals(80, tp_4_2.getValue());
+    }
+
+    public void testCharacterProps() throws Exception {
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+        stpb.setParentTextSize(data_b_text_len);
+
+        LinkedList b_ch_l = stpb.getCharacterStyles();
+        TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
+        TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
+        TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
+        TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
+
+        // 1st is bold
+        CharFlagsTextProp cf_1_1 = (CharFlagsTextProp)b_ch_1.getTextPropList().get(0);
+        assertEquals(true,cf_1_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
+        assertEquals(false,cf_1_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+
+        // 2nd is italic
+        CharFlagsTextProp cf_2_1 = (CharFlagsTextProp)b_ch_2.getTextPropList().get(0);
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
+        assertEquals(true,cf_2_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
+        assertEquals(false,cf_2_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+
+        // 3rd is normal, so lacks a CharFlagsTextProp
+        assertFalse(b_ch_3.getTextPropList().get(0) instanceof CharFlagsTextProp);
+
+        // 4th is underlined
+        CharFlagsTextProp cf_4_1 = (CharFlagsTextProp)b_ch_4.getTextPropList().get(0);
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
+        assertEquals(true,cf_4_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+
+        // The value for this should be 4
+        assertEquals(0x0004, cf_4_1.getValue());
+
+        // Now make the 4th bold, italic and not underlined
+        cf_4_1.setSubValue(true, CharFlagsTextProp.BOLD_IDX);
+        cf_4_1.setSubValue(true, CharFlagsTextProp.ITALIC_IDX);
+        cf_4_1.setSubValue(false, CharFlagsTextProp.UNDERLINE_IDX);
+
+        assertEquals(true,cf_4_1.getSubValue(CharFlagsTextProp.BOLD_IDX));
+        assertEquals(true,cf_4_1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_1_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.ENABLE_NUMBERING_2_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RELIEF_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.RESET_NUMBERING_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.SHADOW_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.STRIKETHROUGH_IDX));
+        assertEquals(false,cf_4_1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+
+        // The value should now be 3
+        assertEquals(0x0003, cf_4_1.getValue());
+    }
+
+    public void testFindAddTextProp() {
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+        stpb.setParentTextSize(data_b_text_len);
+
+        LinkedList b_p_l = stpb.getParagraphStyles();
+        TextPropCollection b_p_1 = (TextPropCollection)b_p_l.get(0);
+        TextPropCollection b_p_2 = (TextPropCollection)b_p_l.get(1);
+        TextPropCollection b_p_3 = (TextPropCollection)b_p_l.get(2);
+        TextPropCollection b_p_4 = (TextPropCollection)b_p_l.get(3);
+
+        LinkedList b_ch_l = stpb.getCharacterStyles();
+        TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
+        TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
+        TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
+        TextPropCollection b_ch_4 = (TextPropCollection)b_ch_l.get(3);
+
+        // CharFlagsTextProp: 3 doesn't have, 4 does
+        assertNull(b_ch_3.findByName("char_flags"));
+        assertNotNull(b_ch_4.findByName("char_flags"));
+
+        // Now add in on 3, should go to front
+        assertEquals(2, b_ch_3.getTextPropList().size());
+        TextProp new_cftp = b_ch_3.addWithName("char_flags");
+        assertEquals(3, b_ch_3.getTextPropList().size());
+        assertEquals(new_cftp, b_ch_3.getTextPropList().get(0));
+
+        // alignment: 1 does have, 2 doesn't
+        assertNotNull(b_p_1.findByName("alignment"));
+        assertNull(b_p_2.findByName("alignment"));
+
+        // Now add in on 2, should go to the front
+        assertEquals(1, b_p_2.getTextPropList().size());
+        TextProp new_al = b_p_2.addWithName("alignment");
+        assertEquals(2, b_p_2.getTextPropList().size());
+        assertEquals(new_al, b_p_2.getTextPropList().get(0));
+
+        // This should go at the end
+        TextProp new_sa = b_p_2.addWithName("spaceafter");
+        assertEquals(3, b_p_2.getTextPropList().size());
+        assertEquals(new_sa, b_p_2.getTextPropList().get(2));
+
+        // Check we get an error with a made up one
+        try {
+            b_p_2.addWithName("madeUpOne");
+            fail();
+        } catch(IllegalArgumentException e) {
+            // Good, as expected
+        }
+    }
+
+    /**
+     * Try to recreate an existing StyleTextPropAtom (a) from the empty
+     *  constructor, and setting the required properties
+     */
+    public void testCreateAFromScatch() throws Exception {
+        // Start with an empty one
+        StyleTextPropAtom stpa = new StyleTextPropAtom(54);
+
+        // Don't need to touch the paragraph styles
+        // Add two more character styles
+        LinkedList cs = stpa.getCharacterStyles();
+
+        // First char style is boring, and 21 long
+        TextPropCollection tpca = (TextPropCollection)cs.get(0);
+        tpca.updateTextSize(21);
+
+        // Second char style is coloured, 00 00 00 05, and 17 long
+        TextPropCollection tpcb = stpa.addCharacterTextPropCollection(17);
+        TextProp tpb = tpcb.addWithName("font.color");
+        tpb.setValue(0x05000000);
+
+        // Third char style is coloured, FF 33 00 FE, and 16 long
+        TextPropCollection tpcc = stpa.addCharacterTextPropCollection(16);
+        TextProp tpc = tpcc.addWithName("font.color");
+        tpc.setValue(0xFE0033FF);
+
+        // Should now be the same as data_a
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        stpa.writeOut(baos);
+        byte[] b = baos.toByteArray();
+
+        assertEquals(data_a.length, b.length);
+        for(int i=0; i<data_a.length; i++) {
+            assertEquals(data_a[i],b[i]);
+        }
+    }
+
+    /**
+     * Try to recreate an existing StyleTextPropAtom (b) from the empty
+     *  constructor, and setting the required properties
+     */
+    public void testCreateBFromScatch() throws Exception {
+        // Start with an empty one
+        StyleTextPropAtom stpa = new StyleTextPropAtom(data_b_text_len);
+
+
+        // Need 4 paragraph styles
+        LinkedList ps = stpa.getParagraphStyles();
+
+        // First is 30 long, left aligned, normal spacing
+        TextPropCollection tppa = (TextPropCollection)ps.get(0);
+        tppa.updateTextSize(30);
+
+        TextProp tp = tppa.addWithName("alignment");
+        tp.setValue(0);
+        tp = tppa.addWithName("linespacing");
+        tp.setValue(80);
+
+        // Second is 28 long, centre aligned and normal spacing
+        TextPropCollection tppb = stpa.addParagraphTextPropCollection(28);
+
+        tp = tppb.addWithName("linespacing");
+        tp.setValue(80);
+
+        // Third is 25 long, right aligned and normal spacing
+        TextPropCollection tppc = stpa.addParagraphTextPropCollection(25);
+
+        tp = tppc.addWithName("alignment");
+        tp.setValue(2);
+        tp = tppc.addWithName("linespacing");
+        tp.setValue(80);
+
+        // Forth is left aligned + normal line spacing (despite differing font)
+        TextPropCollection tppd = stpa.addParagraphTextPropCollection(97);
+
+        tp = tppd.addWithName("alignment");
+        tp.setValue(0);
+        tp = tppd.addWithName("linespacing");
+        tp.setValue(80);
+
+
+        // Now do 4 character styles
+        LinkedList cs = stpa.getCharacterStyles();
+
+        // First is 30 long, bold and font size
+        TextPropCollection tpca = (TextPropCollection)cs.get(0);
+        tpca.updateTextSize(30);
+
+        tp = tpca.addWithName("font.size");
+        tp.setValue(20);
+        CharFlagsTextProp cftp = (CharFlagsTextProp)
+            tpca.addWithName("char_flags");
+        assertEquals(0, cftp.getValue());
+        cftp.setSubValue(true, CharFlagsTextProp.BOLD_IDX);
+        assertEquals(1, cftp.getValue());
+
+        // Second is 28 long, blue and italic
+        TextPropCollection tpcb = stpa.addCharacterTextPropCollection(28);
+
+        tp = tpcb.addWithName("font.size");
+        tp.setValue(20);
+        tp = tpcb.addWithName("font.color");
+        tp.setValue(0x05000000);
+        cftp = (CharFlagsTextProp)tpcb.addWithName("char_flags");
+        cftp.setSubValue(true, CharFlagsTextProp.ITALIC_IDX);
+        assertEquals(2, cftp.getValue());
+
+        // Third is 25 long and red
+        TextPropCollection tpcc = stpa.addCharacterTextPropCollection(25);
+
+        tp = tpcc.addWithName("font.size");
+        tp.setValue(20);
+        tp = tpcc.addWithName("font.color");
+        tp.setValue(0xfe0033ff);
+
+        // Fourth is 96 long, underlined and different+bigger font
+        TextPropCollection tpcd = stpa.addCharacterTextPropCollection(96);
+
+        tp = tpcd.addWithName("font.size");
+        tp.setValue(24);
+        tp = tpcd.addWithName("font.index");
+        tp.setValue(1);
+        cftp = (CharFlagsTextProp)tpcd.addWithName("char_flags");
+        cftp.setSubValue(true, CharFlagsTextProp.UNDERLINE_IDX);
+        assertEquals(4, cftp.getValue());
+
+        // Fifth is 1 long, underlined and different+bigger font + red
+        TextPropCollection tpce = stpa.addCharacterTextPropCollection(1);
+
+        tp = tpce.addWithName("font.size");
+        tp.setValue(24);
+        tp = tpce.addWithName("font.index");
+        tp.setValue(1);
+        tp = tpce.addWithName("font.color");
+        tp.setValue(0xfe0033ff);
+        cftp = (CharFlagsTextProp)tpce.addWithName("char_flags");
+        cftp.setSubValue(true, CharFlagsTextProp.UNDERLINE_IDX);
+        assertEquals(4, cftp.getValue());
+
+
+        // Check it's as expected
+        assertEquals(4, stpa.getParagraphStyles().size());
+        assertEquals(5, stpa.getCharacterStyles().size());
+
+        // Compare in detail to b
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+        stpb.setParentTextSize(data_b_text_len);
+        LinkedList psb = stpb.getParagraphStyles();
+        LinkedList csb = stpb.getCharacterStyles();
+
+        assertEquals(psb.size(), ps.size());
+        assertEquals(csb.size(), cs.size());
+
+        // Ensure Paragraph Character styles match
+        for(int z=0; z<2; z++) {
+            LinkedList lla = cs;
+            LinkedList llb = csb;
+            int upto = 5;
+            if(z == 1) {
+                lla = ps;
+                llb = psb;
+                upto = 4;
+            }
+
+            for(int i=0; i<upto; i++) {
+                TextPropCollection ca = (TextPropCollection)lla.get(i);
+                TextPropCollection cb = (TextPropCollection)llb.get(i);
+
+                assertEquals(ca.getCharactersCovered(), cb.getCharactersCovered());
+                assertEquals(ca.getTextPropList().size(), cb.getTextPropList().size());
+
+                for(int j=0; j<ca.getTextPropList().size(); j++) {
+                    TextProp tpa = (TextProp)ca.getTextPropList().get(j);
+                    TextProp tpb = (TextProp)cb.getTextPropList().get(j);
+                    //System.out.println("TP " + i + " " + j + " " + tpa.getName() + "\t" + tpa.getValue() );
+                    assertEquals(tpa.getName(), tpb.getName());
+                    assertEquals(tpa.getMask(), tpb.getMask());
+                    assertEquals(tpa.getWriteMask(), tpb.getWriteMask());
+                    assertEquals(tpa.getValue(), tpb.getValue());
+                }
+
+                ByteArrayOutputStream ba = new ByteArrayOutputStream();
+                ByteArrayOutputStream bb = new ByteArrayOutputStream();
+
+                ca.writeOut(ba);
+                cb.writeOut(bb);
+                byte[] cab = ba.toByteArray();
+                byte[] cbb = bb.toByteArray();
+
+                assertEquals(cbb.length, cab.length);
+                for(int j=0; j<cab.length; j++) {
+                    //System.out.println("On tp " + z + " " + i + " " + j + "\t" + cab[j] + "\t" + cbb[j]);
+                    assertEquals(cbb[j], cab[j]);
+                }
+            }
+        }
+
+
+
+        // Check byte level with b
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        stpa.writeOut(baos);
+        byte[] b = baos.toByteArray();
+
+        assertEquals(data_b.length, b.length);
+        for(int i=0; i<data_b.length; i++) {
+            //System.out.println(i + "\t" + b[i] + "\t" + data_b[i] + "\t" + Integer.toHexString(b[i]) );
+            assertEquals(data_b[i],b[i]);
+        }
+    }
+
+    public void testWriteA() throws Exception {
+        doReadWrite(data_a, -1);
+    }
+
+    public void testLoadWriteA() throws Exception {
+        doReadWrite(data_b, data_b_text_len);
+    }
+
+
+    public void testWriteB() throws Exception {
+        doReadWrite(data_b, -1);
+    }
+
+    public void testLoadWriteB() throws Exception {
+        doReadWrite(data_b, data_b_text_len);
+    }
+
+    public void testLoadWriteC() throws Exception {
+        doReadWrite(data_c, data_c_text_len);
+    }
+
+    public void testLoadWriteD() throws Exception {
+        doReadWrite(data_d, data_d_text_len);
+    }
+
+    protected void doReadWrite(byte[] data, int textlen) throws Exception {
+        StyleTextPropAtom stpb = new StyleTextPropAtom(data, 0,data.length);
+        if(textlen != -1) stpb.setParentTextSize(textlen);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        stpb.writeOut(out);
+        byte[] bytes = out.toByteArray();
+
+        assertEquals(data.length, bytes.length);
+        try {
+            assertTrue(Arrays.equals(data, bytes));
+        } catch (Throwable e){
+            //print hex dump if failed
+            assertEquals(HexDump.toHex(data), HexDump.toHex(bytes));
+        }
+    }
+
+    public void testNotEnoughDataProp() throws Exception {
+        // We don't have enough data in the record to cover
+        //  all the properties the mask says we have
+        // Make sure we just do the best we can
+        StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
+        stpc.setParentTextSize(data_c_text_len);
+
+        // If we get here, we didn't break
+    }
 
     /**
      * Check the test data for Bug 40143.
@@ -732,8 +720,8 @@
         assertEquals(1, chprops.findByName("char_flags").getValue());
         assertEquals(1, chprops.findByName("font.index").getValue());
         assertEquals(20, chprops.findByName("font.size").getValue());
-        assertEquals(0, chprops.findByName("asian_or_complex").getValue());
-        assertEquals(1, chprops.findByName("char_unknown_2").getValue());
+        assertEquals(0, chprops.findByName("asian.font.index").getValue());
+        assertEquals(1, chprops.findByName("ansi.font.index").getValue());
     }
 
     /**
@@ -747,16 +735,7 @@
                        0x00 , 0x00 , 0x13 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x63 , 0x00 ,
                        0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x0F , 0x00
         };
-        StyleTextPropAtom stpa = new StyleTextPropAtom(data,0,data.length);
-        stpa.setParentTextSize(length);
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        stpa.writeOut(baos);
-        byte[] b = baos.toByteArray();
-
-        assertEquals(data.length, b.length);
-        for(int i=0; i<data.length; i++) {
-            assertEquals(data[i],b[i]);
-        }
+        doReadWrite(data, length);
 
     }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
Binary files - no diff available.

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java Sun Sep  7 10:34:36 2008
@@ -24,6 +24,7 @@
 import org.apache.poi.hssf.model.FormulaParser.FormulaParseException;
 import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
 import org.apache.poi.hssf.record.formula.AddPtg;
+import org.apache.poi.hssf.record.formula.AreaI;
 import org.apache.poi.hssf.record.formula.AreaPtg;
 import org.apache.poi.hssf.record.formula.AttrPtg;
 import org.apache.poi.hssf.record.formula.BoolPtg;
@@ -836,4 +837,29 @@
 		}
 		cell.setCellFormula("count(fp1)"); // plain cell ref, col is in range
 	}
-}
+	
+	public void testParseAreaRefHighRow_bug45358() {
+		Ptg[] ptgs;
+		AreaI aptg;
+		
+		HSSFWorkbook book = new HSSFWorkbook();
+		book.createSheet("Sheet1");
+		
+		ptgs = FormulaParser.parse("Sheet1!A10:A40000", book);
+		aptg = (AreaI) ptgs[0];
+		if (aptg.getLastRow() == -25537) {
+			throw new AssertionFailedError("Identified bug 45358");
+		}
+		assertEquals(39999, aptg.getLastRow());
+		
+		ptgs = FormulaParser.parse("Sheet1!A10:A65536", book);
+		aptg = (AreaI) ptgs[0];
+		assertEquals(65535, aptg.getLastRow());
+		
+		// plain area refs should be ok too
+		ptgs = parseFormula("A10:A65536");
+		aptg = (AreaI) ptgs[0];
+		assertEquals(65535, aptg.getLastRow());
+		
+	}
+}
\ No newline at end of file

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestLinkedDataRecord.java Sun Sep  7 10:34:36 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,8 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
-
 
 package org.apache.poi.hssf.record;
 
@@ -33,9 +30,7 @@
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public class TestLinkedDataRecord
-        extends TestCase
-{
+public final class TestLinkedDataRecord extends TestCase {
 
 /*
     The records below are records that would appear in a simple bar chart
@@ -160,14 +155,7 @@
         (byte)0x00,(byte)0x00,          // index to last column and relative flags
     };
 
-    public TestLinkedDataRecord(String name)
-    {
-        super(name);
-    }
-
-    public void testLoad()
-            throws Exception
-    {
+    public void testLoad() {
 
         LinkedDataRecord record = new LinkedDataRecord(new TestcaseRecordInputStream((short)0x1051, (short)data.length, data));
         assertEquals( LinkedDataRecord.LINK_TYPE_VALUES, record.getLinkType());
@@ -176,19 +164,11 @@
         assertEquals( false, record.isCustomNumberFormat() );
         assertEquals( 0, record.getIndexNumberFmtRecord());
 
-        Area3DPtg ptg = new Area3DPtg();
-        ptg.setExternSheetIndex((short)0);
-        ptg.setFirstColumn((short)0);
-        ptg.setLastColumn((short)0);
-        ptg.setFirstRow((short)0);
-        ptg.setLastRow((short)7936);
-        ptg.setFirstColRelative(false);
-        ptg.setLastColRelative(false);
-        ptg.setFirstRowRelative(false);
-        ptg.setLastRowRelative(false);
-        Stack s = new Stack();
-        s.push(ptg);
-        assertEquals( s, record.getFormulaOfLink().getFormulaTokens() );
+        Area3DPtg ptgExpected = new Area3DPtg(0, 7936, 0, 0,
+                false, false, false, false, 0);
+        
+        Object ptgActual = record.getFormulaOfLink().getFormulaTokens().get(0);
+        assertEquals(ptgExpected.toString(),  ptgActual.toString());
 
         assertEquals( data.length + 4, record.getRecordSize() );
 
@@ -196,24 +176,15 @@
 
     }
 
-    public void testStore()
-    {
+    public void testStore() {
         LinkedDataRecord record = new LinkedDataRecord();
         record.setLinkType( LinkedDataRecord.LINK_TYPE_VALUES );
         record.setReferenceType( LinkedDataRecord.REFERENCE_TYPE_WORKSHEET );
         record.setOptions( (short)0 );
         record.setCustomNumberFormat( false );
         record.setIndexNumberFmtRecord( (short)0 );
-        Area3DPtg ptg = new Area3DPtg();
-        ptg.setExternSheetIndex((short)0);
-        ptg.setFirstColumn((short)0);
-        ptg.setLastColumn((short)0);
-        ptg.setFirstRow((short)0);
-        ptg.setLastRow((short)7936);
-        ptg.setFirstColRelative(false);
-        ptg.setLastColRelative(false);
-        ptg.setFirstRowRelative(false);
-        ptg.setLastRowRelative(false);
+        Area3DPtg ptg = new Area3DPtg(0, 7936, 0, 0,
+        		false, false, false, false, 0);
         Stack s = new Stack();
         s.push(ptg);
         LinkedDataFormulaField formulaOfLink = new LinkedDataFormulaField();

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestAreaEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestAreaEval.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestAreaEval.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestAreaEval.java Sun Sep  7 10:34:36 2008
@@ -20,7 +20,8 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.record.formula.Area3DPtg;
+import org.apache.poi.hssf.record.formula.AreaPtg;
+import org.apache.poi.hssf.record.formula.functions.EvalFactory;
 
 /**
  * Tests for <tt>AreaEval</tt>
@@ -30,8 +31,8 @@
 public final class TestAreaEval extends TestCase {
 
 	public void testGetValue_bug44950() {
-		
-		Area3DPtg ptg = new Area3DPtg("B2:D3", (short)0);
+		// TODO - this test probably isn't testing much anymore
+		AreaPtg ptg = new AreaPtg("B2:D3");
 		NumberEval one = new NumberEval(1);
 		ValueEval[] values = {
 				one,	
@@ -41,7 +42,7 @@
 				new NumberEval(5),	
 				new NumberEval(6),	
 		};
-		AreaEval ae = new Area3DEval(ptg, values);
+		AreaEval ae = EvalFactory.createAreaEval(ptg, values);
 		if (one == ae.getValueAt(1, 2)) {
 			throw new AssertionFailedError("Identified bug 44950 a");
 		}

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestUnaryPlusEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestUnaryPlusEval.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestUnaryPlusEval.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestUnaryPlusEval.java Sun Sep  7 10:34:36 2008
@@ -18,22 +18,23 @@
 
 package org.apache.poi.hssf.record.formula.eval;
 
+import junit.framework.TestCase;
+
 import org.apache.poi.hssf.record.formula.AreaPtg;
 import org.apache.poi.hssf.record.formula.UnaryPlusPtg;
+import org.apache.poi.hssf.record.formula.functions.EvalFactory;
 import org.apache.poi.hssf.record.formula.functions.NumericFunctionInvoker;
 
-import junit.framework.TestCase;
-
 /**
  * Test for unary plus operator evaluator.
- * 
+ *
  * @author Josh Micich
  */
 public final class TestUnaryPlusEval extends TestCase {
-	
+
 	/**
 	 * Test for bug observable at svn revision 618865 (5-Feb-2008)<br/>
-	 * The code for handling column operands had been copy-pasted from the row handling code. 
+	 * The code for handling column operands had been copy-pasted from the row handling code.
 	 */
 	public void testColumnOperand() {
 
@@ -42,15 +43,14 @@
 		short colNum = (short)5;
 		AreaPtg areaPtg = new AreaPtg(firstRow, lastRow, colNum, colNum, false, false, false, false);
 		ValueEval[] values = {
-				new NumberEval(27),	
-				new NumberEval(29),	
-				new NumberEval(35),	// value in row 10 
-				new NumberEval(37),	
-				new NumberEval(38),	
+				new NumberEval(27),
+				new NumberEval(29),
+				new NumberEval(35),	// value in row 10
+				new NumberEval(37),
+				new NumberEval(38),
 		};
-		Eval areaEval = new Area2DEval(areaPtg, values);
-		Eval[] args = { 
-			areaEval,	
+		Eval[] args = {
+			EvalFactory.createAreaEval(areaPtg, values),
 		};
 
 		double result = NumericFunctionInvoker.invoke(new UnaryPlusEval(UnaryPlusPtg.instance), args, 10, (short)20);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/EvalFactory.java Sun Sep  7 10:34:36 2008
@@ -14,17 +14,17 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record.formula.functions;
 
 import org.apache.poi.hssf.record.formula.AreaPtg;
+import org.apache.poi.hssf.record.formula.Ref3DPtg;
 import org.apache.poi.hssf.record.formula.RefPtg;
-import org.apache.poi.hssf.record.formula.eval.Area2DEval;
 import org.apache.poi.hssf.record.formula.eval.AreaEval;
+import org.apache.poi.hssf.record.formula.eval.AreaEvalBase;
 import org.apache.poi.hssf.record.formula.eval.NumberEval;
-import org.apache.poi.hssf.record.formula.eval.Ref2DEval;
 import org.apache.poi.hssf.record.formula.eval.RefEval;
+import org.apache.poi.hssf.record.formula.eval.RefEvalBase;
 import org.apache.poi.hssf.record.formula.eval.ValueEval;
 
 /**
@@ -32,7 +32,7 @@
  * 
  * @author Josh Micich
  */
-final class EvalFactory {
+public final class EvalFactory {
 
 	private EvalFactory() {
 		// no instances of this class
@@ -44,6 +44,14 @@
 	 */
 	public static AreaEval createAreaEval(String areaRefStr, ValueEval[] values) {
 		AreaPtg areaPtg = new AreaPtg(areaRefStr);
+		return createAreaEval(areaPtg, values);
+	}
+
+	/**
+	 * Creates a dummy AreaEval 
+	 * @param values empty (<code>null</code>) entries in this array will be converted to NumberEval.ZERO
+	 */
+	public static AreaEval createAreaEval(AreaPtg areaPtg, ValueEval[] values) {
 		int nCols = areaPtg.getLastColumn() - areaPtg.getFirstColumn() + 1;
 		int nRows = areaPtg.getLastRow() - areaPtg.getFirstRow() + 1;
 		int nExpected = nRows * nCols;
@@ -55,13 +63,57 @@
 				values[i] = NumberEval.ZERO;
 			}
 		}
-		return new Area2DEval(areaPtg, values);
+		return new MockAreaEval(areaPtg, values);
 	}
 
 	/**
 	 * Creates a single RefEval (with value zero)
 	 */
 	public static RefEval createRefEval(String refStr) {
-		return new Ref2DEval(new RefPtg(refStr), NumberEval.ZERO);
+		return createRefEval(refStr, NumberEval.ZERO);
+	}
+	public static RefEval createRefEval(String refStr, ValueEval value) {
+		return new MockRefEval(new RefPtg(refStr), value);
+	}
+	
+	private static final class MockAreaEval extends AreaEvalBase {
+		private final ValueEval[] _values;
+		public MockAreaEval(AreaPtg areaPtg, ValueEval[] values) {
+			super(areaPtg);
+			_values = values;
+		}
+		public ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex) {
+			if (relativeRowIndex < 0 || relativeRowIndex >=getHeight()) {
+				throw new IllegalArgumentException("row index out of range");
+			}
+			int width = getWidth();
+			if (relativeColumnIndex < 0 || relativeColumnIndex >=width) {
+				throw new IllegalArgumentException("column index out of range");
+			}
+			int oneDimensionalIndex = relativeRowIndex * width + relativeColumnIndex;
+			return _values[oneDimensionalIndex];
+		}
+		public AreaEval offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx) {
+			throw new RuntimeException("Operation not implemented on this mock object");
+		}
+	}
+	
+	private static final class MockRefEval extends RefEvalBase {
+		private final ValueEval _value;
+		public MockRefEval(RefPtg ptg, ValueEval value) {
+			super(ptg.getRow(), ptg.getColumn());
+			_value = value;
+		}
+		public MockRefEval(Ref3DPtg ptg, ValueEval value) {
+			super(ptg.getRow(), ptg.getColumn());
+			_value = value;
+		}
+		public ValueEval getInnerValueEval() {
+			return _value;
+		}
+		public AreaEval offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx) {
+			throw new RuntimeException("Operation not implemented on this mock object");
+		}
 	}
+	
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestCountFuncs.java Sun Sep  7 10:34:36 2008
@@ -21,9 +21,7 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.record.formula.AreaPtg;
 import org.apache.poi.hssf.record.formula.RefPtg;
-import org.apache.poi.hssf.record.formula.eval.Area2DEval;
 import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.BlankEval;
 import org.apache.poi.hssf.record.formula.eval.BoolEval;
@@ -91,7 +89,7 @@
 				BoolEval.TRUE,
 				BlankEval.INSTANCE,
 		};
-		range = createAreaEval("A1:B3", values);
+		range = EvalFactory.createAreaEval("A1:B3", values);
 		confirmCountIf(2, range, BoolEval.TRUE);
 
 		// when criteria is numeric
@@ -103,7 +101,7 @@
 				new NumberEval(2),
 				BoolEval.TRUE,
 		};
-		range = createAreaEval("A1:B3", values);
+		range = EvalFactory.createAreaEval("A1:B3", values);
 		confirmCountIf(3, range, new NumberEval(2));
 		// note - same results when criteria is a string that parses as the number with the same value
 		confirmCountIf(3, range, new StringEval("2.00"));
@@ -126,20 +124,15 @@
 				new NumberEval(25),
 				new NumberEval(25),
 		};
-		Area2DEval arg0 = new Area2DEval(new AreaPtg("C1:C6"), values);
+		AreaEval arg0 = EvalFactory.createAreaEval("C1:C6", values);
 
-		Ref2DEval criteriaArg = new Ref2DEval(new RefPtg("A1"), new NumberEval(25));
+		ValueEval criteriaArg = EvalFactory.createRefEval("A1", new NumberEval(25));
 		Eval[] args=  { arg0, criteriaArg, };
 
 		double actual = NumericFunctionInvoker.invoke(new Countif(), args);
 		assertEquals(4, actual, 0D);
 	}
 
-
-	private static AreaEval createAreaEval(String areaRefStr, ValueEval[] values) {
-		return new Area2DEval(new AreaPtg(areaRefStr), values);
-	}
-
 	private static void confirmCountA(int expected, Eval[] args) {
 		double result = NumericFunctionInvoker.invoke(new Counta(), args);
 		assertEquals(expected, result, 0);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java?rev=692907&r1=692906&r2=692907&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestIndex.java Sun Sep  7 10:34:36 2008
@@ -19,8 +19,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.record.formula.AreaPtg;
-import org.apache.poi.hssf.record.formula.eval.Area2DEval;
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.Eval;
 import org.apache.poi.hssf.record.formula.eval.NumberEval;
 import org.apache.poi.hssf.record.formula.eval.ValueEval;
@@ -68,7 +67,7 @@
 		for (int i = 0; i < values.length; i++) {
 			values[i] = new NumberEval(dValues[i]);
 		}
-		Area2DEval arg0 = new Area2DEval(new AreaPtg(areaRefString), values);
+		AreaEval arg0 = EvalFactory.createAreaEval(areaRefString, values);
 		
 		Eval[] args;
 		if (colNum > 0) {



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


Mime
View raw message