Di posting sebelumnya, Anda telah melihat cara memuat dan bekerja dengan font CFF, TrueType, OpenType, dan Type1 dari dalam aplikasi C++ Anda. Artikel ini membawa Anda selangkah lebih maju dengan mendemonstrasikan cara mendeteksi simbol Latin dalam font secara terprogram menggunakan C++. Setelah deteksi, Anda dapat memutuskan apakah font mendukung simbol Latin atau tidak.

C++ API untuk Mendeteksi Simbol Latin di Font

Aspose.Font for C++ adalah API manajemen dan manipulasi font yang memungkinkan Anda mendeteksi dukungan simbol Latin di font dengan cukup mudah. Anda dapat mengunduh API atau menginstalnya melalui NuGet.

PM> Install-Package Aspose.Font.Cpp

Deteksi Simbol Latin di TrueType Fonts di C++

Mendeteksi dukungan simbol Latin menggunakan Aspose.Font for C++ sangatlah mudah. Berikut adalah langkah-langkah untuk memeriksa apakah font TrueType tertentu mendukung simbol Latin atau tidak.

  • Buat objek kelas FontDefinition untuk memuat font dengan menentukan jenisnya sebagai TrueType.
  • Buat objek kelas TtfFont untuk mengakses informasi font.
  • Ulangi kode yang mungkin dan dekodekan menjadi ID mesin terbang.
  • Cocokkan ID mesin terbang untuk memeriksa apakah simbol Latin didukung dalam font TrueType sumber atau tidak.

Contoh kode berikut menunjukkan cara mendeteksi simbol Latin di font TrueType menggunakan C++.

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";
//Nama file font dengan path lengkap
    
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()));
}

Deteksi Simbol Latin di Font Type1 di C++

Proses mendeteksi simbol Latin di font Type1 sama seperti yang Anda lakukan untuk font TrueType. Satu-satunya perbedaan adalah penggunaan kelas Type1Font. Langkah-langkah berikut mendemonstrasikan proses lengkap deteksi simbol Latin dalam font Type1.

  • Gunakan kelas FontDefinition untuk memuat font dengan menentukan tipenya sebagai Type1.
  • Gunakan kelas Type1Font untuk mengakses informasi font.
  • Ulangi kode yang mungkin dan dekodekan menjadi ID mesin terbang.
  • Cocokkan ID mesin terbang untuk memeriksa dukungan simbol Latin dalam font Type1 yang disediakan.

Contoh kode berikut menunjukkan cara mendeteksi simbol Latin di font Type1 menggunakan C++.

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";
//Nama file font dengan path lengkap
    
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()));
}

Kesimpulan

Pada artikel ini, Anda telah mempelajari cara mendeteksi simbol Latin di font TrueType dan Type1 menggunakan C++. Contoh kode dalam artikel ini memungkinkan Anda menentukan apakah simbol Latin didukung oleh font tertentu atau tidak. Anda dapat mempelajari lebih lanjut tentang API manipulasi font C++ menggunakan dokumentasi.

Lihat juga