Glyphs and Metrics of Type1 Fonts | Java
Contents
[
Hide
Show
]Get Font Metrics
Font metrics contain information such as Ascender
, Descender
, TypoAscender
, TypoDescender
and UnitsPerEm
. Aspose.Font for Java API can read the Font Metrics information from the Type1 Font File using the following sample code.
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);
Detect Latin Symbols
Aspose.Font for Java lets you detect Latin Symbols from Type1 font files. This can be achieved using the following sample code.
- Load the Font file using FontFileDefinition
- Decode the GlyphId using the DecodeToGid() method
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 }