Гліфи та метрики шрифтів TrueType | .NET

Отримати показники шрифту

Показники шрифту містять таку інформацію, як Ascender, Descender, TypoAscender, TypoDescender і UnitsPerEm. API Aspose.Font для .NET може зчитувати інформацію про показники шрифту з файлу шрифту TrueType за допомогою наступного прикладу коду.

Виявлення латинських символів

Aspose.Font для .NET дозволяє виявляти латинські символи у файлах шрифтів TrueType. Цього можна досягти за допомогою наступного прикладу коду.

 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}

Витяг ліцензійних обмежень

Використовуйте Aspose.Font для .NET API, щоб отримати обмеження ліцензування з файлів шрифтів. Шрифти можуть мати вбудовану інформацію про ліцензування в одному з наведених нижче режимів.

У наведеному нижче прикладі коду показано, як використовувати об’єкт Aspose.Font.Ttf.LicenseFlags для отримання інформації про ліцензійні обмеження шрифтів (прапор fsType з таблиці OS/2) у зручній формі.

 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}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.