You can find detailed information at: Detect Latin Symbols in TrueType and Type1 Fonts using Java
Last active
August 20, 2021 13:35
-
-
Save aspose-com-gists/1947a7e974012064eb40f96e6ac8c543 to your computer and use it in GitHub Desktop.
Detect Latin Symbols in TrueType and Type1 Fonts using Java | https://blog.aspose.com/2021/08/17/detect-latin-symbols-in-truetype-and-type1-fonts-using-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Font file path | |
String fileName = Utils.getDataDir() + "Montserrat-Regular.ttf"; //Font file name with full path | |
// Load the font file | |
FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName))); | |
TtfFont ttfFont = (TtfFont) Font.open(fd); | |
boolean latinText = true; | |
// Check for the support of latin symbols | |
for (int code = 65; code < 123; code++) | |
{ | |
GlyphId gid = ttfFont.getEncoding().decodeToGid(code); | |
if (gid == null || gid == GlyphUInt32Id.getNotDef()) | |
{ | |
latinText = false; | |
} | |
} | |
if (latinText) | |
{ | |
System.out.println(MessageFormat.format("Font {0} supports latin symbols.", ttfFont.getFontName())); | |
} | |
else | |
{ | |
System.out.println(MessageFormat.format("Latin symbols are not supported by font {0}.", ttfFont.getFontName())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Font file path | |
String fileName = Utils.getDataDir() + "courier.pfb"; //Font file name with full path | |
// Load the font file | |
FontDefinition fd = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName))); | |
Type1Font font = (Type1Font) Font.open(fd); | |
boolean latinText = true; | |
// Check for the support of latin symbols | |
for (int code = 65; code < 123; code++) | |
{ | |
GlyphId gid = font.getEncoding().decodeToGid(code); | |
if (gid == null || gid == GlyphUInt32Id.getNotDef()) | |
{ | |
latinText = false; | |
} | |
} | |
if (latinText) | |
{ | |
System.out.println(MessageFormat.format("Font {0} supports latin symbols.", font.getFontName())); | |
} | |
else | |
{ | |
System.out.println(MessageFormat.format("Latin symbols are not supported by font {0}.", font.getFontName())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment