summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorwileyrya <wileyrr@gmail.com>2017-05-31 14:49:05 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-06-01 15:03:14 +0000
commite858aa4b70db7408bda1aed71827d9eee1dd98c5 (patch)
treeb80ff68a8a32487bb2511fb8d83af917e6e6583b /core
parent5be0b291bce26e1a12c9a7becb7c9a9e7857a456 (diff)
downloadpdfium-e858aa4b70db7408bda1aed71827d9eee1dd98c5.tar.xz
Fix content generation to only generate dirty page objects.
BUG=pdfium:717 R=dsinclair@chromium.org,thestig@chromium.org Change-Id: I7e0e6fd301d40f9b5341d40cf11167b7748af243 Reviewed-on: https://pdfium-review.googlesource.com/6071 Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp68
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.h1
-rw-r--r--core/fpdfapi/page/cpdf_imageobject.cpp1
-rw-r--r--core/fpdfapi/page/cpdf_pageobject.cpp5
-rw-r--r--core/fpdfapi/page/cpdf_pageobject.h4
-rw-r--r--core/fpdfapi/page/cpdf_pathobject.cpp1
-rw-r--r--core/fpdfapi/page/cpdf_textobject.cpp2
7 files changed, 69 insertions, 13 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 2cf10bd7cb..7abf7a4964 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -17,6 +17,7 @@
#include "core/fpdfapi/page/cpdf_path.h"
#include "core/fpdfapi/page/cpdf_pathobject.h"
#include "core/fpdfapi/page/cpdf_textobject.h"
+#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_name.h"
@@ -59,23 +60,49 @@ CPDF_PageContentGenerator::CPDF_PageContentGenerator(CPDF_Page* pPage)
CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {}
void CPDF_PageContentGenerator::GenerateContent() {
+ CPDF_Document* pDoc = m_pDocument.Get();
CFX_ByteTextBuf buf;
- for (auto& pPageObj : m_pageObjects) {
- if (CPDF_ImageObject* pImageObject = pPageObj->AsImage())
- ProcessImage(&buf, pImageObject);
- else if (CPDF_PathObject* pPathObj = pPageObj->AsPath())
- ProcessPath(&buf, pPathObj);
- else if (CPDF_TextObject* pTextObj = pPageObj->AsText())
- ProcessText(&buf, pTextObj);
+ if (!m_pageObjects.empty()) {
+ if (!ProcessPageObjects(&buf))
+ return;
}
CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict.Get();
CPDF_Object* pContent =
- pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr;
- if (pContent)
- pPageDict->RemoveFor("Contents");
-
- CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>();
+ pPageDict ? pPageDict->GetObjectFor("Contents") : nullptr;
+ CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>();
pStream->SetData(buf.GetBuffer(), buf.GetLength());
+ if (pContent) {
+ CPDF_Array* pArray = ToArray(pContent);
+ if (pArray) {
+ pArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
+ return;
+ }
+ CPDF_Reference* pReference = ToReference(pContent);
+ if (!pReference) {
+ pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument.Get(),
+ pStream->GetObjNum());
+ return;
+ }
+ CPDF_Object* pDirectObj = pReference->GetDirect();
+ if (!pDirectObj) {
+ pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument.Get(),
+ pStream->GetObjNum());
+ return;
+ }
+ CPDF_Array* pObjArray = pDirectObj->AsArray();
+ if (pObjArray) {
+ pObjArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
+ return;
+ }
+ if (pDirectObj->IsStream()) {
+ CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
+ pPageDict->SetNewFor<CPDF_Reference>("Contents", pDoc,
+ pContentArray->GetObjNum());
+ return;
+ }
+ }
pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument.Get(),
pStream->GetObjNum());
}
@@ -107,6 +134,23 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
return name;
}
+bool CPDF_PageContentGenerator::ProcessPageObjects(CFX_ByteTextBuf* buf) {
+ bool bDirty = false;
+ for (auto& pPageObj : m_pageObjects) {
+ if (!pPageObj->IsDirty())
+ continue;
+ bDirty = true;
+ if (CPDF_ImageObject* pImageObject = pPageObj->AsImage())
+ ProcessImage(buf, pImageObject);
+ else if (CPDF_PathObject* pPathObj = pPageObj->AsPath())
+ ProcessPath(buf, pPathObj);
+ else if (CPDF_TextObject* pTextObj = pPageObj->AsText())
+ ProcessText(buf, pTextObj);
+ pPageObj->SetDirty(false);
+ }
+ return bDirty;
+}
+
void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf* buf,
CPDF_ImageObject* pImageObj) {
if ((pImageObj->matrix().a == 0 && pImageObj->matrix().b == 0) ||
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
index 6c54d3130e..302375d536 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
@@ -30,6 +30,7 @@ class CPDF_PageContentGenerator {
private:
friend class CPDF_PageContentGeneratorTest;
+ bool ProcessPageObjects(CFX_ByteTextBuf* buf);
void ProcessPath(CFX_ByteTextBuf* buf, CPDF_PathObject* pPathObj);
void ProcessImage(CFX_ByteTextBuf* buf, CPDF_ImageObject* pImageObj);
void ProcessGraphics(CFX_ByteTextBuf* buf, CPDF_PageObject* pPageObj);
diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp
index 8732c00954..a74ac4802c 100644
--- a/core/fpdfapi/page/cpdf_imageobject.cpp
+++ b/core/fpdfapi/page/cpdf_imageobject.cpp
@@ -25,6 +25,7 @@ CPDF_PageObject::Type CPDF_ImageObject::GetType() const {
void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) {
m_Matrix.Concat(matrix);
CalcBoundingBox();
+ SetDirty(true);
}
bool CPDF_ImageObject::IsImage() const {
diff --git a/core/fpdfapi/page/cpdf_pageobject.cpp b/core/fpdfapi/page/cpdf_pageobject.cpp
index 09a98eee7d..79d9bbc540 100644
--- a/core/fpdfapi/page/cpdf_pageobject.cpp
+++ b/core/fpdfapi/page/cpdf_pageobject.cpp
@@ -6,7 +6,7 @@
#include "core/fpdfapi/page/cpdf_pageobject.h"
-CPDF_PageObject::CPDF_PageObject() {}
+CPDF_PageObject::CPDF_PageObject() : m_bDirty(false) {}
CPDF_PageObject::~CPDF_PageObject() {}
@@ -76,18 +76,21 @@ void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) {
m_Right = pSrc->m_Right;
m_Top = pSrc->m_Top;
m_Bottom = pSrc->m_Bottom;
+ m_bDirty = true;
}
void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) {
if (!m_ClipPath.HasRef())
return;
m_ClipPath.Transform(matrix);
+ SetDirty(true);
}
void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
if (!m_GeneralState.HasRef())
return;
m_GeneralState.GetMutableMatrix()->Concat(matrix);
+ SetDirty(true);
}
FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const {
diff --git a/core/fpdfapi/page/cpdf_pageobject.h b/core/fpdfapi/page/cpdf_pageobject.h
index 668621ff51..d23cd971f8 100644
--- a/core/fpdfapi/page/cpdf_pageobject.h
+++ b/core/fpdfapi/page/cpdf_pageobject.h
@@ -49,6 +49,8 @@ class CPDF_PageObject : public CPDF_GraphicStates {
virtual CPDF_FormObject* AsForm();
virtual const CPDF_FormObject* AsForm() const;
+ void SetDirty(bool value) { m_bDirty = value; }
+ bool IsDirty() const { return m_bDirty; }
void TransformClipPath(CFX_Matrix& matrix);
void TransformGeneralState(CFX_Matrix& matrix);
@@ -69,6 +71,8 @@ class CPDF_PageObject : public CPDF_GraphicStates {
private:
CPDF_PageObject(const CPDF_PageObject& src) = delete;
void operator=(const CPDF_PageObject& src) = delete;
+
+ bool m_bDirty;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_PAGEOBJECT_H_
diff --git a/core/fpdfapi/page/cpdf_pathobject.cpp b/core/fpdfapi/page/cpdf_pathobject.cpp
index c4d55bc20f..b54ad6e151 100644
--- a/core/fpdfapi/page/cpdf_pathobject.cpp
+++ b/core/fpdfapi/page/cpdf_pathobject.cpp
@@ -17,6 +17,7 @@ CPDF_PageObject::Type CPDF_PathObject::GetType() const {
void CPDF_PathObject::Transform(const CFX_Matrix& matrix) {
m_Matrix.Concat(matrix);
CalcBoundingBox();
+ SetDirty(true);
}
bool CPDF_PathObject::IsPath() const {
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp
index b8f3f61073..7a70101789 100644
--- a/core/fpdfapi/page/cpdf_textobject.cpp
+++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -115,6 +115,7 @@ void CPDF_TextObject::Transform(const CFX_Matrix& matrix) {
pTextMatrix[3] = text_matrix.d;
m_Pos = CFX_PointF(text_matrix.e, text_matrix.f);
CalcPositionData(0);
+ SetDirty(true);
}
bool CPDF_TextObject::IsText() const {
@@ -164,6 +165,7 @@ void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs,
void CPDF_TextObject::SetText(const CFX_ByteString& str) {
SetSegments(&str, nullptr, 1);
RecalcPositionData();
+ SetDirty(true);
}
float CPDF_TextObject::GetCharWidth(uint32_t charcode) const {