Update the order of the TextProps, as it seems not to be based quite on the mask order. Fix from Yegor, from bug #40143

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@496369 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2007-01-15 15:22:39 +00:00
parent dec3b4b591
commit 3b14ab1eb2
2 changed files with 73 additions and 10 deletions

View File

@ -25,6 +25,8 @@ import java.io.OutputStream;
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 @@ public class StyleTextPropAtom extends RecordAtom
"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 @@ public class StyleTextPropAtom extends RecordAtom
new TextProp(2, 0x80000000, "char_unknown_10"),
};
/* *************** record code follows ********************** */
/**
@ -730,4 +731,34 @@ public class StyleTextPropAtom extends RecordAtom
);
}
}
/**
* 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();
}
}

View File

@ -127,7 +127,17 @@ public class TestStyleTextPropAtom extends TestCase {
};
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 @@ public class TestStyleTextPropAtom extends TestCase {
// 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());
}
}