Esempio n. 1
0
  public Font getFont(String text, Locale locale) {
    int maxChars = -1;
    Font bestMatch = fontBundle.getFontFor(locale);
    if (bestMatch != null && (maxChars = bestMatch.canDisplayUpTo(text)) == -1) {
      return bestMatch;
    }

    for (Font font : fontBundle.getAllFonts()) {
      int upTo = font.canDisplayUpTo(text);
      if (upTo == -1) {
        return font;
      }
      if (upTo > maxChars) {
        bestMatch = font;
      }
    }
    return bestMatch;
  }
Esempio n. 2
0
 /**
  * Sets the font to use. The resource must either point to a Type 1 or a TrueType font or a
  * directory containing fonts. In case a directory is specified, the font that contains the most
  * glyphs needed to render a given text is used. The font type is determined by the filename
  * extension. Supported extensions are <i>.pfa</i>, <i>.pfb</i> and <i>.ttf</i>.
  */
 public void setFont(Resource res) throws FontFormatException, IOException {
   try {
     File f = res.getFile();
     if (f.isDirectory()) {
       addAllFonts(f);
     } else {
       addFont(f);
     }
   } catch (IOException e) {
     addFont(res);
   }
   Assert.notEmpty(fontBundle.getAllFonts(), "Found no fonts at " + res.getFilename());
 }
Esempio n. 3
0
 private void addFont(String name, InputStream input) throws FontFormatException, IOException {
   int format = getFontFormat(name);
   if (format != -1) {
     fontBundle.addFont(name, Font.createFont(format, input));
   }
 }