Search in sources :

Example 1 with PStyle

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);
    }
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) ObjectFactory(org.docx4j.wml.ObjectFactory) Text(org.docx4j.wml.Text) PStyle(org.docx4j.wml.PPrBase.PStyle)

Example 2 with PStyle

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;
}
Also used : PStyle(org.docx4j.wml.PPrBase.PStyle) FootnoteRef(org.docx4j.wml.R.FootnoteRef) BigInteger(java.math.BigInteger)

Example 3 with PStyle

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);
    }
}
Also used : PStyle(org.docx4j.wml.PPrBase.PStyle) Spacing(org.docx4j.wml.PPrBase.Spacing)

Example 4 with PStyle

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 + "]");
            }
        }
    }
}
Also used : Text(org.docx4j.wml.Text) PStyle(org.docx4j.wml.PPrBase.PStyle) JAXBException(javax.xml.bind.JAXBException) InvalidFormatException(org.docx4j.openpackaging.exceptions.InvalidFormatException) IOException(java.io.IOException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) ObjectFactory(org.docx4j.wml.ObjectFactory)

Example 5 with PStyle

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;
}
Also used : PStyle(org.docx4j.wml.PPrBase.PStyle) PStyle(org.docx4j.wml.PPrBase.PStyle)

Aggregations

PStyle (org.docx4j.wml.PPrBase.PStyle)6 ObjectFactory (org.docx4j.wml.ObjectFactory)2 P (org.docx4j.wml.P)2 PPr (org.docx4j.wml.PPr)2 R (org.docx4j.wml.R)2 Text (org.docx4j.wml.Text)2 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 JAXBException (javax.xml.bind.JAXBException)1 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 InvalidFormatException (org.docx4j.openpackaging.exceptions.InvalidFormatException)1 Spacing (org.docx4j.wml.PPrBase.Spacing)1 FootnoteRef (org.docx4j.wml.R.FootnoteRef)1