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
setFont( context, foListItemLabelBody, pPr, actual, triple.getNumString());
// .. before taking rPrParagraphMark into account
StyleUtil.apply(rPrParagraphMark, actual);
// System.out.println(XmlUtils.marshaltoString(actual));
createFoAttributes(context.getWmlPackage(), actual, foListItemLabel );
createFoAttributes(context.getWmlPackage(), actual, foListItemBody );
}
int numChars=1;
if (triple.getBullet()!=null ) {
foListItemLabelBody.setTextContent(triple.getBullet() );
} else if (triple.getNumString()==null) {
log.debug("computed NumString was null!");
if (log.isDebugEnabled() ) {
foListItemLabelBody.setAttribute("color", "red");
foListItemLabelBody.setTextContent("null#");
}
numChars=0;
} else {
Text number = document.createTextNode( triple.getNumString() );
foListItemLabelBody.appendChild(number);
numChars = triple.getNumString().length();
}
// Indent (setting provisional-distance-between-starts)
// Indent on direct pPr trumps indent in pPr in numbering, which trumps indent
// specified in a style. Well, not exactly, components which aren't set in
// the direct formatting will be contributed by the numbering's indent settings
Indent indent = new Indent(pPrDirect.getInd(), triple.getIndent());
if (indent.isHanging() ) {
indent.setXslFOListBlock(foListBlock, -1);
} else {
int numWidth = 90 * numChars; // crude .. TODO take font size into account