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

Side by Side Diff: fpdfsdk/cpdfsdk_baannot.cpp

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

Powered by Google App Engine
This is Rietveld 408576698