Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_contentmark.cpp

Issue 2358043003: Make ownership explicit in CPDF_ContentMarkItem (Closed)
Patch Set: Not owned Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_page/cpdf_contentmark.h" 7 #include "core/fpdfapi/fpdf_page/cpdf_contentmark.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
10 #include "third_party/base/stl_util.h" 10 #include "third_party/base/stl_util.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 bool CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark, 60 bool CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark,
61 CPDF_Dictionary*& pDict) const { 61 CPDF_Dictionary*& pDict) const {
62 const MarkData* pData = m_Ref.GetObject(); 62 const MarkData* pData = m_Ref.GetObject();
63 if (!pData) 63 if (!pData)
64 return false; 64 return false;
65 65
66 for (int i = 0; i < pData->CountItems(); i++) { 66 for (int i = 0; i < pData->CountItems(); i++) {
67 const CPDF_ContentMarkItem& item = pData->GetItem(i); 67 const CPDF_ContentMarkItem& item = pData->GetItem(i);
68 if (item.GetName() == mark) { 68 if (item.GetName() == mark) {
69 pDict = nullptr; 69 pDict = item.GetParam();
70 if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict ||
71 item.GetParamType() == CPDF_ContentMarkItem::DirectDict) {
72 pDict = item.GetParam();
73 }
74 return true; 70 return true;
75 } 71 }
76 } 72 }
77 return false; 73 return false;
78 } 74 }
79 75
80 CPDF_ContentMark::MarkData::MarkData() {} 76 CPDF_ContentMark::MarkData::MarkData() {}
81 77
82 CPDF_ContentMark::MarkData::MarkData(const MarkData& src) 78 CPDF_ContentMark::MarkData::MarkData(const MarkData& src)
83 : m_Marks(src.m_Marks) {} 79 : m_Marks(src.m_Marks) {}
84 80
85 CPDF_ContentMark::MarkData::~MarkData() {} 81 CPDF_ContentMark::MarkData::~MarkData() {}
86 82
87 int CPDF_ContentMark::MarkData::CountItems() const { 83 int CPDF_ContentMark::MarkData::CountItems() const {
88 return pdfium::CollectionSize<int>(m_Marks); 84 return pdfium::CollectionSize<int>(m_Marks);
89 } 85 }
90 86
91 CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem(int index) { 87 CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem(int index) {
92 return m_Marks[index]; 88 return m_Marks[index];
93 } 89 }
94 90
95 const CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem( 91 const CPDF_ContentMarkItem& CPDF_ContentMark::MarkData::GetItem(
96 int index) const { 92 int index) const {
97 return m_Marks[index]; 93 return m_Marks[index];
98 } 94 }
99 95
100 int CPDF_ContentMark::MarkData::GetMCID() const { 96 int CPDF_ContentMark::MarkData::GetMCID() const {
101 for (const auto& mark : m_Marks) { 97 for (const auto& mark : m_Marks) {
102 CPDF_ContentMarkItem::ParamType type = mark.GetParamType(); 98 CPDF_Dictionary* pDict = mark.GetParam();
103 if (type == CPDF_ContentMarkItem::PropertiesDict || 99 if (pDict && pDict->KeyExist("MCID"))
104 type == CPDF_ContentMarkItem::DirectDict) { 100 return pDict->GetIntegerFor("MCID");
105 CPDF_Dictionary* pDict = mark.GetParam();
106 if (pDict->KeyExist("MCID"))
107 return pDict->GetIntegerFor("MCID");
108 }
109 } 101 }
110 return -1; 102 return -1;
111 } 103 }
112 104
113 void CPDF_ContentMark::MarkData::AddMark(const CFX_ByteString& name, 105 void CPDF_ContentMark::MarkData::AddMark(const CFX_ByteString& name,
114 CPDF_Dictionary* pDict, 106 CPDF_Dictionary* pDict,
115 FX_BOOL bDirect) { 107 FX_BOOL bDirect) {
116 CPDF_ContentMarkItem item; 108 CPDF_ContentMarkItem item;
117 item.SetName(name); 109 item.SetName(name);
118 if (pDict) { 110 if (pDict) {
119 if (bDirect) { 111 if (bDirect) {
120 item.SetParam(CPDF_ContentMarkItem::DirectDict, 112 item.SetDirectDict(
121 ToDictionary(pDict->Clone())); 113 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>(
114 ToDictionary(pDict->Clone())));
122 } else { 115 } else {
123 item.SetParam(CPDF_ContentMarkItem::PropertiesDict, pDict); 116 item.SetPropertiesDict(pDict);
124 } 117 }
125 } 118 }
126 m_Marks.push_back(item); 119 m_Marks.push_back(std::move(item));
127 } 120 }
128 121
129 void CPDF_ContentMark::MarkData::DeleteLastMark() { 122 void CPDF_ContentMark::MarkData::DeleteLastMark() {
130 if (!m_Marks.empty()) 123 if (!m_Marks.empty())
131 m_Marks.pop_back(); 124 m_Marks.pop_back();
132 } 125 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698