예제 #1
0
  /**
   * Derive a new version of this font based on a new size
   *
   * @param size The size of the new font
   * @param style The style of the new font
   * @return The new font data
   */
  public FontData deriveFont(float size, int style) {
    FontData original = getStyled(getFamilyName(), style);
    FontData data = new FontData();
    data.size = size;
    data.javaFont = original.javaFont.deriveFont(style, size);
    data.upem = upem;
    data.ansiKerning = ansiKerning;
    data.charWidth = charWidth;

    return data;
  }
예제 #2
0
  /**
   * Process a directory potentially full of fonts
   *
   * @param dir The directory of fonts to process
   * @param fonts The fonts list to add to
   */
  private static void processFontDirectory(File dir, ArrayList fonts) {
    if (!dir.exists()) {
      return;
    }
    if (processed.contains(dir)) {
      return;
    }
    processed.add(dir);

    File[] sources = dir.listFiles();
    if (sources == null) {
      return;
    }

    for (int j = 0; j < sources.length; j++) {
      File source = sources[j];

      if (source.getName().equals(".")) {
        continue;
      }
      if (source.getName().equals("..")) {
        continue;
      }
      if (source.isDirectory()) {
        processFontDirectory(source, fonts);
        continue;
      }
      if (source.getName().toLowerCase().endsWith(".ttf")) {
        try {
          if (statusListener != null) {
            statusListener.updateStatus("Processing " + source.getName());
          }
          FontData data = new FontData(new FileInputStream(source), 1);
          fonts.add(data);

          String famName = data.getFamilyName();
          if (!families.contains(famName)) {
            families.add(famName);
          }

          boolean bo = data.getJavaFont().isBold();
          boolean it = data.getJavaFont().isItalic();

          if ((bo) && (it)) {
            bolditalic.put(famName, data);
          } else if (bo) {
            bold.put(famName, data);
          } else if (it) {
            italic.put(famName, data);
          } else {
            plain.put(famName, data);
          }
        } catch (Exception e) {
          if (DEBUG) {
            System.err.println(
                "Unable to process: "
                    + source.getAbsolutePath()
                    + " ("
                    + e.getClass()
                    + ": "
                    + e.getMessage()
                    + ")");
          }
          if (statusListener != null) {
            statusListener.updateStatus("Unable to process: " + source.getName());
          }
        }
      }
    }
  }