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

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


      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


    //   * 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();
    charStyles = new LinkedList();

    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);
      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

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // First up, we need to serialise the paragraph properties
    for(int i=0; i<paragraphStyles.size(); i++) {
      TextPropCollection tpc = (TextPropCollection)paragraphStyles.get(i);
      tpc.writeOut(baos);
    }

    // Now, we do the character ones
    for(int i=0; i<charStyles.size(); i++) {
      TextPropCollection tpc = (TextPropCollection)charStyles.get(i);
      tpc.writeOut(baos);
    }

    rawContents  = baos.toByteArray();
  }
View Full Code Here

   * Create a new Paragraph TextPropCollection, and add it to the list
   * @param charactersCovered The number of characters this TextPropCollection will cover
   * @return the new TextPropCollection, which will then be in the list
   */
  public TextPropCollection addParagraphTextPropCollection(int charactersCovered) {
    TextPropCollection tpc = new TextPropCollection(charactersCovered, (short)0);
    paragraphStyles.add(tpc);
    return tpc;
  }
View Full Code Here

   * Create a new Character TextPropCollection, and add it to the list
   * @param charactersCovered The number of characters this TextPropCollection will cover
   * @return the new TextPropCollection, which will then be in the list
   */
  public TextPropCollection addCharacterTextPropCollection(int charactersCovered) {
    TextPropCollection tpc = new TextPropCollection(charactersCovered);
    charStyles.add(tpc);
    return tpc;
  }
View Full Code Here

        } else {

          out.append("Paragraph properties\n");

          for (Iterator it1 = getParagraphStyles().iterator(); it1.hasNext();) {
              TextPropCollection pr = (TextPropCollection)it1.next();
              out.append("  chars covered: " + pr.getCharactersCovered());
              out.append("  special mask flags: 0x" + HexDump.toHex(pr.getSpecialMask()) + "\n");
              for (Iterator it2 = pr.getTextPropList().iterator(); it2.hasNext(); ) {
                  TextProp p = (TextProp)it2.next();
                  out.append("    " + p.getName() + " = " + p.getValue() );
                  out.append(" (0x" + HexDump.toHex(p.getValue()) + ")\n");
              }

              out.append("  para bytes that would be written: \n");

              try {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          pr.writeOut(baos);
          byte[] b = baos.toByteArray();
          out.append(HexDump.dump(b, 0, 0));
              } catch (Exception e ) {
                e.printStackTrace();
              }
          }

          out.append("Character properties\n");
          for (Iterator it1 = getCharacterStyles().iterator(); it1.hasNext();) {
              TextPropCollection pr = (TextPropCollection)it1.next();
              out.append("  chars covered: " + pr.getCharactersCovered() );
              out.append("  special mask flags: 0x" + HexDump.toHex(pr.getSpecialMask()) + "\n");
              for (Iterator it2 = pr.getTextPropList().iterator(); it2.hasNext(); ) {
                  TextProp p = (TextProp)it2.next();
                  out.append("    " + p.getName() + " = " + p.getValue() );
                  out.append(" (0x" + HexDump.toHex(p.getValue()) + ")\n");
              }

              out.append("  char bytes that would be written: \n");

              try {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          pr.writeOut(baos);
          byte[] b = baos.toByteArray();
          out.append(HexDump.dump(b, 0, 0));
              } catch (Exception e ) {
                e.printStackTrace();
              }
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

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.