Пример #1
0
  public RPr getEffectiveRPr(String styleId) {
    // styleId passed in could be a run style
    // or a *paragraph* style

    RPr resolvedRPr = resolvedStyleRPrComponent.get(styleId);

    if (resolvedRPr != null) {
      return resolvedRPr;
    }

    // Hmm, have to do the work
    Style s = liveStyles.get(styleId);

    if (s == null) {
      log.error("Couldn't find style: " + styleId);
      return null;
    }

    // Comment out - this style might not have rPr,
    // but an ancestor might!

    //		RPr expressRPr = s.getRPr();
    //		if (expressRPr==null) {
    //			log.error("style: " + runStyleId + " has no RPr");
    //			resolvedRPr = resolvedStyleRPrComponent.get(defaultCharacterStyleId);
    //			return resolvedRPr;
    //		}

    //	Next, run properties are applied to each run with a specific character style
    //	applied.
    Stack<RPr> rPrStack = new Stack<RPr>();
    // Haven't done this one yet
    fillRPrStack(styleId, rPrStack);
    // Finally, on top
    rPrStack.push(documentDefaultRPr);

    resolvedRPr = factory.createRPr();
    // Now, apply the properties starting at the top of the stack
    while (!rPrStack.empty()) {
      RPr rPr = rPrStack.pop();
      applyRPr(rPr, resolvedRPr);
    }
    resolvedStyleRPrComponent.put(styleId, resolvedRPr);
    return resolvedRPr;
  }
Пример #2
0
  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);
  }
Пример #3
0
  /**
   * @param expressRPr
   * @param pPr -
   * @return
   */
  public RPr getEffectiveRPr(RPr expressRPr, PPr pPr) {

    // NB Currently used in PDF viaXSLFO only

    log.debug("in getEffectiveRPr");

    //		Idea is that you pass pPr if you are using this for XSL FO,
    //		since we need to take account of rPr in paragraph styles
    //		(but not the rPr in a pPr direct formatting, since
    //       that only applies to the paragraph mark).
    //		 * For HTML/CSS, this would be null (since the pPr level rPr
    //		 * is made into a separate style applied via a second value in
    //		 * the class attribute).  But, in the CSS case, this
    // function is not used - since the rPr is made into a style as well.

    //	First, the document defaults are applied

    RPr effectiveRPr = (RPr) XmlUtils.deepCopy(documentDefaultRPr);

    // Apply DefaultParagraphFont.  We only do it explicitly
    // here as per conditions, because if there is a run style,
    // walking the hierarchy will include this if it is needed
    if (expressRPr == null || expressRPr.getRStyle() == null) {
      applyRPr(resolvedStyleRPrComponent.get(defaultCharacterStyleId), effectiveRPr);
    }

    //	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
    // (this includes run properties defined in a paragraph style,
    //  but not run properties directly included in a pPr in the
    //  document (those only apply to a paragraph mark).

    if (pPr == null) {
      log.debug("pPr was null");
    } else {
      // At the pPr level, what rPr do we have?
      // .. ascend the paragraph style tree
      if (pPr.getPStyle() == null) {
        //					log.warn("No pstyle:");
        //					log.debug(XmlUtils.marshaltoString(pPr, true, true));
      } else {
        log.debug("pstyle:" + pPr.getPStyle().getVal());
        RPr pPrLevelRunStyle = getEffectiveRPr(pPr.getPStyle().getVal());
        // .. and apply those
        applyRPr(pPrLevelRunStyle, effectiveRPr);
      }
      // Check Paragraph rPr (our special hack of using ParaRPr
      // to format a fo:block)
      if ((expressRPr == null)
          && (pPr.getRPr() != null)
          && (hasDirectRPrFormatting(pPr.getRPr()))) {
        applyRPr(pPr.getRPr(), effectiveRPr);
      }
    }
    //	Next, run properties are applied to each run with a specific character style
    //	applied.
    RPr resolvedRPr = null;
    String runStyleId;
    if (expressRPr != null && expressRPr.getRStyle() != null) {
      runStyleId = expressRPr.getRStyle().getVal();
      resolvedRPr = getEffectiveRPr(runStyleId);
      applyRPr(resolvedRPr, effectiveRPr);
    }

    //	Finally, we apply direct formatting (run properties not from
    //	styles).
    if (hasDirectRPrFormatting(expressRPr)) {
      // effectiveRPr = (RPr)XmlUtils.deepCopy(effectiveRPr);
      applyRPr(expressRPr, effectiveRPr);
    }
    return effectiveRPr;
  }