teststyletextpropatom.java
来自「EXCEL read and write」· Java 代码 · 共 773 行 · 第 1/3 页
JAVA
773 行
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);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?