From 144107d3ca6ddd2724a460c4da4a20e6e1b7f1b7 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Tue, 10 Jul 2018 21:04:05 +0000 Subject: Create API for adding content marks and setting their params. This CL creates the following new functions in the public API: - FPDFPageObj_AddMark - FPDFPageObjMark_SetIntParam - FPDFPageObjMark_SetStringParam Bug: pdfium:1037 Change-Id: Icabf3fdd8e8153b9156bab807a3708d38a9365d8 Reviewed-on: https://pdfium-review.googlesource.com/37330 Commit-Queue: Henrique Nakashima Reviewed-by: Lei Zhang --- core/fpdfapi/page/cpdf_contentmark.cpp | 19 ++++++++++++++----- core/fpdfapi/page/cpdf_contentmark.h | 14 ++++++++------ core/fpdfapi/page/cpdf_contentmarkitem.cpp | 14 +++++++++++++- core/fpdfapi/page/cpdf_contentmarkitem.h | 7 ++++--- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 4 ++-- 5 files changed, 41 insertions(+), 17 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp index 6021dc893d..912cc0ea03 100644 --- a/core/fpdfapi/page/cpdf_contentmark.cpp +++ b/core/fpdfapi/page/cpdf_contentmark.cpp @@ -29,7 +29,12 @@ size_t CPDF_ContentMark::CountItems() const { return m_pMarkData->CountItems(); } -const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(size_t i) const { +CPDF_ContentMarkItem* CPDF_ContentMark::GetItem(size_t i) { + ASSERT(i < CountItems()); + return m_pMarkData->GetItem(i); +} + +const CPDF_ContentMarkItem* CPDF_ContentMark::GetItem(size_t i) const { ASSERT(i < CountItems()); return m_pMarkData->GetItem(i); } @@ -42,7 +47,7 @@ int CPDF_ContentMark::GetMarkedContentID() const { } void CPDF_ContentMark::AddMark(ByteString name, - const CPDF_Dictionary* pDict, + CPDF_Dictionary* pDict, bool bDirect) { if (!m_pMarkData) m_pMarkData.Reset(new MarkData()); @@ -70,9 +75,13 @@ size_t CPDF_ContentMark::MarkData::CountItems() const { return m_Marks.size(); } -const CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem( +CPDF_ContentMarkItem* CPDF_ContentMark::MarkData::GetItem(size_t index) { + return m_Marks[index].Get(); +} + +const CPDF_ContentMarkItem* CPDF_ContentMark::MarkData::GetItem( size_t index) const { - return *m_Marks[index]; + return m_Marks[index].Get(); } int CPDF_ContentMark::MarkData::GetMarkedContentID() const { @@ -85,7 +94,7 @@ int CPDF_ContentMark::MarkData::GetMarkedContentID() const { } void CPDF_ContentMark::MarkData::AddMark(ByteString name, - const CPDF_Dictionary* pDict, + CPDF_Dictionary* pDict, bool bDirect) { auto pItem = pdfium::MakeRetain(); pItem->SetName(std::move(name)); diff --git a/core/fpdfapi/page/cpdf_contentmark.h b/core/fpdfapi/page/cpdf_contentmark.h index ac21151ede..e0ae1bf549 100644 --- a/core/fpdfapi/page/cpdf_contentmark.h +++ b/core/fpdfapi/page/cpdf_contentmark.h @@ -24,9 +24,12 @@ class CPDF_ContentMark { std::unique_ptr Clone(); int GetMarkedContentID() const; size_t CountItems() const; - const CPDF_ContentMarkItem& GetItem(size_t i) const; - void AddMark(ByteString name, const CPDF_Dictionary* pDict, bool bDirect); + // The returned pointer is never null. + CPDF_ContentMarkItem* GetItem(size_t i); + const CPDF_ContentMarkItem* GetItem(size_t i) const; + + void AddMark(ByteString name, CPDF_Dictionary* pDict, bool bDirect); void DeleteLastMark(); private: @@ -37,12 +40,11 @@ class CPDF_ContentMark { ~MarkData() override; size_t CountItems() const; - const CPDF_ContentMarkItem& GetItem(size_t index) const; + CPDF_ContentMarkItem* GetItem(size_t index); + const CPDF_ContentMarkItem* GetItem(size_t index) const; int GetMarkedContentID() const; - void AddMark(ByteString name, - const CPDF_Dictionary* pDict, - bool bDictNeedClone); + void AddMark(ByteString name, CPDF_Dictionary* pDict, bool bDictNeedClone); void DeleteLastMark(); private: diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp index 4f56eea919..dd9f7e884c 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp +++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp @@ -26,6 +26,18 @@ const CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() const { } } +CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() { + switch (m_ParamType) { + case PropertiesDict: + return m_pPropertiesDict.Get(); + case DirectDict: + return m_pDirectDict.get(); + case None: + default: + return nullptr; + } +} + bool CPDF_ContentMarkItem::HasMCID() const { const CPDF_Dictionary* pDict = GetParam(); return pDict && pDict->KeyExist("MCID"); @@ -37,7 +49,7 @@ void CPDF_ContentMarkItem::SetDirectDict( m_pDirectDict = std::move(pDict); } -void CPDF_ContentMarkItem::SetPropertiesDict(const CPDF_Dictionary* pDict) { +void CPDF_ContentMarkItem::SetPropertiesDict(CPDF_Dictionary* pDict) { m_ParamType = PropertiesDict; m_pPropertiesDict = pDict; } diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.h b/core/fpdfapi/page/cpdf_contentmarkitem.h index 72548cef9c..343db9d1a6 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.h +++ b/core/fpdfapi/page/cpdf_contentmarkitem.h @@ -27,17 +27,18 @@ class CPDF_ContentMarkItem : public Retainable { ByteString GetName() const { return m_MarkName; } ParamType GetParamType() const { return m_ParamType; } const CPDF_Dictionary* GetParam() const; + CPDF_Dictionary* GetParam(); bool HasMCID() const; void SetName(const ByteString& name) { m_MarkName = name; } void SetDirectDict(std::unique_ptr pDict); - void SetPropertiesDict(const CPDF_Dictionary* pDict); + void SetPropertiesDict(CPDF_Dictionary* pDict); private: ByteString m_MarkName; ParamType m_ParamType = None; - UnownedPtr m_pPropertiesDict; - std::unique_ptr m_pDirectDict; + UnownedPtr m_pPropertiesDict; + std::unique_ptr m_pDirectDict; }; #endif // CORE_FPDFAPI_PAGE_CPDF_CONTENTMARKITEM_H_ diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index ba7388cf15..01fb347a9a 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -603,7 +603,7 @@ void CPDF_StreamContentParser::Handle_EOFillStrokePath() { void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() { ByteString tag = GetString(1); - const CPDF_Object* pProperty = GetObject(0); + CPDF_Object* pProperty = GetObject(0); if (!pProperty) return; @@ -614,7 +614,7 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() { return; bDirect = false; } - if (const CPDF_Dictionary* pDict = pProperty->AsDictionary()) { + if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) { std::unique_ptr new_marks = m_ContentMarksStack.top()->Clone(); new_marks->AddMark(std::move(tag), pDict, bDirect); -- cgit v1.2.3