Glyphes et mesures des polices TrueType | .FILET

Obtenir les métriques de police

Les métriques de police contiennent des informations telles que « Ascender », « Descender », « TypoAscender », « TypoDescender » et « UnitsPerEm ». L’API Aspose.Font for .NET peut lire les informations sur les métriques de police à partir du fichier de police TrueType à l’aide de l’exemple de code suivant.

Détecter les symboles latins

Aspose.Font for .NET vous permet de détecter les symboles latins à partir des fichiers de polices TrueType. Ceci peut être réalisé en utilisant l’exemple de code suivant .

 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}

Extraire les restrictions de licence

Utilisez l’API Aspose.Font for .NET pour extraire les restrictions de licence des fichiers de polices. Les polices peuvent contenir des informations de licence intégrées dans l’un des modes suivants .

L’exemple de code suivant montre comment utiliser un objet Aspose.Font.Ttf.LicenseFlags pour obtenir des informations sur les restrictions de licence de police (drapeau fsType de la table OS/2) sous une forme pratique.

 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.