summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-08-28 18:00:37 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-08-29 13:37:46 +0000
commit081d41208489a318163a306789de4139b2dddfc7 (patch)
treee0bc3c7e2ad095013cd5398e65a7a0d067e62284
parent7bec2ff744a71a0a7e0fec86be13095a323375ab (diff)
downloadpdfium-081d41208489a318163a306789de4139b2dddfc7.tar.xz
Make some CPDF_StreamContentParser methods static.
For methods that are only exposed for testing. Once they are static, there is no need for dummy CPDF_StreamContentParser constructor calls in the unit tests. Adjust the CPDF_StreamContentParser constructor now that one of the parameters can no longer be a nullptr. Change-Id: If29b02ea216002a7bb325b1913281f58b70382aa Reviewed-on: https://pdfium-review.googlesource.com/12230 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.cpp4
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp7
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.h12
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser_unittest.cpp38
4 files changed, 34 insertions, 27 deletions
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 36dea17572..f7aef176bf 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -99,7 +99,7 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm,
CPDF_Dictionary* pResources = pForm->m_pFormDict->GetDictFor("Resources");
m_pParser = pdfium::MakeUnique<CPDF_StreamContentParser>(
pForm->m_pDocument.Get(), pForm->m_pPageResources.Get(),
- pForm->m_pResources.Get(), pParentMatrix, pForm, pResources, &form_bbox,
+ pForm->m_pResources.Get(), pParentMatrix, pForm, pResources, form_bbox,
pGraphicStates, level);
m_pParser->GetCurStates()->m_CTM = form_matrix;
m_pParser->GetCurStates()->m_ParentMatrix = form_matrix;
@@ -172,7 +172,7 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
m_pObjectHolder->m_pDocument.Get(),
m_pObjectHolder->m_pPageResources.Get(), nullptr, nullptr,
m_pObjectHolder.Get(), m_pObjectHolder->m_pResources.Get(),
- &m_pObjectHolder->m_BBox, nullptr, 0);
+ m_pObjectHolder->m_BBox, nullptr, 0);
m_pParser->GetCurStates()->m_ColorState.SetDefault();
}
if (m_CurrentOffset >= m_Size) {
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 6f09f92c60..a6af91d9ff 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -241,7 +241,7 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
const CFX_Matrix* pmtContentToUser,
CPDF_PageObjectHolder* pObjHolder,
CPDF_Dictionary* pResources,
- CFX_FloatRect* pBBox,
+ const CFX_FloatRect& rcBBox,
CPDF_AllStates* pStates,
int level)
: m_pDocument(pDocument),
@@ -250,6 +250,7 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
m_pResources(pResources),
m_pObjectHolder(pObjHolder),
m_Level(level),
+ m_BBox(rcBBox),
m_ParamStartPos(0),
m_ParamCount(0),
m_pCurStates(pdfium::MakeUnique<CPDF_AllStates>()),
@@ -269,8 +270,6 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
m_pResources = m_pParentResources;
if (!m_pResources)
m_pResources = m_pPageResources;
- if (pBBox)
- m_BBox = *pBBox;
if (pStates) {
m_pCurStates->Copy(*pStates);
} else {
@@ -1625,11 +1624,13 @@ void CPDF_StreamContentParser::ParsePathObject() {
}
}
+// static
CFX_ByteStringC CPDF_StreamContentParser::FindKeyAbbreviationForTesting(
const CFX_ByteStringC& abbr) {
return FindFullName(InlineKeyAbbr, FX_ArraySize(InlineKeyAbbr), abbr);
}
+// static
CFX_ByteStringC CPDF_StreamContentParser::FindValueAbbreviationForTesting(
const CFX_ByteStringC& abbr) {
return FindFullName(InlineValueAbbr, FX_ArraySize(InlineValueAbbr), abbr);
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h
index 41385558d3..5cbe0ce734 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.h
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.h
@@ -37,7 +37,7 @@ class CPDF_StreamContentParser {
const CFX_Matrix* pmtContentToUser,
CPDF_PageObjectHolder* pObjectHolder,
CPDF_Dictionary* pResources,
- CFX_FloatRect* pBBox,
+ const CFX_FloatRect& rcBBox,
CPDF_AllStates* pAllStates,
int level);
~CPDF_StreamContentParser();
@@ -51,8 +51,10 @@ class CPDF_StreamContentParser {
const float* GetType3Data() const { return m_Type3Data; }
CPDF_Font* FindFont(const CFX_ByteString& name);
- CFX_ByteStringC FindKeyAbbreviationForTesting(const CFX_ByteStringC& abbr);
- CFX_ByteStringC FindValueAbbreviationForTesting(const CFX_ByteStringC& abbr);
+ static CFX_ByteStringC FindKeyAbbreviationForTesting(
+ const CFX_ByteStringC& abbr);
+ static CFX_ByteStringC FindValueAbbreviationForTesting(
+ const CFX_ByteStringC& abbr);
private:
struct ContentParam {
@@ -196,9 +198,9 @@ class CPDF_StreamContentParser {
CFX_UnownedPtr<CPDF_Dictionary> m_pParentResources;
CFX_UnownedPtr<CPDF_Dictionary> m_pResources;
CFX_UnownedPtr<CPDF_PageObjectHolder> m_pObjectHolder;
- int m_Level;
+ const int m_Level;
CFX_Matrix m_mtContentToUser;
- CFX_FloatRect m_BBox;
+ const CFX_FloatRect m_BBox;
ContentParam m_ParamBuf[kParamBufSize];
uint32_t m_ParamStartPos;
uint32_t m_ParamCount;
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser_unittest.cpp b/core/fpdfapi/page/cpdf_streamcontentparser_unittest.cpp
index ffc0d95107..6b43935a1d 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser_unittest.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser_unittest.cpp
@@ -6,35 +6,39 @@
#include "testing/gtest/include/gtest/gtest.h"
TEST(cpdf_streamcontentparser, PDF_FindKeyAbbreviation) {
- CPDF_StreamContentParser parser(nullptr, nullptr, nullptr, nullptr, nullptr,
- nullptr, nullptr, nullptr, 0);
-
EXPECT_EQ(CFX_ByteStringC("BitsPerComponent"),
- parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("BPC")));
+ CPDF_StreamContentParser::FindKeyAbbreviationForTesting(
+ CFX_ByteStringC("BPC")));
EXPECT_EQ(CFX_ByteStringC("Width"),
- parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("W")));
+ CPDF_StreamContentParser::FindKeyAbbreviationForTesting(
+ CFX_ByteStringC("W")));
EXPECT_EQ(CFX_ByteStringC(""),
- parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("")));
+ CPDF_StreamContentParser::FindKeyAbbreviationForTesting(
+ CFX_ByteStringC("")));
EXPECT_EQ(CFX_ByteStringC(""),
- parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("NoInList")));
+ CPDF_StreamContentParser::FindKeyAbbreviationForTesting(
+ CFX_ByteStringC("NoInList")));
// Prefix should not match.
EXPECT_EQ(CFX_ByteStringC(""),
- parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("WW")));
+ CPDF_StreamContentParser::FindKeyAbbreviationForTesting(
+ CFX_ByteStringC("WW")));
}
TEST(cpdf_streamcontentparser, PDF_FindValueAbbreviation) {
- CPDF_StreamContentParser parser(nullptr, nullptr, nullptr, nullptr, nullptr,
- nullptr, nullptr, nullptr, 0);
-
EXPECT_EQ(CFX_ByteStringC("DeviceGray"),
- parser.FindValueAbbreviationForTesting(CFX_ByteStringC("G")));
+ CPDF_StreamContentParser::FindValueAbbreviationForTesting(
+ CFX_ByteStringC("G")));
EXPECT_EQ(CFX_ByteStringC("DCTDecode"),
- parser.FindValueAbbreviationForTesting(CFX_ByteStringC("DCT")));
+ CPDF_StreamContentParser::FindValueAbbreviationForTesting(
+ CFX_ByteStringC("DCT")));
+ EXPECT_EQ(CFX_ByteStringC(""),
+ CPDF_StreamContentParser::FindValueAbbreviationForTesting(
+ CFX_ByteStringC("")));
EXPECT_EQ(CFX_ByteStringC(""),
- parser.FindValueAbbreviationForTesting(CFX_ByteStringC("")));
- EXPECT_EQ(CFX_ByteStringC(""), parser.FindValueAbbreviationForTesting(
- CFX_ByteStringC("NoInList")));
+ CPDF_StreamContentParser::FindValueAbbreviationForTesting(
+ CFX_ByteStringC("NoInList")));
// Prefix should not match.
EXPECT_EQ(CFX_ByteStringC(""),
- parser.FindValueAbbreviationForTesting(CFX_ByteStringC("II")));
+ CPDF_StreamContentParser::FindValueAbbreviationForTesting(
+ CFX_ByteStringC("II")));
}