Package org.apache.poi.hslf.usermodel

Examples of org.apache.poi.hslf.usermodel.RichTextRun


    public void testWritesOutTheSameRich() throws Exception {
      // Grab the first text run on the first sheet
      TextRun tr1 = ss.getSlides()[0].getTextRuns()[0];
     
      // Get the first rich text run
      RichTextRun rtr1 = tr1.getRichTextRuns()[0];
     
     
      // Check that the text sizes are as expected
      assertEquals(1, tr1.getRichTextRuns().length);
      assertEquals(30, tr1.getText().length());
      assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
      assertEquals(30, rtr1.getLength());
      assertEquals(30, rtr1.getText().length());
      assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
      assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
     
      // Set the text to be as it is now
      rtr1.setText( rtr1.getText() );
      rtr1 = tr1.getRichTextRuns()[0];
     
      // Check that the text sizes are still as expected
      assertEquals(1, tr1.getRichTextRuns().length);
      assertEquals(30, tr1.getText().length());
      assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
      assertEquals(30, rtr1.getLength());
      assertEquals(30, rtr1.getText().length());
      assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
      assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
     
     
    // Write the slideshow out to a byte array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ss.write(baos);
View Full Code Here


            TextBox txtbox = (TextBox)sh[i];
            String text = txtbox.getText();
            assertNotNull(text);

            assertEquals(txtbox.getTextRun().getRichTextRuns().length, 1);
            RichTextRun rt = txtbox.getTextRun().getRichTextRuns()[0];

            if (text.equals("Hello, World!!!")){
                assertEquals(32, rt.getFontSize());
                assertTrue(rt.isBold());
                assertTrue(rt.isItalic());
            } else if (text.equals("I am just a poor boy")){
                assertEquals(44, rt.getFontSize());
                assertTrue(rt.isBold());
            } else if (text.equals("This is Times New Roman")){
                assertEquals(16, rt.getFontSize());
                assertTrue(rt.isBold());
                assertTrue(rt.isItalic());
                assertTrue(rt.isUnderlined());
            } else if (text.equals("Plain Text")){
                assertEquals(18, rt.getFontSize());
            }
        }
    }
View Full Code Here

    }

    // Handle case of no current style, with a default
    if(pStyles.size() == 0 || cStyles.size() == 0) {
      _rtRuns = new RichTextRun[1];
      _rtRuns[0] = new RichTextRun(this, 0, runRawText.length());
    } else {
      // Build up Rich Text Runs, one for each
      //  character/paragraph style pair
      Vector rtrs = new Vector();

      int pos = 0;
     
      int curP = 0;
      int curC = 0;
      int pLenRemain = -1;
      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; }
        if(cLenRemain == -1) { cLenRemain = cLen; }
       
        // So we know how to build the eventual run
        int runLen = -1;
        boolean pShared = false;
        boolean cShared = false;
       
        // Same size, new styles - neither shared
        if(pLen == cLen && freshSet) {
          runLen = cLen;
          pShared = false;
          cShared = false;
          curP++;
          curC++;
          pLenRemain = -1;
          cLenRemain = -1;
        } else {
          // Some sharing
         
          // See if we are already in a shared block
          if(pLenRemain < pLen) {
            // Existing shared p block
            pShared = true;
           
            // Do we end with the c block, or either side of it?
            if(pLenRemain == cLenRemain) {
              // We end at the same time
              cShared = false;
              runLen = pLenRemain;
              curP++;
              curC++;
              pLenRemain = -1;
              cLenRemain = -1;
            } else if(pLenRemain < cLenRemain) {
              // We end before the c block
              cShared = true;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            } else {
              // We end after the c block
              cShared = false;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            }
          } else if(cLenRemain < cLen) {
            // Existing shared c block
            cShared = true;
           
            // Do we end with the p block, or either side of it?
            if(pLenRemain == cLenRemain) {
              // We end at the same time
              pShared = false;
              runLen = cLenRemain;
              curP++;
              curC++;
              pLenRemain = -1;
              cLenRemain = -1;
            } else if(cLenRemain < pLenRemain) {
              // We end before the p block
              pShared = true;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            } else {
              // We end after the p block
              pShared = false;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            }
          } else {
            // Start of a shared block
            if(pLenRemain < cLenRemain) {
              // Shared c block
              pShared = false;
              cShared = true;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            } else {
              // Shared p block
              pShared = true;
              cShared = false;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            }
          }
        }
       
        // Wind on
        int prevPos = pos;
        pos += runLen;
        // Adjust for end-of-run extra 1 length
        if(pos > runRawText.length()) {
          runLen--;
        }
       
        // Save
        RichTextRun rtr = new RichTextRun(this, prevPos, runLen, pProps, cProps, pShared, cShared);
        rtrs.add(rtr);
      }
     
      // Build the array
      _rtRuns = new RichTextRun[rtrs.size()];
View Full Code Here

   * If you care about styling, do setText on a RichTextRun instead
   */
  public synchronized void setText(String s) {
    // Save the new text to the atoms
    storeText(s);
    RichTextRun fst = _rtRuns[0];

    // Finally, zap and re-do the RichTextRuns
    for(int i=0; i<_rtRuns.length; i++) { _rtRuns[i] = null; }
    _rtRuns = new RichTextRun[1];
        _rtRuns[0] = fst;

    // Now handle record stylings:
    // If there isn't styling
    //  no change, stays with no styling
    // If there is styling:
    //  everthing gets the same style that the first block has
    if(_styleAtom != null) {
      LinkedList pStyles = _styleAtom.getParagraphStyles();
      while(pStyles.size() > 1) { pStyles.removeLast(); }
     
      LinkedList cStyles = _styleAtom.getCharacterStyles();
      while(cStyles.size() > 1) { cStyles.removeLast(); }
     
      _rtRuns[0].setText(s);
    } else {
      // Recreate rich text run with no styling
      _rtRuns[0] = new RichTextRun(this,0,s.length());
    }
  }
View Full Code Here

      */
     public static void formataFonte(TextBox ct, int tamanho, String nome,
               boolean ehNegrito, boolean ehItalico,
               boolean ehSublinhado, Color cor, int alinhamento) {
                 
      RichTextRun rt = ct.getTextRun().getRichTextRuns()[0];
      rt.setFontSize(tamanho);
      rt.setFontName(nome);
      rt.setBold(ehNegrito);
      rt.setItalic(ehItalico);
      rt.setUnderlined(ehSublinhado);
      rt.setFontColor(cor);
      rt.setAlignment(alinhamento);
                 
  }
View Full Code Here

    }

    // Handle case of no current style, with a default
    if(pStyles.size() == 0 || cStyles.size() == 0) {
      _rtRuns = new RichTextRun[1];
      _rtRuns[0] = new RichTextRun(this, 0, runRawText.length());
    } else {
      // Build up Rich Text Runs, one for each
      //  character/paragraph style pair
      Vector rtrs = new Vector();

      int pos = 0;
     
      int curP = 0;
      int curC = 0;
      int pLenRemain = -1;
      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; }
        if(cLenRemain == -1) { cLenRemain = cLen; }
       
        // So we know how to build the eventual run
        int runLen = -1;
        boolean pShared = false;
        boolean cShared = false;
       
        // Same size, new styles - neither shared
        if(pLen == cLen && freshSet) {
          runLen = cLen;
          pShared = false;
          cShared = false;
          curP++;
          curC++;
          pLenRemain = -1;
          cLenRemain = -1;
        } else {
          // Some sharing
         
          // See if we are already in a shared block
          if(pLenRemain < pLen) {
            // Existing shared p block
            pShared = true;
           
            // Do we end with the c block, or either side of it?
            if(pLenRemain == cLenRemain) {
              // We end at the same time
              cShared = false;
              runLen = pLenRemain;
              curP++;
              curC++;
              pLenRemain = -1;
              cLenRemain = -1;
            } else if(pLenRemain < cLenRemain) {
              // We end before the c block
              cShared = true;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            } else {
              // We end after the c block
              cShared = false;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            }
          } else if(cLenRemain < cLen) {
            // Existing shared c block
            cShared = true;
           
            // Do we end with the p block, or either side of it?
            if(pLenRemain == cLenRemain) {
              // We end at the same time
              pShared = false;
              runLen = cLenRemain;
              curP++;
              curC++;
              pLenRemain = -1;
              cLenRemain = -1;
            } else if(cLenRemain < pLenRemain) {
              // We end before the p block
              pShared = true;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            } else {
              // We end after the p block
              pShared = false;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            }
          } else {
            // Start of a shared block
            if(pLenRemain < cLenRemain) {
              // Shared c block
              pShared = false;
              cShared = true;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            } else {
              // Shared p block
              pShared = true;
              cShared = false;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            }
          }
        }
       
        // Wind on
        int prevPos = pos;
        pos += runLen;
        // Adjust for end-of-run extra 1 length
        if(pos > runRawText.length()) {
          runLen--;
        }
       
        // Save
        RichTextRun rtr = new RichTextRun(this, prevPos, runLen, pProps, cProps, pShared, cShared);
        rtrs.add(rtr);
      }
     
      // Build the array
      _rtRuns = new RichTextRun[rtrs.size()];
View Full Code Here

   * If you care about styling, do setText on a RichTextRun instead
   */
  public synchronized void setText(String s) {
    // Save the new text to the atoms
    storeText(s);
    RichTextRun fst = _rtRuns[0];

    // Finally, zap and re-do the RichTextRuns
    for(int i=0; i<_rtRuns.length; i++) { _rtRuns[i] = null; }
    _rtRuns = new RichTextRun[1];
        _rtRuns[0] = fst;

    // Now handle record stylings:
    // If there isn't styling
    //  no change, stays with no styling
    // If there is styling:
    //  everthing gets the same style that the first block has
    if(_styleAtom != null) {
      LinkedList pStyles = _styleAtom.getParagraphStyles();
      while(pStyles.size() > 1) { pStyles.removeLast(); }
     
      LinkedList cStyles = _styleAtom.getCharacterStyles();
      while(cStyles.size() > 1) { cStyles.removeLast(); }
     
      _rtRuns[0].setText(s);
    } else {
      // Recreate rich text run with no styling
      _rtRuns[0] = new RichTextRun(this,0,s.length());
    }
  }
View Full Code Here

            TextBox txtbox = (TextBox)sh[i];
            String text = txtbox.getText();
            assertNotNull(text);

            assertEquals(txtbox.getTextRun().getRichTextRuns().length, 1);
            RichTextRun rt = txtbox.getTextRun().getRichTextRuns()[0];

            if (text.equals("Hello, World!!!")){
                assertEquals(32, rt.getFontSize());
                assertTrue(rt.isBold());
                assertTrue(rt.isItalic());
            } else if (text.equals("I am just a poor boy")){
                assertEquals(44, rt.getFontSize());
                assertTrue(rt.isBold());
            } else if (text.equals("This is Times New Roman")){
                assertEquals(16, rt.getFontSize());
                assertTrue(rt.isBold());
                assertTrue(rt.isItalic());
                assertTrue(rt.isUnderlined());
            } else if (text.equals("Plain Text")){
                assertEquals(18, rt.getFontSize());
            }
        }
    }
View Full Code Here

     * and set some of the style attributes
     */
    public void testTextBoxWriteBytes() throws Exception {
        ppt = new SlideShow();
        Slide sl = ppt.createSlide();
        RichTextRun rt;

        String val = "Hello, World!";

        // Create a new textbox, and give it lots of properties
        TextBox txtbox = new TextBox();
        rt = txtbox.getTextRun().getRichTextRuns()[0];
        txtbox.setText(val);
        rt.setFontName("Arial");
        rt.setFontSize(42);
        rt.setBold(true);
        rt.setItalic(true);
        rt.setUnderlined(false);
        rt.setFontColor(Color.red);
        sl.addShape(txtbox);

        // Check it before save
        rt = txtbox.getTextRun().getRichTextRuns()[0];
        assertEquals(val, rt.getText());
        assertEquals(42, rt.getFontSize());
        assertTrue(rt.isBold());
        assertTrue(rt.isItalic());
        assertFalse(rt.isUnderlined());
        assertEquals("Arial", rt.getFontName());
        assertEquals(Color.red, rt.getFontColor());

        // Serialize and read again
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ppt.write(out);
        out.close();

        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
        sl = ppt.getSlides()[0];
       
        txtbox = (TextBox)sl.getShapes()[0];
        rt = txtbox.getTextRun().getRichTextRuns()[0];

        // Check after save
        assertEquals(val, rt.getText());
        assertEquals(42, rt.getFontSize());
        assertTrue(rt.isBold());
        assertTrue(rt.isItalic());
        assertFalse(rt.isUnderlined());
        assertEquals("Arial", rt.getFontName());
        assertEquals(Color.red, rt.getFontColor());
    }
View Full Code Here

    }

    // Handle case of no current style, with a default
    if(pStyles.size() == 0 || cStyles.size() == 0) {
      _rtRuns = new RichTextRun[1];
      _rtRuns[0] = new RichTextRun(this, 0, runRawText.length());
    } else {
      // Build up Rich Text Runs, one for each
      //  character/paragraph style pair
      Vector rtrs = new Vector();

      int pos = 0;
     
      int curP = 0;
      int curC = 0;
      int pLenRemain = -1;
      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; }
        if(cLenRemain == -1) { cLenRemain = cLen; }
       
        // So we know how to build the eventual run
        int runLen = -1;
        boolean pShared = false;
        boolean cShared = false;
       
        // Same size, new styles - neither shared
        if(pLen == cLen && freshSet) {
          runLen = cLen;
          pShared = false;
          cShared = false;
          curP++;
          curC++;
          pLenRemain = -1;
          cLenRemain = -1;
        } else {
          // Some sharing
         
          // See if we are already in a shared block
          if(pLenRemain < pLen) {
            // Existing shared p block
            pShared = true;
           
            // Do we end with the c block, or either side of it?
            if(pLenRemain == cLenRemain) {
              // We end at the same time
              cShared = false;
              runLen = pLenRemain;
              curP++;
              curC++;
              pLenRemain = -1;
              cLenRemain = -1;
            } else if(pLenRemain < cLenRemain) {
              // We end before the c block
              cShared = true;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            } else {
              // We end after the c block
              cShared = false;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            }
          } else if(cLenRemain < cLen) {
            // Existing shared c block
            cShared = true;
           
            // Do we end with the p block, or either side of it?
            if(pLenRemain == cLenRemain) {
              // We end at the same time
              pShared = false;
              runLen = cLenRemain;
              curP++;
              curC++;
              pLenRemain = -1;
              cLenRemain = -1;
            } else if(cLenRemain < pLenRemain) {
              // We end before the p block
              pShared = true;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            } else {
              // We end after the p block
              pShared = false;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            }
          } else {
            // Start of a shared block
            if(pLenRemain < cLenRemain) {
              // Shared c block
              pShared = false;
              cShared = true;
              runLen = pLenRemain;
              curP++;
              cLenRemain -= pLenRemain;
              pLenRemain = -1;
            } else {
              // Shared p block
              pShared = true;
              cShared = false;
              runLen = cLenRemain;
              curC++;
              pLenRemain -= cLenRemain;
              cLenRemain = -1;
            }
          }
        }
       
        // Wind on
        int prevPos = pos;
        pos += runLen;
        // Adjust for end-of-run extra 1 length
        if(pos > runRawText.length()) {
          runLen--;
        }
       
        // Save
        RichTextRun rtr = new RichTextRun(this, prevPos, runLen, pProps, cProps, pShared, cShared);
        rtrs.add(rtr);
      }
     
      // Build the array
      _rtRuns = new RichTextRun[rtrs.size()];
View Full Code Here

TOP

Related Classes of org.apache.poi.hslf.usermodel.RichTextRun

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.