Package org.apache.poi.hslf.model.textproperties

Examples of org.apache.poi.hslf.model.textproperties.TextPropCollection


     */
    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());
    }
View Full Code Here


    System.out.println("\nFound a StyleTextPropAtom");

    LinkedList paragraphStyles = stpa.getParagraphStyles();
    System.out.println("Contains " + paragraphStyles.size() + " paragraph styles:");
    for(int i=0; i<paragraphStyles.size(); i++) {
      TextPropCollection tpc = (TextPropCollection)paragraphStyles.get(i);
      System.out.println(" In paragraph styling " + i + ":");
      System.out.println("  Characters covered is " + tpc.getCharactersCovered());
      showTextProps(tpc);
    }
   
    LinkedList charStyles = stpa.getCharacterStyles();
    System.out.println("Contains " + charStyles.size() + " character styles:");
    for(int i=0; i<charStyles.size(); i++) {
      TextPropCollection tpc = (TextPropCollection)charStyles.get(i);
      System.out.println("  In character styling " + i + ":");
      System.out.println("    Characters covered is " + tpc.getCharactersCovered());
      showTextProps(tpc);
    }
  }
View Full Code Here

    /**
     * Test styles for type=TextHeaderAtom.OTHER_TYPE
     */
    private void checkOtherType(TxMasterStyleAtom txmaster){
        TextPropCollection props;
        TextProp prop;

        //paragraph styles
        props = txmaster.getParagraphStyles()[0];

        prop = props.findByName("alignment");
        assertEquals(0, prop.getValue());

        //character styles
        props = txmaster.getCharacterStyles()[0];

        prop = props.findByName("font.color");
        assertEquals(0x1000000, prop.getValue());

        prop = props.findByName("font.index");
        assertEquals(0, prop.getValue());

        prop = props.findByName("font.size");
        assertEquals(18, prop.getValue());
    }
View Full Code Here

    /**
     * Test styles for type=TextHeaderAtom.NOTES_TYPE
     */
    private void checkNotesType(TxMasterStyleAtom txmaster){
        TextPropCollection props;
        TextProp prop;

        //paragraph styles
        props = txmaster.getParagraphStyles()[0];

        prop = props.findByName("alignment");
        assertEquals(0, prop.getValue()); //title has center alignment

        //character styles
        props = txmaster.getCharacterStyles()[0];

        prop = props.findByName("font.color");
        assertEquals(0x1000000, prop.getValue());

        prop = props.findByName("font.index");
        assertEquals(0, prop.getValue());

        prop = props.findByName("font.size");
        assertEquals(12, prop.getValue());

    }
View Full Code Here

    assertEquals(3, trB.getRichTextRuns().length);
   
    RichTextRun rtrB = trB.getRichTextRuns()[0];
    RichTextRun rtrC = trB.getRichTextRuns()[1];
    RichTextRun rtrD = trB.getRichTextRuns()[2];
    TextPropCollection tpBP = rtrB._getRawParagraphStyle();
    TextPropCollection tpBC = rtrB._getRawCharacterStyle();
    TextPropCollection tpCP = rtrC._getRawParagraphStyle();
    TextPropCollection tpCC = rtrC._getRawCharacterStyle();
    TextPropCollection tpDP = rtrD._getRawParagraphStyle();
    TextPropCollection tpDC = rtrD._getRawCharacterStyle();
   
    assertEquals(trB.getText().substring(0, 30), rtrB.getText());
    assertNotNull(tpBP);
    assertNotNull(tpBC);
    assertNotNull(tpCP);
View Full Code Here

    // We start with 3 text runs, each with their own set of styles,
    //  but all sharing the same paragraph styles
    RichTextRun rtrB = trB.getRichTextRuns()[0];
    RichTextRun rtrC = trB.getRichTextRuns()[1];
    RichTextRun rtrD = trB.getRichTextRuns()[2];
    TextPropCollection tpBP = rtrB._getRawParagraphStyle();
    TextPropCollection tpBC = rtrB._getRawCharacterStyle();
    TextPropCollection tpCP = rtrC._getRawParagraphStyle();
    TextPropCollection tpCC = rtrC._getRawCharacterStyle();
    TextPropCollection tpDP = rtrD._getRawParagraphStyle();
    TextPropCollection tpDC = rtrD._getRawCharacterStyle();
   
    // Check text and stylings
    assertEquals(trB.getText().substring(0, 30), rtrB.getText());
    assertNotNull(tpBP);
    assertNotNull(tpBC);
    assertNotNull(tpCP);
    assertNotNull(tpCC);
    assertNotNull(tpDP);
    assertNotNull(tpDC);
    assertTrue(tpBP.equals(tpCP));
    assertTrue(tpBP.equals(tpDP));
    assertTrue(tpCP.equals(tpDP));
    assertFalse(tpBC.equals(tpCC));
    assertFalse(tpBC.equals(tpDC));
    assertFalse(tpCC.equals(tpDC));
   
    // Check text in the rich runs
    assertEquals("This is the subtitle, in bold\n", rtrB.getText());
    assertEquals("This bit is blue and italic\n", rtrC.getText());
    assertEquals("This bit is red (normal)", rtrD.getText());
   
    String newBText = "New Subtitle, will still be bold\n";
    String newCText = "New blue and italic text\n";
    String newDText = "Funky new normal red text";
    rtrB.setText(newBText);
    rtrC.setText(newCText);
    rtrD.setText(newDText);
    assertEquals(newBText, rtrB.getText());
    assertEquals(newCText, rtrC.getText());
    assertEquals(newDText, rtrD.getText());
   
    assertEquals(newBText + newCText + newDText, trB.getText());
   
    // The styles should have been updated for the new sizes
    assertEquals(newBText.length(), tpBC.getCharactersCovered());
    assertEquals(newCText.length(), tpCC.getCharactersCovered());
    assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // Last one is always one larger
   
    assertEquals(
        newBText.length() + newCText.length() + newDText.length(),
        tpBP.getCharactersCovered()
    );
   
    // Paragraph style should be sum of text length
    assertEquals(newBText.length() + newCText.length() + newDText.length(), tpBP.getCharactersCovered());
   
    // Check stylings still as expected
    TextPropCollection ntpBC = rtrB._getRawCharacterStyle();
    TextPropCollection ntpCC = rtrC._getRawCharacterStyle();
    TextPropCollection ntpDC = rtrD._getRawCharacterStyle();
    assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList());
    assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList());
    assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList());
    }
View Full Code Here

    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());
  }
View Full Code Here

  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());
View Full Code Here

  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());
View Full Code Here

  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));
View Full Code Here

TOP

Related Classes of org.apache.poi.hslf.model.textproperties.TextPropCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.