From 36bbc24e2d7e5082047ad5b783c69518accafe42 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 21 Mar 2018 18:39:06 +0000 Subject: Use more const pointers in CPDF_ContentMarkItem. Transitively mark the same pointers as const in callers. Change-Id: I1f9669b35c6d7f4b1a11c25163480bc687fbc7f8 Reviewed-on: https://pdfium-review.googlesource.com/28870 Reviewed-by: Henrique Nakashima Commit-Queue: Lei Zhang --- core/fpdfapi/page/cpdf_contentmark.cpp | 5 +++-- core/fpdfapi/page/cpdf_contentmark.h | 6 ++++-- core/fpdfapi/page/cpdf_contentmarkitem.cpp | 9 ++++----- core/fpdfapi/page/cpdf_contentmarkitem.h | 10 +++++----- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 8 ++++---- core/fpdftext/cpdf_textpage.cpp | 6 +++--- 6 files changed, 23 insertions(+), 21 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp index c54ef55b1f..e17a30560f 100644 --- a/core/fpdfapi/page/cpdf_contentmark.cpp +++ b/core/fpdfapi/page/cpdf_contentmark.cpp @@ -22,6 +22,7 @@ size_t CPDF_ContentMark::CountItems() const { } const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(size_t i) const { + ASSERT(i < CountItems()); return m_Ref.GetObject()->GetItem(i); } @@ -31,7 +32,7 @@ int CPDF_ContentMark::GetMarkedContentID() const { } void CPDF_ContentMark::AddMark(const ByteString& name, - CPDF_Dictionary* pDict, + const CPDF_Dictionary* pDict, bool bDirect) { m_Ref.GetPrivateCopy()->AddMark(name, pDict, bDirect); } @@ -68,7 +69,7 @@ int CPDF_ContentMark::MarkData::GetMarkedContentID() const { } void CPDF_ContentMark::MarkData::AddMark(const ByteString& name, - CPDF_Dictionary* pDict, + const CPDF_Dictionary* pDict, bool bDirect) { CPDF_ContentMarkItem item; item.SetName(name); diff --git a/core/fpdfapi/page/cpdf_contentmark.h b/core/fpdfapi/page/cpdf_contentmark.h index 78a948697e..1d8b9e2515 100644 --- a/core/fpdfapi/page/cpdf_contentmark.h +++ b/core/fpdfapi/page/cpdf_contentmark.h @@ -25,7 +25,9 @@ class CPDF_ContentMark { size_t CountItems() const; const CPDF_ContentMarkItem& GetItem(size_t i) const; - void AddMark(const ByteString& name, CPDF_Dictionary* pDict, bool bDirect); + void AddMark(const ByteString& name, + const CPDF_Dictionary* pDict, + bool bDirect); void DeleteLastMark(); bool HasRef() const { return !!m_Ref; } @@ -42,7 +44,7 @@ class CPDF_ContentMark { int GetMarkedContentID() const; void AddMark(const ByteString& name, - CPDF_Dictionary* pDict, + const CPDF_Dictionary* pDict, bool bDictNeedClone); void DeleteLastMark(); diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp index de720b39fc..205f14de35 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp +++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp @@ -10,8 +10,7 @@ #include "core/fpdfapi/parser/cpdf_dictionary.h" -CPDF_ContentMarkItem::CPDF_ContentMarkItem() - : m_ParamType(None), m_pPropertiesDict(nullptr) {} +CPDF_ContentMarkItem::CPDF_ContentMarkItem() {} CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& that) : m_MarkName(that.m_MarkName), @@ -23,7 +22,7 @@ CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& that) CPDF_ContentMarkItem::~CPDF_ContentMarkItem() {} -CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() const { +const CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() const { switch (m_ParamType) { case PropertiesDict: return m_pPropertiesDict.Get(); @@ -36,7 +35,7 @@ CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() const { } bool CPDF_ContentMarkItem::HasMCID() const { - CPDF_Dictionary* pDict = GetParam(); + const CPDF_Dictionary* pDict = GetParam(); return pDict && pDict->KeyExist("MCID"); } @@ -46,7 +45,7 @@ void CPDF_ContentMarkItem::SetDirectDict( m_pDirectDict = std::move(pDict); } -void CPDF_ContentMarkItem::SetPropertiesDict(CPDF_Dictionary* pDict) { +void CPDF_ContentMarkItem::SetPropertiesDict(const 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 ea89606816..5dcc7d480a 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.h +++ b/core/fpdfapi/page/cpdf_contentmarkitem.h @@ -28,18 +28,18 @@ class CPDF_ContentMarkItem { ByteString GetName() const { return m_MarkName; } ParamType GetParamType() const { return m_ParamType; } - CPDF_Dictionary* GetParam() const; + const CPDF_Dictionary* GetParam() const; bool HasMCID() const; void SetName(const ByteString& name) { m_MarkName = name; } void SetDirectDict(std::unique_ptr pDict); - void SetPropertiesDict(CPDF_Dictionary* pDict); + void SetPropertiesDict(const CPDF_Dictionary* pDict); private: ByteString m_MarkName; - ParamType m_ParamType; - UnownedPtr m_pPropertiesDict; - std::unique_ptr m_pDirectDict; + ParamType m_ParamType = None; + 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 4e3857bf85..697349e987 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -586,10 +586,10 @@ void CPDF_StreamContentParser::Handle_EOFillStrokePath() { void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() { ByteString tag = GetString(1); - CPDF_Object* pProperty = GetObject(0); - if (!pProperty) { + const CPDF_Object* pProperty = GetObject(0); + if (!pProperty) return; - } + bool bDirect = true; if (pProperty->IsName()) { pProperty = FindResourceObj("Properties", pProperty->GetString()); @@ -597,7 +597,7 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() { return; bDirect = false; } - if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) { + if (const CPDF_Dictionary* pDict = pProperty->AsDictionary()) { m_CurContentMark.AddMark(tag, pDict, bDirect); } } diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index a5eb14579e..e2d1f5f0a6 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -799,13 +799,13 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { WideString actText; bool bExist = false; - CPDF_Dictionary* pDict = nullptr; + const CPDF_Dictionary* pDict = nullptr; for (size_t i = 0; i < nContentMark; ++i) { const CPDF_ContentMarkItem& item = pTextObj->m_ContentMark.GetItem(i); pDict = item.GetParam(); if (!pDict) continue; - CPDF_String* temp = ToString(pDict->GetObjectFor("ActualText")); + const CPDF_String* temp = ToString(pDict->GetObjectFor("ActualText")); if (temp) { bExist = true; actText = temp->GetUnicodeText(); @@ -862,7 +862,7 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { WideString actText; for (int n = 0; n < nContentMark; n++) { const CPDF_ContentMarkItem& item = pTextObj->m_ContentMark.GetItem(n); - CPDF_Dictionary* pDict = item.GetParam(); + const CPDF_Dictionary* pDict = item.GetParam(); if (pDict) actText = pDict->GetUnicodeTextFor("ActualText"); } -- cgit v1.2.3