Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 27, 2022 09:34
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/142085143efe3b00c101e631d1ddd9d8 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/142085143efe3b00c101e631d1ddd9d8 to your computer and use it in GitHub Desktop.
Detect Latin Symbols Support in Fonts using C#
// This code example demonstrates how to detect if a particular TrueType font supports Latin symbols or not.
// TTF file path
string fontPath = @"D:\Files\font\Montserrat-Regular.ttf";
// Load the font file
FontFileDefinition fontFileDefinition = new FontFileDefinition("ttf", new FileSystemStreamSource(fontPath));
// Font definition object
FontDefinition fd = new FontDefinition(FontType.TTF, fontFileDefinition);
// Open the font
TtfFont font = (TtfFont)Font.Open(fd);
var latinText = true;
// Check for the support of latin symbols
for (uint code = 65; code < 123; code++)
{
GlyphId gid = font.Encoding.DecodeToGid(code);
if (gid == null || gid == GlyphUInt32Id.NotDefId)
{
latinText = false;
}
}
if (latinText)
{
Console.WriteLine("Font {0} supports latin symbols.", font.FontName);
}
else
{
Console.WriteLine("Latin symbols are not supported by font {0}.", font.FontName);
}
// This code example demonstrates how to detect if a particular Type1 font supports Latin symbols or not.
// Type1 font file path
string fontPath = @"D:\Files\font\courier.pfb";
// Load the font file
FontFileDefinition fontFileDefinition = new FontFileDefinition("pfb", new FileSystemStreamSource(fontPath));
// Font definition object
FontDefinition fd = new FontDefinition(FontType.Type1, fontFileDefinition);
// Open the font
Type1Font font = (Type1Font)Font.Open(fd);
var latinText = true;
// Check for the support of latin symbols
for (uint code = 65; code < 123; code++)
{
GlyphId gid = font.Encoding.DecodeToGid(code);
if (gid == null || gid == GlyphUInt32Id.NotDefId)
{
latinText = false;
}
}
if (latinText)
{
Console.WriteLine("Font {0} supports latin symbols.", font.FontName);
}
else
{
Console.WriteLine("Latin symbols are not supported by font {0}.", font.FontName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment