poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r496369 - in /jakarta/poi/trunk/src/scratchpad: src/org/apache/poi/hslf/record/StyleTextPropAtom.java testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
Date Mon, 15 Jan 2007 15:22:40 GMT
Author: nick
Date: Mon Jan 15 07:22:39 2007
New Revision: 496369

URL: http://svn.apache.org/viewvc?view=rev&rev=496369
Log:
Update the order of the TextProps, as it seems not to be based quite on the mask order. Fix
from Yegor, from bug #40143

Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?view=diff&rev=496369&r1=496368&r2=496369
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
Mon Jan 15 07:22:39 2007
@@ -25,6 +25,8 @@
 import java.io.ByteArrayOutputStream;
 import java.util.LinkedList;
 import java.util.Vector;
+import java.util.List;
+import java.util.Iterator;
 
 /**
  * A StyleTextPropAtom (type 4001). Holds basic character properties 
@@ -90,33 +92,33 @@
 					"bullet", "bullet.hardfont", 
 					"bullet.hardcolor", "bullet.hardsize"}
 				),
+                new TextProp(2, 0x80, "bullet.char"),
 				new TextProp(2, 0x10, "bullet.font"),
 				new TextProp(4, 0x20, "bullet.color"),
 				new TextProp(2, 0x40, "bullet.size"),
-				new TextProp(2, 0x80, "bullet.char"),
-				new TextProp(2, 0x100, "text.offset"),
+                new AlignmentTextProp(),
+                new TextProp(2, 0x400, "bullet.offset"),
 				new TextProp(2, 0x200, "para_unknown_2"),
-				new TextProp(2, 0x400, "bullet.offset"),
-				new AlignmentTextProp(), // 0x800
+                new TextProp(2, 0x100, "text.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, 0xE0000, "para_unknown_6"),
 				new TextProp(2, 0x200000, "para_unknown_7")
 	};
 	/** All the different kinds of character properties we might handle */
 	public static TextProp[] characterTextPropTypes = new TextProp[] {
 				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(2, 0x20000, "font.size"),
 				new TextProp(4, 0x40000, "font.color"),
 				new TextProp(2, 0x80000, "offset"),
 				new TextProp(2, 0x100000, "char_unknown_1"),
-				new TextProp(2, 0x200000, "asian_or_complex"),
-				new TextProp(2, 0x400000, "char_unknown_2"),
-				new TextProp(2, 0x800000, "symbol"),
 				new TextProp(2, 0x1000000, "char_unknown_3"),
 				new TextProp(2, 0x2000000, "char_unknown_4"),
 				new TextProp(2, 0x4000000, "char_unknown_5"),
@@ -127,7 +129,6 @@
 				new TextProp(2, 0x80000000, "char_unknown_10"),
 	};
 
-	
 	/* *************** record code follows ********************** */
 
 	/** 
@@ -730,4 +731,34 @@
 			);
 		}
 	}
+
+    /**
+     * Dump the record content into <code>StringBuffer</code>
+     *
+     * @return the string representation of the record data
+     */
+    public String toString(){
+        StringBuffer out = new StringBuffer();
+        out.append("Paragraph properties\n");
+        for (Iterator it1 = getParagraphStyles().iterator(); it1.hasNext();) {
+            TextPropCollection pr = (TextPropCollection)it1.next();
+            out.append("  chars covered: " + pr.getCharactersCovered() + "\n");
+            for (Iterator it2 = pr.getTextPropList().iterator(); it2.hasNext(); ) {
+                TextProp p = (TextProp)it2.next();
+                out.append("    " + p.getName() + " = " + p.getValue() + "\n");
+            }
+        }
+
+        out.append("Character properties\n");
+        for (Iterator it1 = getCharacterStyles().iterator(); it1.hasNext();) {
+            TextPropCollection pr = (TextPropCollection)it1.next();
+            out.append("  chars covered: " + pr.getCharactersCovered() + "\n");
+            for (Iterator it2 = pr.getTextPropList().iterator(); it2.hasNext(); ) {
+                TextProp p = (TextProp)it2.next();
+                out.append("    " + p.getName() + " = " + p.getValue() + "\n");
+            }
+        }
+
+        return out.toString();
+    }
 }

Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java?view=diff&rev=496369&r1=496368&r2=496369
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
Mon Jan 15 07:22:39 2007
@@ -127,7 +127,17 @@
 	};
 	private int data_c_text_len = 123-1;
 
-	
+    /**
+     * From a real file supplied for Bug 40143 by tales@great.ufc.br
+     */
+    private byte[] data_d = {
+        0x00, 0x00, 0xA1-256, 0x0F, 0x1E, 0x00, 0x00, 0x00, //header
+        (byte)0xA0, 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x08 , 0x00 , 0x00 ,
+        0x01 , 0x00, (byte)0xA0 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x63 , 0x00 ,
+        0x01 , 0x00, 0x01 , 0x00 , 0x00, 0x00 , 0x01 , 0x00 , 0x14 , 0x00
+    };
+    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);
@@ -699,4 +709,26 @@
 		
 		// If we get here, we didn't break
 	}
+
+    /**
+     * Check the test data for Bug 40143.
+     */
+    public void testBug40143() throws Exception {
+        StyleTextPropAtom atom = new StyleTextPropAtom(data_d, 0, data_d.length);
+        atom.setParentTextSize(data_d_text_len);
+
+        TextPropCollection prprops = (TextPropCollection)atom.getParagraphStyles().getFirst();
+        assertEquals(data_d_text_len+1, prprops.getCharactersCovered());
+        assertEquals(1, prprops.getTextPropList().size()); //1 property found
+        assertEquals(1, prprops.findByName("alignment").getValue());
+
+        TextPropCollection chprops = (TextPropCollection)atom.getCharacterStyles().getFirst();
+        assertEquals(data_d_text_len+1, chprops.getCharactersCovered());
+        assertEquals(5, chprops.getTextPropList().size()); //5 properties found
+        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());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message