Esempio n. 1
0
  @Override
  protected Node toNode(AbstractWmlConversionContext context, R.Sym sym, Document doc)
      throws TransformerException {
    String value = sym.getChar();

    // Pre-process according to ECMA-376 2.3.3.29
    if (value.startsWith("F0") || value.startsWith("f0")) {
      value = value.substring(2);
    }

    Text theChar = doc.createTextNode(new String(hexStringToByteArray(value)));

    DocumentFragment docfrag = doc.createDocumentFragment();

    String fontName = sym.getFont();
    PhysicalFont pf = context.getWmlPackage().getFontMapper().getFontMappings().get(fontName);

    if (pf == null) {
      log.warn("No physical font present for:" + fontName);
      docfrag.appendChild(theChar);

    } else {

      Element span = doc.createElement("span");
      docfrag.appendChild(span);

      span.setAttribute("style", "font-family:" + pf.getName());
      span.appendChild(theChar);
    }

    return docfrag;
  }
Esempio n. 2
0
    @Override
    public List<Object> apply(Object o) {

      if (o instanceof org.docx4j.wml.P) {
        pPr = ((P) o).getPPr();
        if (stylesInUse != null) { // do the styles
          boolean customPStyle = false;
          if (pPr != null) {
            if (pPr.getPStyle() != null) {
              // Note this paragraph style
              // log.debug("put style " + pPr.getPStyle().getVal());
              customPStyle = true;
              stylesInUse.add(pPr.getPStyle().getVal());
            }
            if ((pPr.getRPr() != null) && (pPr.getRPr().getRStyle() != null)) {
              // 	Note this run style
              // log.debug("put style " + pPr.getRPr().getRStyle().getVal() );
              stylesInUse.add(pPr.getRPr().getRStyle().getVal());
            }
          }
          defaultParagraphStyleUsed = defaultParagraphStyleUsed || (!customPStyle);
        }

      } else if (o instanceof org.docx4j.wml.R) {
        rPr = ((R) o).getRPr();
        if (stylesInUse != null) {
          if (rPr != null) {
            if (rPr.getRStyle() == null) {
              defaultCharacterStyleUsed = true;
            } else {
              stylesInUse.add(rPr.getRStyle().getVal());
            }
          }
        }

      } else if (o instanceof org.docx4j.wml.Text) {

        if (runFontSelector != null) {
          // discover the fonts which apply to this text
          log.debug(((Text) o).getValue());
          runFontSelector.fontSelector(pPr, rPr, ((Text) o));
        }

      } else if (o instanceof org.docx4j.wml.R.Sym) {

        if (fontsDiscovered != null) {
          org.docx4j.wml.R.Sym sym = (org.docx4j.wml.R.Sym) o;
          fontsDiscovered.add(sym.getFont());
        }

      } else if (o instanceof org.docx4j.wml.Tbl) {
        // The table could have a table style;
        // Tables created in Word 2007 default to table style "TableGrid",
        // which is based on "TableNormal".
        org.docx4j.wml.Tbl tbl = (org.docx4j.wml.Tbl) o;
        if (stylesInUse != null && tbl.getTblPr() != null && tbl.getTblPr().getTblStyle() != null) {
          //					log.debug("Adding table style: " + tbl.getTblPr().getTblStyle().getVal() );
          stylesInUse.add(tbl.getTblPr().getTblStyle().getVal());
        }
        // There is no such thing as a tr or a tc style,
        // so we don't need to look for them,
        // but since a tc can contain w:p or nested table,
        // we still need to recurse

      }
      return null;
    }