diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-18 16:57:17 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-18 16:57:17 +0000 |
commit | 95d525e83f1f5b5fac15970f767410b21debbb81 (patch) | |
tree | 78bea45f5ec078412c46553e5949bebbb267ffc3 | |
parent | 7281ed762c675717429fc78447055ccdb1171927 (diff) | |
download | pdfium-95d525e83f1f5b5fac15970f767410b21debbb81.tar.xz |
Shuffle platform-specifc code in CFGAS_FontMgr::GetFontByUnicode().
Move most of it into GetFontByUnicodeImpl().
Change-Id: Ibbfe458589d0d1aea8f52179110690ed83e40fac
Reviewed-on: https://pdfium-review.googlesource.com/c/44250
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 116 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.h | 7 |
2 files changed, 74 insertions, 49 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 8a51941627..8881be74f6 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -158,6 +158,34 @@ bool CFGAS_FontMgr::EnumFonts() { return true; } +RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicodeImpl( + wchar_t wUnicode, + uint32_t dwFontStyles, + const wchar_t* pszFontFamily, + uint32_t dwHash, + uint16_t wCodePage, + uint16_t wBitField) { + const FX_FONTDESCRIPTOR* pFD = FindFont(pszFontFamily, dwFontStyles, false, + wCodePage, wBitField, wUnicode); + if (!pFD && pszFontFamily) { + pFD = + FindFont(nullptr, dwFontStyles, false, wCodePage, wBitField, wUnicode); + } + if (!pFD) + return nullptr; + + uint16_t newCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); + const wchar_t* pFontFace = pFD->wsFontFace; + RetainPtr<CFGAS_GEFont> pFont = + CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, newCodePage, this); + if (!pFont) + return nullptr; + + pFont->SetLogicalFontStyle(dwFontStyles); + m_Hash2Fonts[dwHash].push_back(pFont); + return pFont; +} + const FX_FONTDESCRIPTOR* CFGAS_FontMgr::FindFont(const wchar_t* pszFontFamily, uint32_t dwFontStyles, bool matchParagraphStyle, @@ -619,6 +647,39 @@ bool CFGAS_FontMgr::EnumFonts() { return EnumFontsFromFontMapper() || EnumFontsFromFiles(); } +RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicodeImpl( + wchar_t wUnicode, + uint32_t dwFontStyles, + const wchar_t* pszFontFamily, + uint32_t dwHash, + uint16_t wCodePage, + uint16_t /* wBitField */) { + std::vector<CFX_FontDescriptorInfo>* sortedFontInfos = + m_Hash2CandidateList[dwHash].get(); + if (!sortedFontInfos) { + auto pNewFonts = pdfium::MakeUnique<std::vector<CFX_FontDescriptorInfo>>(); + sortedFontInfos = pNewFonts.get(); + MatchFonts(sortedFontInfos, wCodePage, dwFontStyles, + WideString(pszFontFamily), wUnicode); + m_Hash2CandidateList[dwHash] = std::move(pNewFonts); + } + for (const auto& info : *sortedFontInfos) { + CFX_FontDescriptor* pDesc = info.pFont; + if (!VerifyUnicodeForFontDescriptor(pDesc, wUnicode)) + continue; + RetainPtr<CFGAS_GEFont> pFont = + LoadFontInternal(pDesc->m_wsFaceName, pDesc->m_nFaceIndex); + if (!pFont) + continue; + pFont->SetLogicalFontStyle(dwFontStyles); + m_Hash2Fonts[dwHash].push_back(pFont); + return pFont; + } + if (!pszFontFamily) + m_FailedUnicodesSet.insert(wUnicode); + return nullptr; +} + RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::LoadFontInternal( const WideString& wsFaceName, int32_t iFaceIndex) { @@ -813,57 +874,14 @@ RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode( } bsHash += FX_UTF8Encode(WideStringView(pszFontFamily)); uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringView(), false); - std::vector<RetainPtr<CFGAS_GEFont>>* pFonts = &m_Hash2Fonts[dwHash]; - for (size_t i = 0; i < pFonts->size(); ++i) { - if (VerifyUnicode((*pFonts)[i], wUnicode)) - return (*pFonts)[i]; - } -#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ - const FX_FONTDESCRIPTOR* pFD = FindFont(pszFontFamily, dwFontStyles, false, - wCodePage, wBitField, wUnicode); - if (!pFD && pszFontFamily) { - pFD = - FindFont(nullptr, dwFontStyles, false, wCodePage, wBitField, wUnicode); + std::vector<RetainPtr<CFGAS_GEFont>>& fonts = m_Hash2Fonts[dwHash]; + for (auto& pFont : fonts) { + if (VerifyUnicode(pFont, wUnicode)) + return pFont; } - if (!pFD) - return nullptr; - - uint16_t newCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); - const wchar_t* pFontFace = pFD->wsFontFace; - RetainPtr<CFGAS_GEFont> pFont = - CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, newCodePage, this); - if (!pFont) - return nullptr; - pFont->SetLogicalFontStyle(dwFontStyles); - pFonts->push_back(pFont); - return pFont; -#else // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ - std::vector<CFX_FontDescriptorInfo>* sortedFontInfos = - m_Hash2CandidateList[dwHash].get(); - if (!sortedFontInfos) { - auto pNewFonts = pdfium::MakeUnique<std::vector<CFX_FontDescriptorInfo>>(); - sortedFontInfos = pNewFonts.get(); - MatchFonts(sortedFontInfos, wCodePage, dwFontStyles, - WideString(pszFontFamily), wUnicode); - m_Hash2CandidateList[dwHash] = std::move(pNewFonts); - } - for (const auto& info : *sortedFontInfos) { - CFX_FontDescriptor* pDesc = info.pFont; - if (!VerifyUnicodeForFontDescriptor(pDesc, wUnicode)) - continue; - RetainPtr<CFGAS_GEFont> pFont = - LoadFontInternal(pDesc->m_wsFaceName, pDesc->m_nFaceIndex); - if (!pFont) - continue; - pFont->SetLogicalFontStyle(dwFontStyles); - pFonts->push_back(pFont); - return pFont; - } - if (!pszFontFamily) - m_FailedUnicodesSet.insert(wUnicode); - return nullptr; -#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ + return GetFontByUnicodeImpl(wUnicode, dwFontStyles, pszFontFamily, dwHash, + wCodePage, wBitField); } RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::LoadFont(const wchar_t* pszFontFamily, diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index 2bda20ceb1..b784bedfe8 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -114,6 +114,13 @@ class CFGAS_FontMgr final : public Observable<CFGAS_FontMgr> { bool EnumFonts(); private: + RetainPtr<CFGAS_GEFont> GetFontByUnicodeImpl(wchar_t wUnicode, + uint32_t dwFontStyles, + const wchar_t* pszFontFamily, + uint32_t dwHash, + uint16_t wCodePage, + uint16_t wBitField); + #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ const FX_FONTDESCRIPTOR* FindFont(const wchar_t* pszFontFamily, uint32_t dwFontStyles, |