if (r.startsWith("<span")) {
// Wrap the XHTML in a span element with @class, @style as appropriate
// so FS uses suitable CSS
// Code copied from XsltHTMLFunctions.createBlockForRPr
Style defaultRunStyle =
(pkg.getMainDocumentPart().getStyleDefinitionsPart(false) != null ?
pkg.getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultCharacterStyle() :
null);
String defaultCharacterStyleId;
if (defaultRunStyle.getStyleId()==null) // possible, for non MS source docx
defaultCharacterStyleId = "DefaultParagraphFont";
else defaultCharacterStyleId = defaultRunStyle.getStyleId();
StyleTree styleTree = pkg.getMainDocumentPart().getStyleTree();
// Set @class
String classVal =null;
String rStyleVal = defaultCharacterStyleId;
if ( rPrSDT!=null && rPrSDT.getRStyle()!=null) {
rStyleVal = rPrSDT.getRStyle().getVal();
}
Tree<AugmentedStyle> cTree = styleTree.getCharacterStylesTree();
org.docx4j.model.styles.Node<AugmentedStyle> asn = cTree.get(rStyleVal);
if (asn==null) {
log.warn("No style node for: " + rStyleVal);
} else {
classVal = StyleTree.getHtmlClassAttributeValue(cTree, asn);
}
String css = null;
if ( rPrSDT!=null) {
StringBuilder result = new StringBuilder();
HtmlCssHelper.createCss(pkg, rPrSDT, result);
css = result.toString();
if (css.equals("")) {
css =null;
}
}
if (css==null && classVal==null) {
// Do nothing
} else if (classVal==null) {
// just @style
r = "<span style=\"" + css + "\">" + r + "</span>";
} else if (css==null) {
// just @class
r = "<span class=\"" + classVal + "\">" + r + "</span>";
} else {
r = "<span style=\"" + css + "\" class=\"" + classVal + "\">" + r + "</span>";
}
log.debug("\nenhanced with css: \n" + r);
} else if (Docx4jProperties.getProperty("docx4j.model.datastorage.BindingTraverser.XHTML.Block.rStyle.Adopt", false)) {
log.debug("Block.rStyle.Adopt..");
// its block level, and we're instructed to apply the paragraph style
// linked to w:sdtPr/w:rPr/w:rStyle (if any)
String rStyleVal=null;
if ( rPrSDT!=null && rPrSDT.getRStyle()!=null) {
rStyleVal = rPrSDT.getRStyle().getVal();
log.debug(".." + rStyleVal);
}
if (rStyleVal==null) {
log.debug("No rStyle specified ");
} else {
Style pStyle = pkg.getMainDocumentPart().getStyleDefinitionsPart(false).getLinkedStyle(rStyleVal);
if (pStyle==null) {
log.warn("No linked style for " + rStyleVal);
} else {
// Got the pStyle .. now apply it in the XHTML
StyleTree styleTree = pkg.getMainDocumentPart().getStyleTree();
String pStyleVal = pStyle.getStyleId();
log.debug(".." + pStyleVal);
// Set @class
String classVal =null;
Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree();