이 주제에서는 C++를 사용하여 글꼴 메트릭을 얻는 방법을 살펴봅니다. 글꼴 메트릭에는 글꼴 파일의 글리프에 대한 정보가 포함됩니다. API 호출이 거의 없는 C++*를 사용하여 글꼴 메트릭에 대한 정보를 얻는 것이 그렇게 간단하지 않기 때문에 *글꼴 메트릭을 쉽게 추출할 수 있습니다.
C++를 사용하여 글꼴 메트릭을 가져오는 단계
- NuGet 패키지 관리자 도구를 사용하여 Aspose.Font for C++ 라이브러리 설치
- Aspose::Font 네임스페이스에 대한 참조 포함
- FontDefinition 클래스 객체 생성
- Type1Font 클래스의 객체 초기화
- 글꼴 메트릭의 다른 속성 가져오기
몇 가지 간단한 API 호출로 *C++*를 사용하여 글꼴 메트릭을 추출할 수 있습니다. 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); | |
} | |
}; |
이전에 C#에서 글꼴 메트릭을 얻는 방법에 대해 배웠습니다. 그러나 이 주제에서는 C++*를 사용하여 *글꼴 메트릭을 추출하는 방법을 구현했습니다.