Esempio n. 1
0
  static {
    try {

      osName = System.getProperty("os.name");

      fontCache = FontCache.load();
      if (fontCache == null) {
        fontCache = new FontCache();
      }

      physicalFontMap = new HashMap<String, PhysicalFont>();
      physicalFontMapByFilenameLowercase = new HashMap<String, PhysicalFont>();

      //			physicalFontFamiliesMap = new HashMap<String, PhysicalFontFamily>();

      fontResolver = FontSetup.createMinimalFontResolver();

      // parse font to ascertain font info
      fontInfoFinder = new FontInfoFinder();

      // setupPhysicalFonts();

    } catch (Exception exc) {
      throw new RuntimeException(exc);
    }
  }
Esempio n. 2
0
  /** Autodetect fonts available on the system. */
  public static final void discoverPhysicalFonts() throws Exception {

    // Currently we use FOP - inspired by org.apache.fop.render.PrintRendererConfigurator
    // iText also has a font discoverer (which we could use
    // instead, but don't, since in docx4j we're settled on
    // PDF output via XSL FO)

    FontFileFinder fontFileFinder = new FontFileFinder();

    // Automagically finds a list of font files on local system
    // based on os.name
    List fontFileList = fontFileFinder.find();

    if (regex == null) {
      for (Iterator iter = fontFileList.iterator(); iter.hasNext(); ) {

        URL fontUrl = getURL(iter.next());

        // parse font to ascertain font info
        addPhysicalFont(fontUrl);
      }
    } else {
      Pattern pattern = Pattern.compile(regex);
      for (Iterator iter = fontFileList.iterator(); iter.hasNext(); ) {

        URL fontUrl = getURL(iter.next());

        // parse font to ascertain font info
        if (pattern.matcher(fontUrl.toString()).matches()) {
          addPhysicalFont(fontUrl);
        } else {
          //                	log.debug("Ignoring " + fontUrl.toString() );

        }
      }
    }

    // Add fonts from our Temporary Embedded Fonts dir
    fontFileList = fontFileFinder.find(ObfuscatedFontPart.getTemporaryEmbeddedFontsDir());
    for (Iterator iter = fontFileList.iterator(); iter.hasNext(); ) {
      URL fontUrl = getURL(iter.next());
      addPhysicalFont(fontUrl);
    }

    fontCache.save();
  }