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

Side by Side Diff: fpdfsdk/cpdfsdk_baannot.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: Plug leaks Created 4 years, 1 month 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
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 "fpdfsdk/cpdfsdk_baannot.h" 7 #include "fpdfsdk/cpdfsdk_baannot.h"
8 8
9 #include "core/fpdfapi/parser/cpdf_array.h" 9 #include "core/fpdfapi/parser/cpdf_array.h"
10 #include "core/fpdfapi/parser/cpdf_document.h" 10 #include "core/fpdfapi/parser/cpdf_document.h"
11 #include "core/fpdfapi/parser/cpdf_name.h"
11 #include "core/fpdfapi/parser/cpdf_number.h" 12 #include "core/fpdfapi/parser/cpdf_number.h"
13 #include "core/fpdfapi/parser/cpdf_reference.h"
12 #include "core/fpdfapi/parser/cpdf_stream.h" 14 #include "core/fpdfapi/parser/cpdf_stream.h"
15 #include "core/fpdfapi/parser/cpdf_string.h"
13 #include "core/fpdfapi/parser/fpdf_parser_decode.h" 16 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
14 #include "fpdfsdk/cpdfsdk_datetime.h" 17 #include "fpdfsdk/cpdfsdk_datetime.h"
15 #include "fpdfsdk/cpdfsdk_pageview.h" 18 #include "fpdfsdk/cpdfsdk_pageview.h"
16 19
17 CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, 20 CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
18 CPDFSDK_PageView* pPageView) 21 CPDFSDK_PageView* pPageView)
19 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {} 22 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {}
20 23
21 CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {} 24 CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {}
22 25
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const CFX_Matrix* pUser2Device, 85 const CFX_Matrix* pUser2Device,
83 const CPDF_RenderOptions* pOptions) { 86 const CPDF_RenderOptions* pOptions) {
84 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions); 87 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
85 } 88 }
86 89
87 void CPDFSDK_BAAnnot::ClearCachedAP() { 90 void CPDFSDK_BAAnnot::ClearCachedAP() {
88 m_pAnnot->ClearCachedAP(); 91 m_pAnnot->ClearCachedAP();
89 } 92 }
90 93
91 void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) { 94 void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
92 if (sContents.IsEmpty()) 95 if (sContents.IsEmpty()) {
93 m_pAnnot->GetAnnotDict()->RemoveFor("Contents"); 96 m_pAnnot->GetAnnotDict()->RemoveFor("Contents");
94 else 97 } else {
95 m_pAnnot->GetAnnotDict()->SetStringFor("Contents", 98 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
96 PDF_EncodeText(sContents)); 99 "Contents", PDF_EncodeText(sContents), false);
100 }
97 } 101 }
98 102
99 CFX_WideString CPDFSDK_BAAnnot::GetContents() const { 103 CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
100 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("Contents"); 104 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("Contents");
101 } 105 }
102 106
103 void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) { 107 void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
104 if (sName.IsEmpty()) 108 if (sName.IsEmpty()) {
105 m_pAnnot->GetAnnotDict()->RemoveFor("NM"); 109 m_pAnnot->GetAnnotDict()->RemoveFor("NM");
106 else 110 } else {
107 m_pAnnot->GetAnnotDict()->SetStringFor("NM", PDF_EncodeText(sName)); 111 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
112 "NM", PDF_EncodeText(sName), false);
113 }
108 } 114 }
109 115
110 CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const { 116 CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
111 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("NM"); 117 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("NM");
112 } 118 }
113 119
114 void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) { 120 void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
115 CPDFSDK_DateTime dt(st); 121 CPDFSDK_DateTime dt(st);
116 CFX_ByteString str = dt.ToPDFDateTimeString(); 122 CFX_ByteString str = dt.ToPDFDateTimeString();
117
118 if (str.IsEmpty()) 123 if (str.IsEmpty())
119 m_pAnnot->GetAnnotDict()->RemoveFor("M"); 124 m_pAnnot->GetAnnotDict()->RemoveFor("M");
120 else 125 else
121 m_pAnnot->GetAnnotDict()->SetStringFor("M", str); 126 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("M", str, false);
122 } 127 }
123 128
124 FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const { 129 FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
125 FX_SYSTEMTIME systime; 130 FX_SYSTEMTIME systime;
126 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetStringFor("M"); 131 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetStringFor("M");
127
128 CPDFSDK_DateTime dt(str); 132 CPDFSDK_DateTime dt(str);
129 dt.ToSystemTime(systime); 133 dt.ToSystemTime(systime);
130
131 return systime; 134 return systime;
132 } 135 }
133 136
134 void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) { 137 void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) {
135 m_pAnnot->GetAnnotDict()->SetIntegerFor("F", nFlags); 138 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F",
139 static_cast<int>(nFlags));
136 } 140 }
137 141
138 uint32_t CPDFSDK_BAAnnot::GetFlags() const { 142 uint32_t CPDFSDK_BAAnnot::GetFlags() const {
139 return m_pAnnot->GetAnnotDict()->GetIntegerFor("F"); 143 return m_pAnnot->GetAnnotDict()->GetIntegerFor("F");
140 } 144 }
141 145
142 void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) { 146 void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
143 if (str.IsEmpty()) 147 if (str.IsEmpty())
144 m_pAnnot->GetAnnotDict()->RemoveFor("AS"); 148 m_pAnnot->GetAnnotDict()->RemoveFor("AS");
145 else 149 else
146 m_pAnnot->GetAnnotDict()->SetStringFor("AS", str); 150 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("AS", str, false);
147 } 151 }
148 152
149 CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const { 153 CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
150 return m_pAnnot->GetAnnotDict()->GetStringFor("AS"); 154 return m_pAnnot->GetAnnotDict()->GetStringFor("AS");
151 } 155 }
152 156
153 void CPDFSDK_BAAnnot::SetStructParent(int key) { 157 void CPDFSDK_BAAnnot::SetStructParent(int key) {
154 m_pAnnot->GetAnnotDict()->SetIntegerFor("StructParent", key); 158 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("StructParent", key);
155 } 159 }
156 160
157 int CPDFSDK_BAAnnot::GetStructParent() const { 161 int CPDFSDK_BAAnnot::GetStructParent() const {
158 return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent"); 162 return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent");
159 } 163 }
160 164
161 // border 165 // border
162 void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) { 166 void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
163 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"); 167 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
164 if (pBorder) { 168 if (pBorder) {
165 pBorder->SetNewAt<CPDF_Number>(2, nWidth); 169 pBorder->SetNewAt<CPDF_Number>(2, nWidth);
166 } else { 170 } else {
167 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); 171 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
168 if (!pBSDict) { 172 if (!pBSDict)
169 pBSDict = 173 pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
170 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); 174
171 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict); 175 pBSDict->SetNewFor<CPDF_Number>("W", nWidth);
172 }
173 pBSDict->SetIntegerFor("W", nWidth);
174 } 176 }
175 } 177 }
176 178
177 int CPDFSDK_BAAnnot::GetBorderWidth() const { 179 int CPDFSDK_BAAnnot::GetBorderWidth() const {
178 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border")) 180 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"))
179 return pBorder->GetIntegerAt(2); 181 return pBorder->GetIntegerAt(2);
180 182
181 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS")) 183 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"))
182 return pBSDict->GetIntegerFor("W", 1); 184 return pBSDict->GetIntegerFor("W", 1);
183 185
184 return 1; 186 return 1;
185 } 187 }
186 188
187 void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { 189 void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) {
188 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); 190 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
189 if (!pBSDict) { 191 if (!pBSDict)
190 pBSDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); 192 pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
191 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict);
192 }
193 193
194 switch (nStyle) { 194 switch (nStyle) {
195 case BorderStyle::SOLID: 195 case BorderStyle::SOLID:
196 pBSDict->SetNameFor("S", "S"); 196 pBSDict->SetNewFor<CPDF_Name>("S", "S");
197 break; 197 break;
198 case BorderStyle::DASH: 198 case BorderStyle::DASH:
199 pBSDict->SetNameFor("S", "D"); 199 pBSDict->SetNewFor<CPDF_Name>("S", "D");
200 break; 200 break;
201 case BorderStyle::BEVELED: 201 case BorderStyle::BEVELED:
202 pBSDict->SetNameFor("S", "B"); 202 pBSDict->SetNewFor<CPDF_Name>("S", "B");
203 break; 203 break;
204 case BorderStyle::INSET: 204 case BorderStyle::INSET:
205 pBSDict->SetNameFor("S", "I"); 205 pBSDict->SetNewFor<CPDF_Name>("S", "I");
206 break; 206 break;
207 case BorderStyle::UNDERLINE: 207 case BorderStyle::UNDERLINE:
208 pBSDict->SetNameFor("S", "U"); 208 pBSDict->SetNewFor<CPDF_Name>("S", "U");
209 break; 209 break;
210 default: 210 default:
211 break; 211 break;
212 } 212 }
213 } 213 }
214 214
215 BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const { 215 BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
216 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"); 216 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
217 if (pBSDict) { 217 if (pBSDict) {
218 CFX_ByteString sBorderStyle = pBSDict->GetStringFor("S", "S"); 218 CFX_ByteString sBorderStyle = pBSDict->GetStringFor("S", "S");
(...skipping 15 matching lines...) Expand all
234 CPDF_Array* pDP = pBorder->GetArrayAt(3); 234 CPDF_Array* pDP = pBorder->GetArrayAt(3);
235 if (pDP && pDP->GetCount() > 0) 235 if (pDP && pDP->GetCount() > 0)
236 return BorderStyle::DASH; 236 return BorderStyle::DASH;
237 } 237 }
238 } 238 }
239 239
240 return BorderStyle::SOLID; 240 return BorderStyle::SOLID;
241 } 241 }
242 242
243 void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) { 243 void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
244 CPDF_Array* pArray = new CPDF_Array; 244 CPDF_Array* pArray = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("C");
245 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetRValue(color)) / 245 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetRValue(color)) /
246 255.0f); 246 255.0f);
247 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetGValue(color)) / 247 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetGValue(color)) /
248 255.0f); 248 255.0f);
249 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetBValue(color)) / 249 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetBValue(color)) /
250 255.0f); 250 255.0f);
251 m_pAnnot->GetAnnotDict()->SetFor("C", pArray);
252 } 251 }
253 252
254 void CPDFSDK_BAAnnot::RemoveColor() { 253 void CPDFSDK_BAAnnot::RemoveColor() {
255 m_pAnnot->GetAnnotDict()->RemoveFor("C"); 254 m_pAnnot->GetAnnotDict()->RemoveFor("C");
256 } 255 }
257 256
258 bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { 257 bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
259 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) { 258 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) {
260 size_t nCount = pEntry->GetCount(); 259 size_t nCount = pEntry->GetCount();
261 if (nCount == 1) { 260 if (nCount == 1) {
(...skipping 28 matching lines...) Expand all
290 289
291 return false; 290 return false;
292 } 291 }
293 292
294 void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, 293 void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
295 const CFX_FloatRect& rcBBox, 294 const CFX_FloatRect& rcBBox,
296 const CFX_Matrix& matrix, 295 const CFX_Matrix& matrix,
297 const CFX_ByteString& sContents, 296 const CFX_ByteString& sContents,
298 const CFX_ByteString& sAPState) { 297 const CFX_ByteString& sAPState) {
299 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); 298 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
300 if (!pAPDict) { 299 if (!pAPDict)
301 pAPDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); 300 pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP");
302 m_pAnnot->GetAnnotDict()->SetFor("AP", pAPDict);
303 }
304 301
305 CPDF_Stream* pStream = nullptr; 302 CPDF_Stream* pStream = nullptr;
306 CPDF_Dictionary* pParentDict = nullptr; 303 CPDF_Dictionary* pParentDict = nullptr;
307 if (sAPState.IsEmpty()) { 304 if (sAPState.IsEmpty()) {
308 pParentDict = pAPDict; 305 pParentDict = pAPDict;
309 pStream = pAPDict->GetStreamFor(sAPType); 306 pStream = pAPDict->GetStreamFor(sAPType);
310 } else { 307 } else {
311 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType); 308 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType);
312 if (!pAPTypeDict) { 309 if (!pAPTypeDict)
313 pAPTypeDict = 310 pAPTypeDict = pAPDict->SetNewFor<CPDF_Dictionary>(sAPType);
314 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); 311
315 pAPDict->SetFor(sAPType, pAPTypeDict);
316 }
317 pParentDict = pAPTypeDict; 312 pParentDict = pAPTypeDict;
318 pStream = pAPTypeDict->GetStreamFor(sAPState); 313 pStream = pAPTypeDict->GetStreamFor(sAPState);
319 } 314 }
320 315
321 if (!pStream) { 316 if (!pStream) {
322 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); 317 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
323 pStream = pDoc->NewIndirect<CPDF_Stream>(); 318 pStream = pDoc->NewIndirect<CPDF_Stream>();
324 pParentDict->SetReferenceFor(sAPType, pDoc, pStream); 319 pParentDict->SetNewFor<CPDF_Reference>(sAPType, pDoc, pStream->GetObjNum());
325 } 320 }
326 321
327 CPDF_Dictionary* pStreamDict = pStream->GetDict(); 322 CPDF_Dictionary* pStreamDict = pStream->GetDict();
328 if (!pStreamDict) { 323 if (!pStreamDict) {
329 pStreamDict = 324 pStreamDict =
330 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool()); 325 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
331 pStreamDict->SetNameFor("Type", "XObject"); 326 pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject");
332 pStreamDict->SetNameFor("Subtype", "Form"); 327 pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form");
333 pStreamDict->SetIntegerFor("FormType", 1); 328 pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
334 pStream->InitStream(nullptr, 0, pStreamDict); 329 pStream->InitStream(nullptr, 0, pStreamDict);
335 } 330 }
336 331
337 if (pStreamDict) { 332 if (pStreamDict) {
338 pStreamDict->SetMatrixFor("Matrix", matrix); 333 pStreamDict->SetMatrixFor("Matrix", matrix);
339 pStreamDict->SetRectFor("BBox", rcBBox); 334 pStreamDict->SetRectFor("BBox", rcBBox);
340 } 335 }
341 336
342 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength()); 337 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength());
343 } 338 }
344 339
345 bool CPDFSDK_BAAnnot::IsVisible() const { 340 bool CPDFSDK_BAAnnot::IsVisible() const {
346 uint32_t nFlags = GetFlags(); 341 uint32_t nFlags = GetFlags();
347 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || 342 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
348 (nFlags & ANNOTFLAG_NOVIEW)); 343 (nFlags & ANNOTFLAG_NOVIEW));
349 } 344 }
350 345
351 CPDF_Action CPDFSDK_BAAnnot::GetAction() const { 346 CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
352 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A")); 347 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A"));
353 } 348 }
354 349
355 void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { 350 void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
356 CPDF_Dictionary* pDict = action.GetDict(); 351 CPDF_Dictionary* pDict = action.GetDict();
357 if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) { 352 if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) {
358 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); 353 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
359 if (pDict->IsInline()) 354 if (pDict->IsInline())
360 pDict = pDoc->AddIndirectObject(pDict->Clone())->AsDictionary(); 355 pDict = pDoc->AddIndirectObject(pDict->Clone())->AsDictionary();
361 m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc, pDict); 356 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Reference>("A", pDoc,
357 pDict->GetObjNum());
362 } 358 }
363 } 359 }
364 360
365 void CPDFSDK_BAAnnot::RemoveAction() { 361 void CPDFSDK_BAAnnot::RemoveAction() {
366 m_pAnnot->GetAnnotDict()->RemoveFor("A"); 362 m_pAnnot->GetAnnotDict()->RemoveFor("A");
367 } 363 }
368 364
369 CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const { 365 CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
370 return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA")); 366 return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA"));
371 } 367 }
372 368
373 void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) { 369 void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
374 if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA")) 370 if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA"))
375 m_pAnnot->GetAnnotDict()->SetFor("AA", aa.GetDict()); 371 m_pAnnot->GetAnnotDict()->SetFor("AA", pdfium::WrapUnique(aa.GetDict()));
376 } 372 }
377 373
378 void CPDFSDK_BAAnnot::RemoveAAction() { 374 void CPDFSDK_BAAnnot::RemoveAAction() {
379 m_pAnnot->GetAnnotDict()->RemoveFor("AA"); 375 m_pAnnot->GetAnnotDict()->RemoveFor("AA");
380 } 376 }
381 377
382 CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { 378 CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
383 CPDF_AAction AAction = GetAAction(); 379 CPDF_AAction AAction = GetAAction();
384
385 if (AAction.ActionExist(eAAT)) 380 if (AAction.ActionExist(eAAT))
386 return AAction.GetAction(eAAT); 381 return AAction.GetAction(eAAT);
387 382
388 if (eAAT == CPDF_AAction::ButtonUp) 383 if (eAAT == CPDF_AAction::ButtonUp)
389 return GetAction(); 384 return GetAction();
390 385
391 return CPDF_Action(); 386 return CPDF_Action();
392 } 387 }
393 388
394 void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, 389 void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
395 CFX_Matrix* pUser2Device, 390 CFX_Matrix* pUser2Device,
396 CPDF_RenderOptions* pOptions) { 391 CPDF_RenderOptions* pOptions) {
397 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); 392 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
398 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, 393 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
399 CPDF_Annot::Normal, nullptr); 394 CPDF_Annot::Normal, nullptr);
400 } 395 }
401 396
402 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) { 397 void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) {
403 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot()) 398 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot())
404 pAnnot->SetOpenState(bOpenState); 399 pAnnot->SetOpenState(bOpenState);
405 } 400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698