Гліфи та метрики шрифтів Type1 | Java

Отримати показники шрифту

Показники шрифту містять таку інформацію, як Ascender, Descender, TypoAscender, TypoDescender і UnitsPerEm. API Aspose.Font для Java може зчитувати інформацію про показники шрифту з файлу шрифтів Type1 за допомогою наступного прикладу коду.

 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);

Виявлення латинських символів

Aspose.Font для Java дозволяє виявляти латинські символи у файлах шрифтів Type1. Цього можна досягти за допомогою наступного прикладу коду.

 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.