Simplify POSIX font descriptor storage in CFGAS_FontMgr.
Use the existence of a key in the std::map as the indicator of whether a
given element is in the map, rather than the presence of absl::nullopt
values.
Change-Id: Ifc4de90998e2e465ea15ebaf2a93ff0e6b4d7c38
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/87734
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index f209e62..1da4dc7 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -666,11 +666,11 @@
uint32_t dwHash,
FX_CodePage wCodePage,
uint16_t /* wBitField*/) {
- if (!m_Hash2CandidateList[dwHash].has_value()) {
+ if (!pdfium::Contains(m_Hash2CandidateList, dwHash)) {
m_Hash2CandidateList[dwHash] =
MatchFonts(wCodePage, dwFontStyles, pszFontFamily, wUnicode);
}
- for (const auto& info : m_Hash2CandidateList[dwHash].value()) {
+ for (const auto& info : m_Hash2CandidateList[dwHash]) {
CFGAS_FontDescriptor* pDesc = info.pFont;
if (!VerifyUnicodeForFontDescriptor(pDesc, wUnicode))
continue;
@@ -806,16 +806,14 @@
RetainPtr<CFGAS_GEFont> pFont =
CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage);
#else // defined(OS_WIN)
- if (!m_Hash2CandidateList[dwHash].has_value()) {
+ if (!pdfium::Contains(m_Hash2CandidateList, dwHash)) {
m_Hash2CandidateList[dwHash] =
MatchFonts(wCodePage, dwFontStyles, WideString(pszFontFamily), 0);
}
- std::vector<CFGAS_FontDescriptorInfo>* sortedFontInfos =
- &m_Hash2CandidateList[dwHash].value();
- if (sortedFontInfos->empty())
+ if (m_Hash2CandidateList[dwHash].empty())
return nullptr;
- CFGAS_FontDescriptor* pDesc = (*sortedFontInfos)[0].pFont;
+ CFGAS_FontDescriptor* pDesc = m_Hash2CandidateList[dwHash].front().pFont;
RetainPtr<CFGAS_GEFont> pFont =
LoadFontInternal(pDesc->m_wsFaceName, pDesc->m_nFaceIndex);
#endif // defined(OS_WIN)
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 801c974..ec9e972 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -19,7 +19,6 @@
#include "core/fxcrt/widestring.h"
#include "core/fxge/cfx_face.h"
#include "core/fxge/fx_freetype.h"
-#include "third_party/abseil-cpp/absl/types/optional.h"
class CFGAS_GEFont;
class IFX_SeekableReadStream;
@@ -137,7 +136,7 @@
std::deque<FX_FONTDESCRIPTOR> m_FontFaces;
#else
std::vector<std::unique_ptr<CFGAS_FontDescriptor>> m_InstalledFonts;
- std::map<uint32_t, absl::optional<std::vector<CFGAS_FontDescriptorInfo>>>
+ std::map<uint32_t, std::vector<CFGAS_FontDescriptorInfo>>
m_Hash2CandidateList;
#endif // defined(OS_WIN)
};