summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-09-01 07:11:15 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-01 07:11:15 -0700
commit22b64c361bf4630cdfe2b783d5b1e582f4842711 (patch)
treef2791406df5b4cc0225ab44508d9eb6dfef585ff /core/fpdfapi
parent380f53ec1d0a46648473e407934c9adede6cc1bd (diff)
downloadpdfium-22b64c361bf4630cdfe2b783d5b1e582f4842711.tar.xz
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
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmark.cpp40
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmark.h24
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp16
3 files changed, 61 insertions, 19 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<CPDF_ContentMarkData> {
+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<CPDF_ContentMarkData> 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() {