폰트 정보 읽기

C++용 Aspose.Font API 솔루션으로 폰트 메트릭을 탐색하세요. 각 획, 곡선, 세부 사항에 대한 상세한 인사이트를 배우세요. 우리의 솔루션을 사용하면 글리프를 손쉽게 다룰 수 있으며, 어떤 폰트든 고유 특성에 대한 정보를 추출할 수 있습니다.

 

Aspose.Font API 솔루션 for C++는 강력한 기능 세트를 제공하며, 폰트 변환, 글리프 조작, 라틴 기호 감지 등을 포함합니다. 또한 API를 통해 글리프를 작업하고 폰트에 포함된 글리프 정보를 얻을 수 있습니다. 디자인을 향상시키고 프로젝트를 강화하며 Aspose.Font for C++와 함께 글리프의 전체 잠재력을 활용하세요. 주저하지 말고 무료 체험을 시작하세요!

글리프는 서체에서 문자 또는 기호를 위한 고유한 디자인입니다. 이 글꼴 단위를 더 잘 이해하려면 글리프 소개 문서를 참조하세요. 글꼴 메트릭은 서체의 시각적 모양을 설명하는 데 사용되는 측정값 및 사양입니다. 이러한 메트릭에는 문자 높이, 문자 너비, 문자 간 간격, 기준선 위치 등의 정보가 포함될 수 있습니다. 이를 통해 디자이너와 소프트웨어 개발자는 디지털 문서 및 사용자 인터페이스에서 텍스트 레이아웃을 정확하게 예측할 수 있습니다.

이 페이지에서는 글리프 개수, 문자 높이, 글리프 ‘A’의 너비 등 다양한 글꼴 메트릭을 가져오는 방법을 설명합니다. 글리프를 사용하는 전체 기능은 ‘글리프 객체 사용’ 문서에서 자세히 설명합니다. 코드 예제에는 글꼴 이름을 포함한 글꼴 메타데이터를 가져오는 부분이 포함되어 있습니다. 이러한 기능은 Aspose 에코시스템에서 제공되는 글꼴 메타데이터 앱과 같은 웹 애플리케이션에 통합할 수 있습니다. 완전한 예제와 데이터 파일을 보려면 Aspose Github 프로젝트 를 방문하세요.

폰트 메트릭을 얻기 위해서는 다음이 필요합니다:

  • Aspose.Font for C++ API는 다양한 기능을 갖춘 강력하고 사용하기 쉬운 문서 조작 및 변환 API입니다.

  • NuGet 패키지 관리자를 열고 Aspose.Font를 검색하여 설치하세요. 또한 패키지 관리자 콘솔에서 다음 명령을 사용할 수 있습니다.

Package Manager Console Command


    PM> Install-Package Aspose.Font

C++를 사용하여 폰트 메트릭을 얻는 단계:

  1. 폰트에 대한 정보를 추출하려면 TtfFont 클래스를 인스턴스화합니다.
  2. FontName 속성을 사용하여 폰트 이름을 출력합니다.
  3. NumGlyphs 속성을 사용하여 폰트의 글리프 수를 출력합니다. 또한 어센더, 디센더, 타이포 어센더, 타이포 디센더, UnitsPerEm과 같은 폰트 메트릭도 출력됩니다.
  4. 코드는 폰트에서 cmap 유니코드 인코딩 테이블을 가져와 문자 코드를 글리프 인덱스로 매핑합니다. 폰트에 cmap 테이블과 glyf 테이블이 모두 있는지 확인합니다. 두 테이블이 모두 존재하면 문자 A에 대한 glyf 인덱스를 가져와 A 기호에 해당하는 글리프를 얻습니다.
  5. A 글리프의 경계 상자와 너비를 출력합니다.

폰트 글리프 정보를 얻기 위한 C++ 코드

    using Aspose::Font;
    using Aspose::Font::Glyphs;
    using Aspose::Font::Ttf;
    //Font file name with the full path
    
    System::SharedPtr<FontDefinition> fd = System::MakeObject<FontDefinition>(Aspose::Font::FontType::TTF, System::MakeObject<FontFileDefinition>(u"ttf", System::MakeObject<FileSystemStreamSource>(fileName)));
    System::SharedPtr<TtfFont> font = System::DynamicCast_noexcept<Aspose::Font::Ttf::TtfFont>(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);
    
    //Get cmap unicode encoding table from the font as object TtfCMapFormatBaseTable to access the information about the font glyph for symbol 'A'.
    //Also check that font has object TtfGlyfTable (table 'glyf') to access glyph.
    System::SharedPtr<Aspose::Font::TtfCMapFormats::TtfCMapFormatBaseTable> cmapTable;
    if (font->get_TtfTables()->get_CMapTable() != nullptr)
    {
        cmapTable = font->get_TtfTables()->get_CMapTable()->FindUnicodeTable();
    }
    if (cmapTable != nullptr && font->get_TtfTables()->get_GlyfTable() != nullptr)
    {
        System::Console::WriteLine(System::String(u"Font cmap unicode table: PlatformID = ") + cmapTable->get_PlatformId() + u", PlatformSpecificID = " + cmapTable->get_PlatformSpecificId());
    
        //Code for 'A' symbol
        char16_t unicode = (char16_t)65;
    
        //Glyph index for 'A'
        uint32_t glIndex = cmapTable->GetGlyphIndex(unicode);
    
        if (glIndex != static_cast<uint32_t>(0))
        {
            //Glyph for 'A'
            System::SharedPtr<Glyph> glyph = font->GetGlyphById(glIndex);
            if (glyph != nullptr)
            {
                //Print glyph metrics
                System::Console::WriteLine(u"Glyph metrics for 'A' symbol:");
                System::String bbox = System::String::Format(System::String(u"Glyph BBox: Xmin = {0}, Xmax = {1}") + u", Ymin = {2}, Ymax = {3}", glyph->get_GlyphBBox()->get_XMin(), glyph->get_GlyphBBox()->get_XMax(), glyph->get_GlyphBBox()->get_YMin(), glyph->get_GlyphBBox()->get_YMax());
                System::Console::WriteLine(bbox);
                System::Console::WriteLine(System::String(u"Width:") + font->get_Metrics()->GetGlyphWidth(System::MakeObject<GlyphUInt32Id>(glIndex)));
            }
        }
    }