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