summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/cmaps/cmap_int.h15
-rw-r--r--core/fpdfapi/cmaps/fpdf_cmaps.cpp47
-rw-r--r--core/fpdfapi/font/cpdf_cmap.cpp2
3 files changed, 31 insertions, 33 deletions
diff --git a/core/fpdfapi/cmaps/cmap_int.h b/core/fpdfapi/cmaps/cmap_int.h
index e661792843..15e153114e 100644
--- a/core/fpdfapi/cmaps/cmap_int.h
+++ b/core/fpdfapi/cmaps/cmap_int.h
@@ -11,22 +11,21 @@
#include "core/fxcrt/fx_system.h"
struct FXCMAP_CMap {
- enum MapType { None, Single, Range, Reverse };
+ enum MapType { None, Single, Range };
const char* m_Name;
MapType m_WordMapType;
const uint16_t* m_pWordMap;
- int m_WordCount;
+ uint16_t m_WordCount;
MapType m_DWordMapType;
const uint16_t* m_pDWordMap;
- int m_DWordCount;
- int m_UseOffset;
+ uint16_t m_DWordCount;
+ int8_t m_UseOffset;
};
-void FPDFAPI_FindEmbeddedCMap(const ByteString& name,
- int charset,
- int coding,
- const FXCMAP_CMap*& pMap);
+const FXCMAP_CMap* FPDFAPI_FindEmbeddedCMap(const ByteString& name,
+ int charset,
+ int coding);
uint16_t FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode);
uint32_t FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, uint16_t cid);
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
index ac8456dc69..051f493723 100644
--- a/core/fpdfapi/cmaps/fpdf_cmaps.cpp
+++ b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
@@ -53,11 +53,17 @@ static int compareDWordSingle(const void* p1, const void* p2) {
}; // extern "C"
-void FPDFAPI_FindEmbeddedCMap(const ByteString& bsName,
- int charset,
- int coding,
- const FXCMAP_CMap*& pMap) {
- pMap = nullptr;
+namespace {
+
+const FXCMAP_CMap* FindNextCMap(const FXCMAP_CMap* pMap) {
+ return pMap->m_UseOffset ? pMap + pMap->m_UseOffset : nullptr;
+}
+
+} // namespace
+
+const FXCMAP_CMap* FPDFAPI_FindEmbeddedCMap(const ByteString& bsName,
+ int charset,
+ int coding) {
CPDF_FontGlobals* pFontGlobals =
CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
@@ -65,16 +71,16 @@ void FPDFAPI_FindEmbeddedCMap(const ByteString& bsName,
uint32_t count;
std::tie(count, pCMaps) = pFontGlobals->GetEmbeddedCharset(charset);
for (uint32_t i = 0; i < count; i++) {
- if (bsName == pCMaps[i].m_Name) {
- pMap = &pCMaps[i];
- break;
- }
+ if (bsName == pCMaps[i].m_Name)
+ return &pCMaps[i];
}
+ return nullptr;
}
uint16_t FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode) {
+ ASSERT(pMap);
if (charcode >> 16) {
- while (1) {
+ while (pMap) {
if (pMap->m_DWordMapType == FXCMAP_CMap::Range) {
uint16_t* found = static_cast<uint16_t*>(
bsearch(&charcode, pMap->m_pDWordMap, pMap->m_DWordCount, 8,
@@ -89,16 +95,13 @@ uint16_t FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode) {
if (found)
return found[2];
}
- if (pMap->m_UseOffset == 0)
- return 0;
-
- pMap = pMap + pMap->m_UseOffset;
+ pMap = FindNextCMap(pMap);
}
return 0;
}
uint16_t code = (uint16_t)charcode;
- while (1) {
+ while (pMap) {
if (!pMap->m_pWordMap)
return 0;
if (pMap->m_WordMapType == FXCMAP_CMap::Single) {
@@ -113,10 +116,7 @@ uint16_t FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode) {
if (found)
return found[2] + code - found[0];
}
- if (pMap->m_UseOffset == 0)
- return 0;
-
- pMap = pMap + pMap->m_UseOffset;
+ pMap = FindNextCMap(pMap);
}
return 0;
}
@@ -127,7 +127,8 @@ uint32_t FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, uint16_t cid) {
// the first always returns. Investigate and determine how this should
// really be working. (https://codereview.chromium.org/2235743003 removed the
// second while loop.)
- while (1) {
+ ASSERT(pMap);
+ while (pMap) {
if (pMap->m_WordMapType == FXCMAP_CMap::Single) {
const uint16_t* pCur = pMap->m_pWordMap;
const uint16_t* pEnd = pMap->m_pWordMap + pMap->m_WordCount * 2;
@@ -147,9 +148,7 @@ uint32_t FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, uint16_t cid) {
pCur += 3;
}
}
- if (pMap->m_UseOffset == 0)
- return 0;
-
- pMap = pMap + pMap->m_UseOffset;
+ pMap = FindNextCMap(pMap);
}
+ return 0;
}
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp
index 1eabfff866..a654fcced3 100644
--- a/core/fpdfapi/font/cpdf_cmap.cpp
+++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -283,7 +283,7 @@ void CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr,
m_MixedTwoByteLeadingBytes[b] = true;
}
}
- FPDFAPI_FindEmbeddedCMap(bsName, m_Charset, m_Coding, m_pEmbedMap);
+ m_pEmbedMap = FPDFAPI_FindEmbeddedCMap(bsName, m_Charset, m_Coding);
if (!m_pEmbedMap)
return;