Глифы и метрика шрифтов Type1 | .NET
Получить метрики шрифта
Метрики шрифта содержат такую информацию, как Ascender, Descender, TypoAscender, TypoDescender и UnitsPerEm. Aspose.Font для .NET API может считывать информацию о метриках шрифта из файла шрифта Type1, используя следующий пример кода.
- Создайте
FontDefinition– укажите полный путь к файлу шрифта Type1 (например,string fontPath = Path.Combine(dataDir, "courier.pfb");) и создайтеFontFileDefinitionдля формата.pfb, затем создайтеFontDefinitionсFontType.Type1и определением файла. - Откройте шрифт и получите доступ к метрикам – откройте шрифт с помощью
Aspose.Font.Font.Open(fd), который возвращает объектFont. Приведите его кType1Fontдля доступа к свойствам, специфичным для Type1, затем прочитайте свойства метрик, такие какAscender,Descender,TypoAscender,TypoDescenderиUnitsPerEm. - Используйте метрики – Эти значения можно использовать для расчёта макета, масштабирования или любой типографской обработки, необходимой вашему приложению.
1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
2string fileName = dataDir + "courier.pfb"; //Font file name with full path
3
4FontDefinition fd = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName)));
5Type1Font font = Aspose.Font.Font.Open(fd) as Type1Font;
6
7string name = font.FontName;
8Console.WriteLine("Font name: " + name);
9Console.WriteLine("Glyph count: " + font.NumGlyphs);
10string metrics = string.Format(
11 "Font metrics: ascender - {0}, descender - {1}, typo ascender = {2}, typo descender = {3}, UnitsPerEm = {4}",
12 font.Metrics.Ascender, font.Metrics.Descender,
13 font.Metrics.TypoAscender, font.Metrics.TypoDescender, font.Metrics.UnitsPerEM);
14
15Console.WriteLine(metrics);Обнаружение латинских символов
Aspose.Font для .NET позволяет обнаруживать латинские символы в файлах шрифтов Type1. Этого можно добиться, используя следующий пример кода.
Загрузите шрифт Type1 – Создайте
FontFileDefinitionдля файла.pfb(например,string fontPath = Path.Combine(dataDir, "courier.pfb");), затем создайтеFontDefinitionсFontType.Type1и определением файла.Определите поддерживаемые латинские символы – Пройдитесь по коллекции глифов шрифта и используйте
DecodeToGid()для преобразования каждого символа Unicode во внутренний идентификатор глифа. Если метод возвращает ненулевой идентификатор, глиф присутствует в шрифте, что указывает на поддержку этого латинского символа.
1// For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-.NET
2string fileName = dataDir + "courier.pfb"; //Font file name with full path
3
4FontDefinition fd = new FontDefinition(FontType.Type1, new FontFileDefinition("pfb", new FileSystemStreamSource(fileName)));
5Type1Font font = Aspose.Font.Font.Open(fd) as Type1Font;
6
7bool latinText = true;
8
9
10for (uint code = 65; code < 123; code++)
11{
12 GlyphId gid = font.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.", font.FontName));
22}
23else
24{
25 Console.WriteLine(string.Format("Latin symbols are not supported by font {0}.", font.FontName));
26}