diff options
Diffstat (limited to 'xfa/fgas/font/cfgas_fontmgr.cpp')
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 570 |
1 files changed, 286 insertions, 284 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index d0a6127bbc..ed1fe78ccf 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -389,6 +389,274 @@ void ftStreamClose(FXFT_Stream stream) {} }; // extern "C" +// TODO(thestig): Pass in |name_table| as a std::vector? +std::vector<WideString> GetNames(const uint8_t* name_table) { + std::vector<WideString> results; + if (!name_table) + return results; + + const uint8_t* lpTable = name_table; + WideString wsFamily; + const uint8_t* sp = lpTable + 2; + const uint8_t* lpNameRecord = lpTable + 6; + uint16_t nNameCount = GetUInt16(sp); + const uint8_t* lpStr = lpTable + GetUInt16(sp + 2); + for (uint16_t j = 0; j < nNameCount; j++) { + uint16_t nNameID = GetUInt16(lpNameRecord + j * 12 + 6); + if (nNameID != 1) + continue; + + uint16_t nPlatformID = GetUInt16(lpNameRecord + j * 12 + 0); + uint16_t nNameLength = GetUInt16(lpNameRecord + j * 12 + 8); + uint16_t nNameOffset = GetUInt16(lpNameRecord + j * 12 + 10); + wsFamily.clear(); + if (nPlatformID != 1) { + for (uint16_t k = 0; k < nNameLength / 2; k++) { + wchar_t wcTemp = GetUInt16(lpStr + nNameOffset + k * 2); + wsFamily += wcTemp; + } + results.push_back(wsFamily); + continue; + } + for (uint16_t k = 0; k < nNameLength; k++) { + wchar_t wcTemp = GetUInt8(lpStr + nNameOffset + k); + wsFamily += wcTemp; + } + results.push_back(wsFamily); + } + return results; +} + +std::vector<uint16_t> GetCharsets(FXFT_Face pFace) { + std::vector<uint16_t> charsets; + TT_OS2* pOS2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(pFace, ft_sfnt_os2)); + if (!pOS2) { + charsets.push_back(FX_CHARSET_Default); + return charsets; + } + uint16_t a[4] = { + pOS2->ulCodePageRange1 & 0xffff, (pOS2->ulCodePageRange1 >> 16) & 0xffff, + pOS2->ulCodePageRange2 & 0xffff, (pOS2->ulCodePageRange2 >> 16) & 0xffff}; + for (int n = 0; n < 4; n++) { + for (int32_t i = 0; i < 16; i++) { + if ((a[n] & g_FX_Bit2Charset[n][i].wBit) != 0) + charsets.push_back(g_FX_Bit2Charset[n][i].wCharset); + } + } + return charsets; +} + +void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) { + TT_OS2* pOS2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(pFace, ft_sfnt_os2)); + if (!pOS2) { + USB[0] = 0; + USB[1] = 0; + USB[2] = 0; + USB[3] = 0; + CSB[0] = 0; + CSB[1] = 0; + return; + } + USB[0] = pOS2->ulUnicodeRange1; + USB[1] = pOS2->ulUnicodeRange2; + USB[2] = pOS2->ulUnicodeRange3; + USB[3] = pOS2->ulUnicodeRange4; + CSB[0] = pOS2->ulCodePageRange1; + CSB[1] = pOS2->ulCodePageRange2; +} + +uint32_t GetFlags(FXFT_Face pFace) { + uint32_t flag = 0; + if (FT_IS_FIXED_WIDTH(pFace)) + flag |= FXFONT_FIXED_PITCH; + TT_OS2* pOS2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(pFace, ft_sfnt_os2)); + if (!pOS2) + return flag; + + if (pOS2->ulCodePageRange1 & (1 << 31)) + flag |= FXFONT_SYMBOLIC; + if (pOS2->panose[0] == 2) { + uint8_t uSerif = pOS2->panose[1]; + if ((uSerif > 1 && uSerif < 10) || uSerif > 13) + flag |= FXFONT_SERIF; + } + return flag; +} + +RetainPtr<IFX_SeekableReadStream> CreateFontStream( + CFX_FontMapper* pFontMapper, + SystemFontInfoIface* pSystemFontInfo, + uint32_t index) { + void* hFont = pSystemFontInfo->MapFont( + 0, 0, FX_CHARSET_Default, 0, pFontMapper->GetFaceName(index).c_str()); + if (!hFont) + return nullptr; + + uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); + if (dwFileSize == 0) + return nullptr; + + std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer( + FX_Alloc(uint8_t, dwFileSize + 1)); + dwFileSize = + pSystemFontInfo->GetFontData(hFont, 0, pBuffer.get(), dwFileSize); + return pdfium::MakeRetain<CFX_MemoryStream>(std::move(pBuffer), dwFileSize); +} + +RetainPtr<IFX_SeekableReadStream> CreateFontStream( + const ByteString& bsFaceName) { + CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); + CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); + if (!pFontMapper) + return nullptr; + + SystemFontInfoIface* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); + if (!pSystemFontInfo) + return nullptr; + + pSystemFontInfo->EnumFontList(pFontMapper); + for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { + if (pFontMapper->GetFaceName(i) == bsFaceName) + return CreateFontStream(pFontMapper, pSystemFontInfo, i); + } + return nullptr; +} + +FXFT_Face LoadFace(const RetainPtr<IFX_SeekableReadStream>& pFontStream, + int32_t iFaceIndex) { + if (!pFontStream) + return nullptr; + + CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); + pFontMgr->InitFTLibrary(); + + FXFT_Library library = pFontMgr->GetFTLibrary(); + if (!library) + return nullptr; + + // TODO(palmer): This memory will be freed with |ft_free| (which is |free|). + // Ultimately, we want to change this to: + // FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); + // https://bugs.chromium.org/p/pdfium/issues/detail?id=690 + FXFT_Stream ftStream = + static_cast<FXFT_Stream>(ft_scalloc(sizeof(FXFT_StreamRec), 1)); + memset(ftStream, 0, sizeof(FXFT_StreamRec)); + ftStream->base = nullptr; + ftStream->descriptor.pointer = static_cast<void*>(pFontStream.Get()); + ftStream->pos = 0; + ftStream->size = static_cast<unsigned long>(pFontStream->GetSize()); + ftStream->read = ftStreamRead; + ftStream->close = ftStreamClose; + + FXFT_Open_Args ftArgs; + memset(&ftArgs, 0, sizeof(FXFT_Open_Args)); + ftArgs.flags |= FT_OPEN_STREAM; + ftArgs.stream = ftStream; + + FXFT_Face pFace = nullptr; + if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { + ft_sfree(ftStream); + return nullptr; + } + + FXFT_Set_Pixel_Sizes(pFace, 0, 64); + return pFace; +} + +bool VerifyUnicodeForFontDescriptor(CFX_FontDescriptor* pDesc, + wchar_t wcUnicode) { + RetainPtr<IFX_SeekableReadStream> pFileRead = + CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); + if (!pFileRead) + return false; + + FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); + FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); + FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); + if (!pFace) + return false; + + if (FXFT_Get_Face_External_Stream(pFace)) + FXFT_Clear_Face_External_Stream(pFace); + + FXFT_Done_Face(pFace); + return !retCharmap && retIndex; +} + +bool IsPartName(const WideString& name1, const WideString& name2) { + return name1.Contains(name2.AsStringView()); +} + +int32_t CalcPenalty(CFX_FontDescriptor* pInstalled, + uint16_t wCodePage, + uint32_t dwFontStyles, + const WideString& FontName, + wchar_t wcUnicode) { + int32_t nPenalty = 30000; + if (FontName.GetLength() != 0) { + if (FontName != pInstalled->m_wsFaceName) { + size_t i; + for (i = 0; i < pInstalled->m_wsFamilyNames.size(); ++i) { + if (pInstalled->m_wsFamilyNames[i] == FontName) + break; + } + if (i == pInstalled->m_wsFamilyNames.size()) + nPenalty += 0xFFFF; + else + nPenalty -= 28000; + } else { + nPenalty -= 30000; + } + if (nPenalty == 30000 && !IsPartName(pInstalled->m_wsFaceName, FontName)) { + size_t i; + for (i = 0; i < pInstalled->m_wsFamilyNames.size(); i++) { + if (IsPartName(pInstalled->m_wsFamilyNames[i], FontName)) + break; + } + if (i == pInstalled->m_wsFamilyNames.size()) + nPenalty += 0xFFFF; + else + nPenalty -= 26000; + } else { + nPenalty -= 27000; + } + } + uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; + if (FontStyleIsBold(dwStyleMask)) + nPenalty += 4500; + if (FontStyleIsFixedPitch(dwStyleMask)) + nPenalty += 10000; + if (FontStyleIsItalic(dwStyleMask)) + nPenalty += 10000; + if (FontStyleIsSerif(dwStyleMask)) + nPenalty += 500; + if (FontStyleIsSymbolic(dwStyleMask)) + nPenalty += 0xFFFF; + if (nPenalty >= 0xFFFF) + return 0xFFFF; + + uint16_t wBit = (wCodePage == FX_CODEPAGE_DefANSI || wCodePage == 0xFFFF) + ? static_cast<uint16_t>(-1) + : FX_GetCodePageBit(wCodePage); + if (wBit != static_cast<uint16_t>(-1)) { + ASSERT(wBit < 64); + if ((pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32))) == 0) + nPenalty += 0xFFFF; + else + nPenalty -= 60000; + } + wBit = (wcUnicode == 0 || wcUnicode == 0xFFFE) ? static_cast<uint16_t>(999) + : FX_GetUnicodeBit(wcUnicode); + if (wBit != static_cast<uint16_t>(999)) { + ASSERT(wBit < 128); + if ((pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32))) == 0) + nPenalty += 0xFFFF; + else + nPenalty -= 60000; + } + return nPenalty; +} + } // namespace CFX_FontDescriptor::CFX_FontDescriptor() @@ -452,13 +720,12 @@ ByteString CFX_FontSourceEnum_File::GetNextFile() { bool CFX_FontSourceEnum_File::HasStartPosition() { m_wsNext = GetNextFile().UTF8Decode(); - return m_wsNext.GetLength() != 0; + return !m_wsNext.IsEmpty(); } -// <next exists, stream for next> std::pair<bool, RetainPtr<IFX_SeekableStream>> CFX_FontSourceEnum_File::GetNext() { - if (m_wsNext.GetLength() == 0) + if (m_wsNext.IsEmpty()) return {false, nullptr}; auto stream = IFX_SeekableStream::CreateFromFilename(m_wsNext.c_str(), @@ -519,26 +786,6 @@ bool CFGAS_FontMgr::EnumFonts() { return EnumFontsFromFontMapper() || EnumFontsFromFiles(); } -bool CFGAS_FontMgr::VerifyUnicode(CFX_FontDescriptor* pDesc, - wchar_t wcUnicode) { - RetainPtr<IFX_SeekableReadStream> pFileRead = - CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); - if (!pFileRead) - return false; - - FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); - FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); - FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); - if (!pFace) - return false; - - if (FXFT_Get_Face_External_Stream(pFace)) - FXFT_Clear_Face_External_Stream(pFace); - - FXFT_Done_Face(pFace); - return !retCharmap && retIndex; -} - RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::LoadFont(const WideString& wsFaceName, int32_t iFaceIndex, int32_t* pFaceCount) { @@ -571,87 +818,6 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::LoadFont(const WideString& wsFaceName, return pFont; } -FXFT_Face CFGAS_FontMgr::LoadFace( - const RetainPtr<IFX_SeekableReadStream>& pFontStream, - int32_t iFaceIndex) { - if (!pFontStream) - return nullptr; - - CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); - pFontMgr->InitFTLibrary(); - - FXFT_Library library = pFontMgr->GetFTLibrary(); - if (!library) - return nullptr; - - // TODO(palmer): This memory will be freed with |ft_free| (which is |free|). - // Ultimately, we want to change this to: - // FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); - // https://bugs.chromium.org/p/pdfium/issues/detail?id=690 - FXFT_Stream ftStream = - static_cast<FXFT_Stream>(ft_scalloc(sizeof(FXFT_StreamRec), 1)); - memset(ftStream, 0, sizeof(FXFT_StreamRec)); - ftStream->base = nullptr; - ftStream->descriptor.pointer = static_cast<void*>(pFontStream.Get()); - ftStream->pos = 0; - ftStream->size = static_cast<unsigned long>(pFontStream->GetSize()); - ftStream->read = ftStreamRead; - ftStream->close = ftStreamClose; - - FXFT_Open_Args ftArgs; - memset(&ftArgs, 0, sizeof(FXFT_Open_Args)); - ftArgs.flags |= FT_OPEN_STREAM; - ftArgs.stream = ftStream; - - FXFT_Face pFace = nullptr; - if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { - ft_sfree(ftStream); - return nullptr; - } - - FXFT_Set_Pixel_Sizes(pFace, 0, 64); - return pFace; -} - -RetainPtr<IFX_SeekableReadStream> CFGAS_FontMgr::CreateFontStream( - CFX_FontMapper* pFontMapper, - SystemFontInfoIface* pSystemFontInfo, - uint32_t index) { - void* hFont = pSystemFontInfo->MapFont( - 0, 0, FX_CHARSET_Default, 0, pFontMapper->GetFaceName(index).c_str()); - if (!hFont) - return nullptr; - - uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); - if (dwFileSize == 0) - return nullptr; - - std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer( - FX_Alloc(uint8_t, dwFileSize + 1)); - dwFileSize = - pSystemFontInfo->GetFontData(hFont, 0, pBuffer.get(), dwFileSize); - return pdfium::MakeRetain<CFX_MemoryStream>(std::move(pBuffer), dwFileSize); -} - -RetainPtr<IFX_SeekableReadStream> CFGAS_FontMgr::CreateFontStream( - const ByteString& bsFaceName) { - CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); - CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); - if (!pFontMapper) - return nullptr; - - SystemFontInfoIface* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); - if (!pSystemFontInfo) - return nullptr; - - pSystemFontInfo->EnumFontList(pFontMapper); - for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { - if (pFontMapper->GetFaceName(i) == bsFaceName) - return CreateFontStream(pFontMapper, pSystemFontInfo, i); - } - return nullptr; -} - void CFGAS_FontMgr::MatchFonts( std::vector<CFX_FontDescriptorInfo>* pMatchedFonts, uint16_t wCodePage, @@ -671,76 +837,6 @@ void CFGAS_FontMgr::MatchFonts( std::sort(pMatchedFonts->begin(), pMatchedFonts->end()); } -int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, - uint16_t wCodePage, - uint32_t dwFontStyles, - const WideString& FontName, - wchar_t wcUnicode) { - int32_t nPenalty = 30000; - if (FontName.GetLength() != 0) { - if (FontName != pInstalled->m_wsFaceName) { - size_t i; - for (i = 0; i < pInstalled->m_wsFamilyNames.size(); ++i) { - if (pInstalled->m_wsFamilyNames[i] == FontName) - break; - } - if (i == pInstalled->m_wsFamilyNames.size()) - nPenalty += 0xFFFF; - else - nPenalty -= 28000; - } else { - nPenalty -= 30000; - } - if (nPenalty == 30000 && !IsPartName(pInstalled->m_wsFaceName, FontName)) { - size_t i; - for (i = 0; i < pInstalled->m_wsFamilyNames.size(); i++) { - if (IsPartName(pInstalled->m_wsFamilyNames[i], FontName)) - break; - } - if (i == pInstalled->m_wsFamilyNames.size()) - nPenalty += 0xFFFF; - else - nPenalty -= 26000; - } else { - nPenalty -= 27000; - } - } - uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; - if (FontStyleIsBold(dwStyleMask)) - nPenalty += 4500; - if (FontStyleIsFixedPitch(dwStyleMask)) - nPenalty += 10000; - if (FontStyleIsItalic(dwStyleMask)) - nPenalty += 10000; - if (FontStyleIsSerif(dwStyleMask)) - nPenalty += 500; - if (FontStyleIsSymbolic(dwStyleMask)) - nPenalty += 0xFFFF; - if (nPenalty >= 0xFFFF) - return 0xFFFF; - - uint16_t wBit = (wCodePage == FX_CODEPAGE_DefANSI || wCodePage == 0xFFFF) - ? static_cast<uint16_t>(-1) - : FX_GetCodePageBit(wCodePage); - if (wBit != static_cast<uint16_t>(-1)) { - ASSERT(wBit < 64); - if ((pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32))) == 0) - nPenalty += 0xFFFF; - else - nPenalty -= 60000; - } - wBit = (wcUnicode == 0 || wcUnicode == 0xFFFE) ? static_cast<uint16_t>(999) - : FX_GetUnicodeBit(wcUnicode); - if (wBit != static_cast<uint16_t>(999)) { - ASSERT(wBit < 128); - if ((pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32))) == 0) - nPenalty += 0xFFFF; - else - nPenalty -= 60000; - } - return nPenalty; -} - void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace, const WideString* pFaceName) { if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) return; @@ -764,7 +860,7 @@ void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace, const WideString* pFaceName) { if (FXFT_Load_Sfnt_Table(pFace, dwTag, 0, table.data(), nullptr)) table.clear(); } - GetNames(table.empty() ? nullptr : table.data(), pFont->m_wsFamilyNames); + pFont->m_wsFamilyNames = GetNames(table.empty() ? nullptr : table.data()); pFont->m_wsFamilyNames.push_back(ByteString(pFace->family_name).UTF8Decode()); pFont->m_wsFaceName = pFaceName ? *pFaceName @@ -792,104 +888,27 @@ void CFGAS_FontMgr::RegisterFaces( } while (index < num_faces); } -uint32_t CFGAS_FontMgr::GetFlags(FXFT_Face pFace) { - uint32_t flag = 0; - if (FT_IS_FIXED_WIDTH(pFace)) - flag |= FXFONT_FIXED_PITCH; - TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); - if (!pOS2) - return flag; - - if (pOS2->ulCodePageRange1 & (1 << 31)) - flag |= FXFONT_SYMBOLIC; - if (pOS2->panose[0] == 2) { - uint8_t uSerif = pOS2->panose[1]; - if ((uSerif > 1 && uSerif < 10) || uSerif > 13) - flag |= FXFONT_SERIF; - } - return flag; -} - -void CFGAS_FontMgr::GetNames(const uint8_t* name_table, - std::vector<WideString>& Names) { - if (!name_table) - return; +#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ - uint8_t* lpTable = (uint8_t*)name_table; - WideString wsFamily; - uint8_t* sp = lpTable + 2; - uint8_t* lpNameRecord = lpTable + 6; - uint16_t nNameCount = GetUInt16(sp); - uint8_t* lpStr = lpTable + GetUInt16(sp + 2); - for (uint16_t j = 0; j < nNameCount; j++) { - uint16_t nNameID = GetUInt16(lpNameRecord + j * 12 + 6); - if (nNameID != 1) - continue; +namespace { - uint16_t nPlatformID = GetUInt16(lpNameRecord + j * 12 + 0); - uint16_t nNameLength = GetUInt16(lpNameRecord + j * 12 + 8); - uint16_t nNameOffset = GetUInt16(lpNameRecord + j * 12 + 10); - wsFamily.clear(); - if (nPlatformID != 1) { - for (uint16_t k = 0; k < nNameLength / 2; k++) { - wchar_t wcTemp = GetUInt16(lpStr + nNameOffset + k * 2); - wsFamily += wcTemp; - } - Names.push_back(wsFamily); - continue; - } - for (uint16_t k = 0; k < nNameLength; k++) { - wchar_t wcTemp = GetUInt8(lpStr + nNameOffset + k); - wsFamily += wcTemp; - } - Names.push_back(wsFamily); - } -} +bool VerifyUnicode(const RetainPtr<CFGAS_GEFont>& pFont, wchar_t wcUnicode) { + if (!pFont) + return false; -std::vector<uint16_t> CFGAS_FontMgr::GetCharsets(FXFT_Face pFace) const { - std::vector<uint16_t> charsets; - TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); - if (!pOS2) { - charsets.push_back(FX_CHARSET_Default); - return charsets; - } - uint16_t a[4] = { - pOS2->ulCodePageRange1 & 0xffff, (pOS2->ulCodePageRange1 >> 16) & 0xffff, - pOS2->ulCodePageRange2 & 0xffff, (pOS2->ulCodePageRange2 >> 16) & 0xffff}; - for (int n = 0; n < 4; n++) { - for (int32_t i = 0; i < 16; i++) { - if ((a[n] & g_FX_Bit2Charset[n][i].wBit) != 0) - charsets.push_back(g_FX_Bit2Charset[n][i].wCharset); - } - } - return charsets; -} + FXFT_Face pFace = pFont->GetDevFont()->GetFace(); + FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); + if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) + return false; -void CFGAS_FontMgr::GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) { - TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); - if (!pOS2) { - USB[0] = 0; - USB[1] = 0; - USB[2] = 0; - USB[3] = 0; - CSB[0] = 0; - CSB[1] = 0; - return; + if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { + FXFT_Set_Charmap(pFace, charmap); + return false; } - USB[0] = pOS2->ulUnicodeRange1; - USB[1] = pOS2->ulUnicodeRange2; - USB[2] = pOS2->ulUnicodeRange3; - USB[3] = pOS2->ulUnicodeRange4; - CSB[0] = pOS2->ulCodePageRange1; - CSB[1] = pOS2->ulCodePageRange2; -} - -bool CFGAS_FontMgr::IsPartName(const WideString& name1, - const WideString& name2) { - return name1.Contains(name2.AsStringView()); + return true; } -#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ +} // namespace RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage( uint16_t wCodePage, @@ -1003,7 +1022,7 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode( } for (const auto& info : *sortedFontInfos) { CFX_FontDescriptor* pDesc = info.pFont; - if (!VerifyUnicode(pDesc, wUnicode)) + if (!VerifyUnicodeForFontDescriptor(pDesc, wUnicode)) continue; RetainPtr<CFGAS_GEFont> pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); @@ -1019,23 +1038,6 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode( #endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ } -bool CFGAS_FontMgr::VerifyUnicode(const RetainPtr<CFGAS_GEFont>& pFont, - wchar_t wcUnicode) { - if (!pFont) - return false; - - FXFT_Face pFace = pFont->GetDevFont()->GetFace(); - FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); - if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) - return false; - - if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { - FXFT_Set_Charmap(pFace, charmap); - return false; - } - return true; -} - RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::LoadFont(const wchar_t* pszFontFamily, uint32_t dwFontStyles, uint16_t wCodePage) { |