Examples of RichTextRun


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

        SlideShow ppt = new SlideShow();

        Slide slide = ppt.createSlide();

        TextBox shape = new TextBox();
        RichTextRun rt = shape.getTextRun().getRichTextRuns()[0];
        shape.setText(
                "January\r" +
                "February\r" +
                "March\r" +
                "April");
        rt.setFontSize(42);
        rt.setBullet(true);
        rt.setBulletOffset(0)//bullet offset
        rt.setTextOffset(50);   //text offset (should be greater than bullet offset)
        rt.setBulletChar('\u263A'); //bullet character
        slide.addShape(shape);

        shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300))//position of the text box in the slide
        slide.addShape(shape);
View Full Code Here

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

        Table table1 = new Table(6, 2);
        for (int i = 0; i < txt1.length; i++) {
            for (int j = 0; j < txt1[i].length; j++) {
                TableCell cell = table1.getCell(i, j);
                cell.setText(txt1[i][j]);
                RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
                rt.setFontName("Arial");
                rt.setFontSize(10);
                if(i == 0){
                    cell.getFill().setForegroundColor(new Color(227, 227, 227));
                } else {
                    rt.setBold(true);
                }
                cell.setVerticalAlignment(TextBox.AnchorMiddle);
                cell.setHorizontalAlignment(TextBox.AlignCenter);
            }
        }

        Line border1 = table1.createBorder();
        border1.setLineColor(Color.black);
        border1.setLineWidth(1.0);
        table1.setAllBorders(border1);

        table1.setColumnWidth(0, 300);
        table1.setColumnWidth(1, 150);

        slide.addShape(table1);
        int pgWidth = ppt.getPageSize().width;
        table1.moveTo((pgWidth - table1.getAnchor().width)/2, 100);

        //test data for the second taable
        String[][] txt2 = {
            {"Data Source"},
            {"CAS Internal Metrics - Item Master Summary\r" +
             "CAS Internal Metrics - Vendor Summary\r" +
             "CAS Internal Metrics - PO History Summary"}
        };

        //two rows, one column
        Table table2 = new Table(2, 1);
        for (int i = 0; i < txt2.length; i++) {
            for (int j = 0; j < txt2[i].length; j++) {
                TableCell cell = table2.getCell(i, j);
                cell.setText(txt2[i][j]);
                RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
                rt.setFontSize(10);
                rt.setFontName("Arial");
                if(i == 0){
                    cell.getFill().setForegroundColor(new Color(0, 51, 102));
                    rt.setFontColor(Color.white);
                    rt.setBold(true);
                    rt.setFontSize(14);
                    cell.setHorizontalAlignment(TextBox.AlignCenter);
                } else {
                    rt.setBullet(true);
                    rt.setFontSize(12);
                    cell.setHorizontalAlignment(TextBox.AlignLeft);
                }
                cell.setVerticalAlignment(TextBox.AnchorMiddle);
            }
        }
View Full Code Here

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

     */
    public Rectangle2D resizeToFitText(){
        String txt = getText();
        if(txt == null || txt.length() == 0) return new Rectangle2D.Float();

        RichTextRun rt = getTextRun().getRichTextRuns()[0];
        int size = rt.getFontSize();
        int style = 0;
        if (rt.isBold()) style |= Font.BOLD;
        if (rt.isItalic()) style |= Font.ITALIC;
        String fntname = rt.getFontName();
        Font font = new Font(fntname, style, size);

        float width = 0, height = 0;
        String[] lines = txt.split("\r");
        for (int i = 0; i < lines.length; i++) {
View Full Code Here

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

        TextBox txt = new TextBox(group);
        txt.getTextRun().supplySlideShow(group.getSheet().getSlideShow());
        txt.getTextRun().setSheet(group.getSheet());
        txt.setText(s);

        RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
        rt.setFontSize(font.getSize());
        rt.setFontName(font.getFamily());

        if (getColor() != null) rt.setFontColor(getColor());
        if (font.isBold()) rt.setBold(true);
        if (font.isItalic()) rt.setItalic(true);

        txt.setMarginBottom(0);
        txt.setMarginTop(0);
        txt.setMarginLeft(0);
        txt.setMarginRight(0);
View Full Code Here

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

    }

    // 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

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

      _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(),
        newPTP, newCTP, false, false
    );
   
    // Add the new RichTextRun onto our list
View Full Code Here

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

   * 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());
    }

        /**
         * If TextSpecInfoAtom is present, we must update the text size,
         * otherwise the ppt will be corrupted
View Full Code Here

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

            int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);

            boolean prStart = text.charAt(startIndex) == '\n';
            if(prStart) measurer.setPosition(startIndex++);

            RichTextRun rt = run.getRichTextRunAt(startIndex == text.length() ? (startIndex-1) : startIndex);
            if(rt == null) {
                logger.log(POILogger.WARN,  "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());
                break;
            }

            float wrappingWidth = (float)anchor.getWidth() - _shape.getMarginLeft() - _shape.getMarginRight();
            wrappingWidth -= rt.getTextOffset();

            if (_shape.getWordWrap() == TextShape.WrapNone) {
                wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;
            }

            TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,
                    nextBreak == -1 ? paragraphEnd : nextBreak, true);
            if (textLayout == null) {
                textLayout = measurer.nextLayout((float)anchor.getWidth(),
                    nextBreak == -1 ? paragraphEnd : nextBreak, false);
            }
            if(textLayout == null){
                logger.log(POILogger.WARN, "Failed to break text into lines: wrappingWidth: "+wrappingWidth+
                        "; text: " + rt.getText());
                measurer.setPosition(rt.getEndIndex());
                continue;
            }
            int endIndex = measurer.getPosition();

            float lineHeight = (float)textLayout.getBounds().getHeight();
            int linespacing = rt.getLineSpacing();
            if(linespacing == 0) linespacing = 100;

            TextElement el = new TextElement();
            if(linespacing >= 0){
                el.ascent = textLayout.getAscent()*linespacing/100;
            } else {
                el.ascent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
            }

            el._align = rt.getAlignment();
            el._text = textLayout;
            el._textOffset = rt.getTextOffset();

            if (prStart){
                int sp = rt.getSpaceBefore();
                float spaceBefore;
                if(sp >= 0){
                    spaceBefore = lineHeight * sp/100;
                } else {
                    spaceBefore = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;
                }
                el.ascent += spaceBefore;
            }

            float descent;
            if(linespacing >= 0){
                descent = (textLayout.getDescent() + textLayout.getLeading())*linespacing/100;
            } else {
                descent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
            }
            if (prStart){
                int sp = rt.getSpaceAfter();
                float spaceAfter;
                if(sp >= 0){
                    spaceAfter = lineHeight * sp/100;
                } else {
                    spaceAfter = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;
                }
                el.ascent += spaceAfter;
            }
            el.descent = descent;

            textHeight += el.ascent + el.descent;

            if(rt.isBullet() && (prStart || startIndex == 0)){
                it.setIndex(startIndex);

                AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()));
                Color clr = rt.getBulletColor();
                if (clr != null) bat.addAttribute(TextAttribute.FOREGROUND, clr);
                else bat.addAttribute(TextAttribute.FOREGROUND, it.getAttribute(TextAttribute.FOREGROUND));
                bat.addAttribute(TextAttribute.FAMILY, it.getAttribute(TextAttribute.FAMILY));
                bat.addAttribute(TextAttribute.SIZE, it.getAttribute(TextAttribute.SIZE));

                TextLayout bulletLayout = new TextLayout(bat.getIterator(), graphics.getFontRenderContext());
                if(text.substring(startIndex, endIndex).length() > 1){
                    el._bullet = bulletLayout;
                    el._bulletOffset = rt.getBulletOffset();
                }
            }
            lines.add(el);
        }

View Full Code Here

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

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

            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
TOP
Copyright © 2018 www.massapi.com. 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.