summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/page/cpdf_contentmark.cpp50
-rw-r--r--core/fpdfapi/page/cpdf_contentmark.h10
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp12
-rw-r--r--fpdfsdk/fpdf_editpage.cpp2
4 files changed, 52 insertions, 22 deletions
diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp
index 912cc0ea03..08b38f20c2 100644
--- a/core/fpdfapi/page/cpdf_contentmark.cpp
+++ b/core/fpdfapi/page/cpdf_contentmark.cpp
@@ -46,13 +46,26 @@ int CPDF_ContentMark::GetMarkedContentID() const {
return m_pMarkData->GetMarkedContentID();
}
-void CPDF_ContentMark::AddMark(ByteString name,
- CPDF_Dictionary* pDict,
- bool bDirect) {
+void CPDF_ContentMark::AddMark(ByteString name) {
+ EnsureMarkDataExists();
+ m_pMarkData->AddMark(std::move(name));
+}
+
+void CPDF_ContentMark::AddMarkWithDirectDict(ByteString name,
+ CPDF_Dictionary* pDict) {
+ EnsureMarkDataExists();
+ m_pMarkData->AddMarkWithDirectDict(std::move(name), pDict);
+}
+
+void CPDF_ContentMark::AddMarkWithPropertiesDict(ByteString name,
+ CPDF_Dictionary* pDict) {
+ EnsureMarkDataExists();
+ m_pMarkData->AddMarkWithPropertiesDict(std::move(name), pDict);
+}
+
+void CPDF_ContentMark::EnsureMarkDataExists() {
if (!m_pMarkData)
m_pMarkData.Reset(new MarkData());
-
- m_pMarkData->AddMark(std::move(name), pDict, bDirect);
}
void CPDF_ContentMark::DeleteLastMark() {
@@ -93,17 +106,26 @@ int CPDF_ContentMark::MarkData::GetMarkedContentID() const {
return -1;
}
-void CPDF_ContentMark::MarkData::AddMark(ByteString name,
- CPDF_Dictionary* pDict,
- bool bDirect) {
+void CPDF_ContentMark::MarkData::AddMark(ByteString name) {
auto pItem = pdfium::MakeRetain<CPDF_ContentMarkItem>();
pItem->SetName(std::move(name));
- if (pDict) {
- if (bDirect)
- pItem->SetDirectDict(ToDictionary(pDict->Clone()));
- else
- pItem->SetPropertiesDict(pDict);
- }
+ m_Marks.push_back(pItem);
+}
+
+void CPDF_ContentMark::MarkData::AddMarkWithDirectDict(ByteString name,
+ CPDF_Dictionary* pDict) {
+ auto pItem = pdfium::MakeRetain<CPDF_ContentMarkItem>();
+ pItem->SetName(std::move(name));
+ pItem->SetDirectDict(ToDictionary(pDict->Clone()));
+ m_Marks.push_back(pItem);
+}
+
+void CPDF_ContentMark::MarkData::AddMarkWithPropertiesDict(
+ ByteString name,
+ CPDF_Dictionary* pDict) {
+ auto pItem = pdfium::MakeRetain<CPDF_ContentMarkItem>();
+ pItem->SetName(std::move(name));
+ pItem->SetPropertiesDict(pDict);
m_Marks.push_back(pItem);
}
diff --git a/core/fpdfapi/page/cpdf_contentmark.h b/core/fpdfapi/page/cpdf_contentmark.h
index e0ae1bf549..b9b10b0a48 100644
--- a/core/fpdfapi/page/cpdf_contentmark.h
+++ b/core/fpdfapi/page/cpdf_contentmark.h
@@ -29,7 +29,9 @@ class CPDF_ContentMark {
CPDF_ContentMarkItem* GetItem(size_t i);
const CPDF_ContentMarkItem* GetItem(size_t i) const;
- void AddMark(ByteString name, CPDF_Dictionary* pDict, bool bDirect);
+ void AddMark(ByteString name);
+ void AddMarkWithDirectDict(ByteString name, CPDF_Dictionary* pDict);
+ void AddMarkWithPropertiesDict(ByteString name, CPDF_Dictionary* pDict);
void DeleteLastMark();
private:
@@ -44,13 +46,17 @@ class CPDF_ContentMark {
const CPDF_ContentMarkItem* GetItem(size_t index) const;
int GetMarkedContentID() const;
- void AddMark(ByteString name, CPDF_Dictionary* pDict, bool bDictNeedClone);
+ void AddMark(ByteString name);
+ void AddMarkWithDirectDict(ByteString name, CPDF_Dictionary* pDict);
+ void AddMarkWithPropertiesDict(ByteString name, CPDF_Dictionary* pDict);
void DeleteLastMark();
private:
std::vector<RetainPtr<CPDF_ContentMarkItem>> m_Marks;
};
+ void EnsureMarkDataExists();
+
RetainPtr<MarkData> m_pMarkData;
};
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 01fb347a9a..ae55390eb2 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -607,17 +607,19 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
if (!pProperty)
return;
- bool bDirect = true;
- if (pProperty->IsName()) {
+ bool bIndirect = pProperty->IsName();
+ if (bIndirect) {
pProperty = FindResourceObj("Properties", pProperty->GetString());
if (!pProperty)
return;
- bDirect = false;
}
if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) {
std::unique_ptr<CPDF_ContentMark> new_marks =
m_ContentMarksStack.top()->Clone();
- new_marks->AddMark(std::move(tag), pDict, bDirect);
+ if (bIndirect)
+ new_marks->AddMarkWithPropertiesDict(std::move(tag), pDict);
+ else
+ new_marks->AddMarkWithDirectDict(std::move(tag), pDict);
m_ContentMarksStack.push(std::move(new_marks));
}
}
@@ -685,7 +687,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
std::unique_ptr<CPDF_ContentMark> new_marks =
m_ContentMarksStack.top()->Clone();
- new_marks->AddMark(GetString(0), nullptr, false);
+ new_marks->AddMark(GetString(0));
m_ContentMarksStack.push(std::move(new_marks));
}
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 4151de5dfd..8d8c315b07 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -326,7 +326,7 @@ FPDFPageObj_AddMark(FPDF_PAGEOBJECT page_object, FPDF_BYTESTRING name) {
return nullptr;
auto* mark = &CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark;
- mark->AddMark(name, nullptr, true);
+ mark->AddMark(name);
unsigned long index = mark->CountItems() - 1;
return FPDFPageObjectMarkFromCPDFContentMarkItem(mark->GetItem(index));