Use compound key in another font manager (CFGAS_PDFFontMgr).
Change-Id: Ieecdd140ebcf61a2d65dd04aa65f1c851c00a497
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/92950
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp
index 84070ca..835401d 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.cpp
+++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -74,12 +74,12 @@
return nullptr;
}
-RetainPtr<CFGAS_GEFont> CFGAS_PDFFontMgr::GetFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- bool bStrictMatch) {
- uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily);
- ByteString strKey = ByteString::Format("%u%u", dwHashCode, dwFontStyles);
- auto it = m_FontMap.find(strKey);
+RetainPtr<CFGAS_GEFont> CFGAS_PDFFontMgr::GetFont(
+ const WideString& wsFontFamily,
+ uint32_t dwFontStyles,
+ bool bStrictMatch) {
+ auto key = std::make_pair(wsFontFamily, dwFontStyles);
+ auto it = m_FontMap.find(key);
if (it != m_FontMap.end())
return it->second;
@@ -89,9 +89,10 @@
ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
RetainPtr<CFGAS_GEFont> pFont =
FindFont(strFontName, bBold, bItalic, bStrictMatch);
- if (pFont)
- m_FontMap[strKey] = pFont;
+ if (!pFont)
+ return nullptr;
+ m_FontMap[key] = pFont;
return pFont;
}
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.h b/xfa/fgas/font/cfgas_pdffontmgr.h
index 5d69ac0..a261c30 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.h
+++ b/xfa/fgas/font/cfgas_pdffontmgr.h
@@ -8,6 +8,7 @@
#define XFA_FGAS_FONT_CFGAS_PDFFONTMGR_H_
#include <map>
+#include <utility>
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/retain_ptr.h"
@@ -22,7 +23,7 @@
explicit CFGAS_PDFFontMgr(const CPDF_Document* pDoc);
~CFGAS_PDFFontMgr();
- RetainPtr<CFGAS_GEFont> GetFont(WideStringView wsFontFamily,
+ RetainPtr<CFGAS_GEFont> GetFont(const WideString& wsFontFamily,
uint32_t dwFontStyles,
bool bStrictMatch);
@@ -41,7 +42,7 @@
bool bStrictMatch);
UnownedPtr<const CPDF_Document> const m_pDoc;
- std::map<ByteString, RetainPtr<CFGAS_GEFont>> m_FontMap;
+ std::map<std::pair<WideString, uint32_t>, RetainPtr<CFGAS_GEFont>> m_FontMap;
};
#endif // XFA_FGAS_FONT_CFGAS_PDFFONTMGR_H_
diff --git a/xfa/fxfa/cxfa_fontmgr.cpp b/xfa/fxfa/cxfa_fontmgr.cpp
index 9ec76c8..283b768 100644
--- a/xfa/fxfa/cxfa_fontmgr.cpp
+++ b/xfa/fxfa/cxfa_fontmgr.cpp
@@ -34,7 +34,7 @@
CFGAS_PDFFontMgr* pMgr = hDoc->GetPDFFontMgr();
RetainPtr<CFGAS_GEFont> pFont;
if (pMgr) {
- pFont = pMgr->GetFont(wsEnglishName.AsStringView(), dwFontStyles, true);
+ pFont = pMgr->GetFont(wsEnglishName, dwFontStyles, true);
if (pFont)
return pFont;
}
@@ -42,7 +42,7 @@
pFont = CFGAS_DefaultFontManager::GetFont(wsFontFamily, dwFontStyles);
}
if (!pFont && pMgr) {
- pFont = pMgr->GetFont(wsEnglishName.AsStringView(), dwFontStyles, false);
+ pFont = pMgr->GetFont(wsEnglishName, dwFontStyles, false);
if (pFont)
return pFont;
}