private void setFontFamily(RPr runProperties, String fontFamily) {
   if (fontFamily != null) {
     RFonts rf = runProperties.getRFonts();
     if (rf == null) {
       rf = new RFonts();
       runProperties.setRFonts(rf);
     }
     rf.setAscii(fontFamily);
   }
 }
예제 #2
0
  /**
   * Returns default document font, by attempting to look at
   * styles/docDefaults/rPrDefault/rPr/rFonts.
   *
   * @return default document font.
   */
  public String getDefaultFont() {

    // First look at the defaults
    // 3 look at styles/rPrDefault
    //   eg <w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorEastAsia"
    //				  w:hAnsiTheme="minorHAnsi" w:cstheme="minorBidi"/>
    // 3.1 if there is an rFonts element, do what it says (it may refer you to the theme part,
    //     in which case if there is no theme part, default to "internally stored settings"
    //	   (there is no normal.dot; see http://support.microsoft.com/kb/924460/en-us )
    //	   in this case Calibri and Cambria)
    // 3.2 if there is no rFonts element, default to Times New Roman.

    org.docx4j.wml.RFonts rFonts = documentDefaultRPr.getRFonts();
    if (rFonts == null) {
      log.info("No styles/docDefaults/rPrDefault/rPr/rFonts - default to Times New Roman");
      // Yes, Times New Roman is still buried in Word 2007
      return "Times New Roman";
    } else {
      // Usual case
      if (rFonts.getAsciiTheme() != null) {
        // for example minorHAnsi, which I think translates to minorFont/latin
        if (rFonts.getAsciiTheme().equals(org.docx4j.wml.STTheme.MINOR_H_ANSI)) {
          if (themePart != null) {
            org.docx4j.dml.BaseStyles.FontScheme fontScheme = themePart.getFontScheme();
            if (fontScheme.getMinorFont() != null && fontScheme.getMinorFont().getLatin() != null) {

              org.docx4j.dml.TextFont textFont = fontScheme.getMinorFont().getLatin();
              log.debug("minorFont/latin font is " + textFont.getTypeface());
              return textFont.getTypeface();
            } else {
              // No minorFont/latin in theme part - default to Calibri
              log.info("No minorFont/latin in theme part - default to Calibri");
              return "Calibri";
            }
          } else {
            // No theme part - default to Calibri
            log.info("No theme part - default to Calibri");
            return "Calibri";
          }
        } else {
          // TODO
          log.error("Don't know how to handle: " + rFonts.getAsciiTheme());
          return null;
        }
      } else if (rFonts.getAscii() != null) {
        log.info("rPrDefault/rFonts referenced " + rFonts.getAscii());
        return rFonts.getAscii();
      } else {
        // TODO
        log.error("Neither ascii or asciTheme.  What to do? ");
        return null;
      }
    }
  }
예제 #3
0
  public String getDefaultFontEastAsia() {

    org.docx4j.wml.RFonts rFonts = documentDefaultRPr.getRFonts();
    if (rFonts == null) {
      log.info("No styles/docDefaults/rPrDefault/rPr/rFonts - default to SimSun");
      return "SimSun";
    } else {
      // Usual case

      if (rFonts.getEastAsiaTheme() != null) {
        // for example minorEastAsia
        if (rFonts.getEastAsiaTheme().equals(org.docx4j.wml.STTheme.MINOR_EAST_ASIA)) {
          if (themePart != null) {
            org.docx4j.dml.BaseStyles.FontScheme fontScheme = themePart.getFontScheme();
            if (fontScheme.getMinorFont() != null
                && fontScheme.getMinorFont().getEa() != null
                && !fontScheme.getMinorFont().getEa().getTypeface().equals("")) {

              log.debug("minorFont/EA font is " + fontScheme.getMinorFont().getEa().getTypeface());
              return fontScheme.getMinorFont().getEa().getTypeface();
            } else {
              // No minorFont/EA in theme part - default to SimSun
              log.info("No minorFont/latin in theme part - default to SimSun");
              return "SimSun";
            }
          } else {
            // No theme part - default to SimSun
            log.info("No theme part - default to SimSun");
            return "SimSun";
          }
        } else {
          // TODO
          log.error("Don't know how to handle: " + rFonts.getEastAsiaTheme());
          return null;
        }
      } else if (rFonts.getEastAsia() != null) {
        log.info("rPrDefault/rFonts referenced " + rFonts.getEastAsia());
        return rFonts.getEastAsia();
      } else {
        // TODO
        log.error("Neither EastAsia or EastAsiaTheme.  What to do? ");
        return null;
      }
    }
  }
예제 #4
0
 private RFonts geRFontsForCSSListStyleType(String listStyleType) {
   RFonts rfonts = null;
   if (listStyleType.equals("disc")) {
     rfonts = wmlObjectFactory.createRFonts();
     rfonts.setAscii("Symbol");
     rfonts.setHint(org.docx4j.wml.STHint.DEFAULT);
     rfonts.setHAnsi("Symbol");
   }
   if (listStyleType.equals("circle")) {
     rfonts = wmlObjectFactory.createRFonts();
     rfonts.setAscii("Courier New");
     rfonts.setHint(org.docx4j.wml.STHint.DEFAULT);
     rfonts.setHAnsi("Courier New");
     rfonts.setCs("Courier New");
   }
   if (listStyleType.equals("square")) {
     rfonts = wmlObjectFactory.createRFonts();
     rfonts.setAscii("Wingdings");
     rfonts.setHint(org.docx4j.wml.STHint.DEFAULT);
     rfonts.setHAnsi("Wingdings");
   }
   return rfonts;
 }