summaryrefslogtreecommitdiff
path: root/core/fpdfapi/cmaps
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-11-02 18:30:32 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-02 18:30:32 +0000
commit92492c1455e59c18f274c1f2b3ecfe9d042509fa (patch)
tree3f0daa69d9f4e82fedcd71aecd0f140573e8dd73 /core/fpdfapi/cmaps
parent8a884a481d9f31dbb2d21972b52639b33626b4de (diff)
downloadpdfium-92492c1455e59c18f274c1f2b3ecfe9d042509fa.tar.xz
Simplify some CMap code.
Change-Id: Ie7eb2605a789d2c841cb1dc123509f473c4c5a5e Reviewed-on: https://pdfium-review.googlesource.com/17410 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/cmaps')
-rw-r--r--core/fpdfapi/cmaps/cmap_int.h15
-rw-r--r--core/fpdfapi/cmaps/fpdf_cmaps.cpp47
2 files changed, 30 insertions, 32 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;
}