Glifos e métricas das fontes do tipo1 | C++
Contents
[
Hide
Show
]Obtenha métricas de fonte
Aspose.Font para C++ API pode ler as informações das métricas de font das fontes do tipo 1. A amostra de código a seguir mostra como ler informações de métricas como ascender
, descender
, typeSoSeScender
, typodescender
e 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);
Detectar símbolos latinos
Aspose.Font para C++ permite detectar símbolos latinos dos arquivos de fonte Type1 em seus aplicativos C ++. Isso pode ser alcançado usando o seguinte código de amostra.
- Carregue o arquivo de fonte usando a FontFiledEfinition
- Decodificar o glifídeo usando o método decodetogId()
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}