blob: ee4b55d290a8999065977335d380e9293c5cd845 [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
dsinclair488b7ad2016-10-04 11:55:50 -07009#include "core/fpdfapi/parser/cpdf_array.h"
10#include "core/fpdfapi/parser/cpdf_document.h"
11#include "core/fpdfapi/parser/cpdf_number.h"
12#include "core/fpdfapi/parser/cpdf_stream.h"
13#include "core/fpdfapi/parser/fpdf_parser_decode.h"
dsinclair114e46a2016-09-29 17:18:21 -070014#include "fpdfsdk/cpdfsdk_datetime.h"
dsinclair114e46a2016-09-29 17:18:21 -070015#include "fpdfsdk/cpdfsdk_pageview.h"
jaepark27362762016-08-11 13:10:39 -070016
17CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
18 CPDFSDK_PageView* pPageView)
19 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {}
20
21CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {}
22
23CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
24 return m_pAnnot;
25}
26
jaepark35512aa2016-08-29 17:15:08 -070027CPDF_Annot* CPDFSDK_BAAnnot::GetPDFPopupAnnot() const {
28 return m_pAnnot->GetPopupAnnot();
29}
30
jaepark27362762016-08-11 13:10:39 -070031CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
32 return m_pAnnot->GetAnnotDict();
33}
34
35void CPDFSDK_BAAnnot::SetRect(const CFX_FloatRect& rect) {
36 ASSERT(rect.right - rect.left >= GetMinWidth());
37 ASSERT(rect.top - rect.bottom >= GetMinHeight());
38
dsinclair38fd8442016-09-15 10:15:32 -070039 m_pAnnot->GetAnnotDict()->SetRectFor("Rect", rect);
jaepark27362762016-08-11 13:10:39 -070040}
41
42CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const {
jaeparka1d21112016-08-25 13:33:34 -070043 return m_pAnnot->GetRect();
jaepark27362762016-08-11 13:10:39 -070044}
45
jaepark956553e2016-08-31 06:49:27 -070046CPDF_Annot::Subtype CPDFSDK_BAAnnot::GetAnnotSubtype() const {
jaepark9ed91372016-08-26 16:16:10 -070047 return m_pAnnot->GetSubtype();
jaepark27362762016-08-11 13:10:39 -070048}
49
50void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
51 const CFX_Matrix* pUser2Device,
52 CPDF_Annot::AppearanceMode mode,
53 const CPDF_RenderOptions* pOptions) {
54 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
55 mode, pOptions);
56}
57
tsepez4cf55152016-11-02 14:37:54 -070058bool CPDFSDK_BAAnnot::IsAppearanceValid() {
dsinclair38fd8442016-09-15 10:15:32 -070059 return !!m_pAnnot->GetAnnotDict()->GetDictFor("AP");
jaepark27362762016-08-11 13:10:39 -070060}
61
tsepez4cf55152016-11-02 14:37:54 -070062bool CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -070063 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
jaepark27362762016-08-11 13:10:39 -070064 if (!pAP)
tsepez4cf55152016-11-02 14:37:54 -070065 return false;
jaepark27362762016-08-11 13:10:39 -070066
67 // Choose the right sub-ap
68 const FX_CHAR* ap_entry = "N";
69 if (mode == CPDF_Annot::Down)
70 ap_entry = "D";
71 else if (mode == CPDF_Annot::Rollover)
72 ap_entry = "R";
73 if (!pAP->KeyExist(ap_entry))
74 ap_entry = "N";
75
76 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -070077 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
jaepark27362762016-08-11 13:10:39 -070078 return !!psub;
79}
80
81void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
82 const CFX_Matrix* pUser2Device,
83 const CPDF_RenderOptions* pOptions) {
84 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
85}
86
87void CPDFSDK_BAAnnot::ClearCachedAP() {
88 m_pAnnot->ClearCachedAP();
89}
90
91void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
92 if (sContents.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -070093 m_pAnnot->GetAnnotDict()->RemoveFor("Contents");
jaepark27362762016-08-11 13:10:39 -070094 else
dsinclair38fd8442016-09-15 10:15:32 -070095 m_pAnnot->GetAnnotDict()->SetStringFor("Contents",
96 PDF_EncodeText(sContents));
jaepark27362762016-08-11 13:10:39 -070097}
98
99CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
dsinclair38fd8442016-09-15 10:15:32 -0700100 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("Contents");
jaepark27362762016-08-11 13:10:39 -0700101}
102
103void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
104 if (sName.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -0700105 m_pAnnot->GetAnnotDict()->RemoveFor("NM");
jaepark27362762016-08-11 13:10:39 -0700106 else
dsinclair38fd8442016-09-15 10:15:32 -0700107 m_pAnnot->GetAnnotDict()->SetStringFor("NM", PDF_EncodeText(sName));
jaepark27362762016-08-11 13:10:39 -0700108}
109
110CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
dsinclair38fd8442016-09-15 10:15:32 -0700111 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("NM");
jaepark27362762016-08-11 13:10:39 -0700112}
113
114void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
115 CPDFSDK_DateTime dt(st);
116 CFX_ByteString str = dt.ToPDFDateTimeString();
117
118 if (str.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -0700119 m_pAnnot->GetAnnotDict()->RemoveFor("M");
jaepark27362762016-08-11 13:10:39 -0700120 else
dsinclair38fd8442016-09-15 10:15:32 -0700121 m_pAnnot->GetAnnotDict()->SetStringFor("M", str);
jaepark27362762016-08-11 13:10:39 -0700122}
123
124FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
125 FX_SYSTEMTIME systime;
dsinclair38fd8442016-09-15 10:15:32 -0700126 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetStringFor("M");
jaepark27362762016-08-11 13:10:39 -0700127
128 CPDFSDK_DateTime dt(str);
129 dt.ToSystemTime(systime);
130
131 return systime;
132}
133
134void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) {
dsinclair38fd8442016-09-15 10:15:32 -0700135 m_pAnnot->GetAnnotDict()->SetIntegerFor("F", nFlags);
jaepark27362762016-08-11 13:10:39 -0700136}
137
138uint32_t CPDFSDK_BAAnnot::GetFlags() const {
dsinclair38fd8442016-09-15 10:15:32 -0700139 return m_pAnnot->GetAnnotDict()->GetIntegerFor("F");
jaepark27362762016-08-11 13:10:39 -0700140}
141
142void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
143 if (str.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -0700144 m_pAnnot->GetAnnotDict()->RemoveFor("AS");
jaepark27362762016-08-11 13:10:39 -0700145 else
dsinclair38fd8442016-09-15 10:15:32 -0700146 m_pAnnot->GetAnnotDict()->SetStringFor("AS", str);
jaepark27362762016-08-11 13:10:39 -0700147}
148
149CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
dsinclair38fd8442016-09-15 10:15:32 -0700150 return m_pAnnot->GetAnnotDict()->GetStringFor("AS");
jaepark27362762016-08-11 13:10:39 -0700151}
152
153void CPDFSDK_BAAnnot::SetStructParent(int key) {
dsinclair38fd8442016-09-15 10:15:32 -0700154 m_pAnnot->GetAnnotDict()->SetIntegerFor("StructParent", key);
jaepark27362762016-08-11 13:10:39 -0700155}
156
157int CPDFSDK_BAAnnot::GetStructParent() const {
dsinclair38fd8442016-09-15 10:15:32 -0700158 return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent");
jaepark27362762016-08-11 13:10:39 -0700159}
160
161// border
162void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
dsinclair38fd8442016-09-15 10:15:32 -0700163 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
jaepark27362762016-08-11 13:10:39 -0700164 if (pBorder) {
tsepez8a3aa452016-11-16 12:26:06 -0800165 pBorder->SetNewAt<CPDF_Number>(2, nWidth);
jaepark27362762016-08-11 13:10:39 -0700166 } else {
dsinclair38fd8442016-09-15 10:15:32 -0700167 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
jaepark27362762016-08-11 13:10:39 -0700168 if (!pBSDict) {
tsepez698c5712016-09-28 16:47:07 -0700169 pBSDict =
170 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
dsinclair38fd8442016-09-15 10:15:32 -0700171 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict);
jaepark27362762016-08-11 13:10:39 -0700172 }
dsinclair38fd8442016-09-15 10:15:32 -0700173 pBSDict->SetIntegerFor("W", nWidth);
jaepark27362762016-08-11 13:10:39 -0700174 }
175}
176
177int CPDFSDK_BAAnnot::GetBorderWidth() const {
tsepez698c5712016-09-28 16:47:07 -0700178 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"))
jaepark27362762016-08-11 13:10:39 -0700179 return pBorder->GetIntegerAt(2);
tsepez698c5712016-09-28 16:47:07 -0700180
181 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"))
dsinclair38fd8442016-09-15 10:15:32 -0700182 return pBSDict->GetIntegerFor("W", 1);
tsepez698c5712016-09-28 16:47:07 -0700183
jaepark27362762016-08-11 13:10:39 -0700184 return 1;
185}
186
187void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) {
dsinclair38fd8442016-09-15 10:15:32 -0700188 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
jaepark27362762016-08-11 13:10:39 -0700189 if (!pBSDict) {
tsepez698c5712016-09-28 16:47:07 -0700190 pBSDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
dsinclair38fd8442016-09-15 10:15:32 -0700191 m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict);
jaepark27362762016-08-11 13:10:39 -0700192 }
193
194 switch (nStyle) {
195 case BorderStyle::SOLID:
dsinclair38fd8442016-09-15 10:15:32 -0700196 pBSDict->SetNameFor("S", "S");
jaepark27362762016-08-11 13:10:39 -0700197 break;
198 case BorderStyle::DASH:
dsinclair38fd8442016-09-15 10:15:32 -0700199 pBSDict->SetNameFor("S", "D");
jaepark27362762016-08-11 13:10:39 -0700200 break;
201 case BorderStyle::BEVELED:
dsinclair38fd8442016-09-15 10:15:32 -0700202 pBSDict->SetNameFor("S", "B");
jaepark27362762016-08-11 13:10:39 -0700203 break;
204 case BorderStyle::INSET:
dsinclair38fd8442016-09-15 10:15:32 -0700205 pBSDict->SetNameFor("S", "I");
jaepark27362762016-08-11 13:10:39 -0700206 break;
207 case BorderStyle::UNDERLINE:
dsinclair38fd8442016-09-15 10:15:32 -0700208 pBSDict->SetNameFor("S", "U");
jaepark27362762016-08-11 13:10:39 -0700209 break;
210 default:
211 break;
212 }
213}
214
215BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
dsinclair38fd8442016-09-15 10:15:32 -0700216 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
jaepark27362762016-08-11 13:10:39 -0700217 if (pBSDict) {
dsinclair38fd8442016-09-15 10:15:32 -0700218 CFX_ByteString sBorderStyle = pBSDict->GetStringFor("S", "S");
jaepark27362762016-08-11 13:10:39 -0700219 if (sBorderStyle == "S")
220 return BorderStyle::SOLID;
221 if (sBorderStyle == "D")
222 return BorderStyle::DASH;
223 if (sBorderStyle == "B")
224 return BorderStyle::BEVELED;
225 if (sBorderStyle == "I")
226 return BorderStyle::INSET;
227 if (sBorderStyle == "U")
228 return BorderStyle::UNDERLINE;
229 }
230
dsinclair38fd8442016-09-15 10:15:32 -0700231 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
jaepark27362762016-08-11 13:10:39 -0700232 if (pBorder) {
233 if (pBorder->GetCount() >= 4) {
234 CPDF_Array* pDP = pBorder->GetArrayAt(3);
235 if (pDP && pDP->GetCount() > 0)
236 return BorderStyle::DASH;
237 }
238 }
239
240 return BorderStyle::SOLID;
241}
242
243void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
244 CPDF_Array* pArray = new CPDF_Array;
tsepez8a3aa452016-11-16 12:26:06 -0800245 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetRValue(color)) /
246 255.0f);
247 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetGValue(color)) /
248 255.0f);
249 pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetBValue(color)) /
250 255.0f);
dsinclair38fd8442016-09-15 10:15:32 -0700251 m_pAnnot->GetAnnotDict()->SetFor("C", pArray);
jaepark27362762016-08-11 13:10:39 -0700252}
253
254void CPDFSDK_BAAnnot::RemoveColor() {
dsinclair38fd8442016-09-15 10:15:32 -0700255 m_pAnnot->GetAnnotDict()->RemoveFor("C");
jaepark27362762016-08-11 13:10:39 -0700256}
257
tsepez4cf55152016-11-02 14:37:54 -0700258bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
dsinclair38fd8442016-09-15 10:15:32 -0700259 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) {
jaepark27362762016-08-11 13:10:39 -0700260 size_t nCount = pEntry->GetCount();
261 if (nCount == 1) {
262 FX_FLOAT g = pEntry->GetNumberAt(0) * 255;
263
264 color = FXSYS_RGB((int)g, (int)g, (int)g);
265
tsepez4cf55152016-11-02 14:37:54 -0700266 return true;
jaepark27362762016-08-11 13:10:39 -0700267 } else if (nCount == 3) {
268 FX_FLOAT r = pEntry->GetNumberAt(0) * 255;
269 FX_FLOAT g = pEntry->GetNumberAt(1) * 255;
270 FX_FLOAT b = pEntry->GetNumberAt(2) * 255;
271
272 color = FXSYS_RGB((int)r, (int)g, (int)b);
273
tsepez4cf55152016-11-02 14:37:54 -0700274 return true;
jaepark27362762016-08-11 13:10:39 -0700275 } else if (nCount == 4) {
276 FX_FLOAT c = pEntry->GetNumberAt(0);
277 FX_FLOAT m = pEntry->GetNumberAt(1);
278 FX_FLOAT y = pEntry->GetNumberAt(2);
279 FX_FLOAT k = pEntry->GetNumberAt(3);
280
281 FX_FLOAT r = 1.0f - std::min(1.0f, c + k);
282 FX_FLOAT g = 1.0f - std::min(1.0f, m + k);
283 FX_FLOAT b = 1.0f - std::min(1.0f, y + k);
284
285 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
286
tsepez4cf55152016-11-02 14:37:54 -0700287 return true;
jaepark27362762016-08-11 13:10:39 -0700288 }
289 }
290
tsepez4cf55152016-11-02 14:37:54 -0700291 return false;
jaepark27362762016-08-11 13:10:39 -0700292}
293
294void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
295 const CFX_FloatRect& rcBBox,
296 const CFX_Matrix& matrix,
297 const CFX_ByteString& sContents,
298 const CFX_ByteString& sAPState) {
dsinclair38fd8442016-09-15 10:15:32 -0700299 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
jaepark27362762016-08-11 13:10:39 -0700300 if (!pAPDict) {
tsepez698c5712016-09-28 16:47:07 -0700301 pAPDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
dsinclair38fd8442016-09-15 10:15:32 -0700302 m_pAnnot->GetAnnotDict()->SetFor("AP", pAPDict);
jaepark27362762016-08-11 13:10:39 -0700303 }
304
305 CPDF_Stream* pStream = nullptr;
306 CPDF_Dictionary* pParentDict = nullptr;
jaepark27362762016-08-11 13:10:39 -0700307 if (sAPState.IsEmpty()) {
308 pParentDict = pAPDict;
dsinclair38fd8442016-09-15 10:15:32 -0700309 pStream = pAPDict->GetStreamFor(sAPType);
jaepark27362762016-08-11 13:10:39 -0700310 } else {
dsinclair38fd8442016-09-15 10:15:32 -0700311 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType);
jaepark27362762016-08-11 13:10:39 -0700312 if (!pAPTypeDict) {
tsepez698c5712016-09-28 16:47:07 -0700313 pAPTypeDict =
314 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
dsinclair38fd8442016-09-15 10:15:32 -0700315 pAPDict->SetFor(sAPType, pAPTypeDict);
jaepark27362762016-08-11 13:10:39 -0700316 }
317 pParentDict = pAPTypeDict;
dsinclair38fd8442016-09-15 10:15:32 -0700318 pStream = pAPTypeDict->GetStreamFor(sAPState);
jaepark27362762016-08-11 13:10:39 -0700319 }
320
321 if (!pStream) {
jaepark27362762016-08-11 13:10:39 -0700322 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
tsepez70c4afd2016-11-15 11:33:44 -0800323 pStream = pDoc->NewIndirect<CPDF_Stream>();
324 pParentDict->SetReferenceFor(sAPType, pDoc, pStream);
jaepark27362762016-08-11 13:10:39 -0700325 }
326
327 CPDF_Dictionary* pStreamDict = pStream->GetDict();
328 if (!pStreamDict) {
tsepez698c5712016-09-28 16:47:07 -0700329 pStreamDict =
330 new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
dsinclair38fd8442016-09-15 10:15:32 -0700331 pStreamDict->SetNameFor("Type", "XObject");
332 pStreamDict->SetNameFor("Subtype", "Form");
333 pStreamDict->SetIntegerFor("FormType", 1);
jaepark27362762016-08-11 13:10:39 -0700334 pStream->InitStream(nullptr, 0, pStreamDict);
335 }
336
337 if (pStreamDict) {
dsinclair38fd8442016-09-15 10:15:32 -0700338 pStreamDict->SetMatrixFor("Matrix", matrix);
339 pStreamDict->SetRectFor("BBox", rcBBox);
jaepark27362762016-08-11 13:10:39 -0700340 }
341
tsepeze6db16e2016-09-19 10:45:09 -0700342 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength());
jaepark27362762016-08-11 13:10:39 -0700343}
344
tsepez4cf55152016-11-02 14:37:54 -0700345bool CPDFSDK_BAAnnot::IsVisible() const {
jaepark27362762016-08-11 13:10:39 -0700346 uint32_t nFlags = GetFlags();
347 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
348 (nFlags & ANNOTFLAG_NOVIEW));
349}
350
351CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
dsinclair38fd8442016-09-15 10:15:32 -0700352 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A"));
jaepark27362762016-08-11 13:10:39 -0700353}
354
355void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
tsepezbb577af2016-09-21 19:10:19 -0700356 CPDF_Dictionary* pDict = action.GetDict();
357 if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) {
jaepark27362762016-08-11 13:10:39 -0700358 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
tsepez70c4afd2016-11-15 11:33:44 -0800359 if (pDict->IsInline())
360 pDict = pDoc->AddIndirectObject(pDict->Clone())->AsDictionary();
361 m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc, pDict);
jaepark27362762016-08-11 13:10:39 -0700362 }
363}
364
365void CPDFSDK_BAAnnot::RemoveAction() {
dsinclair38fd8442016-09-15 10:15:32 -0700366 m_pAnnot->GetAnnotDict()->RemoveFor("A");
jaepark27362762016-08-11 13:10:39 -0700367}
368
369CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
dsinclair38fd8442016-09-15 10:15:32 -0700370 return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA"));
jaepark27362762016-08-11 13:10:39 -0700371}
372
373void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
dsinclair38fd8442016-09-15 10:15:32 -0700374 if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA"))
375 m_pAnnot->GetAnnotDict()->SetFor("AA", aa.GetDict());
jaepark27362762016-08-11 13:10:39 -0700376}
377
378void CPDFSDK_BAAnnot::RemoveAAction() {
dsinclair38fd8442016-09-15 10:15:32 -0700379 m_pAnnot->GetAnnotDict()->RemoveFor("AA");
jaepark27362762016-08-11 13:10:39 -0700380}
381
382CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
383 CPDF_AAction AAction = GetAAction();
384
385 if (AAction.ActionExist(eAAT))
386 return AAction.GetAction(eAAT);
387
388 if (eAAT == CPDF_AAction::ButtonUp)
389 return GetAction();
390
391 return CPDF_Action();
392}
393
394void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
395 CFX_Matrix* pUser2Device,
396 CPDF_RenderOptions* pOptions) {
397 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
398 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
399 CPDF_Annot::Normal, nullptr);
400}
jaepark35512aa2016-08-29 17:15:08 -0700401
402void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) {
403 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot())
404 pAnnot->SetOpenState(bOpenState);
405}