/** * 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(); } }
/** * Add a new run of text * * @return a new run of text */ public XSLFTextRun addNewTextRun(){ CTRegularTextRun r = _p.addNewR(); CTTextCharacterProperties rPr = r.addNewRPr(); rPr.setLang("en-US"); XSLFTextRun run = newTextRun(r); _runs.add(run); return run; }
public XDDFRunProperties getAfterLastRunProperties() { if (_p.isSetEndParaRPr()) { return new XDDFRunProperties(_p.getEndParaRPr()); } else { return null; } }
public XDDFRunProperties addAfterLastRunProperties() { if (!_p.isSetEndParaRPr()) { _p.addNewEndParaRPr(); } return getAfterLastRunProperties(); }
CTTextParagraph otherP = other.getXmlObject(); if (thisP.isSetPPr()) thisP.unsetPPr(); if (thisP.isSetEndParaRPr()) thisP.unsetEndParaRPr(); 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();
para = _paragraphs.get(_paragraphs.size() - 1); CTTextParagraph ctp = para.getXmlObject(); otherPPr = ctp.getPPr(); List<XSLFTextRun> runs = para.getTextRuns(); if (!runs.isEmpty()) { otherRPr = r0.getRPr(false); if (otherRPr == null) { otherRPr = ctp.getEndParaRPr(); if (para != null) { CTTextParagraph ctp = para.getXmlObject(); CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr(); if (unexpectedRPr != null && unexpectedRPr != otherRPr) { ctp.unsetEndParaRPr(); para.getXmlObject().setPPr(otherPPr);
public static void setAxisTitle(XSSFChart chart, int axisIdx, String title) { CTValAx valAx = chart.getCTChart().getPlotArea().getValAxArray(axisIdx); CTTitle ctTitle = valAx.addNewTitle(); ctTitle.addNewLayout(); ctTitle.addNewOverlay().setVal(false); CTTextBody rich = ctTitle.addNewTx().addNewRich(); rich.addNewBodyPr(); rich.addNewLstStyle(); CTTextParagraph p = rich.addNewP(); p.addNewPPr().addNewDefRPr(); p.addNewR().setT(title); p.addNewEndParaRPr(); }
public List<XDDFTabStop> getTabStops() { if (_p.isSetPPr()) { return getProperties().getTabStops(); } else { return Collections.emptyList(); } }
bodypr.setRtlCol(false); CTTextParagraph p = body.addNewP(); p.addNewPPr().setAlgn(STTextAlignType.CTR); CTTextCharacterProperties endPr = p.addNewEndParaRPr(); endPr.setLang("en-US"); endPr.setSz(1100);
/** * Insert a line break * * @return text run representing this line break ('\n') */ public XSSFTextRun addLineBreak(){ CTTextLineBreak br = _p.addNewBr(); CTTextCharacterProperties brProps = br.addNewRPr(); if(_runs.size() > 0){ // by default line break has the font size of the last text run CTTextCharacterProperties prevRun = _runs.get(_runs.size() - 1).getRPr(); brProps.set(prevRun); } CTRegularTextRun r = CTRegularTextRun.Factory.newInstance(); r.setRPr(brProps); r.setT("\n"); XSSFTextRun run = new XSSFLineBreak(r, this, brProps); _runs.add(run); return run; }
/** * Returns the level of text properties that this paragraph will follow. * * @return the text level of this paragraph (0-based). Default is 0. */ public int getLevel(){ CTTextParagraphProperties pr = _p.getPPr(); if(pr == null) return 0; return pr.getLvl(); }
@Override public Double getDefaultFontSize() { CTTextCharacterProperties endPr = _p.getEndParaRPr(); if (endPr == null || !endPr.isSetSz()) { // inherit the font size from the master style CTTextParagraphProperties masterStyle = getDefaultMasterStyle(); if (masterStyle != null) { endPr = masterStyle.getDefRPr(); } } return (endPr == null || !endPr.isSetSz()) ? 12 : (endPr.getSz() / 100.); }
XSLFTextParagraph(CTTextParagraph p, XSLFTextShape shape){ _p = p; _runs = new ArrayList<>(); _shape = shape; XmlCursor c = _p.newCursor(); try { if (c.toFirstChild()) { do { XmlObject r = c.getObject(); if (r instanceof CTTextLineBreak) { _runs.add(new XSLFLineBreak((CTTextLineBreak)r, this)); } else if (r instanceof CTRegularTextRun || r instanceof CTTextField) { _runs.add(new XSLFTextRun(r, this)); } } while (c.toNextSibling()); } } finally { c.dispose(); } }
XSSFTextParagraph(CTTextParagraph p, CTShape ctShape){ _p = p; _shape = ctShape; _runs = new ArrayList<>(); for(XmlObject ch : _p.selectPath("*")){ if(ch instanceof CTRegularTextRun){ CTRegularTextRun r = (CTRegularTextRun)ch; _runs.add(new XSSFTextRun(r, this)); } else if (ch instanceof CTTextLineBreak){ CTTextLineBreak br = (CTTextLineBreak)ch; CTRegularTextRun r = CTRegularTextRun.Factory.newInstance(); r.setRPr(br.getRPr()); r.setT("\n"); _runs.add(new XSSFTextRun(r, this)); } else if (ch instanceof CTTextField){ CTTextField f = (CTTextField)ch; CTRegularTextRun r = CTRegularTextRun.Factory.newInstance(); r.setRPr(f.getRPr()); r.setT(f.getT()); _runs.add(new XSSFTextRun(r, this)); } } }
/** * Append a new text field. * * @return the new text field. */ public XDDFTextRun appendField(String id, String type, String text) { CTTextField f = _p.addNewFld(); f.setId(id); f.setType(type); f.setT(text); CTTextCharacterProperties rPr = f.addNewRPr(); rPr.setLang(LocaleUtil.getUserLocale().toLanguageTag()); XDDFTextRun run = new XDDFTextRun(f, this); _runs.add(run); return run; }
CTTextParagraph otherP = other.getXmlObject(); if (thisP.isSetPPr()) thisP.unsetPPr(); if (thisP.isSetEndParaRPr()) thisP.unsetEndParaRPr(); 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();
para = _paragraphs.get(_paragraphs.size() - 1); CTTextParagraph ctp = para.getXmlObject(); otherPPr = ctp.getPPr(); List<XSLFTextRun> runs = para.getTextRuns(); if (!runs.isEmpty()) { otherRPr = r0.getRPr(false); if (otherRPr == null) { otherRPr = ctp.getEndParaRPr(); if (para != null) { CTTextParagraph ctp = para.getXmlObject(); CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr(); if (unexpectedRPr != null && unexpectedRPr != otherRPr) { ctp.unsetEndParaRPr(); para.getXmlObject().setPPr(otherPPr);