이전 게시물에서 CFF, TrueType, OpenTypeType1 글꼴을 로드하고 사용하는 방법을 살펴보았습니다. C++ 애플리케이션. 이 기사에서는 C++를 사용하여 프로그래밍 방식으로 글꼴에서 라틴 기호를 감지하는 방법을 보여줌으로써 한 단계 더 나아갑니다. 감지 후 글꼴이 라틴 기호를 지원하는지 여부를 결정할 수 있습니다.

글꼴에서 라틴 기호를 감지하는 C++ API

Aspose.Font for C++은 글꼴에서 라틴 기호 지원을 아주 쉽게 감지할 수 있는 글꼴 조작 및 관리 API입니다. API를 다운로드하거나 NuGet을 통해 설치할 수 있습니다.

PM> Install-Package Aspose.Font.Cpp

C++의 트루타입 글꼴에서 라틴 기호 감지

C++용 Aspose.Font를 사용하여 라틴 기호 지원을 감지하는 것은 파이만큼 간단합니다. 특정 트루타입 글꼴이 라틴 기호를 지원하는지 확인하는 단계는 다음과 같습니다.

  • FontDefinition 클래스의 객체를 생성하여 해당 유형을 TrueType으로 지정하여 글꼴을 로드합니다.
  • 글꼴 정보에 접근하기 위해 TtfFont 클래스의 객체를 생성합니다.
  • 가능한 코드를 반복하고 글리프 ID로 디코딩합니다.
  • 소스 트루타입 글꼴에서 라틴 기호가 지원되는지 여부를 확인하려면 글리프 ID를 일치시키십시오.

다음 코드 샘플은 C++를 사용하여 TrueType 글꼴에서 라틴 기호를 감지하는 방법을 보여줍니다.

For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
System::String fileName = dataDir + u"Montserrat-Regular.ttf";
//전체 경로가 있는 글꼴 파일 이름
    
System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<FileSystemStreamSource>(fileName)));
System::SharedPtr<TtfFont> ttfFont = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(Aspose::Font::Font::Open(fd));
    
bool latinText = true;
    
    
for (uint32_t code = 65; code < static_cast<uint32_t>(123); code++)
{
    System::SharedPtr<GlyphId> gid = ttfFont->get_Encoding()->DecodeToGid(code);
    if (gid == nullptr || gid == System::StaticCast<System::Object>(GlyphUInt32Id::get_NotDefId()))
    {
        latinText = false;
    }
}
    
if (latinText)
{
    System::Console::WriteLine(System::String::Format(u"Font {0} supports latin symbols.", ttfFont->get_FontName()));
}
else
{
    System::Console::WriteLine(System::String::Format(u"Latin symbols are not supported by font {0}.", ttfFont->get_FontName()));
}

C++의 Type1 글꼴에서 라틴 기호 감지

Type1 글꼴에서 라틴 기호를 감지하는 프로세스는 TrueType 글꼴에 대해 수행한 것과 동일합니다. 유일한 차이점은 Type1Font 클래스의 사용입니다. 다음 단계는 Type1 글꼴에서 라틴 기호 감지의 전체 프로세스를 보여줍니다.

  • FontDefinition 클래스를 사용하여 유형을 Type1로 지정하여 글꼴을 로드합니다.
  • Type1Font 클래스를 사용하여 글꼴 정보에 액세스합니다.
  • 가능한 코드를 반복하고 글리프 ID로 디코딩합니다.
  • 제공된 Type1 글꼴의 라틴 기호 지원을 확인하려면 글리프 ID를 일치시키십시오.

다음 코드 샘플은 C++를 사용하여 Type1 글꼴의 라틴 기호를 감지하는 방법을 보여줍니다.

For complete examples and data files, please go to https://github.com/aspose-font/Aspose.Font-for-C
System::String fileName = dataDir + 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));
    
bool latinText = true;
    
    
for (uint32_t code = 65; code < static_cast<uint32_t>(123); code++)
{
    System::SharedPtr<GlyphId> gid = font->get_Encoding()->DecodeToGid(code);
    if (gid == nullptr || gid == System::StaticCast<System::Object>(GlyphUInt32Id::get_NotDefId()))
    {
        latinText = false;
    }
}
    
if (latinText)
{
    System::Console::WriteLine(System::String::Format(u"Font {0} supports latin symbols.", font->get_FontName()));
}
else
{
    System::Console::WriteLine(System::String::Format(u"Latin symbols are not supported by font {0}.", font->get_FontName()));
}

결론

이 기사에서는 C++를 사용하여 TrueType 및 Type1 글꼴에서 라틴 기호를 감지하는 방법을 배웠습니다. 이 기사의 코드 샘플을 통해 라틴 기호가 특정 글꼴에서 지원되는지 여부를 확인할 수 있습니다. 문서를 사용하여 C++ 글꼴 조작 API에 대해 자세히 알아볼 수 있습니다.

또한보십시오