From 41bf73a2c389d8fa811cabb1867b8b6a5585d5eb Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 4 Oct 2017 14:52:34 -0400 Subject: Remove CPDF_CMapParser friends This CL removes the friends from CPDF_CMapParser. The two needed methods have been moved from private statics to public methods on the class. Change-Id: Ida76aa8748435e089874d9ef9c6545527b175561 Reviewed-on: https://pdfium-review.googlesource.com/15454 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- core/fpdfapi/font/cpdf_cmapparser.cpp | 17 +++++------ core/fpdfapi/font/cpdf_cmapparser.h | 12 +++----- core/fpdfapi/font/cpdf_cmapparser_unittest.cpp | 42 ++++++++++++++------------ 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 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 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("", "")); + EXPECT_FALSE(parser.GetCodeRange(range, "", "")); 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, "", "")); + EXPECT_TRUE(parser.GetCodeRange(range, "", "")); 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, "", "")); + EXPECT_TRUE(parser.GetCodeRange(range, "", "")); EXPECT_EQ(1u, range.m_CharSize); EXPECT_EQ(161, range.m_Lower[0]); EXPECT_EQ(0, range.m_Upper[0]); -- cgit v1.2.3