Search in sources :

Example 6 with CTTextParagraph

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

the class XSSFSimpleShape method prototype.

/**
     * Prototype with the default structure of a new auto-shape.
     */
protected static CTShape prototype() {
    if (prototype == null) {
        CTShape shape = CTShape.Factory.newInstance();
        CTShapeNonVisual nv = shape.addNewNvSpPr();
        CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
        nvp.setId(1);
        nvp.setName("Shape 1");
        nv.addNewCNvSpPr();
        CTShapeProperties sp = shape.addNewSpPr();
        CTTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPresetGeometry2D geom = sp.addNewPrstGeom();
        geom.setPrst(STShapeType.RECT);
        geom.addNewAvLst();
        CTTextBody body = shape.addNewTxBody();
        CTTextBodyProperties bodypr = body.addNewBodyPr();
        bodypr.setAnchor(STTextAnchoringType.T);
        bodypr.setRtlCol(false);
        CTTextParagraph p = body.addNewP();
        p.addNewPPr().setAlgn(STTextAlignType.L);
        CTTextCharacterProperties endPr = p.addNewEndParaRPr();
        endPr.setLang("en-US");
        endPr.setSz(1100);
        CTSolidColorFillProperties scfpr = endPr.addNewSolidFill();
        scfpr.addNewSrgbClr().setVal(new byte[] { 0, 0, 0 });
        body.addNewLstStyle();
        prototype = shape;
    }
    return prototype;
}
Also used : CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)

Example 7 with CTTextParagraph

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

the class XSLFTextShape method appendText.

@Override
public XSLFTextRun appendText(String text, boolean newParagraph) {
    if (text == null)
        return null;
    // copy properties from last paragraph / textrun or paragraph end marker
    CTTextParagraphProperties otherPPr = null;
    CTTextCharacterProperties otherRPr = null;
    boolean firstPara;
    XSLFTextParagraph para;
    if (_paragraphs.isEmpty()) {
        firstPara = false;
        para = null;
    } else {
        firstPara = !newParagraph;
        para = _paragraphs.get(_paragraphs.size() - 1);
        CTTextParagraph ctp = para.getXmlObject();
        otherPPr = ctp.getPPr();
        List<XSLFTextRun> runs = para.getTextRuns();
        if (!runs.isEmpty()) {
            XSLFTextRun r0 = runs.get(runs.size() - 1);
            otherRPr = r0.getRPr(false);
            if (otherRPr == null) {
                otherRPr = ctp.getEndParaRPr();
            }
        }
    // don't copy endParaRPr to the run in case there aren't any other runs
    // this is the case when setText() was called initially
    // otherwise the master style will be overridden/ignored
    }
    XSLFTextRun run = null;
    for (String lineTxt : text.split("\\r\\n?|\\n")) {
        if (!firstPara) {
            if (para != null) {
                CTTextParagraph ctp = para.getXmlObject();
                CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr();
                if (unexpectedRPr != null && unexpectedRPr != otherRPr) {
                    ctp.unsetEndParaRPr();
                }
            }
            para = addNewTextParagraph();
            if (otherPPr != null) {
                para.getXmlObject().setPPr(otherPPr);
            }
        }
        boolean firstRun = true;
        for (String runText : lineTxt.split("[]")) {
            if (!firstRun) {
                para.addLineBreak();
            }
            run = para.addNewTextRun();
            run.setText(runText);
            if (otherRPr != null) {
                run.getRPr(true).set(otherRPr);
            }
            firstRun = false;
        }
        firstPara = false;
    }
    assert (run != null);
    return run;
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Example 8 with CTTextParagraph

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

the class TestXSSFDrawing method testRichText.

/**
     * ensure that rich text attributes defined in a XSSFRichTextString
     * are passed to XSSFSimpleShape.
     *
     * See Bugzilla 52219.
     */
@Test
public void testRichText() 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.setItalic(true);
    font.setBold(true);
    font.setUnderline(FontUnderline.SINGLE);
    rt.applyFont(font);
    shape.setText(rt);
    CTTextParagraph pr = shape.getCTShape().getTxBody().getPArray(0);
    assertEquals(1, pr.sizeOfRArray());
    CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
    assertEquals(true, rPr.getB());
    assertEquals(true, rPr.getI());
    assertEquals(STTextUnderlineType.SNG, rPr.getU());
    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 9 with CTTextParagraph

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

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