Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/1947a7e974012064eb40f96e6ac8c543 to your computer and use it in GitHub Desktop.
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/
// 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()));
}
// 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