blob: 9fb1e88a84b2900b45cf7e829f5abb4b1435a037 [file] [log] [blame]
jaepark27362762016-08-11 13:10:39 -07001// Copyright 2016 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair114e46a2016-09-29 17:18:21 -07007#include "fpdfsdk/cpdfsdk_baannot.h"
jaepark27362762016-08-11 13:10:39 -07008
tsepez0e606b52016-11-18 16:22:41 -08009#include <algorithm>
10
dsinclair488b7ad2016-10-04 11:55:50 -070011#include "core/fpdfapi/parser/cpdf_array.h"
12#include "core/fpdfapi/parser/cpdf_document.h"
tsepez0e606b52016-11-18 16:22:41 -080013#include "core/fpdfapi/parser/cpdf_name.h"
dsinclair488b7ad2016-10-04 11:55:50 -070014#include "core/fpdfapi/parser/cpdf_number.h"
tsepez0e606b52016-11-18 16:22:41 -080015#include "core/fpdfapi/parser/cpdf_reference.h"
dsinclair488b7ad2016-10-04 11:55:50 -070016#include "core/fpdfapi/parser/cpdf_stream.h"
tsepez0e606b52016-11-18 16:22:41 -080017#include "core/fpdfapi/parser/cpdf_string.h"
dsinclair488b7ad2016-10-04 11:55:50 -070018#include "core/fpdfapi/parser/fpdf_parser_decode.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/cpdfsdk_datetime.h"
dsinclair114e46a2016-09-29 17:18:21 -070020#include "fpdfsdk/cpdfsdk_pageview.h"
jaepark27362762016-08-11 13:10:39 -070021
22CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
23 CPDFSDK_PageView* pPageView)
24 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {}
25
26CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {}
27
28CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
29 return m_pAnnot;
30}
31
jaepark35512aa2016-08-29 17:15:08 -070032CPDF_Annot* CPDFSDK_BAAnnot::GetPDFPopupAnnot() const {
33 return m_pAnnot->GetPopupAnnot();
34}
35
jaepark27362762016-08-11 13:10:39 -070036CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
37 return m_pAnnot->GetAnnotDict();
38}
39
40void CPDFSDK_BAAnnot::SetRect(const CFX_FloatRect& rect) {
41 ASSERT(rect.right - rect.left >= GetMinWidth());
42 ASSERT(rect.top - rect.bottom >= GetMinHeight());
43
dsinclair38fd8442016-09-15 10:15:32 -070044 m_pAnnot->GetAnnotDict()->SetRectFor("Rect", rect);
jaepark27362762016-08-11 13:10:39 -070045}
46
47CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const {
jaeparka1d21112016-08-25 13:33:34 -070048 return m_pAnnot->GetRect();
jaepark27362762016-08-11 13:10:39 -070049}
50
jaepark956553e2016-08-31 06:49:27 -070051CPDF_Annot::Subtype CPDFSDK_BAAnnot::GetAnnotSubtype() const {
jaepark9ed91372016-08-26 16:16:10 -070052 return m_pAnnot->GetSubtype();
jaepark27362762016-08-11 13:10:39 -070053}
54
55void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
56 const CFX_Matrix* pUser2Device,
57 CPDF_Annot::AppearanceMode mode,
58 const CPDF_RenderOptions* pOptions) {
59 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
60 mode, pOptions);
61}
62
tsepez4cf55152016-11-02 14:37:54 -070063bool CPDFSDK_BAAnnot::IsAppearanceValid() {
dsinclair38fd8442016-09-15 10:15:32 -070064 return !!m_pAnnot->GetAnnotDict()->GetDictFor("AP");
jaepark27362762016-08-11 13:10:39 -070065}
66
tsepez4cf55152016-11-02 14:37:54 -070067bool CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -070068 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
jaepark27362762016-08-11 13:10:39 -070069 if (!pAP)
tsepez4cf55152016-11-02 14:37:54 -070070 return false;
jaepark27362762016-08-11 13:10:39 -070071
72 // Choose the right sub-ap
73 const FX_CHAR* ap_entry = "N";
74 if (mode == CPDF_Annot::Down)
75 ap_entry = "D";
76 else if (mode == CPDF_Annot::Rollover)
77 ap_entry = "R";
78 if (!pAP->KeyExist(ap_entry))
79 ap_entry = "N";
80
81 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -070082 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
jaepark27362762016-08-11 13:10:39 -070083 return !!psub;
84}
85
86void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
87 const CFX_Matrix* pUser2Device,
88 const CPDF_RenderOptions* pOptions) {
89 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
90}
91
92void CPDFSDK_BAAnnot::ClearCachedAP() {
93 m_pAnnot->ClearCachedAP();
94}
95
96void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
tsepez0e606b52016-11-18 16:22:41 -080097 if (sContents.IsEmpty()) {
dsinclair38fd8442016-09-15 10:15:32 -070098 m_pAnnot->GetAnnotDict()->RemoveFor("Contents");
tsepez0e606b52016-11-18 16:22:41 -080099 } else {
100 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
101 "Contents", PDF_EncodeText(sContents), false);
102 }
jaepark27362762016-08-11 13:10:39 -0700103}
104
105CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
dsinclair38fd8442016-09-15 10:15:32 -0700106 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("Contents");
jaepark27362762016-08-11 13:10:39 -0700107}
108
109void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
tsepez0e606b52016-11-18 16:22:41 -0800110 if (sName.IsEmpty()) {
dsinclair38fd8442016-09-15 10:15:32 -0700111 m_pAnnot->GetAnnotDict()->RemoveFor("NM");
tsepez0e606b52016-11-18 16:22:41 -0800112 } else {
113 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
114 "NM", PDF_EncodeText(sName), false);
115 }
jaepark27362762016-08-11 13:10:39 -0700116}
117
118CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
dsinclair38fd8442016-09-15 10:15:32 -0700119 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("NM");
jaepark27362762016-08-11 13:10:39 -0700120}
121
122void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
123 CPDFSDK_DateTime dt(st);
124 CFX_ByteString str = dt.ToPDFDateTimeString();
jaepark27362762016-08-11 13:10:39 -0700125 if (str.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -0700126 m_pAnnot->GetAnnotDict()->RemoveFor("M");
jaepark27362762016-08-11 13:10:39 -0700127 else
tsepez0e606b52016-11-18 16:22:41 -0800128 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("M", str, false);
jaepark27362762016-08-11 13:10:39 -0700129}
130
131FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
132 FX_SYSTEMTIME systime;
dsinclair38fd8442016-09-15 10:15:32 -0700133 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetStringFor("M");
jaepark27362762016-08-11 13:10:39 -0700134 CPDFSDK_DateTime dt(str);
135 dt.ToSystemTime(systime);
jaepark27362762016-08-11 13:10:39 -0700136 return systime;
137}
138
139void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) {
tsepez0e606b52016-11-18 16:22:41 -0800140 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F",
141 static_cast<int>(nFlags));
jaepark27362762016-08-11 13:10:39 -0700142}
143
144uint32_t CPDFSDK_BAAnnot::GetFlags() const {
dsinclair38fd8442016-09-15 10:15:32 -0700145 return m_pAnnot->GetAnnotDict()->GetIntegerFor("F");
jaepark27362762016-08-11 13:10:39 -0700146}
147
148void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
149 if (str.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -0700150 m_pAnnot->GetAnnotDict()->RemoveFor("AS");
jaepark27362762016-08-11 13:10:39 -0700151 else
tsepez0e606b52016-11-18 16:22:41 -0800152 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("AS", str, false);
jaepark27362762016-08-11 13:10:39 -0700153}
154
155CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
dsinclair38fd8442016-09-15 10:15:32 -0700156 return m_pAnnot->GetAnnotDict()->GetStringFor("AS");
jaepark27362762016-08-11 13:10:39 -0700157}
158
159void CPDFSDK_BAAnnot::SetStructParent(int key) {
tsepez0e606b52016-11-18 16:22:41 -0800160 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("StructParent", key);
jaepark27362762016-08-11 13:10:39 -0700161}
162
163int CPDFSDK_BAAnnot::GetStructParent() const {
dsinclair38fd8442016-09-15 10:15:32 -0700164 return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent");
jaepark27362762016-08-11 13:10:39 -0700165}
166
167// border
168void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
dsinclair38fd8442016-09-15 10:15:32 -0700169 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
jaepark27362762016-08-11 13:10:39 -0700170 if (pBorder) {
tsepez8a3aa452016-11-16 12:26:06 -0800171 pBorder->SetNewAt<CPDF_Number>(2, nWidth);
jaepark27362762016-08-11 13:10:39 -0700172 } else {
dsinclair38fd8442016-09-15 10:15:32 -0700173 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
tsepez0e606b52016-11-18 16:22:41 -0800174 if (!pBSDict)
175 pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
176
177 pBSDict->SetNewFor<CPDF_Number>("W", nWidth);
jaepark27362762016-08-11 13:10:39 -0700178 }
179}
180
181int CPDFSDK_BAAnnot::GetBorderWidth() const {
tsepez698c5712016-09-28 16:47:07 -0700182 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"))
jaepark27362762016-08-11 13:10:39 -0700183 return pBorder->GetIntegerAt(2);
tsepez698c5712016-09-28 16:47:07 -0700184
185 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"))
dsinclair38fd8442016-09-15 10:15:32 -0700186 return pBSDict->GetIntegerFor("W", 1);
tsepez698c5712016-09-28 16:47:07 -0700187
jaepark27362762016-08-11 13:10:39 -0700188 return 1;
189}
190
191void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) {
dsinclair38fd8442016-09-15 10:15:32 -0700192 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
tsepez0e606b52016-11-18 16:22:41 -0800193 if (!pBSDict)
194 pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
jaepark27362762016-08-11 13:10:39 -0700195
196 switch (nStyle) {
197 case BorderStyle::SOLID:
tsepez0e606b52016-11-18 16:22:41 -0800198 pBSDict->SetNewFor<CPDF_Name>("S", "S");
jaepark27362762016-08-11 13:10:39 -0700199 break;
200 case BorderStyle::DASH:
tsepez0e606b52016-11-18 16:22:41 -0800201 pBSDict->SetNewFor<CPDF_Name>("S", "D");
jaepark27362762016-08-11 13:10:39 -0700202 break;
203 case BorderStyle::BEVELED:
tsepez0e606b52016-11-18 16:22:41 -0800204 pBSDict->SetNewFor<CPDF_Name>("S", "B");
jaepark27362762016-08-11 13:10:39 -0700205 break;
206 case BorderStyle::INSET:
tsepez0e606b52016-11-18 16:22:41 -0800207 pBSDict->SetNewFor<CPDF_Name>("S", "I");
jaepark27362762016-08-11 13:10:39 -0700208 break;
209 case BorderStyle::UNDERLINE:
tsepez0e606b52016-11-18 16:22:41 -0800210 pBSDict->SetNewFor<CPDF_Name>("S", "U");
jaepark27362762016-08-11 13:10:39 -0700211 break;
212 default:
213 break;
214 }
215}
216
217BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
dsinclair38fd8442016-09-15 10:15:32 -0700218 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
jaepark27362762016-08-11 13:10:39 -0700219 if (pBSDict) {
dsinclair38fd8442016-09-15 10:15:32 -0700220 CFX_ByteString sBorderStyle = pBSDict->GetStringFor("S", "S");
jaepark27362762016-08-11 13:10:39 -0700221 if (sBorderStyle == "S")
222 return BorderStyle::SOLID;
223 if (sBorderStyle == "D")
224 return BorderStyle::DASH;
225 if (sBorderStyle == "B")
226 return BorderStyle::BEVELED;
227 if (sBorderStyle == "I")
228 return BorderStyle::INSET;
229 if (sBorderStyle == "U")
230 return BorderStyle::UNDERLINE;
231 }
232
dsinclair38fd8442016-09-15 10:15:32 -0700233 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
jaepark27362762016-08-11 13:10:39 -0700234 if (pBorder) {
235 if (pBorder->GetCount() >= 4) {
236 CPDF_Array* pDP = pBorder->GetArrayAt(3);
237 if (pDP && pDP->GetCount() > 0)
238 return BorderStyle::DASH;
239 }
240 }
241
242 return BorderStyle::SOLID;
243}
244
245void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
tsepez0e606b52016-11-18 16:22:41 -0800246 CPDF_Array* pArray = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("C");
tsepez8a3aa452016-11-16 12:26:06 -0800247 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetRValue(color)) /
248 255.0f);
249 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetGValue(color)) /
250 255.0f);
251 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetBValue(color)) /
252 255.0f);
jaepark27362762016-08-11 13:10:39 -0700253}
254
255void CPDFSDK_BAAnnot::RemoveColor() {
dsinclair38fd8442016-09-15 10:15:32 -0700256 m_pAnnot->GetAnnotDict()->RemoveFor("C");
jaepark27362762016-08-11 13:10:39 -0700257}
258
tsepez4cf55152016-11-02 14:37:54 -0700259bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
dsinclair38fd8442016-09-15 10:15:32 -0700260 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) {
jaepark27362762016-08-11 13:10:39 -0700261 size_t nCount = pEntry->GetCount();
262 if (nCount == 1) {
263 FX_FLOAT g = pEntry->GetNumberAt(0) * 255;
264
265 color = FXSYS_RGB((int)g, (int)g, (int)g);
266
tsepez4cf55152016-11-02 14:37:54 -0700267 return true;
jaepark27362762016-08-11 13:10:39 -0700268 } else if (nCount == 3) {
269 FX_FLOAT r = pEntry->GetNumberAt(0) * 255;
270 FX_FLOAT g = pEntry->GetNumberAt(1) * 255;
271 FX_FLOAT b = pEntry->GetNumberAt(2) * 255;
272
273 color = FXSYS_RGB((int)r, (int)g, (int)b);
274
tsepez4cf55152016-11-02 14:37:54 -0700275 return true;
jaepark27362762016-08-11 13:10:39 -0700276 } else if (nCount == 4) {
277 FX_FLOAT c = pEntry->GetNumberAt(0);
278 FX_FLOAT m = pEntry->GetNumberAt(1);
279 FX_FLOAT y = pEntry->GetNumberAt(2);
280 FX_FLOAT k = pEntry->GetNumberAt(3);
281
282 FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
283 FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
284 FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
285
286 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
287
tsepez4cf55152016-11-02 14:37:54 -0700288 return true;
jaepark27362762016-08-11 13:10:39 -0700289 }
290 }
291
tsepez4cf55152016-11-02 14:37:54 -0700292 return false;
jaepark27362762016-08-11 13:10:39 -0700293}
294
295void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
296 const CFX_FloatRect& rcBBox,
297 const CFX_Matrix& matrix,
298 const CFX_ByteString& sContents,
299 const CFX_ByteString& sAPState) {
dsinclair38fd8442016-09-15 10:15:32 -0700300 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
tsepez0e606b52016-11-18 16:22:41 -0800301 if (!pAPDict)
302 pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP");
jaepark27362762016-08-11 13:10:39 -0700303
304 CPDF_Stream* pStream = nullptr;
305 CPDF_Dictionary* pParentDict = nullptr;
jaepark27362762016-08-11 13:10:39 -0700306 if (sAPState.IsEmpty()) {
307 pParentDict = pAPDict;
dsinclair38fd8442016-09-15 10:15:32 -0700308 pStream = pAPDict->GetStreamFor(sAPType);
jaepark27362762016-08-11 13:10:39 -0700309 } else {
dsinclair38fd8442016-09-15 10:15:32 -0700310 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType);
tsepez0e606b52016-11-18 16:22:41 -0800311 if (!pAPTypeDict)
312 pAPTypeDict = pAPDict->SetNewFor<CPDF_Dictionary>(sAPType);
313
jaepark27362762016-08-11 13:10:39 -0700314 pParentDict = pAPTypeDict;
dsinclair38fd8442016-09-15 10:15:32 -0700315 pStream = pAPTypeDict->GetStreamFor(sAPState);
jaepark27362762016-08-11 13:10:39 -0700316 }
317
318 if (!pStream) {
jaepark27362762016-08-11 13:10:39 -0700319 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
tsepez70c4afd2016-11-15 11:33:44 -0800320 pStream = pDoc->NewIndirect<CPDF_Stream>();
tsepez0e606b52016-11-18 16:22:41 -0800321 pParentDict->SetNewFor<CPDF_Reference>(sAPType, pDoc, pStream->GetObjNum());
jaepark27362762016-08-11 13:10:39 -0700322 }
323
324 CPDF_Dictionary* pStreamDict = pStream->GetDict();
325 if (!pStreamDict) {
tsepez698c5712016-09-28 16:47:07 -0700326 pStreamDict =
327 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
tsepez0e606b52016-11-18 16:22:41 -0800328 pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject");
329 pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form");
330 pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
jaepark27362762016-08-11 13:10:39 -0700331 pStream->InitStream(nullptr, 0, pStreamDict);
332 }
333
334 if (pStreamDict) {
dsinclair38fd8442016-09-15 10:15:32 -0700335 pStreamDict->SetMatrixFor("Matrix", matrix);
336 pStreamDict->SetRectFor("BBox", rcBBox);
jaepark27362762016-08-11 13:10:39 -0700337 }
338
tsepeze6db16e2016-09-19 10:45:09 -0700339 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength());
jaepark27362762016-08-11 13:10:39 -0700340}
341
tsepez4cf55152016-11-02 14:37:54 -0700342bool CPDFSDK_BAAnnot::IsVisible() const {
jaepark27362762016-08-11 13:10:39 -0700343 uint32_t nFlags = GetFlags();
344 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
345 (nFlags & ANNOTFLAG_NOVIEW));
346}
347
348CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
dsinclair38fd8442016-09-15 10:15:32 -0700349 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A"));
jaepark27362762016-08-11 13:10:39 -0700350}
351
352void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
tsepezbb577af2016-09-21 19:10:19 -0700353 CPDF_Dictionary* pDict = action.GetDict();
354 if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) {
jaepark27362762016-08-11 13:10:39 -0700355 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
tsepez70c4afd2016-11-15 11:33:44 -0800356 if (pDict->IsInline())
357 pDict = pDoc->AddIndirectObject(pDict->Clone())->AsDictionary();
tsepez0e606b52016-11-18 16:22:41 -0800358 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Reference>("A", pDoc,
359 pDict->GetObjNum());
jaepark27362762016-08-11 13:10:39 -0700360 }
361}
362
363void CPDFSDK_BAAnnot::RemoveAction() {
dsinclair38fd8442016-09-15 10:15:32 -0700364 m_pAnnot->GetAnnotDict()->RemoveFor("A");
jaepark27362762016-08-11 13:10:39 -0700365}
366
367CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
dsinclair38fd8442016-09-15 10:15:32 -0700368 return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA"));
jaepark27362762016-08-11 13:10:39 -0700369}
370
371void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
dsinclair38fd8442016-09-15 10:15:32 -0700372 if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA"))
tsepez0e606b52016-11-18 16:22:41 -0800373 m_pAnnot->GetAnnotDict()->SetFor("AA", pdfium::WrapUnique(aa.GetDict()));
jaepark27362762016-08-11 13:10:39 -0700374}
375
376void CPDFSDK_BAAnnot::RemoveAAction() {
dsinclair38fd8442016-09-15 10:15:32 -0700377 m_pAnnot->GetAnnotDict()->RemoveFor("AA");
jaepark27362762016-08-11 13:10:39 -0700378}
379
380CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
381 CPDF_AAction AAction = GetAAction();
jaepark27362762016-08-11 13:10:39 -0700382 if (AAction.ActionExist(eAAT))
383 return AAction.GetAction(eAAT);
384
385 if (eAAT == CPDF_AAction::ButtonUp)
386 return GetAction();
387
388 return CPDF_Action();
389}
390
391void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
392 CFX_Matrix* pUser2Device,
393 CPDF_RenderOptions* pOptions) {
394 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
395 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
396 CPDF_Annot::Normal, nullptr);
397}
jaepark35512aa2016-08-29 17:15:08 -0700398
399void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) {
400 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot())
401 pAnnot->SetOpenState(bOpenState);
402}