Այս թեմայում մենք կուսումնասիրենք, թե ինչպես ստանալ տառաչափերի չափումներ՝ օգտագործելով C++: Տառատեսակի չափումները ներառում են տեղեկատվություն տառատեսակի ֆայլի հոլովակների մասին: Դուք կարող եք հեշտությամբ արտահանել Տառաչափերի չափումներ՝ օգտագործելով C++ API-ի մի քանի զանգերի միջոցով, քանի որ այլապես տառատեսակների չափման մասին տեղեկատվությունը ստանում եք ոչ այնքան պարզ:
C++-ի միջոցով տառատեսակների չափումներ ստանալու քայլեր
- Տեղադրեք Aspose.Font for C++ գրադարանը՝ օգտագործելով NuGet փաթեթների կառավարիչ գործիքը
- Ներառեք հղումը Aspose::Font անվանատարածքին
- Ստեղծեք FontDefinition դասի օբյեկտ
- Նախաձեռնել Type1Font դասի օբյեկտ
- Ստացեք Font Metrics-ի տարբեր հատկություններ
Դուք կարող եք արտահանել Տառատեսակի չափումներ՝ օգտագործելով C++ մի քանի պարզ API զանգերի միջոցով: Ձեզ անհրաժեշտ է միայն մուտք գործել FontDefinition դասի օրինակ և կարդալ տառատեսակների չափումները C++-ով:
Կոդ՝ C++-ի միջոցով տառատեսակների չափումները կարդալու համար
#pragma once | |
#include <cstdint> | |
#include <stdio.h> | |
#include <system/console.h> | |
#include <system/string.h> | |
#include <system/shared_ptr.h> | |
#include <system/io/file.h> | |
#include <system/exceptions.h> | |
#include <Aspose.Font.Cpp/src/Sources/FontFileDefinition.h> | |
#include <Aspose.Font.Cpp/src/Sources/FontDefinition.h> | |
#include <Aspose.Font.Cpp/src/Sources/FileSystemStreamSource.h> | |
#include <Aspose.Font.Cpp/src/Sources/ByteContentStreamSource.h> | |
#include <Aspose.Font.Cpp/src/FontType.h> | |
#include <Aspose.Font.Cpp/src/Font.h> | |
#include <Aspose.Font.Cpp/src/Cff/CffFont.h> | |
#include <Aspose.Font.Cpp/src/License.h> | |
#include <Aspose.Font.Cpp/src/Type1/Type1Font.h> | |
#include <Aspose.Font.Cpp/src/Font.h> | |
#include <Aspose.Font.Cpp/src/IFontMetrics.h> | |
using namespace System; | |
using namespace Aspose::Font; | |
using namespace Aspose::Font::Type1; | |
using namespace Aspose::Font::Cff; | |
using namespace Aspose::Font::Sources; | |
class GetFontMetricsEx { | |
public: | |
static void GetFontMetricsInfo() | |
{ | |
// Initialize license object of Aspose.PUB to convert PUB to PDF | |
auto Fontslicense = System::MakeObject<Aspose::Font::License>(); | |
// Set license | |
Fontslicense->SetLicense(u"Aspose.Total.NET.lic"); | |
//Font file name with full path | |
System::String fileName = u"courier.pfb"; | |
System::SharedPtr<FontDefinition> fd = | |
System::MakeObject<FontDefinition>(Aspose::Font::FontType::Type1, | |
System::MakeObject<FontFileDefinition>(u"pfb", System::MakeObject<FileSystemStreamSource>(fileName))); | |
System::SharedPtr<Type1Font> font = | |
System::DynamicCast_noexcept<Aspose::Font::Type1::Type1Font>(Aspose::Font::Font::Open(fd)); | |
System::String name = font->get_FontName(); | |
System::Console::WriteLine(System::String(u"Font name: ") + name); | |
System::Console::WriteLine(System::String(u"Glyph count: ") + font->get_NumGlyphs()); | |
System::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()); | |
System::Console::WriteLine(metrics); | |
} | |
}; |
Նախկինում մենք սովորեցինք ինչպես ստանալ Font Metric-ը C#-ում: Այնուամենայնիվ, այս թեմայում մենք իրականացրեցինք այն մասին, թե ինչպես կարելի է արտահանել տառաչափերի չափումներ՝ օգտագործելով C++: