// Font size and jc for the style (which could be the default style),
// without following its based on values
Style expressStyle = allStyles.get(styleVal);
Jc expressStyleJc = expressStyle.getPPr()==null ? null : expressStyle.getPPr().getJc();
HpsMeasure expressStyleFontSize = null;
if (expressStyle.getRPr()!=null) {
expressStyleFontSize=expressStyle.getRPr().getSz();
}
// Font size and jc for the style following its based on values
PPr effectivePPr = propertyResolver.getEffectivePPr(styleVal);
Jc effectiveJc = effectivePPr.getJc();
RPr effectiveRPr = propertyResolver.getEffectiveRPr(styleVal);
HpsMeasure effectiveFontSize = null;
if (effectiveRPr!=null) {
effectiveFontSize=effectiveRPr.getSz();
}
String tableStyle=null;
TblPr tblPr = tblStack.peek().getTblPr();
if (tblPr!=null && tblPr.getTblStyle()!=null) {
tableStyle = tblPr.getTblStyle().getVal();
} else if (defaultTableStyle==null) {
log.warn("No default table style defined in docx Style Definitions part");
return null;
} else {
if (defaultTableStyle.getName()!=null
&& defaultTableStyle.getName().getVal()!=null
&& defaultTableStyle.getName().getVal().equals("Normal Table")) {
// Word 2010 x64 ignores any table style with that name!
log.debug("Ignoring style with name 'Normal Table' (mimicking Word)");
return null;
} else {
// We have a default table style
tableStyle = defaultTableStyle.getStyleId();
// shouldn't happen, but just in case..
if (tableStyle==null) {
log.error("Default table style has no ID!");
log.error(XmlUtils.marshaltoString(tableStyle));
return null;
}
}
}
String resultStyleID = styleVal+"-"+tableStyle;
if (tableStyle.endsWith("-BR")) {
// don't want to add this twice
} else {
resultStyleID = resultStyleID +"-BR";
}
if (cellPStyles.contains(resultStyleID)) return resultStyleID;
List<Style> hierarchy = new ArrayList<Style>();
Style basedOn = null;
String currentStyle = styleVal;
do {
// System.out.println("Getting " + currentStyle);
Style thisStyle = allStyles.get(currentStyle);
hierarchy.add(thisStyle);
if (thisStyle.getBasedOn()!=null) {
currentStyle = thisStyle.getBasedOn().getVal();
} else {
currentStyle = null;
}
} while (currentStyle != null);
Style newStyle = Context.getWmlObjectFactory().createStyle();
newStyle.setType("paragraph");
// First, docDefaults
Style styleToApply = hierarchy.get(hierarchy.size()-1); // DocDefault
log.debug("DocDefault");
log.debug(XmlUtils.marshaltoString(styleToApply, true, true));
StyleUtil.apply(styleToApply, newStyle);
log.debug("Result");
log.debug(XmlUtils.marshaltoString(newStyle, true, true));
// Next, table style - first/temporarily in tableStyleContrib
Style tableStyleContrib = null;
List<Style> tblStyles = new ArrayList<Style>();
if (tableStyle!=null) {
currentStyle = tableStyle;
do {
log.debug(currentStyle);
Style thisStyle = allStyles.get(currentStyle);
if (thisStyle.getName().getVal().equals("Normal Table")) {
// Very surprising, but testing using Word 2010 SP1,
// it turns out that table style with name "Normal Table"
// is IGNORED (whatever its ID, and whether default or not)!!
// Change the name to something
// else, and it is given effect! GO figure..
//TBD how localisation affects this.
// In theory, this style could be based on
// another. Haven't tested to see whether that is
// honoured or not. Assume not.
break;
}
tblStyles.add(thisStyle);
if (thisStyle.getBasedOn()!=null) {
currentStyle = thisStyle.getBasedOn().getVal();
} else {
currentStyle = null;
}
} while (currentStyle != null);
for (int i = tblStyles.size()-1; i>=0; i--) {
styleToApply = tblStyles.get(i);
log.debug("Applying " + styleToApply.getStyleId() + "\n" + XmlUtils.marshaltoString(styleToApply, true, true));
tableStyleContrib = StyleUtil.apply(styleToApply, tableStyleContrib);
log.debug(XmlUtils.marshaltoString(tableStyleContrib, true, true));
}
}
if (tableStyleContrib==null) {
// will happen if the style was Normal Table, since we break above..
// .. so just make an empty object, to avoid having to do isNull tests below..
tableStyleContrib = Context.getWmlObjectFactory().createStyle();
}
// What do the table styles contribute?
Jc tableStyleJc = tableStyleContrib.getPPr()==null ? null : tableStyleContrib.getPPr().getJc();
HpsMeasure tableStyleFontSize = null;
if (tableStyleContrib.getRPr()!=null) {
tableStyleFontSize=tableStyleContrib.getRPr().getSz();
}
// Now we can apply to table style contrib on top of docDefaults