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

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


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


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

   
    // 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++) {
View Full Code Here

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

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

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

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

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

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

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

    }
View Full Code Here

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

        TextPropCollection[] prstyles = txmaster.getParagraphStyles();
        TextPropCollection[] chstyles = txmaster.getCharacterStyles();
        assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
                "must contain styles for 5 indentation levels", 5, prstyles.length);
        assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
                "must contain styles for 5 indentation levels", 5, chstyles.length);

        //paragraph styles
        props = prstyles[0];

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


        for (int i = 0; i < prstyles.length; i++) {
            assertNotNull("text.offset is null for indentation level " + i, prstyles[i].findByName("text.offset"));
            assertNotNull("bullet.offset is null for indentation level " + i, prstyles[i].findByName("bullet.offset"));
        }

        //character styles
        props = chstyles[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(32, prop.getValue());
    }
View Full Code Here

            int cLenRemain = -1;

            // Build one for each run with the same style
            while(pos <= runRawText.length() && curP < pStyles.size() && curC < cStyles.size()) {
                // Get the Props to use
                TextPropCollection pProps = (TextPropCollection)pStyles.get(curP);
                TextPropCollection cProps = (TextPropCollection)cStyles.get(curC);

                int pLen = pProps.getCharactersCovered();
                int cLen = cProps.getCharactersCovered();

                // Handle new pass
                boolean freshSet = false;
                if(pLenRemain == -1 && cLenRemain == -1) { freshSet = true; }
                if(pLenRemain == -1) { pLenRemain = pLen; }
View Full Code Here

    //  the text by one, we need to shuffle that
    //  extra character onto the new ones
    int pOverRun = _styleAtom.getParagraphTextLengthCovered() - oldSize;
    int cOverRun = _styleAtom.getCharacterTextLengthCovered() - oldSize;
    if(pOverRun > 0) {
      TextPropCollection tpc = (TextPropCollection)
        _styleAtom.getParagraphStyles().getLast();
      tpc.updateTextSize(
          tpc.getCharactersCovered() - pOverRun
      );
    }
    if(cOverRun > 0) {
      TextPropCollection tpc = (TextPropCollection)
        _styleAtom.getCharacterStyles().getLast();
      tpc.updateTextSize(
          tpc.getCharactersCovered() - cOverRun
      );
    }

    // Next, add the styles for its paragraph and characters
    TextPropCollection newPTP =
      _styleAtom.addParagraphTextPropCollection(s.length()+pOverRun);
    TextPropCollection newCTP =
      _styleAtom.addCharacterTextPropCollection(s.length()+cOverRun);

    // Now, create the new RichTextRun
    RichTextRun nr = new RichTextRun(
        this, oldSize, s.length(),
View Full Code Here

    //   * reset the length, to the new string's length
    //   * add on +1 if the last block
    // The last run needs its stylings to be 1 longer than the raw
    //  text is. This is to define the stylings that any new text
    //  that is added will inherit
    TextPropCollection pCol = run._getRawParagraphStyle();
    TextPropCollection cCol = run._getRawCharacterStyle();
    int newSize = s.length();
    if(runID == _rtRuns.length-1) {
      newSize++;
    }

    if(run._isParagraphStyleShared()) {
      pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length() );
    } else {
      pCol.updateTextSize(newSize);
    }
    if(run._isCharacterStyleShared()) {
      cCol.updateTextSize( cCol.getCharactersCovered() - run.getLength() + s.length() );
    } else {
      cCol.updateTextSize(newSize);
    }

    // Build up the new text
    // As we go through, update the start position for all subsequent runs
    // The building relies on the old text still being present
View Full Code Here

        // Set empty paragraph and character styles
        paragraphStyles = new LinkedList<TextPropCollection>();
        charStyles = new LinkedList<TextPropCollection>();

        TextPropCollection defaultParagraphTextProps =
                new TextPropCollection(parentTextSize, (short)0);
        paragraphStyles.add(defaultParagraphTextProps);

        TextPropCollection defaultCharacterTextProps =
                new TextPropCollection(parentTextSize);
        charStyles.add(defaultCharacterTextProps);

        // Set us as now initialised
        initialised = true;
    }
View Full Code Here

            // Grab the 4 byte value that tells us what properties follow
            int paraFlags = LittleEndian.getInt(rawContents,pos);
            pos += 4;

            // Now make sense of those properties
            TextPropCollection thisCollection = new TextPropCollection(textLen, indent);
            int plSize = thisCollection.buildTextPropList(
                    paraFlags, paragraphTextPropTypes, rawContents, pos);
            pos += plSize;

            // Save this properties set
            paragraphStyles.add(thisCollection);

            // Handle extra 1 paragraph styles at the end
            if(pos < rawContents.length && textHandled == size) {
                prsize++;
            }

        }
        if (rawContents.length > 0 && textHandled != (size+1)){
            logger.log(POILogger.WARN, "Problem reading paragraph style runs: textHandled = " + textHandled + ", text.size+1 = " + (size+1));
        }

        // Now do the character stylings
        textHandled = 0;
        int chsize = size;
        while(pos < rawContents.length && textHandled < chsize) {
            // First up, fetch the number of characters this applies to
            int textLen = LittleEndian.getInt(rawContents,pos);
            textLen = checkTextLength(textLen, textHandled, size);
            textHandled += textLen;
            pos += 4;

            // There is no 2 byte value
            short no_val = -1;

            // Grab the 4 byte value that tells us what properties follow
            int charFlags = LittleEndian.getInt(rawContents,pos);
            pos += 4;

            // Now make sense of those properties
            // (Assuming we actually have some)
            TextPropCollection thisCollection = new TextPropCollection(textLen, no_val);
            int chSize = thisCollection.buildTextPropList(
                               charFlags, characterTextPropTypes, rawContents, pos);
            pos += chSize;

            // Save this properties set
            charStyles.add(thisCollection);
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.