Glyphen und Metriken von Type1-Schriftarten | Java

Rufen Sie Schriftmetriken ab

Schriftartmetriken enthalten Informationen wie „Ascender“, „Descender“, „TypoAscender“, „TypoDescender“ und „UnitsPerEm“. Die Aspose.Font for Java-API kann mithilfe des folgenden Beispielcodes die Font-Metrikinformationen aus der Type1-Fontdatei lesen.

 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
 2String fileName = Utils.getDataDir() + "courier.pfb"; //Font file name with full path
 3
 4FontDefinition fd = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName)));
 5      Type1Font font = (Type1Font) Font.open(fd);
 6
 7      String name = font.getFontName();
 8      System.out.println("Font name: " + name);
 9      System.out.println("Glyph count: " + font.getNumGlyphs());
10      String metrics = MessageFormat.format(
11          "Font metrics: ascender - {0}, descender - {1}, typo ascender = {2}, typo descender = {3}, UnitsPerEm = {4}",
12          font.getMetrics().getAscender(), font.getMetrics().getDescender(),
13          font.getMetrics().getTypoAscender(), font.getMetrics().getTypoDescender(), font.getMetrics().getUnitsPerEM());
14
15      System.out.println(metrics);

Erkennen Sie lateinische Symbole

Mit Aspose.Font für Java können Sie lateinische Symbole aus Type1-Schriftdateien erkennen. Dies kann mit dem folgenden Beispielcode erreicht werden.

 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-Java
 2String fileName = Utils.getDataDir() + "courier.pfb"; //Font file name with full path
 3
 4FontDefinition fd = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName)));
 5      Type1Font font = (Type1Font) Font.open(fd);
 6
 7      boolean latinText = true;
 8
 9
10      for (int code = 65; code < 123; code++)
11      {
12          GlyphId gid = font.getEncoding().decodeToGid(code);
13          if (gid == null || gid == GlyphUInt32Id.getNotDef())
14          {
15              latinText = false;
16          }
17      }
18
19      if (latinText)
20      {
21          System.out.println(MessageFormat.format("Font {0} supports latin symbols.", font.getFontName()));
22      }
23      else
24      {
25          System.out.println(MessageFormat.format("Latin symbols are not supported by font {0}.", font.getFontName()));
26      }
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.