diff options
-rw-r--r-- | core/fpdfapi/font/cpdf_cid2unicodemap.cpp | 24 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_cid2unicodemap.h | 8 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_cidfont.cpp | 20 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_fontglobals.h | 7 |
4 files changed, 26 insertions, 33 deletions
diff --git a/core/fpdfapi/font/cpdf_cid2unicodemap.cpp b/core/fpdfapi/font/cpdf_cid2unicodemap.cpp index 650856419a..b2e435b5f1 100644 --- a/core/fpdfapi/font/cpdf_cid2unicodemap.cpp +++ b/core/fpdfapi/font/cpdf_cid2unicodemap.cpp @@ -10,23 +10,21 @@ #include "core/fpdfapi/font/cpdf_cmapmanager.h" #include "core/fpdfapi/page/cpdf_pagemodule.h" -CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() { - m_EmbeddedCount = 0; -} +CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() = default; -CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() {} +CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() = default; -bool CPDF_CID2UnicodeMap::IsLoaded() { - return m_EmbeddedCount != 0; +bool CPDF_CID2UnicodeMap::IsLoaded() const { + return !m_pEmbeddedMap.empty(); } -wchar_t CPDF_CID2UnicodeMap::UnicodeFromCID(uint16_t CID) { - if (m_Charset == CIDSET_UNICODE) { +wchar_t CPDF_CID2UnicodeMap::UnicodeFromCID(uint16_t CID) const { + if (m_Charset == CIDSET_UNICODE) return CID; - } - if (CID < m_EmbeddedCount) { + + if (CID < m_pEmbeddedMap.size()) return m_pEmbeddedMap[CID]; - } + return 0; } @@ -37,6 +35,6 @@ void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); - std::tie(m_EmbeddedCount, m_pEmbeddedMap) = - pFontGlobals->GetEmbeddedToUnicode(charset); + + m_pEmbeddedMap = pFontGlobals->GetEmbeddedToUnicode(charset); } diff --git a/core/fpdfapi/font/cpdf_cid2unicodemap.h b/core/fpdfapi/font/cpdf_cid2unicodemap.h index 2c3fe5b7aa..73c5059558 100644 --- a/core/fpdfapi/font/cpdf_cid2unicodemap.h +++ b/core/fpdfapi/font/cpdf_cid2unicodemap.h @@ -8,6 +8,7 @@ #define CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_ #include "core/fpdfapi/font/cpdf_cidfont.h" +#include "third_party/base/span.h" class CPDF_CMapManager; @@ -16,14 +17,13 @@ class CPDF_CID2UnicodeMap { CPDF_CID2UnicodeMap(); ~CPDF_CID2UnicodeMap(); - bool IsLoaded(); + bool IsLoaded() const; + wchar_t UnicodeFromCID(uint16_t CID) const; void Load(CPDF_CMapManager* pMgr, CIDSet charset, bool bPromptCJK); - wchar_t UnicodeFromCID(uint16_t CID); private: CIDSet m_Charset; - const uint16_t* m_pEmbeddedMap; - uint32_t m_EmbeddedCount; + pdfium::span<const uint16_t> m_pEmbeddedMap; }; #endif // CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_ diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 4b4f04ba5f..ef471d02f1 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp @@ -23,6 +23,7 @@ #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "third_party/base/numerics/safe_math.h" #include "third_party/base/ptr_util.h" +#include "third_party/base/span.h" #include "third_party/base/stl_util.h" namespace { @@ -150,12 +151,9 @@ wchar_t EmbeddedUnicodeFromCharcode(const FXCMAP_CMap* pEmbedMap, if (!cid) return 0; - const uint16_t* map; - uint32_t count; - std::tie(count, map) = GetFontGlobals()->GetEmbeddedToUnicode(charset); - if (map && cid < count) - return map[cid]; - return 0; + pdfium::span<const uint16_t> map = + GetFontGlobals()->GetEmbeddedToUnicode(charset); + return cid < map.size() ? map[cid] : 0; } uint32_t EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap, @@ -164,13 +162,9 @@ uint32_t EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap, if (!IsValidEmbeddedCharcodeFromUnicodeCharset(charset)) return 0; - const uint16_t* map; - uint32_t count; - std::tie(count, map) = GetFontGlobals()->GetEmbeddedToUnicode(charset); - if (!map) - return 0; - - for (uint32_t i = 0; i < count; ++i) { + pdfium::span<const uint16_t> map = + GetFontGlobals()->GetEmbeddedToUnicode(charset); + for (uint32_t i = 0; i < map.size(); ++i) { if (map[i] == unicode) { uint32_t charCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i); if (charCode) diff --git a/core/fpdfapi/font/cpdf_fontglobals.h b/core/fpdfapi/font/cpdf_fontglobals.h index a47dfa13d0..2663490925 100644 --- a/core/fpdfapi/font/cpdf_fontglobals.h +++ b/core/fpdfapi/font/cpdf_fontglobals.h @@ -14,6 +14,7 @@ #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/font/cfx_stockfontarray.h" #include "core/fpdfapi/font/cpdf_cmapmanager.h" +#include "third_party/base/span.h" class CPDF_FontGlobals { public: @@ -40,9 +41,9 @@ class CPDF_FontGlobals { m_EmbeddedToUnicodes[idx].m_pMap = map; m_EmbeddedToUnicodes[idx].m_Count = count; } - std::pair<uint32_t, const uint16_t*> GetEmbeddedToUnicode(size_t idx) { - return {m_EmbeddedToUnicodes[idx].m_Count, - m_EmbeddedToUnicodes[idx].m_pMap}; + pdfium::span<const uint16_t> GetEmbeddedToUnicode(size_t idx) { + return pdfium::make_span(m_EmbeddedToUnicodes[idx].m_pMap, + m_EmbeddedToUnicodes[idx].m_Count); } CPDF_CMapManager* GetCMapManager() { return &m_CMapManager; } |