Glyphs and Metrics of Type1 Fonts | C++

Get Font Metrics

Aspose.Font for C++ API can read Font Metrics information from Type1 fonts. The following code sample shows how to read metrics information such as Ascender, Descender, TypoAscender, TypoDescender and UnitsPerEm.

 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);

Detect Latin Symbols

Aspose.Font for C++ lets you detect Latin Symbols from Type1 font files in your C++ applications. This can be achieved using the following sample code.

 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}

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.