public boolean activateStyle(org.docx4j.wml.Style s) { return activateStyle(s, true); }
public PropertyResolver getPropertyResolver() { if (propertyResolver==null) { try { propertyResolver = new PropertyResolver( (WordprocessingMLPackage)this.pack); } catch (Docx4JException e) { e.printStackTrace(); } } return propertyResolver; }
private PPr getEffectivePPr(P p) { PPr pPrDirect = p.getPPr(); return propertyResolver.getEffectivePPr(pPrDirect); }
RPr pPrLevelRunStyle = getEffectiveRPr(pPr.getPStyle().getVal()); return getEffectiveRPrUsingPStyleRPr(expressRPr, pPrLevelRunStyle); if ((expressRPr == null) && (pPr.getRPr() != null) && (hasDirectRPrFormatting(pPr.getRPr())) ) { return getEffectiveRPrUsingPStyleRPr(expressRPr, StyleUtil.apply(pPr.getRPr(), Context.getWmlObjectFactory().createRPr())); return getEffectiveRPrUsingPStyleRPr( expressRPr, null);
private RPr getEffectiveRPr(RPr expressRPr) { RPr resolvedRPr = null; if (expressRPr != null && expressRPr.getRStyle() != null ) { String runStyleId = expressRPr.getRStyle().getVal(); resolvedRPr = propertyResolver.getEffectiveRPr(runStyleId); // remove the style, so it is not set by apply below expressRPr.setRStyle(null); } return StyleUtil.apply(expressRPr, resolvedRPr); }
/** * Enable the hyperlinkStyle in the docx. * * @param wordMLPackage * @param hyperlinkStyleId */ public void activateHyperlinkStyle(WordprocessingMLPackage wordMLPackage) { if (hyperlinkStyleId !=null) { wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(getHyperlinkStyleId()); } }
private void addDefaultParagraphFontToResolvedStyleRPrComponent() { Stack<RPr> rPrStack = new Stack<RPr>(); fillRPrStack(defaultParagraphStyleId, rPrStack); // Since default font size might be in there. fillRPrStack(defaultCharacterStyleId, rPrStack); rPrStack.push(documentDefaultRPr); RPr effectiveRPr = factory.createRPr(); // Now, apply the properties starting at the top of the stack while (!rPrStack.empty() ) { RPr rPr = rPrStack.pop(); applyRPr(rPr, effectiveRPr); } resolvedStyleRPrComponent.put(defaultCharacterStyleId, effectiveRPr); }
private void addNormalToResolvedStylePPrComponent() { Stack<PPr> pPrStack = new Stack<PPr>(); // String styleId = "Normal"; String styleId = defaultParagraphStyleId; fillPPrStack(styleId, pPrStack); pPrStack.push(documentDefaultPPr); PPr effectivePPr = factory.createPPr(); // Now, apply the properties starting at the top of the stack while (!pPrStack.empty() ) { PPr pPr = pPrStack.pop(); applyPPr(pPr, effectivePPr); } resolvedStylePPrComponent.put(styleId, effectivePPr); }
public boolean isBasedOn(Style thisStyle, String baseStyleId ) { if (thisStyle.getStyleId().equals(baseStyleId)) { return true; } if (thisStyle.getBasedOn()==null) { return false; } else { Style baseStyle =propertyResolver.getStyle(thisStyle.getBasedOn().getVal()); if (baseStyle==null) { log.error(thisStyle.getStyleId() + " is based on missing " + thisStyle.getBasedOn().getVal()); return false; } return isBasedOn(baseStyle, baseStyleId); } }
} else if (style.getBasedOn().getVal()!=null) { String basedOnStyleName = style.getBasedOn().getVal(); fillTableStyleStack( basedOnStyleName, tableStyleStack); } else { log.debug("No basedOn set for: " + style.getStyleId() );
} else if (style.getBasedOn().getVal()!=null) { String basedOnStyleName = style.getBasedOn().getVal(); fillRPrStack( basedOnStyleName, rPrStack); } else { log.debug("No basedOn set for: " + style.getStyleId() );
public PropertyResolver(WordprocessingMLPackage wordMLPackage) throws Docx4JException { this.wordMLPackage = wordMLPackage; MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); styleDefinitionsPart = mdp.getStyleDefinitionsPart(true); themePart = mdp.getThemePart(); numberingDefinitionsPart = mdp.getNumberingDefinitionsPart(); if (wordMLPackage.getMainDocumentPart().getDocumentSettingsPart()!=null && wordMLPackage.getMainDocumentPart().getDocumentSettingsPart().getContents()!=null) { themeFontLang = wordMLPackage.getMainDocumentPart().getDocumentSettingsPart().getContents().getThemeFontLang(); } init(); }
private Ind getInd(String styleId) { if (styleId==null) return null; Ind ind = styleIndent.get(styleId); if (ind == null) { PPr ppr = propertyResolver.getEffectivePPr(styleId); if (ppr==null) { return null; } else { ind = ppr.getInd(); styleIndent.put(styleId, ind); } } return ind; }
public boolean activateStyle( String styleId ) { if (liveStyles.get(styleId)!=null) { // Its already live - nothing to do return true; } // Assumption here is that it doesn't exist in your styles part, so.. java.util.Map<String, org.docx4j.wml.Style> knownStyles = StyleDefinitionsPart.getKnownStyles(); // NB KnownStyles.xml, not those in docx! org.docx4j.wml.Style s = knownStyles.get(styleId); if (s==null) { log.error("Unknown style: " + styleId); return false; } return activateStyle(s, false); // false -> don't replace an existing live style with a template }
fillRPrStack(styleId, rPrStack); log.debug("applying " + XmlUtils.marshaltoString(rPr)); applyRPr(rPr, resolvedRPr);
fillPPrStack(styleId, pPrStack); applyPPr(pPr, resolvedPPr);
return -1; } else { return getBasedOnHeading(propertyResolver.getStyle(s.getBasedOn().getVal()));
PPr effectivePPr = sp.propertyResolver.getEffectivePPr(s.getStyleId());
log.debug("Inspecting style: " + styleName ); if (getPropertyResolver().activateStyle(styleName)) {
/** * Create a paragraph containing the string simpleText, styled * using the specified style (up to user to ensure it is a paragraph style) * without adding it to the document. * * @param styleId * @param text * @return */ public org.docx4j.wml.P createStyledParagraphOfText(String styleId, String text) { org.docx4j.wml.P p = createParagraphOfText(text); if (getPropertyResolver().activateStyle(styleId)) { // Style is available org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory(); org.docx4j.wml.PPr pPr = factory.createPPr(); p.setPPr(pPr); org.docx4j.wml.PPrBase.PStyle pStyle = factory.createPPrBasePStyle(); pPr.setPStyle(pStyle); pStyle.setVal(styleId); } return p; }