Search in sources :

Example 1 with CTTextParagraph

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

the class XSLFTextParagraph method clearButKeepProperties.

/**
     * Helper method for appending text and keeping paragraph and character properties.
     * The character properties are moved to the end paragraph marker
     */
/* package */
void clearButKeepProperties() {
    CTTextParagraph thisP = getXmlObject();
    for (int i = thisP.sizeOfBrArray(); i > 0; i--) {
        thisP.removeBr(i - 1);
    }
    for (int i = thisP.sizeOfFldArray(); i > 0; i--) {
        thisP.removeFld(i - 1);
    }
    if (!_runs.isEmpty()) {
        int size = _runs.size();
        XSLFTextRun lastRun = _runs.get(size - 1);
        CTTextCharacterProperties cpOther = lastRun.getRPr(false);
        if (cpOther != null) {
            if (thisP.isSetEndParaRPr()) {
                thisP.unsetEndParaRPr();
            }
            CTTextCharacterProperties cp = thisP.addNewEndParaRPr();
            cp.set(cpOther);
        }
        for (int i = size; i > 0; i--) {
            thisP.removeR(i - 1);
        }
        _runs.clear();
    }
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) CTTextBulletSizePoint(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint)

Example 2 with CTTextParagraph

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

the class XSLFTextShape method addNewTextParagraph.

/**
     * add a new paragraph run to this shape
     *
     * @return created paragraph run
     */
public XSLFTextParagraph addNewTextParagraph() {
    CTTextBody txBody = getTextBody(false);
    CTTextParagraph p;
    if (txBody == null) {
        txBody = getTextBody(true);
        p = txBody.getPArray(0);
        p.removeR(0);
    } else {
        p = txBody.addNewP();
    }
    XSLFTextParagraph paragraph = newTextParagraph(p);
    _paragraphs.add(paragraph);
    return paragraph;
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextBody(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)

Example 3 with CTTextParagraph

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

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

the class TestXSSFDrawing method testRichTextFontAndColor.

/**
     * ensure that font and color rich text attributes defined in a XSSFRichTextString
     * are passed to XSSFSimpleShape.
     *
     * See Bugzilla 54969.
     */
@Test
public void testRichTextFontAndColor() throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();
    XSSFDrawing drawing = sheet.createDrawingPatriarch();
    XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
    XSSFRichTextString rt = new XSSFRichTextString("Test String");
    XSSFFont font = wb.createFont();
    font.setColor(new XSSFColor(new Color(0, 128, 128)));
    font.setFontName("Arial");
    rt.applyFont(font);
    shape.setText(rt);
    CTTextParagraph pr = shape.getCTShape().getTxBody().getPArray(0);
    assertEquals(1, pr.sizeOfRArray());
    CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
    assertEquals("Arial", rPr.getLatin().getTypeface());
    assertArrayEquals(new byte[] { 0, (byte) 128, (byte) 128 }, rPr.getSolidFill().getSrgbClr().getVal());
    checkRewrite(wb);
    wb.close();
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) Test(org.junit.Test)

Example 5 with CTTextParagraph

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

the class XSLFAutoShape method initTextBody.

protected static void initTextBody(CTTextBody txBody) {
    CTTextBodyProperties bodypr = txBody.addNewBodyPr();
    bodypr.setAnchor(STTextAnchoringType.T);
    bodypr.setRtlCol(false);
    CTTextParagraph p = txBody.addNewP();
    p.addNewPPr().setAlgn(STTextAlignType.L);
    CTTextCharacterProperties endPr = p.addNewEndParaRPr();
    endPr.setLang("en-US");
    endPr.setSz(1100);
    p.addNewR().setT("");
    txBody.addNewLstStyle();
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextBodyProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties)

Aggregations

CTTextParagraph (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph)8 CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)5 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 Test (org.junit.Test)2 CTRegularTextRun (org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)2 CTTextBody (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)2 CTTextBulletSizePoint (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint)2 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 CTTitle (org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)1 CTTx (org.openxmlformats.schemas.drawingml.x2006.chart.CTTx)1 CTTextBodyProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties)1 CTTextField (org.openxmlformats.schemas.drawingml.x2006.main.CTTextField)1 CTTextParagraphProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)1 CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)1 CTShapeNonVisual (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)1