Glyphen und Metriken von Type1-Schriftarten | C++

Rufen Sie Schriftmetriken ab

Die Aspose.Font for C++-API kann Font-Metrikinformationen aus Type1-Schriftarten lesen. Das folgende Codebeispiel zeigt, wie Metrikinformationen wie „Ascender“, „Descender“, „TypoAscender“, „TypoDescender“ und „UnitsPerEm“ gelesen werden.

 1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
 2System::String fileName = dataDir + u"courier.pfb";
 3//Font file name with full path
 4    
 5System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::Type1, System::MakeObject<FontFileDefinition>(u"pfb", System::MakeObject<FileSystemStreamSource>(fileName)));
 6System::SharedPtr<Type1Font> font = System::DynamicCast_noexcept<Aspose::Font::Type1::Type1Font>(Aspose::Font::Font::Open(fd));
 7    
 8System::String name = font->get_FontName();
 9System::Console::WriteLine(System::String(u"Font name: ") + name);
10System::Console::WriteLine(System::String(u"Glyph count: ") + font->get_NumGlyphs());
11System::String metrics = System::String::Format(u"Font metrics: ascender - {0}, descender - {1}, typo ascender = {2}, typo descender = {3}, UnitsPerEm = {4}", font->get_Metrics()->get_Ascender(), font->get_Metrics()->get_Descender(), font->get_Metrics()->get_TypoAscender(), font->get_Metrics()->get_TypoDescender(), font->get_Metrics()->get_UnitsPerEM());
12    
13System::Console::WriteLine(metrics);

Erkennen Sie lateinische Symbole

Mit Aspose.Font für C++ können Sie lateinische Symbole aus Type1-Schriftdateien in Ihren C++-Anwendungen erkennen. Dies kann mit dem folgenden Beispielcode erreicht werden.

 1For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
 2System::String fileName = dataDir + u"courier.pfb";
 3//Font file name with full path
 4    
 5System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::Type1, System::MakeObject<FontFileDefinition>(u"pfb", System::MakeObject<FileSystemStreamSource>(fileName)));
 6System::SharedPtr<Type1Font> font = System::DynamicCast_noexcept<Aspose::Font::Type1::Type1Font>(Aspose::Font::Font::Open(fd));
 7    
 8bool latinText = true;
 9    
10    
11for (uint32_t code = 65; code < static_cast<uint32_t>(123); code++)
12{
13    System::SharedPtr<GlyphId> gid = font->get_Encoding()->DecodeToGid(code);
14    if (gid == nullptr || gid == System::StaticCast<System::Object>(GlyphUInt32Id::get_NotDefId()))
15    {
16        latinText = false;
17    }
18}
19    
20if (latinText)
21{
22    System::Console::WriteLine(System::String::Format(u"Font {0} supports latin symbols.", font->get_FontName()));
23}
24else
25{
26    System::Console::WriteLine(System::String::Format(u"Latin symbols are not supported by font {0}.", font->get_FontName()));
27}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.