Glyphs and Metrics of TrueType Fonts | .NET

Get Font Metrics

Font metrics contain information such as Ascender, Descender, TypoAscender, TypoDescender and UnitsPerEm. Aspose.Font for .NET API can read the Font Metrics information from the TrueType Font file using the following sample code.

Detect Latin Symbols

Aspose.Font for .NET lets you detect Latin Symbols from TrueType font files. This can be achieved using the following sample code.

 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
 2string fileName = dataDir + "Montserrat-Regular.ttf"; //Font file name with full path
 3
 4FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
 5TtfFont ttfFont = Aspose.Font.Font.Open(fd) as TtfFont;
 6
 7bool latinText = true;
 8
 9
10for (uint code = 65; code < 123; code++)
11{
12    GlyphId gid = ttfFont.Encoding.DecodeToGid(code);
13    if (gid == null || gid == GlyphUInt32Id.NotDefId)
14    {
15        latinText = false;
16    }
17}
18
19if (latinText)
20{
21    Console.WriteLine(string.Format("Font {0} supports latin symbols.", ttfFont.FontName));
22}
23else
24{
25    Console.WriteLine(string.Format("Latin symbols are not supported by font {0}.", ttfFont.FontName));
26}

Extract License Restrictions

Use Aspose.Font for .NET API to extract licensing restrictions from font files. Fonts can have licensing information embedded into these in one of the following modes.

The following code sample shows how to use an object Aspose.Font.Ttf.LicenseFlags to get information about font license restrictions(flag fsType from table OS/2) in convenient form.

 1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
 2string dataDir = RunExamples.GetDataDir_Data();
 3//Font to check
 4string fileName = dataDir + "Montserrat-Regular.ttf"; //Font file name with full path
 5
 6FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
 7TtfFont font = Aspose.Font.Font.Open(fd) as TtfFont;
 8LicenseFlags licenseFlags = null;
 9if (font.TtfTables.Os2Table != null)
10{
11    licenseFlags = font.TtfTables.Os2Table.GetLicenseFlags();
12}
13
14if (licenseFlags == null || licenseFlags.FSTypeAbsent)
15{
16    Console.WriteLine(string.Format("Font {0} has no embedded license restrictions", font.FontName));
17}
18else
19{
20    if (licenseFlags.IsEditableEmbedding)
21    {
22        Console.WriteLine(
23            string.Format("Font {0} may be embedded, and may be temporarily loaded on other systems.", font.FontName)
24            + " In addition, editing is permitted, including ability to format new text"
25            + " using the embedded font, and changes may be saved.");
26    }
27    else if (licenseFlags.IsInstallableEmbedding)
28    {
29        Console.WriteLine(
30            string.Format("Font {0} may be embedded, and may be permanently installed", font.FontName)
31            + " for use on a remote systems, or for use by other users.");
32    }
33    else if (licenseFlags.IsPreviewAndPrintEmbedding)
34    {
35        Console.WriteLine(
36            string.Format("Font {0} may be embedded, and may be temporarily loaded", font.FontName)
37            + "  on other systems for purposes of viewing or printing the document.");
38    }
39    else if (licenseFlags.IsRestrictedLicenseEmbedding)
40    {
41        Console.WriteLine(
42            string.Format("Font {0} must not be modified, embedded or exchanged in any manner", font.FontName)
43            + " without first obtaining explicit permission of the legal owner.");
44    }
45}

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.