diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-06-05 16:19:11 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-05 16:19:11 +0000 |
commit | d3d8287e143daf12a602a919c120b4e0c656abf8 (patch) | |
tree | a616529626c6cc5c021cbc5e1309be0ab67108b3 /core/fpdfapi/page | |
parent | eaba5af84597164281ddd972a5e98631b18d783b (diff) | |
download | pdfium-d3d8287e143daf12a602a919c120b4e0c656abf8.tar.xz |
Create m_ContentStream field in CPDF_PageObject.
Content streams are now split and can set nonzero values to identify
each parsed content stream.
Bug: pdfium:1051
Change-Id: Ia2cb1e0997db5264d468043af31f9b41e8d0d349
Reviewed-on: https://pdfium-review.googlesource.com/33591
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r-- | core/fpdfapi/page/cpdf_contentparser.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_formobject.cpp | 7 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_formobject.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_imageobject.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_imageobject.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pageobject.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pageobject.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pathobject.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_pathobject.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_shadingobject.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_shadingobject.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 21 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_textobject.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_textobject.h | 2 |
15 files changed, 48 insertions, 25 deletions
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp index 9e8f70ef18..c74a889ff6 100644 --- a/core/fpdfapi/page/cpdf_contentparser.cpp +++ b/core/fpdfapi/page/cpdf_contentparser.cpp @@ -168,7 +168,7 @@ CPDF_ContentParser::Stage CPDF_ContentParser::Parse() { m_CurrentOffset += m_pParser->Parse( m_StreamArray[m_CurrentStream]->GetData() + m_CurrentOffset, m_StreamArray[m_CurrentStream]->GetSize() - m_CurrentOffset, - PARSE_STEP_LIMIT); + PARSE_STEP_LIMIT, m_CurrentStream); if (m_CurrentOffset >= m_StreamArray[m_CurrentStream]->GetSize()) { m_CurrentOffset = 0; diff --git a/core/fpdfapi/page/cpdf_formobject.cpp b/core/fpdfapi/page/cpdf_formobject.cpp index eca92ca0ff..22ac0d3823 100644 --- a/core/fpdfapi/page/cpdf_formobject.cpp +++ b/core/fpdfapi/page/cpdf_formobject.cpp @@ -10,9 +10,12 @@ #include "core/fpdfapi/page/cpdf_form.h" -CPDF_FormObject::CPDF_FormObject(std::unique_ptr<CPDF_Form> pForm, +CPDF_FormObject::CPDF_FormObject(int32_t content_stream, + std::unique_ptr<CPDF_Form> pForm, const CFX_Matrix& matrix) - : m_pForm(std::move(pForm)), m_FormMatrix(matrix) {} + : CPDF_PageObject(content_stream), + m_pForm(std::move(pForm)), + m_FormMatrix(matrix) {} CPDF_FormObject::~CPDF_FormObject() {} diff --git a/core/fpdfapi/page/cpdf_formobject.h b/core/fpdfapi/page/cpdf_formobject.h index c723cc0eaf..b229dce444 100644 --- a/core/fpdfapi/page/cpdf_formobject.h +++ b/core/fpdfapi/page/cpdf_formobject.h @@ -16,7 +16,9 @@ class CPDF_Form; class CPDF_FormObject : public CPDF_PageObject { public: - CPDF_FormObject(std::unique_ptr<CPDF_Form> pForm, const CFX_Matrix& matrix); + CPDF_FormObject(int32_t content_stream, + std::unique_ptr<CPDF_Form> pForm, + const CFX_Matrix& matrix); ~CPDF_FormObject() override; // CPDF_PageObject: diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp index 3b5a740155..7826742276 100644 --- a/core/fpdfapi/page/cpdf_imageobject.cpp +++ b/core/fpdfapi/page/cpdf_imageobject.cpp @@ -12,7 +12,8 @@ #include "core/fpdfapi/page/cpdf_image.h" #include "core/fpdfapi/parser/cpdf_document.h" -CPDF_ImageObject::CPDF_ImageObject() {} +CPDF_ImageObject::CPDF_ImageObject(int32_t content_stream) + : CPDF_PageObject(content_stream) {} CPDF_ImageObject::~CPDF_ImageObject() { MaybePurgeCache(); diff --git a/core/fpdfapi/page/cpdf_imageobject.h b/core/fpdfapi/page/cpdf_imageobject.h index 16a506e537..465b1628ed 100644 --- a/core/fpdfapi/page/cpdf_imageobject.h +++ b/core/fpdfapi/page/cpdf_imageobject.h @@ -16,7 +16,7 @@ class CPDF_Image; class CPDF_ImageObject : public CPDF_PageObject { public: - CPDF_ImageObject(); + explicit CPDF_ImageObject(int32_t content_stream); ~CPDF_ImageObject() override; // CPDF_PageObject diff --git a/core/fpdfapi/page/cpdf_pageobject.cpp b/core/fpdfapi/page/cpdf_pageobject.cpp index 8bb5bf5978..582b9fff57 100644 --- a/core/fpdfapi/page/cpdf_pageobject.cpp +++ b/core/fpdfapi/page/cpdf_pageobject.cpp @@ -6,7 +6,8 @@ #include "core/fpdfapi/page/cpdf_pageobject.h" -CPDF_PageObject::CPDF_PageObject() : m_bDirty(false) {} +CPDF_PageObject::CPDF_PageObject(int32_t content_stream) + : m_bDirty(false), m_ContentStream(content_stream) {} CPDF_PageObject::~CPDF_PageObject() {} diff --git a/core/fpdfapi/page/cpdf_pageobject.h b/core/fpdfapi/page/cpdf_pageobject.h index d23cd971f8..b7cc5996c9 100644 --- a/core/fpdfapi/page/cpdf_pageobject.h +++ b/core/fpdfapi/page/cpdf_pageobject.h @@ -28,7 +28,7 @@ class CPDF_PageObject : public CPDF_GraphicStates { FORM, }; - CPDF_PageObject(); + explicit CPDF_PageObject(int32_t content_stream); ~CPDF_PageObject() override; virtual Type GetType() const = 0; @@ -58,6 +58,7 @@ class CPDF_PageObject : public CPDF_GraphicStates { return CFX_FloatRect(m_Left, m_Bottom, m_Right, m_Top); } FX_RECT GetBBox(const CFX_Matrix* pMatrix) const; + int32_t GetContentStream() const { return m_ContentStream; } float m_Left; float m_Right; @@ -73,6 +74,7 @@ class CPDF_PageObject : public CPDF_GraphicStates { void operator=(const CPDF_PageObject& src) = delete; bool m_bDirty; + int32_t m_ContentStream; }; #endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECT_H_ diff --git a/core/fpdfapi/page/cpdf_pathobject.cpp b/core/fpdfapi/page/cpdf_pathobject.cpp index d8c2cb8741..39ab134c92 100644 --- a/core/fpdfapi/page/cpdf_pathobject.cpp +++ b/core/fpdfapi/page/cpdf_pathobject.cpp @@ -6,7 +6,8 @@ #include "core/fpdfapi/page/cpdf_pathobject.h" -CPDF_PathObject::CPDF_PathObject() : m_FillType(0), m_bStroke(false) {} +CPDF_PathObject::CPDF_PathObject(int32_t content_stream) + : CPDF_PageObject(content_stream), m_FillType(0), m_bStroke(false) {} CPDF_PathObject::~CPDF_PathObject() {} diff --git a/core/fpdfapi/page/cpdf_pathobject.h b/core/fpdfapi/page/cpdf_pathobject.h index 58499b5a53..d4843d2fb6 100644 --- a/core/fpdfapi/page/cpdf_pathobject.h +++ b/core/fpdfapi/page/cpdf_pathobject.h @@ -14,7 +14,7 @@ class CPDF_PathObject : public CPDF_PageObject { public: - CPDF_PathObject(); + explicit CPDF_PathObject(int32_t content_stream); ~CPDF_PathObject() override; // CPDF_PageObject diff --git a/core/fpdfapi/page/cpdf_shadingobject.cpp b/core/fpdfapi/page/cpdf_shadingobject.cpp index 1b16ac4862..725e2e4591 100644 --- a/core/fpdfapi/page/cpdf_shadingobject.cpp +++ b/core/fpdfapi/page/cpdf_shadingobject.cpp @@ -9,9 +9,10 @@ #include "core/fpdfapi/page/cpdf_shadingpattern.h" #include "core/fpdfapi/parser/cpdf_document.h" -CPDF_ShadingObject::CPDF_ShadingObject(CPDF_ShadingPattern* pattern, +CPDF_ShadingObject::CPDF_ShadingObject(int32_t content_stream, + CPDF_ShadingPattern* pattern, const CFX_Matrix& matrix) - : m_pShading(pattern), m_Matrix(matrix) {} + : CPDF_PageObject(content_stream), m_pShading(pattern), m_Matrix(matrix) {} CPDF_ShadingObject::~CPDF_ShadingObject() {} diff --git a/core/fpdfapi/page/cpdf_shadingobject.h b/core/fpdfapi/page/cpdf_shadingobject.h index 80e062c729..69b606749d 100644 --- a/core/fpdfapi/page/cpdf_shadingobject.h +++ b/core/fpdfapi/page/cpdf_shadingobject.h @@ -15,7 +15,9 @@ class CPDF_ShadingPattern; class CPDF_ShadingObject : public CPDF_PageObject { public: - CPDF_ShadingObject(CPDF_ShadingPattern* pattern, const CFX_Matrix& matrix); + CPDF_ShadingObject(int32_t content_stream, + CPDF_ShadingPattern* pattern, + const CFX_Matrix& matrix); ~CPDF_ShadingObject() override; // CPDF_PageObject: diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 7e7c337d96..051d79ad1d 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -786,7 +786,8 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { CFX_Matrix matrix = m_pCurStates->m_CTM; matrix.Concat(m_mtContentToUser); - auto pFormObj = pdfium::MakeUnique<CPDF_FormObject>(std::move(form), matrix); + auto pFormObj = pdfium::MakeUnique<CPDF_FormObject>(m_CurrentContentStream, + std::move(form), matrix); if (!m_pObjectHolder->BackgroundAlphaNeeded() && pFormObj->form()->BackgroundAlphaNeeded()) { m_pObjectHolder->SetBackgroundAlphaNeeded(true); @@ -801,14 +802,14 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage( if (!pStream) return nullptr; - auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(); + auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(m_CurrentContentStream); pImageObj->SetImage( pdfium::MakeRetain<CPDF_Image>(m_pDocument.Get(), std::move(pStream))); return AddImageObject(std::move(pImageObj)); } CPDF_ImageObject* CPDF_StreamContentParser::AddImage(uint32_t streamObjNum) { - auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(); + auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(m_CurrentContentStream); pImageObj->SetImage(m_pDocument->LoadImageFromPageData(streamObjNum)); return AddImageObject(std::move(pImageObj)); } @@ -818,7 +819,7 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage( if (!pImage) return nullptr; - auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(); + auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(m_CurrentContentStream); pImageObj->SetImage( m_pDocument->GetPageData()->GetImage(pImage->GetStream()->GetObjNum())); @@ -1085,7 +1086,8 @@ void CPDF_StreamContentParser::Handle_ShadeFill() { CFX_Matrix matrix = m_pCurStates->m_CTM; matrix.Concat(m_mtContentToUser); - auto pObj = pdfium::MakeUnique<CPDF_ShadingObject>(pShading, matrix); + auto pObj = pdfium::MakeUnique<CPDF_ShadingObject>(m_CurrentContentStream, + pShading, matrix); SetGraphicStates(pObj.get(), false, false, false); CFX_FloatRect bbox = pObj->m_ClipPath.HasRef() ? pObj->m_ClipPath.GetClipBox() : m_BBox; @@ -1220,7 +1222,7 @@ void CPDF_StreamContentParser::AddTextObject(ByteString* pStrs, pFont->IsType3Font() ? TextRenderingMode::MODE_FILL : m_pCurStates->m_TextState.GetTextMode(); { - auto pText = pdfium::MakeUnique<CPDF_TextObject>(); + auto pText = pdfium::MakeUnique<CPDF_TextObject>(m_CurrentContentStream); m_pLastTextObject = pText.get(); SetGraphicStates(m_pLastTextObject.Get(), true, true, true); if (TextRenderingModeIsStrokeMode(text_mode)) { @@ -1457,7 +1459,7 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) { CFX_Matrix matrix = m_pCurStates->m_CTM; matrix.Concat(m_mtContentToUser); if (bStroke || FillType) { - auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); + auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(m_CurrentContentStream); pPathObj->m_bStroke = bStroke; pPathObj->m_FillType = FillType; pPathObj->m_Path = Path; @@ -1477,7 +1479,10 @@ void CPDF_StreamContentParser::AddPathObject(int FillType, bool bStroke) { uint32_t CPDF_StreamContentParser::Parse(const uint8_t* pData, uint32_t dwSize, - uint32_t max_cost) { + uint32_t max_cost, + uint32_t content_stream) { + m_CurrentContentStream = content_stream; + if (m_ParsedSet->size() > kMaxFormLevel || pdfium::ContainsKey(*m_ParsedSet, pData)) return dwSize; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h index 438be024cc..4c593998fd 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.h +++ b/core/fpdfapi/page/cpdf_streamcontentparser.h @@ -43,7 +43,10 @@ class CPDF_StreamContentParser { std::set<const uint8_t*>* parsedSet); ~CPDF_StreamContentParser(); - uint32_t Parse(const uint8_t* pData, uint32_t dwSize, uint32_t max_cost); + uint32_t Parse(const uint8_t* pData, + uint32_t dwSize, + uint32_t max_cost, + uint32_t content_stream); CPDF_PageObjectHolder* GetPageObjectHolder() const { return m_pObjectHolder.Get(); } @@ -230,6 +233,7 @@ class CPDF_StreamContentParser { std::vector<std::unique_ptr<CPDF_AllStates>> m_StateStack; float m_Type3Data[6]; ContentParam m_ParamBuf[kParamBufSize]; + uint32_t m_CurrentContentStream; }; #endif // CORE_FPDFAPI_PAGE_CPDF_STREAMCONTENTPARSER_H_ diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp index 36a4722773..68d20b6598 100644 --- a/core/fpdfapi/page/cpdf_textobject.cpp +++ b/core/fpdfapi/page/cpdf_textobject.cpp @@ -18,7 +18,8 @@ CPDF_TextObjectItem::CPDF_TextObjectItem() : m_CharCode(0) {} CPDF_TextObjectItem::~CPDF_TextObjectItem() = default; -CPDF_TextObject::CPDF_TextObject() {} +CPDF_TextObject::CPDF_TextObject(int32_t content_stream) + : CPDF_PageObject(content_stream) {} CPDF_TextObject::~CPDF_TextObject() { // Move m_CharCodes to a local variable so it will be captured in crash dumps, @@ -100,7 +101,7 @@ void CPDF_TextObject::GetCharInfo(size_t index, } std::unique_ptr<CPDF_TextObject> CPDF_TextObject::Clone() const { - auto obj = pdfium::MakeUnique<CPDF_TextObject>(); + auto obj = pdfium::MakeUnique<CPDF_TextObject>(-1); obj->CopyData(this); obj->m_CharCodes = m_CharCodes; obj->m_CharPos = m_CharPos; diff --git a/core/fpdfapi/page/cpdf_textobject.h b/core/fpdfapi/page/cpdf_textobject.h index a6fc62369c..3faccfdfe7 100644 --- a/core/fpdfapi/page/cpdf_textobject.h +++ b/core/fpdfapi/page/cpdf_textobject.h @@ -25,7 +25,7 @@ class CPDF_TextObjectItem { class CPDF_TextObject : public CPDF_PageObject { public: - CPDF_TextObject(); + explicit CPDF_TextObject(int32_t content_stream); ~CPDF_TextObject() override; // CPDF_PageObject |