タイプ1フォントのグリフとメトリック| Java
Contents
[
Hide
Show
]フォントメトリックを取得します
フォントメトリックには、ascender
、ascender
、typoascender
、typodescender
、unitsperem
などの情報が含まれています。 Java APIのAspose.Fontは、次のサンプルコードを使用して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);
ラテンシンボルを検出します
JavaのAspose.Fontでは、Type1フォントファイルからラテンシンボルを検出できます。これは、次のサンプルコードを使用して実現できます。
- FontFileDefinitionを使用してフォントファイルをロードします
- decodetogid()メソッドを使用してグリフィドをデコードします
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 }