// so we can read it using our standard
// methods. Its a bit sad that we
// can't just adorn our DOM tree with the
// original JAXB objects?
PPr pPr = null;
RPr rPr = null;
RPr rPrParagraphMark = null; // required for list item label
if (pPrNodeIt==null) { // Never happens?
if (log.isDebugEnabled()) {
log.debug("Here after all!!");
}
pPr = propertyResolver.getEffectivePPr(defaultParagraphStyleId);
rPr = propertyResolver.getEffectiveRPr(defaultParagraphStyleId);
rPrParagraphMark = rPr;
} else {
Node n = pPrNodeIt.nextNode();
if (n==null) {
if (log.isDebugEnabled()) {
log.debug("pPrNodeIt.nextNode() was null (ie there is no pPr in this p)");
}
pPr = propertyResolver.getEffectivePPr(defaultParagraphStyleId);
rPr = propertyResolver.getEffectiveRPr(defaultParagraphStyleId);
// TODO - in this case, we should be able to compute once,
// and on subsequent calls, just return pre computed value
} else {
if (log.isDebugEnabled()) {
log.debug( "P actual pPr: "+ XmlUtils.w3CDomNodeToString(n) );
}
Unmarshaller u = Context.jc.createUnmarshaller();
u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
Object jaxb = u.unmarshal(n);
pPrDirect = (PPr)jaxb;
pPr = propertyResolver.getEffectivePPr(pPrDirect);
if ((pPr==null) && (log.isDebugEnabled())) {
log.debug("pPr null; obtained from: " + XmlUtils.w3CDomNodeToString(n) );
}
// On the block representing the w:p, we want to put both
// pPr and rPr attributes.
if (log.isDebugEnabled()) {
log.debug("getting rPr for paragraph style");
}
rPr = propertyResolver.getEffectiveRPr(null, pPrDirect);
// rPr in pPr direct formatting only applies to paragraph mark,
// and by virtue of that, to list item label,
// so pass null here
// Now, work out the value for list item label
rPrParagraphMark = XmlUtils.deepCopy(rPr);
// System.out.println("p rpr-->" + XmlUtils.marshaltoString(pPrDirect.getRPr()));
StyleUtil.apply(pPrDirect.getRPr(), rPrParagraphMark);
}
}
if (log.isDebugEnabled() && pPr!=null) {
log.debug("P effective pPr: "+ XmlUtils.marshaltoString(pPr, true, true));
}
// Create a DOM builder and parse the fragment
Document document = XmlUtils.getNewDocumentBuilder().newDocument();
//log.info("Document: " + document.getClass().getName() );
boolean indentHandledByNumbering = false;
Element foBlockElement;
Element foListBlock = null;
if (pPr!=null
&& pPr.getNumPr()!=null
&& pPr.getNumPr().getNumId()!=null
&& pPr.getNumPr().getNumId().getVal().longValue()!=0 //zero means no numbering
) {
// Its a list item. At present we make a new list-block for
// each list-item. This is not great; DocumentModel will ultimately
// allow us to use fo:list-block properly.
/* Create something like:
*
<fo:list-block provisional-distance-between-starts="0.5in" start-indent="0.5in">
<fo:list-item>
<fo:list-item-label>
<fo:block font-family="Times New Roman">-</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block font-family="Times New Roman" font-size="9.0pt" line-height="100%" space-after="0.08in" space-before="0.08in" text-align="justify">
<inline xmlns="http://www.w3.org/1999/XSL/Format" id="clauseDPI5123341"/>Content goes here...
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
*/
foListBlock = document.createElementNS("http://www.w3.org/1999/XSL/Format",
"fo:list-block");
document.appendChild(foListBlock);
// foListBlock.setAttribute("provisional-distance-between-starts", "0.5in");
// Need to apply shading at fo:list-block level
if (pPr.getShd()!=null) {
PShading pShading = new PShading(pPr.getShd());
pShading.setXslFO(foListBlock);
}
Element foListItem = document.createElementNS("http://www.w3.org/1999/XSL/Format",
"fo:list-item");
foListBlock.appendChild(foListItem);
Element foListItemLabel = document.createElementNS("http://www.w3.org/1999/XSL/Format",
"fo:list-item-label");
foListItem.appendChild(foListItemLabel);
Element foListItemLabelBody = document.createElementNS("http://www.w3.org/1999/XSL/Format",
"fo:block");
foListItemLabel.appendChild(foListItemLabelBody);
Element foListItemBody = document.createElementNS("http://www.w3.org/1999/XSL/Format",
"fo:list-item-body");
foListItem.appendChild(foListItemBody);
foListItemBody.setAttribute(Indent.FO_NAME, "body-start()");
ResultTriple triple;
if (pPrDirect!=null && pPrDirect.getNumPr()!=null) {
triple = org.docx4j.model.listnumbering.Emulator.getNumber(
context.getWmlPackage(), pStyleVal,
pPrDirect.getNumPr().getNumId().getVal().toString(),
pPrDirect.getNumPr().getIlvl().getVal().toString() );
} else {
// Get the effective values; since we already know this,
// save the effort of doing this again in Emulator
Ilvl ilvl = pPr.getNumPr().getIlvl();
String ilvlString = ilvl == null ? "0" : ilvl.getVal().toString();
triple = null;
if (pPr.getNumPr().getNumId()!=null) {
triple = org.docx4j.model.listnumbering.Emulator.getNumber(
context.getWmlPackage(), pStyleVal,
pPr.getNumPr().getNumId().getVal().toString(),
ilvlString );
}
}
if (triple==null) {
log.warn("computed number ResultTriple was null");
if (log.isDebugEnabled() ) {
foListItemLabelBody.setAttribute("color", "red");
foListItemLabelBody.setTextContent("null#");
}
} else {
/* Format the list item label
*
* Since it turns out (in FOP at least) that the label and the body
* don't have the same vertical alignment
* unless font size is applied at the same level
* (ie to both -label and -body, or to the block inside each),
* we have to format the list-item-body as well.
* This issue only manifests itself if the font size on
* the outer list-block is larger than the font sizes
* set inside it.
*/
// OK just to override specific values
// Values come from numbering rPr, unless overridden in p-level rpr
if(triple.getRPr()==null) {
if (pPr.getRPr()==null) {
// do nothing, since we're already inheriting the formatting in the style
// (as opposed to the paragraph mark formatting)
// EXCEPT for font
// setFont( context, foListItemLabelBody, rPr.getRFonts());
setFont( context, foListItemLabelBody, pPr, rPr, triple.getNumString());
} else {
createFoAttributes(context.getWmlPackage(), rPrParagraphMark, foListItemLabel );
createFoAttributes(context.getWmlPackage(), rPrParagraphMark, foListItemBody );
// setFont( context, foListItemLabelBody, rPrParagraphMark.getRFonts());
setFont( context, foListItemLabelBody, pPr, rPrParagraphMark, triple.getNumString());
}
} else {
RPr actual = XmlUtils.deepCopy(triple.getRPr()); // clone, so the ilvl rpr is not altered
// System.out.println(XmlUtils.marshaltoString(rPrParagraphMark));
// pMark overrides numbering, except for font
// (which makes sense, since that would change the bullet)
// so set the font