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