Search in sources :

Example 1 with CTRegularTextRun

use of org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun in project poi by apache.

the class DrawingParagraph method getText.

public CharSequence getText() {
    StringBuilder text = new StringBuilder();
    XmlCursor c = p.newCursor();
    c.selectPath("./*");
    while (c.toNextSelection()) {
        XmlObject o = c.getObject();
        if (o instanceof CTRegularTextRun) {
            CTRegularTextRun txrun = (CTRegularTextRun) o;
            text.append(txrun.getT());
        } else if (o instanceof CTTextLineBreak) {
            text.append('\n');
        }
    }
    c.dispose();
    return text;
}
Also used : CTTextLineBreak(org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor) CTRegularTextRun(org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)

Example 2 with CTRegularTextRun

use of org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun in project poi by apache.

the class XSLFTextRun method getRenderableText.

String getRenderableText() {
    if (_r instanceof CTTextField) {
        CTTextField tf = (CTTextField) _r;
        XSLFSheet sheet = _p.getParentShape().getSheet();
        if ("slidenum".equals(tf.getType()) && sheet instanceof XSLFSlide) {
            return Integer.toString(((XSLFSlide) sheet).getSlideNumber());
        }
        return tf.getT();
    } else if (_r instanceof CTTextLineBreak) {
        return "\n";
    }
    String txt = ((CTRegularTextRun) _r).getT();
    TextCap cap = getTextCap();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < txt.length(); i++) {
        char c = txt.charAt(i);
        if (c == '\t') {
            // TODO: finish support for tabs
            buf.append("  ");
        } else {
            switch(cap) {
                case ALL:
                    buf.append(Character.toUpperCase(c));
                    break;
                case SMALL:
                    buf.append(Character.toLowerCase(c));
                    break;
                default:
                    buf.append(c);
            }
        }
    }
    return buf.toString();
}
Also used : CTTextLineBreak(org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak) CTTextField(org.openxmlformats.schemas.drawingml.x2006.main.CTTextField) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) CTRegularTextRun(org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)

Example 3 with CTRegularTextRun

use of org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun in project poi by apache.

the class XSLFTextParagraph method addNewTextRun.

/**
     * Add a new run of text
     *
     * @return a new run of text
     */
public XSLFTextRun addNewTextRun() {
    CTRegularTextRun r = _p.addNewR();
    CTTextCharacterProperties rPr = r.addNewRPr();
    rPr.setLang("en-US");
    XSLFTextRun run = newTextRun(r);
    _runs.add(run);
    return run;
}
Also used : CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTRegularTextRun(org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)

Example 4 with CTRegularTextRun

use of org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun in project poi by apache.

the class XSLFTextParagraph method copy.

void copy(XSLFTextParagraph other) {
    if (other == this)
        return;
    CTTextParagraph thisP = getXmlObject();
    CTTextParagraph otherP = other.getXmlObject();
    if (thisP.isSetPPr())
        thisP.unsetPPr();
    if (thisP.isSetEndParaRPr())
        thisP.unsetEndParaRPr();
    _runs.clear();
    for (int i = thisP.sizeOfBrArray(); i > 0; i--) {
        thisP.removeBr(i - 1);
    }
    for (int i = thisP.sizeOfRArray(); i > 0; i--) {
        thisP.removeR(i - 1);
    }
    for (int i = thisP.sizeOfFldArray(); i > 0; i--) {
        thisP.removeFld(i - 1);
    }
    XmlCursor thisC = thisP.newCursor();
    thisC.toEndToken();
    XmlCursor otherC = otherP.newCursor();
    otherC.copyXmlContents(thisC);
    otherC.dispose();
    thisC.dispose();
    List<XSLFTextRun> otherRs = other.getTextRuns();
    int i = 0;
    for (CTRegularTextRun rtr : thisP.getRArray()) {
        XSLFTextRun run = newTextRun(rtr);
        run.copy(otherRs.get(i++));
        _runs.add(run);
    }
    // set properties again, in case we are based on a different
    // template
    TextAlign srcAlign = other.getTextAlign();
    if (srcAlign != getTextAlign()) {
        setTextAlign(srcAlign);
    }
    boolean isBullet = other.isBullet();
    if (isBullet != isBullet()) {
        setBullet(isBullet);
        if (isBullet) {
            String buFont = other.getBulletFont();
            if (buFont != null && !buFont.equals(getBulletFont())) {
                setBulletFont(buFont);
            }
            String buChar = other.getBulletCharacter();
            if (buChar != null && !buChar.equals(getBulletCharacter())) {
                setBulletCharacter(buChar);
            }
            PaintStyle buColor = other.getBulletFontColor();
            if (buColor != null && !buColor.equals(getBulletFontColor())) {
                setBulletFontColor(buColor);
            }
            Double buSize = other.getBulletFontSize();
            if (!doubleEquals(buSize, getBulletFontSize())) {
                setBulletFontSize(buSize);
            }
        }
    }
    Double leftMargin = other.getLeftMargin();
    if (!doubleEquals(leftMargin, getLeftMargin())) {
        setLeftMargin(leftMargin);
    }
    Double indent = other.getIndent();
    if (!doubleEquals(indent, getIndent())) {
        setIndent(indent);
    }
    Double spaceAfter = other.getSpaceAfter();
    if (!doubleEquals(spaceAfter, getSpaceAfter())) {
        setSpaceAfter(spaceAfter);
    }
    Double spaceBefore = other.getSpaceBefore();
    if (!doubleEquals(spaceBefore, getSpaceBefore())) {
        setSpaceBefore(spaceBefore);
    }
    Double lineSpacing = other.getLineSpacing();
    if (!doubleEquals(lineSpacing, getLineSpacing())) {
        setLineSpacing(lineSpacing);
    }
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) CTTextBulletSizePoint(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint) XmlCursor(org.apache.xmlbeans.XmlCursor) CTRegularTextRun(org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)

Example 5 with CTRegularTextRun

use of org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun in project poi by apache.

the class XSSFChart method setTitleText.

/**
     * Sets the title text as a static string.
     * @param newTitle to use
     */
public void setTitleText(String newTitle) {
    CTTitle ctTitle;
    if (chart.isSetTitle()) {
        ctTitle = chart.getTitle();
    } else {
        ctTitle = chart.addNewTitle();
    }
    CTTx tx;
    if (ctTitle.isSetTx()) {
        tx = ctTitle.getTx();
    } else {
        tx = ctTitle.addNewTx();
    }
    if (tx.isSetStrRef()) {
        tx.unsetStrRef();
    }
    CTTextBody rich;
    if (tx.isSetRich()) {
        rich = tx.getRich();
    } else {
        rich = tx.addNewRich();
        // body properties must exist (but can be empty)
        rich.addNewBodyPr();
    }
    CTTextParagraph para;
    if (rich.sizeOfPArray() > 0) {
        para = rich.getPArray(0);
    } else {
        para = rich.addNewP();
    }
    if (para.sizeOfRArray() > 0) {
        CTRegularTextRun run = para.getRArray(0);
        run.setT(newTitle);
    } else if (para.sizeOfFldArray() > 0) {
        CTTextField fld = para.getFldArray(0);
        fld.setT(newTitle);
    } else {
        CTRegularTextRun run = para.addNewR();
        run.setT(newTitle);
    }
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextField(org.openxmlformats.schemas.drawingml.x2006.main.CTTextField) CTTx(org.openxmlformats.schemas.drawingml.x2006.chart.CTTx) CTTextBody(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody) CTTitle(org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle) CTRegularTextRun(org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)

Aggregations

CTRegularTextRun (org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)5 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 CTTextField (org.openxmlformats.schemas.drawingml.x2006.main.CTTextField)2 CTTextLineBreak (org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak)2 CTTextParagraph (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph)2 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTTitle (org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)1 CTTx (org.openxmlformats.schemas.drawingml.x2006.chart.CTTx)1 CTTextBody (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)1 CTTextBulletSizePoint (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint)1 CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)1