summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-25 20:13:39 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-25 20:13:39 +0000
commitc356472262b736607d3daf07046d4796c3a51eee (patch)
treebbb772c2df30aba11b6b42b800fd9b622b247a22
parentbc84a6e9e091b9c8a3824c4d756225f5aef1c66b (diff)
downloadpdfium-c356472262b736607d3daf07046d4796c3a51eee.tar.xz
Use struct {Single,Range}Cmap in FPDFAPI_CIDFromCharCode().
Clearer that just using indexing off of raw pointers, and makes the code more closely resemble other functions. Change-Id: I7cc8363b505e66120bc1c686bb23b2bdf8fc401f Reviewed-on: https://pdfium-review.googlesource.com/38894 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fpdfapi/cmaps/fpdf_cmaps.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
index bb4a397aa4..ad1091910c 100644
--- a/core/fpdfapi/cmaps/fpdf_cmaps.cpp
+++ b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
@@ -15,6 +15,17 @@
namespace {
+struct SingleCmap {
+ uint16_t code;
+ uint16_t cid;
+};
+
+struct RangeCmap {
+ uint16_t low;
+ uint16_t high;
+ uint16_t cid;
+};
+
const FXCMAP_CMap* FindNextCMap(const FXCMAP_CMap* pMap) {
return pMap->m_UseOffset ? pMap + pMap->m_UseOffset : nullptr;
}
@@ -67,10 +78,6 @@ uint16_t FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode) {
if (!pMap->m_pWordMap)
return 0;
if (pMap->m_WordMapType == FXCMAP_CMap::Single) {
- struct SingleCmap {
- uint16_t code;
- uint16_t cid;
- };
const auto* begin = reinterpret_cast<const SingleCmap*>(pMap->m_pWordMap);
const auto* end = begin + pMap->m_WordCount;
const auto* found = std::lower_bound(
@@ -81,11 +88,6 @@ uint16_t FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode) {
return found->cid;
} else {
ASSERT(pMap->m_WordMapType == FXCMAP_CMap::Range);
- struct RangeCmap {
- uint16_t low;
- uint16_t high;
- uint16_t cid;
- };
const auto* begin = reinterpret_cast<const RangeCmap*>(pMap->m_pWordMap);
const auto* end = begin + pMap->m_WordCount;
const auto* found = std::lower_bound(
@@ -109,23 +111,21 @@ uint32_t FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, uint16_t cid) {
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;
+ const auto* pCur = reinterpret_cast<const SingleCmap*>(pMap->m_pWordMap);
+ const auto* pEnd = pCur + pMap->m_WordCount;
while (pCur < pEnd) {
- if (pCur[1] == cid)
- return pCur[0];
-
- pCur += 2;
+ if (pCur->cid == cid)
+ return pCur->code;
+ ++pCur;
}
} else {
ASSERT(pMap->m_WordMapType == FXCMAP_CMap::Range);
- const uint16_t* pCur = pMap->m_pWordMap;
- const uint16_t* pEnd = pMap->m_pWordMap + pMap->m_WordCount * 3;
+ const auto* pCur = reinterpret_cast<const RangeCmap*>(pMap->m_pWordMap);
+ const auto* pEnd = pCur + pMap->m_WordCount;
while (pCur < pEnd) {
- if (cid >= pCur[2] && cid <= pCur[2] + pCur[1] - pCur[0])
- return pCur[0] + cid - pCur[2];
-
- pCur += 3;
+ if (cid >= pCur->cid && cid <= pCur->cid + pCur->high - pCur->low)
+ return pCur->low + cid - pCur->cid;
+ ++pCur;
}
}
pMap = FindNextCMap(pMap);