|
// Learn more: https://docs.aspose.com/font/java/glyphs-and-metrics-truetype-opentype-fonts/
|
|
String fileName = Paths.get(getDataDir(), "..", "TTF", "montserrat-bold.ttf").normalize().toString();
|
|
FontDefinition fd = new FontDefinition(FontType.TTF,
|
|
new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
|
|
TtfFont font = (TtfFont) Font.open(fd);
|
|
|
|
System.out.println("Font name: " + font.getFontName());
|
|
System.out.println("Glyph count: " + font.getNumGlyphs());
|
|
System.out.println(MessageFormat.format(
|
|
"Font metrics: ascender = {0}, descender = {1}, typo ascender = {2}, typo descender = {3}, UnitsPerEm = {4}",
|
|
font.getMetrics().getAscender(), font.getMetrics().getDescender(),
|
|
font.getMetrics().getTypoAscender(), font.getMetrics().getTypoDescender(),
|
|
font.getMetrics().getUnitsPerEM()));
|
|
|
|
// Locate the Unicode cmap and TrueType outlines for the glyph for A.
|
|
TtfCMapFormatBaseTable cmapTable = null;
|
|
if (font.getTtfTables().getCMapTable() != null) {
|
|
cmapTable = font.getTtfTables().getCMapTable().findUnicodeTable();
|
|
}
|
|
if (cmapTable != null && font.getTtfTables().getGlyfTable() != null) {
|
|
System.out.println("Font cmap Unicode table: PlatformID = " + cmapTable.getPlatformId()
|
|
+ ", PlatformSpecificID = " + cmapTable.getPlatformSpecificId());
|
|
long glyphIndex = cmapTable.getGlyphIndex('A');
|
|
if (glyphIndex != 0) {
|
|
Glyph glyph = font.getGlyphById(glyphIndex);
|
|
if (glyph != null) {
|
|
System.out.println(MessageFormat.format(
|
|
"Glyph BBox: Xmin = {0}, Xmax = {1}, Ymin = {2}, Ymax = {3}",
|
|
glyph.getGlyphBBox().getXMin(), glyph.getGlyphBBox().getXMax(),
|
|
glyph.getGlyphBBox().getYMin(), glyph.getGlyphBBox().getYMax()));
|
|
System.out.println("Width: " + font.getMetrics().getGlyphWidth(new GlyphUInt32Id(glyphIndex)));
|
|
}
|
|
}
|
|
} |