From 22b64c361bf4630cdfe2b783d5b1e582f4842711 Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 1 Sep 2016 07:11:15 -0700 Subject: Make CPDF_ContentMark have a CPDF_ContentMarkData. This one doesn't require an explict Emplace(), as the object seems to get constructed only as a side-effect of making a private copy. Review-Url: https://codereview.chromium.org/2298953002 --- core/fpdfapi/fpdf_page/cpdf_contentmark.cpp | 40 +++++++++++++++++++++++++++-- core/fpdfapi/fpdf_page/cpdf_contentmark.h | 24 +++++++++++++---- core/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 16 +++--------- core/fpdfdoc/cpdf_occontext.cpp | 5 ++-- core/fpdftext/cpdf_textpage.cpp | 27 +++++++++---------- 5 files changed, 75 insertions(+), 37 deletions(-) diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp b/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp index 06a6a50443..c36f407c36 100644 --- a/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp @@ -6,8 +6,44 @@ #include "core/fpdfapi/fpdf_page/cpdf_contentmark.h" +CPDF_ContentMark::CPDF_ContentMark() {} + +CPDF_ContentMark::CPDF_ContentMark(const CPDF_ContentMark& that) + : m_Ref(that.m_Ref) {} + +CPDF_ContentMark::~CPDF_ContentMark() {} + +void CPDF_ContentMark::SetNull() { + m_Ref.SetNull(); +} + +int CPDF_ContentMark::CountItems() const { + return m_Ref.GetObject()->CountItems(); +} + +const CPDF_ContentMarkItem& CPDF_ContentMark::GetItem(int i) const { + return m_Ref.GetObject()->GetItem(i); +} + +int CPDF_ContentMark::GetMCID() const { + const CPDF_ContentMarkData* pData = m_Ref.GetObject(); + return pData ? pData->GetMCID() : -1; +} + +void CPDF_ContentMark::AddMark(const CFX_ByteString& name, + CPDF_Dictionary* pDict, + FX_BOOL bDirect) { + m_Ref.GetPrivateCopy()->AddMark(name, pDict, bDirect); +} + +void CPDF_ContentMark::DeleteLastMark() { + m_Ref.GetPrivateCopy()->DeleteLastMark(); + if (CountItems() == 0) + m_Ref.SetNull(); +} + bool CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const { - const CPDF_ContentMarkData* pData = GetObject(); + const CPDF_ContentMarkData* pData = m_Ref.GetObject(); if (!pData) return false; @@ -20,7 +56,7 @@ bool CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const { bool CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark, CPDF_Dictionary*& pDict) const { - const CPDF_ContentMarkData* pData = GetObject(); + const CPDF_ContentMarkData* pData = m_Ref.GetObject(); if (!pData) return false; diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmark.h b/core/fpdfapi/fpdf_page/cpdf_contentmark.h index 2f8c5cdbc7..2941c61ba9 100644 --- a/core/fpdfapi/fpdf_page/cpdf_contentmark.h +++ b/core/fpdfapi/fpdf_page/cpdf_contentmark.h @@ -11,15 +11,29 @@ #include "core/fxcrt/include/cfx_count_ref.h" #include "core/fxcrt/include/fx_basic.h" -class CPDF_ContentMark : public CFX_CountRef { +class CPDF_ContentMark { public: - int GetMCID() const { - const CPDF_ContentMarkData* pData = GetObject(); - return pData ? pData->GetMCID() : -1; - } + CPDF_ContentMark(); + CPDF_ContentMark(const CPDF_ContentMark& that); + ~CPDF_ContentMark(); + + void SetNull(); + + int GetMCID() const; + int CountItems() const; + const CPDF_ContentMarkItem& GetItem(int i) const; bool HasMark(const CFX_ByteStringC& mark) const; bool LookupMark(const CFX_ByteStringC& mark, CPDF_Dictionary*& pDict) const; + void AddMark(const CFX_ByteString& name, + CPDF_Dictionary* pDict, + FX_BOOL bDirect); + void DeleteLastMark(); + + operator bool() const { return !!m_Ref; } + + private: + CFX_CountRef m_Ref; }; #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARK_H_ diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 5272a4464b..4712ea0725 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -583,7 +583,7 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() { bDirect = FALSE; } if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) { - m_CurContentMark.GetPrivateCopy()->AddMark(tag, pDict, bDirect); + m_CurContentMark.AddMark(tag, pDict, bDirect); } } @@ -658,8 +658,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } void CPDF_StreamContentParser::Handle_BeginMarkedContent() { - CFX_ByteString tag = GetString(0); - m_CurContentMark.GetPrivateCopy()->AddMark(tag, nullptr, FALSE); + m_CurContentMark.AddMark(GetString(0), nullptr, FALSE); } void CPDF_StreamContentParser::Handle_BeginText() { @@ -806,15 +805,8 @@ void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} void CPDF_StreamContentParser::Handle_EndImage() {} void CPDF_StreamContentParser::Handle_EndMarkedContent() { - if (!m_CurContentMark) - return; - - int count = m_CurContentMark.GetObject()->CountItems(); - if (count == 1) { - m_CurContentMark.SetNull(); - return; - } - m_CurContentMark.GetPrivateCopy()->DeleteLastMark(); + if (m_CurContentMark) + m_CurContentMark.DeleteLastMark(); } void CPDF_StreamContentParser::Handle_EndText() { diff --git a/core/fpdfdoc/cpdf_occontext.cpp b/core/fpdfdoc/cpdf_occontext.cpp index 9206b97e6f..b4ddb6ab4f 100644 --- a/core/fpdfdoc/cpdf_occontext.cpp +++ b/core/fpdfdoc/cpdf_occontext.cpp @@ -182,9 +182,8 @@ bool CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) { } bool CPDF_OCContext::CheckObjectVisible(const CPDF_PageObject* pObj) { - const CPDF_ContentMarkData* pData = pObj->m_ContentMark.GetObject(); - for (int i = 0; i < pData->CountItems(); i++) { - const CPDF_ContentMarkItem& item = pData->GetItem(i); + for (int i = 0; i < pObj->m_ContentMark.CountItems(); i++) { + const CPDF_ContentMarkItem& item = pObj->m_ContentMark.GetItem(i); if (item.GetName() == "OC" && item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict && !CheckOCGVisible(item.GetParam())) { diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 909e029262..7512453093 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -805,11 +805,10 @@ void CPDF_TextPage::ProcessTextObject( FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { CPDF_TextObject* pTextObj = Obj.m_pTextObj; - const CPDF_ContentMarkData* pMarkData = pTextObj->m_ContentMark.GetObject(); - if (!pMarkData) + if (!pTextObj->m_ContentMark) return FPDFText_MarkedContent::Pass; - int nContentMark = pMarkData->CountItems(); + int nContentMark = pTextObj->m_ContentMark.CountItems(); if (nContentMark < 1) return FPDFText_MarkedContent::Pass; @@ -818,7 +817,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { CPDF_Dictionary* pDict = nullptr; int n = 0; for (n = 0; n < nContentMark; n++) { - const CPDF_ContentMarkItem& item = pMarkData->GetItem(n); + const CPDF_ContentMarkItem& item = pTextObj->m_ContentMark.GetItem(n); if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None) continue; pDict = item.GetParam(); @@ -832,14 +831,12 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { if (!bExist) return FPDFText_MarkedContent::Pass; - if (m_pPreTextObj) { - const CPDF_ContentMarkData* pPreMarkData = - m_pPreTextObj->m_ContentMark.GetObject(); - if (pPreMarkData && pPreMarkData->CountItems() == n && - pDict == pPreMarkData->GetItem(n - 1).GetParam()) { - return FPDFText_MarkedContent::Done; - } + if (m_pPreTextObj && m_pPreTextObj->m_ContentMark && + m_pPreTextObj->m_ContentMark.CountItems() == n && + pDict == m_pPreTextObj->m_ContentMark.GetItem(n - 1).GetParam()) { + return FPDFText_MarkedContent::Done; } + FX_STRSIZE nItems = actText.GetLength(); if (nItems < 1) return FPDFText_MarkedContent::Pass; @@ -872,17 +869,17 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { CPDF_TextObject* pTextObj = Obj.m_pTextObj; - const CPDF_ContentMarkData* pMarkData = pTextObj->m_ContentMark.GetObject(); - if (!pMarkData) + if (!pTextObj->m_ContentMark) return; - int nContentMark = pMarkData->CountItems(); + int nContentMark = pTextObj->m_ContentMark.CountItems(); if (nContentMark < 1) return; + CFX_WideString actText; CPDF_Dictionary* pDict = nullptr; for (int n = 0; n < nContentMark; n++) { - const CPDF_ContentMarkItem& item = pMarkData->GetItem(n); + const CPDF_ContentMarkItem& item = pTextObj->m_ContentMark.GetItem(n); if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None) continue; pDict = item.GetParam(); -- cgit v1.2.3