コード例 #1
0
ファイル: AbstractHtmlExporter.java プロジェクト: pnml/docx4j
  public static String getCssForStyles(HTMLConversionContext context) {
    StringBuffer result = new StringBuffer();

    StyleTree styleTree = null;
    try {
      styleTree = context.getWmlPackage().getMainDocumentPart().getStyleTree();
    } catch (Exception e) {
      log.error("Couldn't getStyleTree", e);
      return result.toString();
    }

    HtmlCssHelper.createCssForStyles(context.getWmlPackage(), styleTree, result);

    if (log.isDebugEnabled()) {
      return result.toString();
    } else {
      String debug = result.toString();
      return debug;
    }
  }
コード例 #2
0
ファイル: AbstractHtmlExporter.java プロジェクト: pnml/docx4j
  public static String getCssForTableCells(HTMLConversionContext context, Tbl tbl, int idx) {

    StringBuffer result = new StringBuffer();
    PropertyResolver pr = context.getPropertyResolver();
    Style s = pr.getEffectiveTableStyle(tbl.getTblPr());

    result.append("#" + TableWriter.getId(idx) + " td { ");
    List<Property> properties = new ArrayList<Property>();
    if (s.getTblPr() != null && s.getTblPr().getTblBorders() != null) {
      TblBorders tblBorders = s.getTblPr().getTblBorders();
      if (tblBorders.getInsideH() != null) {
        if (tblBorders.getInsideH().getVal() == STBorder.NONE
            || tblBorders.getInsideH().getVal() == STBorder.NIL
            || tblBorders.getInsideH().getSz() == BigInteger.ZERO) {
          properties.add(new AdHocProperty("border-top-style", "none", null, null));
          properties.add(new AdHocProperty("border-top-width", "0mm", null, null));
          properties.add(new AdHocProperty("border-bottom-style", "none", null, null));
          properties.add(new AdHocProperty("border-bottom-width", "0mm", null, null));
        } else {
          properties.add(new BorderTop(tblBorders.getTop()));
          properties.add(new BorderBottom(tblBorders.getBottom()));
        }
      }
      if (tblBorders.getInsideV() != null) {
        if (tblBorders.getInsideV().getVal() == STBorder.NONE
            || tblBorders.getInsideV().getVal() == STBorder.NIL
            || tblBorders.getInsideV().getSz() == BigInteger.ZERO) {
          properties.add(new AdHocProperty("border-left-style", "none", null, null));
          properties.add(new AdHocProperty("border-left-width", "0mm", null, null));
          properties.add(new AdHocProperty("border-right-style", "none", null, null));
          properties.add(new AdHocProperty("border-right-width", "0mm", null, null));
        } else {
          properties.add(new BorderRight(tblBorders.getRight()));
          properties.add(new BorderLeft(tblBorders.getLeft()));
        }
      }
    }
    if (s.getTcPr() != null) {
      PropertyFactory.createProperties(properties, s.getTcPr());
    }
    // Ensure empty cells have a sensible height
    // TODO - this is no good with IE8, which doesn't treat this
    // as a minimum; it won't resize if there is more :-(
    properties.add(new AdHocProperty("height", "5mm", null, null));

    for (Property p : properties) {
      if (p != null) {
        result.append(p.getCssProperty());
      }
    }
    result.append("}\n");
    return result.toString();
  }
コード例 #3
0
ファイル: AbstractHtmlExporter.java プロジェクト: pnml/docx4j
  /**
   * The method used by the XSLT extension function during HTML export.
   *
   * <p>If there is no number, it returns an empty span element.
   *
   * @param em
   * @param levelId
   * @param numId
   * @return
   */
  public static String getNumberXmlNode(
      HTMLConversionContext context,
      NodeIterator pPrNodeIt,
      String pStyleVal,
      String numId,
      String levelId) {

    // Note that this is invoked for every paragraph with a pPr node.

    log.debug("numbering, using style '" + pStyleVal + "'; numId=" + numId + "; ilvl " + levelId);

    try {

      ResultTriple triple =
          org.docx4j.model.listnumbering.Emulator.getNumber(
              context.getWmlPackage(), pStyleVal, numId, levelId);

      if (triple == null) {
        log.debug("computed number ResultTriple was null");
        return null;
      }

      String styleVal = "";

      if (triple.getBullet() != null) {
        // return (triple.getBullet() + " " );
        // The old code did that:-
        // https://github.com/plutext/docx4j/commit/7627863e47c5dc7b3c91290b8d993ae5a7cd9fab#docx4j/src/main/java/org/docx4j/convert/out/html/AbstractHtmlExporter.java
        // What is wrong with that approach?
        //
        return "\u2022  ";
        // see notes in docx2xhtmlNG2.xslt as to why we don't use &bull;

      } else if (triple.getNumString() == null) {
        log.error("computed NumString was null!");
        return "?  ";

      } else {
        return triple.getNumString() + " ";
      }

    } catch (Exception e) {
      e.printStackTrace();
      // System.out.println(e.toString() );
      log.error(e);
    }

    return "?  ";
  }