use of org.docx4j.wml.PPrBase.PStyle in project mdw-designer by CenturyLinkCloud.
the class DocxBuilder method addBulletList.
public void addBulletList(List<String> items) throws Exception {
if (bulletNum == null) {
bulletNum = getNdp().addAbstractListNumberingDefinition((Numbering.AbstractNum) XmlUtils.unmarshalString(getFragment("bulletNumbering")));
bulletNumId = bulletNum.getNumId();
} else {
bulletNumId = BigInteger.valueOf(ndp.restart(bulletNumId.longValue(), 0, 1));
}
for (String item : items) {
ObjectFactory factory = Context.getWmlObjectFactory();
P listP = factory.createP();
Text t = factory.createText();
t.setValue(item);
R listRun = factory.createR();
listRun.getContent().add(t);
listP.getContent().add(listRun);
PPr listPpr = factory.createPPr();
listP.setPPr(listPpr);
listPpr.setNumPr(createBulletListNumPr());
PStyle pStyle = factory.createPPrBasePStyle();
pStyle.setVal("ListParagraph");
listPpr.setPStyle(pStyle);
getMdp().addObject(listP);
}
}
use of org.docx4j.wml.PPrBase.PStyle in project flexmark-java by vsch.
the class DocxContextImpl method addFootnote.
@Override
public CTFtnEdn addFootnote(final BigInteger footnoteID) throws Docx4JException {
// Add the note number in the run
CTFtnEdnRef ftnednref = myFactory.createCTFtnEdnRef();
JAXBElement<CTFtnEdnRef> ftnednrefWrapped = myFactory.createRFootnoteReference(ftnednref);
R ftnR = myFactory.createR();
getP().getContent().add(ftnR);
ftnR.getContent().add(ftnednrefWrapped);
RPr ftnRPr = myFactory.createRPr();
ftnR.setRPr(ftnRPr);
RStyle ftnRStyle = myFactory.createRStyle();
ftnRPr.setRStyle(ftnRStyle);
ftnRStyle.setVal(myRendererOptions.FOOTNOTE_ANCHOR_STYLE);
// see if we need to create a new footnote id or can re-use existing one
final boolean haveID = footnoteID.compareTo(BigInteger.ZERO) > 0;
BigInteger i = haveID ? footnoteID : BigInteger.valueOf(myFootnoteRef++);
ftnednref.setId(i);
if (haveID) {
for (CTFtnEdn ftnEdn : getFootnotesPart().getContents().getFootnote()) {
if (ftnEdn.getId().compareTo(footnoteID) == 0) {
return ftnEdn;
}
}
}
// Create a footnote in the footnotesPart
// @formatter:off
// String openXML = "<w:footnote w:id=\"" + i + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\">"
// + "<w:p>"
// + "<w:pPr>"
// + "<w:pStyle w:val=\"Footnote\"/>"
// //+ "<w:rPr>"
// // + "<w:lang w:val=\"en-AU\"/>"
// //+"</w:rPr>"
// +"</w:pPr>"
// + "<w:r>"
// + "<w:rPr>"
// + "<w:rStyle w:val=\"FootnoteAnchor\"/>"
// +"</w:rPr>"
// + "<w:footnoteRef/>"
// +"</w:r>"
// + "<w:r>"
// + "<w:t xml:space=\"preserve\"> </w:t>"
// +"</w:r>"
// + "<w:r>"
// //+ "<w:rPr>"
// // + "<w:lang w:val=\"en-AU\"/>"
// //+"</w:rPr>"
// + "<w:t>" + text +"</w:t>"
// +"</w:r>"
// +"</w:p>"
// +"</w:footnote>";
// // @formatter:on
// CTFtnEdn ftnedn = (CTFtnEdn) XmlUtils.unmarshalString(openXML, Context.jc, CTFtnEdn.class);
CTFtnEdn ftnEdn = myFactory.createCTFtnEdn();
ftnEdn.setId(i);
P p = myFactory.createP();
ftnEdn.getContent().add(p);
PPr pPr = myFactory.createPPr();
p.setPPr(pPr);
PStyle pStyle = myFactory.createPPrBasePStyle();
pPr.setPStyle(pStyle);
pStyle.setVal(myRendererOptions.FOOTNOTE_STYLE);
R r1 = myFactory.createR();
p.getContent().add(r1);
RPr rPr = myFactory.createRPr();
r1.setRPr(rPr);
RStyle rStyle = myFactory.createRStyle();
rPr.setRStyle(rStyle);
rStyle.setVal(myRendererOptions.FOOTNOTE_ANCHOR_STYLE);
final FootnoteRef footnoteRef = myFactory.createRFootnoteRef();
r1.getContent().add(footnoteRef);
R r2 = myFactory.createR();
Text text1 = myFactory.createText();
JAXBElement<Text> textWrapped = myFactory.createRT(text1);
r2.getContent().add(textWrapped);
text1.setSpace(RunFormatProvider.SPACE_PRESERVE);
text1.setValue("\t");
p.getContent().add(r2);
getFootnotesPart().getContents().getFootnote().add(ftnEdn);
return ftnEdn;
}
use of org.docx4j.wml.PPrBase.PStyle in project flexmark-java by vsch.
the class DocxContextImpl method addBlankLine.
@Override
public void addBlankLine(final BigInteger size, final String styleId) {
if (size.compareTo(BigInteger.ZERO) > 0) {
// now add empty for spacing
P p = myFactory.createP();
PPr pPr = myFactory.createPPr();
p.setPPr(pPr);
myParaContainer.addP(p);
if (styleId != null && !styleId.isEmpty()) {
if (pPr.getPStyle() == null) {
PStyle pStyle = myDocxHelper.myFactory.createPPrBasePStyle();
pPr.setPStyle(pStyle);
}
pPr.getPStyle().setVal(styleId);
}
// Create new Spacing which we override
Spacing spacing = myFactory.createPPrBaseSpacing();
pPr.setSpacing(spacing);
spacing.setBefore(BigInteger.ZERO);
spacing.setAfter(BigInteger.ZERO);
spacing.setLine(size);
spacing.setLineRule(STLineSpacingRule.EXACT);
}
}
use of org.docx4j.wml.PPrBase.PStyle in project mdw-designer by CenturyLinkCloud.
the class DocxBuilder method addBulletList.
public void addBulletList(Map<String, Object> items) throws Exception {
if (bulletNum == null) {
bulletNum = getNdp().addAbstractListNumberingDefinition((Numbering.AbstractNum) XmlUtils.unmarshalString(getFragment("bulletNumbering")));
bulletNumId = bulletNum.getNumId();
} else {
bulletNumId = BigInteger.valueOf(ndp.restart(bulletNumId.longValue(), 0, 1));
}
boolean wasTable = false;
for (String name : items.keySet()) {
ObjectFactory factory = Context.getWmlObjectFactory();
P listP = factory.createP();
Object item = items.get(name);
PPr listPpr = factory.createPPr();
listP.setPPr(listPpr);
Text t = factory.createText();
R listRun = factory.createR();
listRun.getContent().add(t);
listP.getContent().add(listRun);
if (item instanceof String) {
t.setValue(name + " = " + item);
if (wasTable)
listPpr.setSpacing(createSpacing(100));
wasTable = false;
} else if (item instanceof DocxTable) {
t.setValue(name + ":");
listPpr.setSpacing(createSpacing(100, 10));
wasTable = true;
} else if (item instanceof DocxCodebox) {
t.setValue(((DocxCodebox) item).label + ":");
try {
listRun.getContent().add(createCodeBox((DocxCodebox) item));
} catch (Exception ex) {
ex.printStackTrace();
t.setValue(((DocxCodebox) item).label + ": ![" + ex + "]");
}
wasTable = false;
}
listPpr.setNumPr(createBulletListNumPr());
PStyle pStyle = factory.createPPrBasePStyle();
pStyle.setVal("ListParagraph");
listPpr.setPStyle(pStyle);
getMdp().addObject(listP);
if (item instanceof DocxTable) {
try {
addTable((DocxTable) item);
} catch (Exception ex) {
ex.printStackTrace();
t.setValue(name + ": ![" + ex + "]");
}
}
}
}
use of org.docx4j.wml.PPrBase.PStyle in project flexmark-java by vsch.
the class DocxContextImpl method createR.
@Override
public R createR() {
P p = getP();
R r = myFactory.createR();
RPr rPr = myFactory.createRPr();
r.setRPr(rPr);
myRunContainer.addR(r);
if (myBlockFormatProvider != this || myRunFormatProvider != this) {
RPr blockRPr = myFactory.createRPr();
myBlockFormatProvider.getParaRPr(blockRPr);
myRunFormatProvider.getRPr(rPr);
StyleUtil.apply(rPr, blockRPr);
StyleUtil.apply(blockRPr, rPr);
// minimize the rPr
final RStyle rStyle = rPr.getRStyle();
if (rStyle != null && rStyle.getVal() != null) {
Style style = getStyle(rStyle.getVal());
if (style != null) {
RPr styleRPr = myDocxHelper.getExplicitRPr(style.getRPr(), p.getPPr());
myDocxHelper.keepDiff(rPr, styleRPr);
}
}
final PStyle pStyle = p.getPPr().getPStyle();
if (pStyle != null && pStyle.getVal() != null) {
Style style = getStyle(pStyle.getVal());
if (style != null) {
RPr styleRPr = myDocxHelper.getExplicitRPr(style.getRPr(), p.getPPr());
myDocxHelper.keepDiff(rPr, styleRPr);
}
}
if (StyleUtil.isEmpty(rPr.getRFonts())) {
// Style util adds empty destination before checking if there is anything to copy
rPr.setRFonts(null);
}
if (StyleUtil.isEmpty(rPr)) {
r.setRPr(null);
}
}
return r;
}
Aggregations