/** * Follow the resolution rules to return the paragraph properties which actually apply, given this * pPr element (on a w:p). * * <p>Note 1: the properties are not the definition of any style name returned. Note 2: run * properties are not resolved or returned by this method. * * <p>What is returned is a live object. If you want to change it, you should clone it first! * * @param expressPPr * @return */ public PPr getEffectivePPr(PPr expressPPr) { PPr effectivePPr = null; // First, the document defaults are applied // Done elsewhere // PPr effectivePPr = (PPr)XmlUtils.deepCopy(documentDefaultPPr); // Next, the table style properties are applied to each table in the document, // following the conditional formatting inclusions and exclusions specified // per table. // TODO - if the paragraph is in a table? // Next, numbered item and paragraph properties are applied to each paragraph // formatted with a *numbering *style**. // TODO - who uses numbering styles (as opposed to numbering // via a paragraph style or direct formatting)? // Next, paragraph and run properties are // applied to each paragraph as defined by the paragraph style. PPr resolvedPPr = null; String styleId; if (expressPPr == null || expressPPr.getPStyle() == null) { // styleId = "Normal"; styleId = defaultParagraphStyleId; } else { styleId = expressPPr.getPStyle().getVal(); } resolvedPPr = getEffectivePPr(styleId); // Next, run properties are applied to each run with a specific character style // applied. // Not for pPr // Finally, we apply direct formatting (paragraph or run properties not from // styles). if (hasDirectPPrFormatting(expressPPr)) { if (resolvedPPr == null) { log.warn("resolvedPPr was null. Look into this?"); effectivePPr = Context.getWmlObjectFactory().createPPr(); } else { effectivePPr = (PPr) XmlUtils.deepCopy(resolvedPPr); } applyPPr(expressPPr, effectivePPr); return effectivePPr; } else { return resolvedPPr; } }
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); }
/** * Follow the resolution rules to return the paragraph properties which actually apply, given this * paragraph style * * <p>Note 1: the properties are not the definition of any style name returned. Note 2: run * properties are not resolved or returned by this method. * * <p>What is returned is a live object. If you want to change it, you should clone it first! * * @param expressPPr * @return */ public PPr getEffectivePPr(String styleId) { PPr resolvedPPr = resolvedStylePPrComponent.get(styleId); if (resolvedPPr != null) { return resolvedPPr; } // Hmm, have to do the work Style s = liveStyles.get(styleId); if (s == null) { log.error("Couldn't find style: " + styleId); return null; } PPr expressPPr = s.getPPr(); if (expressPPr == null) { // A paragraph style may have no w:pPr component log.debug("style: " + styleId + " has no PPr"); String normalId = this.styleDefinitionsPart.getDefaultParagraphStyle().getStyleId(); resolvedPPr = resolvedStylePPrComponent.get(normalId); return resolvedPPr; } // Next, paragraph and run properties are // applied to each paragraph as defined by the paragraph style. Stack<PPr> pPrStack = new Stack<PPr>(); // Haven't done this one yet fillPPrStack(styleId, pPrStack); // Finally, on top pPrStack.push(documentDefaultPPr); resolvedPPr = factory.createPPr(); // Now, apply the properties starting at the top of the stack while (!pPrStack.empty()) { PPr pPr = pPrStack.pop(); applyPPr(pPr, resolvedPPr); } resolvedStylePPrComponent.put(styleId, resolvedPPr); return resolvedPPr; }