summaryrefslogtreecommitdiff
path: root/core/fpdfapi/font
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/font')
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser.cpp17
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser.h12
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser_unittest.cpp42
3 files changed, 35 insertions, 36 deletions
diff --git a/core/fpdfapi/font/cpdf_cmapparser.cpp b/core/fpdfapi/font/cpdf_cmapparser.cpp
index 4c74761ec9..fbd6daf851 100644
--- a/core/fpdfapi/font/cpdf_cmapparser.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser.cpp
@@ -70,7 +70,7 @@ void CPDF_CMapParser::ParseWord(const ByteStringView& word) {
m_CodeSeq = 0;
} else if (word == "usecmap") {
} else if (m_Status == 1 || m_Status == 2) {
- m_CodePoints[m_CodeSeq] = CMap_GetCode(word);
+ m_CodePoints[m_CodeSeq] = GetCode(word);
m_CodeSeq++;
uint32_t StartCode, EndCode;
uint16_t StartCID;
@@ -106,7 +106,7 @@ void CPDF_CMapParser::ParseWord(const ByteStringView& word) {
} else if (m_Status == 5) {
m_Status = 0;
} else if (m_Status == 6) {
- m_pCMap->SetVertical(CMap_GetCode(word) != 0);
+ m_pCMap->SetVertical(GetCode(word) != 0);
m_Status = 0;
} else if (m_Status == 7) {
if (word == "endcodespacerange") {
@@ -126,7 +126,7 @@ void CPDF_CMapParser::ParseWord(const ByteStringView& word) {
}
if (m_CodeSeq % 2) {
CPDF_CMap::CodeRange range;
- if (CMap_GetCodeRange(range, m_LastWord.AsStringView(), word))
+ if (GetCodeRange(range, m_LastWord.AsStringView(), word))
m_CodeRanges.push_back(range);
}
m_CodeSeq++;
@@ -135,10 +135,10 @@ void CPDF_CMapParser::ParseWord(const ByteStringView& word) {
m_LastWord = word;
}
-// Static.
-uint32_t CPDF_CMapParser::CMap_GetCode(const ByteStringView& word) {
+uint32_t CPDF_CMapParser::GetCode(const ByteStringView& word) const {
if (word.IsEmpty())
return 0;
+
pdfium::base::CheckedNumeric<uint32_t> num = 0;
if (word[0] == '<') {
for (size_t i = 1; i < word.GetLength() && std::isxdigit(word[i]); ++i) {
@@ -157,10 +157,9 @@ uint32_t CPDF_CMapParser::CMap_GetCode(const ByteStringView& word) {
return num.ValueOrDie();
}
-// Static.
-bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
- const ByteStringView& first,
- const ByteStringView& second) {
+bool CPDF_CMapParser::GetCodeRange(CPDF_CMap::CodeRange& range,
+ const ByteStringView& first,
+ const ByteStringView& second) const {
if (first.GetLength() == 0 || first[0] != '<')
return false;
diff --git a/core/fpdfapi/font/cpdf_cmapparser.h b/core/fpdfapi/font/cpdf_cmapparser.h
index 874f6a776d..fc46c58f72 100644
--- a/core/fpdfapi/font/cpdf_cmapparser.h
+++ b/core/fpdfapi/font/cpdf_cmapparser.h
@@ -28,16 +28,14 @@ class CPDF_CMapParser {
return std::move(m_AdditionalCharcodeToCIDMappings);
}
+ uint32_t GetCode(const ByteStringView& word) const;
+ bool GetCodeRange(CPDF_CMap::CodeRange& range,
+ const ByteStringView& first,
+ const ByteStringView& second) const;
+
static CIDSet CharsetFromOrdering(const ByteStringView& ordering);
private:
- friend class cpdf_cmapparser_CMap_GetCode_Test;
- friend class cpdf_cmapparser_CMap_GetCodeRange_Test;
-
- static uint32_t CMap_GetCode(const ByteStringView& word);
- static bool CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
- const ByteStringView& first,
- const ByteStringView& second);
UnownedPtr<CPDF_CMap> const m_pCMap;
int m_Status;
diff --git a/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp b/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
index 8d99b0dbff..1a36eb79ac 100644
--- a/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
@@ -18,37 +18,39 @@ bool uint_ranges_equal(uint8_t* a, uint8_t* b, size_t count) {
} // namespace
-TEST(cpdf_cmapparser, CMap_GetCode) {
- EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode(""));
- EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<"));
- EXPECT_EQ(194u, CPDF_CMapParser::CMap_GetCode("<c2"));
- EXPECT_EQ(162u, CPDF_CMapParser::CMap_GetCode("<A2"));
- EXPECT_EQ(2802u, CPDF_CMapParser::CMap_GetCode("<Af2"));
- EXPECT_EQ(162u, CPDF_CMapParser::CMap_GetCode("<A2z"));
+TEST(cpdf_cmapparser, GetCode) {
+ CPDF_CMapParser parser(nullptr);
- EXPECT_EQ(12u, CPDF_CMapParser::CMap_GetCode("12"));
- EXPECT_EQ(12u, CPDF_CMapParser::CMap_GetCode("12d"));
- EXPECT_EQ(128u, CPDF_CMapParser::CMap_GetCode("128"));
+ EXPECT_EQ(0u, parser.GetCode(""));
+ EXPECT_EQ(0u, parser.GetCode("<"));
+ EXPECT_EQ(194u, parser.GetCode("<c2"));
+ EXPECT_EQ(162u, parser.GetCode("<A2"));
+ EXPECT_EQ(2802u, parser.GetCode("<Af2"));
+ EXPECT_EQ(162u, parser.GetCode("<A2z"));
- EXPECT_EQ(4294967295u, CPDF_CMapParser::CMap_GetCode("<FFFFFFFF"));
+ EXPECT_EQ(12u, parser.GetCode("12"));
+ EXPECT_EQ(12u, parser.GetCode("12d"));
+ EXPECT_EQ(128u, parser.GetCode("128"));
+
+ EXPECT_EQ(4294967295u, parser.GetCode("<FFFFFFFF"));
// Overflow a uint32_t.
- EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<100000000"));
+ EXPECT_EQ(0u, parser.GetCode("<100000000"));
}
-TEST(cpdf_cmapparser, CMap_GetCodeRange) {
+TEST(cpdf_cmapparser, GetCodeRange) {
+ CPDF_CMapParser parser(nullptr);
CPDF_CMap::CodeRange range;
// Must start with a <
- EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "", ""));
- EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "A", ""));
+ EXPECT_FALSE(parser.GetCodeRange(range, "", ""));
+ EXPECT_FALSE(parser.GetCodeRange(range, "A", ""));
// m_CharSize must be <= 4
- EXPECT_FALSE(CPDF_CMapParser::CMap_GetCodeRange(range, "<aaaaaaaaaa>", ""));
+ EXPECT_FALSE(parser.GetCodeRange(range, "<aaaaaaaaaa>", ""));
EXPECT_EQ(5u, range.m_CharSize);
- EXPECT_TRUE(
- CPDF_CMapParser::CMap_GetCodeRange(range, "<12345678>", "<87654321>"));
+ EXPECT_TRUE(parser.GetCodeRange(range, "<12345678>", "<87654321>"));
EXPECT_EQ(4u, range.m_CharSize);
{
uint8_t lower[4] = {18, 52, 86, 120};
@@ -58,13 +60,13 @@ TEST(cpdf_cmapparser, CMap_GetCodeRange) {
}
// Hex characters
- EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", "<F3>"));
+ EXPECT_TRUE(parser.GetCodeRange(range, "<a1>", "<F3>"));
EXPECT_EQ(1u, range.m_CharSize);
EXPECT_EQ(161, range.m_Lower[0]);
EXPECT_EQ(243, range.m_Upper[0]);
// The second string should return 0's if it is shorter
- EXPECT_TRUE(CPDF_CMapParser::CMap_GetCodeRange(range, "<a1>", ""));
+ EXPECT_TRUE(parser.GetCodeRange(range, "<a1>", ""));
EXPECT_EQ(1u, range.m_CharSize);
EXPECT_EQ(161, range.m_Lower[0]);
EXPECT_EQ(0, range.m_Upper[0]);