diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-06-26 17:20:28 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-26 17:20:28 +0000 |
commit | 785da23f6cce8004b8e7759345abd877dab953ea (patch) | |
tree | a1f15eb6e7c9b32c08803f775c01dd5e3225c206 /core/fpdfapi | |
parent | e529390fd5b521e4c223343a4b367b0ced357ed5 (diff) | |
download | pdfium-785da23f6cce8004b8e7759345abd877dab953ea.tar.xz |
Use pdfium::span in CPDF_CID2UnicodeMap.
Change-Id: Ie63f622674d9085fa45642c15e7ee8b22ca98555
Reviewed-on: https://pdfium-review.googlesource.com/36130
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-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; } |