Search in sources :

Example 1 with CTTextLineBreak

use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak 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 2 with CTTextLineBreak

use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak 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)

Aggregations

CTRegularTextRun (org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)2 CTTextLineBreak (org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTTextField (org.openxmlformats.schemas.drawingml.x2006.main.CTTextField)1