blob: 1f4f279b5eeaece17b3ec501bfd7af9f22d05b68 [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>
tsepez9e05ee12016-11-21 13:19:10 -080010#include <utility>
tsepez0e606b52016-11-18 16:22:41 -080011
dsinclair488b7ad2016-10-04 11:55:50 -070012#include "core/fpdfapi/parser/cpdf_array.h"
13#include "core/fpdfapi/parser/cpdf_document.h"
tsepez0e606b52016-11-18 16:22:41 -080014#include "core/fpdfapi/parser/cpdf_name.h"
dsinclair488b7ad2016-10-04 11:55:50 -070015#include "core/fpdfapi/parser/cpdf_number.h"
tsepez0e606b52016-11-18 16:22:41 -080016#include "core/fpdfapi/parser/cpdf_reference.h"
dsinclair488b7ad2016-10-04 11:55:50 -070017#include "core/fpdfapi/parser/cpdf_stream.h"
tsepez0e606b52016-11-18 16:22:41 -080018#include "core/fpdfapi/parser/cpdf_string.h"
dsinclair488b7ad2016-10-04 11:55:50 -070019#include "core/fpdfapi/parser/fpdf_parser_decode.h"
dsinclair114e46a2016-09-29 17:18:21 -070020#include "fpdfsdk/cpdfsdk_datetime.h"
dsinclair114e46a2016-09-29 17:18:21 -070021#include "fpdfsdk/cpdfsdk_pageview.h"
jaepark27362762016-08-11 13:10:39 -070022
23CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
24 CPDFSDK_PageView* pPageView)
25 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {}
26
27CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {}
28
29CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
Tom Sepez797ca5c2017-05-25 12:03:18 -070030 return m_pAnnot.Get();
jaepark27362762016-08-11 13:10:39 -070031}
32
jaepark35512aa2016-08-29 17:15:08 -070033CPDF_Annot* CPDFSDK_BAAnnot::GetPDFPopupAnnot() const {
34 return m_pAnnot->GetPopupAnnot();
35}
36
jaepark27362762016-08-11 13:10:39 -070037CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
38 return m_pAnnot->GetAnnotDict();
39}
40
41void CPDFSDK_BAAnnot::SetRect(const CFX_FloatRect& rect) {
42 ASSERT(rect.right - rect.left >= GetMinWidth());
43 ASSERT(rect.top - rect.bottom >= GetMinHeight());
44
dsinclair38fd8442016-09-15 10:15:32 -070045 m_pAnnot->GetAnnotDict()->SetRectFor("Rect", rect);
jaepark27362762016-08-11 13:10:39 -070046}
47
48CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const {
jaeparka1d21112016-08-25 13:33:34 -070049 return m_pAnnot->GetRect();
jaepark27362762016-08-11 13:10:39 -070050}
51
jaepark956553e2016-08-31 06:49:27 -070052CPDF_Annot::Subtype CPDFSDK_BAAnnot::GetAnnotSubtype() const {
jaepark9ed91372016-08-26 16:16:10 -070053 return m_pAnnot->GetSubtype();
jaepark27362762016-08-11 13:10:39 -070054}
55
56void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
57 const CFX_Matrix* pUser2Device,
58 CPDF_Annot::AppearanceMode mode,
59 const CPDF_RenderOptions* pOptions) {
60 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
61 mode, pOptions);
62}
63
tsepez4cf55152016-11-02 14:37:54 -070064bool CPDFSDK_BAAnnot::IsAppearanceValid() {
dsinclair38fd8442016-09-15 10:15:32 -070065 return !!m_pAnnot->GetAnnotDict()->GetDictFor("AP");
jaepark27362762016-08-11 13:10:39 -070066}
67
tsepez4cf55152016-11-02 14:37:54 -070068bool CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -070069 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
jaepark27362762016-08-11 13:10:39 -070070 if (!pAP)
tsepez4cf55152016-11-02 14:37:54 -070071 return false;
jaepark27362762016-08-11 13:10:39 -070072
73 // Choose the right sub-ap
Dan Sinclair812e96c2017-03-13 16:43:37 -040074 const char* ap_entry = "N";
jaepark27362762016-08-11 13:10:39 -070075 if (mode == CPDF_Annot::Down)
76 ap_entry = "D";
77 else if (mode == CPDF_Annot::Rollover)
78 ap_entry = "R";
79 if (!pAP->KeyExist(ap_entry))
80 ap_entry = "N";
81
82 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -070083 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
jaepark27362762016-08-11 13:10:39 -070084 return !!psub;
85}
86
87void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
88 const CFX_Matrix* pUser2Device,
89 const CPDF_RenderOptions* pOptions) {
90 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
91}
92
93void CPDFSDK_BAAnnot::ClearCachedAP() {
94 m_pAnnot->ClearCachedAP();
95}
96
97void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
tsepez0e606b52016-11-18 16:22:41 -080098 if (sContents.IsEmpty()) {
dsinclair38fd8442016-09-15 10:15:32 -070099 m_pAnnot->GetAnnotDict()->RemoveFor("Contents");
tsepez0e606b52016-11-18 16:22:41 -0800100 } else {
101 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
102 "Contents", PDF_EncodeText(sContents), false);
103 }
jaepark27362762016-08-11 13:10:39 -0700104}
105
106CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
dsinclair38fd8442016-09-15 10:15:32 -0700107 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("Contents");
jaepark27362762016-08-11 13:10:39 -0700108}
109
110void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
tsepez0e606b52016-11-18 16:22:41 -0800111 if (sName.IsEmpty()) {
dsinclair38fd8442016-09-15 10:15:32 -0700112 m_pAnnot->GetAnnotDict()->RemoveFor("NM");
tsepez0e606b52016-11-18 16:22:41 -0800113 } else {
114 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
115 "NM", PDF_EncodeText(sName), false);
116 }
jaepark27362762016-08-11 13:10:39 -0700117}
118
119CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
dsinclair38fd8442016-09-15 10:15:32 -0700120 return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("NM");
jaepark27362762016-08-11 13:10:39 -0700121}
122
123void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
124 CPDFSDK_DateTime dt(st);
125 CFX_ByteString str = dt.ToPDFDateTimeString();
jaepark27362762016-08-11 13:10:39 -0700126 if (str.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -0700127 m_pAnnot->GetAnnotDict()->RemoveFor("M");
jaepark27362762016-08-11 13:10:39 -0700128 else
tsepez0e606b52016-11-18 16:22:41 -0800129 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("M", str, false);
jaepark27362762016-08-11 13:10:39 -0700130}
131
132FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
133 FX_SYSTEMTIME systime;
dsinclair38fd8442016-09-15 10:15:32 -0700134 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetStringFor("M");
jaepark27362762016-08-11 13:10:39 -0700135 CPDFSDK_DateTime dt(str);
136 dt.ToSystemTime(systime);
jaepark27362762016-08-11 13:10:39 -0700137 return systime;
138}
139
140void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) {
tsepez0e606b52016-11-18 16:22:41 -0800141 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F",
142 static_cast<int>(nFlags));
jaepark27362762016-08-11 13:10:39 -0700143}
144
145uint32_t CPDFSDK_BAAnnot::GetFlags() const {
dsinclair38fd8442016-09-15 10:15:32 -0700146 return m_pAnnot->GetAnnotDict()->GetIntegerFor("F");
jaepark27362762016-08-11 13:10:39 -0700147}
148
149void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
150 if (str.IsEmpty())
dsinclair38fd8442016-09-15 10:15:32 -0700151 m_pAnnot->GetAnnotDict()->RemoveFor("AS");
jaepark27362762016-08-11 13:10:39 -0700152 else
tsepez0e606b52016-11-18 16:22:41 -0800153 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("AS", str, false);
jaepark27362762016-08-11 13:10:39 -0700154}
155
156CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
dsinclair38fd8442016-09-15 10:15:32 -0700157 return m_pAnnot->GetAnnotDict()->GetStringFor("AS");
jaepark27362762016-08-11 13:10:39 -0700158}
159
160void CPDFSDK_BAAnnot::SetStructParent(int key) {
tsepez0e606b52016-11-18 16:22:41 -0800161 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("StructParent", key);
jaepark27362762016-08-11 13:10:39 -0700162}
163
164int CPDFSDK_BAAnnot::GetStructParent() const {
dsinclair38fd8442016-09-15 10:15:32 -0700165 return m_pAnnot->GetAnnotDict()->GetIntegerFor("StructParent");
jaepark27362762016-08-11 13:10:39 -0700166}
167
168// border
169void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
dsinclair38fd8442016-09-15 10:15:32 -0700170 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
jaepark27362762016-08-11 13:10:39 -0700171 if (pBorder) {
tsepez8a3aa452016-11-16 12:26:06 -0800172 pBorder->SetNewAt<CPDF_Number>(2, nWidth);
jaepark27362762016-08-11 13:10:39 -0700173 } else {
dsinclair38fd8442016-09-15 10:15:32 -0700174 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
tsepez0e606b52016-11-18 16:22:41 -0800175 if (!pBSDict)
176 pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
177
178 pBSDict->SetNewFor<CPDF_Number>("W", nWidth);
jaepark27362762016-08-11 13:10:39 -0700179 }
180}
181
182int CPDFSDK_BAAnnot::GetBorderWidth() const {
tsepez698c5712016-09-28 16:47:07 -0700183 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"))
jaepark27362762016-08-11 13:10:39 -0700184 return pBorder->GetIntegerAt(2);
tsepez698c5712016-09-28 16:47:07 -0700185
186 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"))
dsinclair38fd8442016-09-15 10:15:32 -0700187 return pBSDict->GetIntegerFor("W", 1);
tsepez698c5712016-09-28 16:47:07 -0700188
jaepark27362762016-08-11 13:10:39 -0700189 return 1;
190}
191
192void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) {
dsinclair38fd8442016-09-15 10:15:32 -0700193 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
tsepez0e606b52016-11-18 16:22:41 -0800194 if (!pBSDict)
195 pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
jaepark27362762016-08-11 13:10:39 -0700196
197 switch (nStyle) {
198 case BorderStyle::SOLID:
tsepez0e606b52016-11-18 16:22:41 -0800199 pBSDict->SetNewFor<CPDF_Name>("S", "S");
jaepark27362762016-08-11 13:10:39 -0700200 break;
201 case BorderStyle::DASH:
tsepez0e606b52016-11-18 16:22:41 -0800202 pBSDict->SetNewFor<CPDF_Name>("S", "D");
jaepark27362762016-08-11 13:10:39 -0700203 break;
204 case BorderStyle::BEVELED:
tsepez0e606b52016-11-18 16:22:41 -0800205 pBSDict->SetNewFor<CPDF_Name>("S", "B");
jaepark27362762016-08-11 13:10:39 -0700206 break;
207 case BorderStyle::INSET:
tsepez0e606b52016-11-18 16:22:41 -0800208 pBSDict->SetNewFor<CPDF_Name>("S", "I");
jaepark27362762016-08-11 13:10:39 -0700209 break;
210 case BorderStyle::UNDERLINE:
tsepez0e606b52016-11-18 16:22:41 -0800211 pBSDict->SetNewFor<CPDF_Name>("S", "U");
jaepark27362762016-08-11 13:10:39 -0700212 break;
213 default:
214 break;
215 }
216}
217
218BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
dsinclair38fd8442016-09-15 10:15:32 -0700219 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
jaepark27362762016-08-11 13:10:39 -0700220 if (pBSDict) {
dsinclair38fd8442016-09-15 10:15:32 -0700221 CFX_ByteString sBorderStyle = pBSDict->GetStringFor("S", "S");
jaepark27362762016-08-11 13:10:39 -0700222 if (sBorderStyle == "S")
223 return BorderStyle::SOLID;
224 if (sBorderStyle == "D")
225 return BorderStyle::DASH;
226 if (sBorderStyle == "B")
227 return BorderStyle::BEVELED;
228 if (sBorderStyle == "I")
229 return BorderStyle::INSET;
230 if (sBorderStyle == "U")
231 return BorderStyle::UNDERLINE;
232 }
233
dsinclair38fd8442016-09-15 10:15:32 -0700234 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
jaepark27362762016-08-11 13:10:39 -0700235 if (pBorder) {
236 if (pBorder->GetCount() >= 4) {
237 CPDF_Array* pDP = pBorder->GetArrayAt(3);
238 if (pDP && pDP->GetCount() > 0)
239 return BorderStyle::DASH;
240 }
241 }
242
243 return BorderStyle::SOLID;
244}
245
246void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
tsepez0e606b52016-11-18 16:22:41 -0800247 CPDF_Array* pArray = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("C");
Dan Sinclair05df0752017-03-14 14:43:42 -0400248 pArray->AddNew<CPDF_Number>(static_cast<float>(FXSYS_GetRValue(color)) /
tsepez8a3aa452016-11-16 12:26:06 -0800249 255.0f);
Dan Sinclair05df0752017-03-14 14:43:42 -0400250 pArray->AddNew<CPDF_Number>(static_cast<float>(FXSYS_GetGValue(color)) /
tsepez8a3aa452016-11-16 12:26:06 -0800251 255.0f);
Dan Sinclair05df0752017-03-14 14:43:42 -0400252 pArray->AddNew<CPDF_Number>(static_cast<float>(FXSYS_GetBValue(color)) /
tsepez8a3aa452016-11-16 12:26:06 -0800253 255.0f);
jaepark27362762016-08-11 13:10:39 -0700254}
255
256void CPDFSDK_BAAnnot::RemoveColor() {
dsinclair38fd8442016-09-15 10:15:32 -0700257 m_pAnnot->GetAnnotDict()->RemoveFor("C");
jaepark27362762016-08-11 13:10:39 -0700258}
259
tsepez4cf55152016-11-02 14:37:54 -0700260bool CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
dsinclair38fd8442016-09-15 10:15:32 -0700261 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArrayFor("C")) {
jaepark27362762016-08-11 13:10:39 -0700262 size_t nCount = pEntry->GetCount();
263 if (nCount == 1) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400264 float g = pEntry->GetNumberAt(0) * 255;
jaepark27362762016-08-11 13:10:39 -0700265
266 color = FXSYS_RGB((int)g, (int)g, (int)g);
267
tsepez4cf55152016-11-02 14:37:54 -0700268 return true;
jaepark27362762016-08-11 13:10:39 -0700269 } else if (nCount == 3) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400270 float r = pEntry->GetNumberAt(0) * 255;
271 float g = pEntry->GetNumberAt(1) * 255;
272 float b = pEntry->GetNumberAt(2) * 255;
jaepark27362762016-08-11 13:10:39 -0700273
274 color = FXSYS_RGB((int)r, (int)g, (int)b);
275
tsepez4cf55152016-11-02 14:37:54 -0700276 return true;
jaepark27362762016-08-11 13:10:39 -0700277 } else if (nCount == 4) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400278 float c = pEntry->GetNumberAt(0);
279 float m = pEntry->GetNumberAt(1);
280 float y = pEntry->GetNumberAt(2);
281 float k = pEntry->GetNumberAt(3);
jaepark27362762016-08-11 13:10:39 -0700282
Dan Sinclair05df0752017-03-14 14:43:42 -0400283 float r = 1.0f - std::min(1.0f, c + k);
284 float g = 1.0f - std::min(1.0f, m + k);
285 float b = 1.0f - std::min(1.0f, y + k);
jaepark27362762016-08-11 13:10:39 -0700286
287 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
288
tsepez4cf55152016-11-02 14:37:54 -0700289 return true;
jaepark27362762016-08-11 13:10:39 -0700290 }
291 }
292
tsepez4cf55152016-11-02 14:37:54 -0700293 return false;
jaepark27362762016-08-11 13:10:39 -0700294}
295
296void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
297 const CFX_FloatRect& rcBBox,
298 const CFX_Matrix& matrix,
299 const CFX_ByteString& sContents,
300 const CFX_ByteString& sAPState) {
dsinclair38fd8442016-09-15 10:15:32 -0700301 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
tsepez0e606b52016-11-18 16:22:41 -0800302 if (!pAPDict)
303 pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP");
jaepark27362762016-08-11 13:10:39 -0700304
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);
tsepez0e606b52016-11-18 16:22:41 -0800312 if (!pAPTypeDict)
313 pAPTypeDict = pAPDict->SetNewFor<CPDF_Dictionary>(sAPType);
314
jaepark27362762016-08-11 13:10:39 -0700315 pParentDict = pAPTypeDict;
dsinclair38fd8442016-09-15 10:15:32 -0700316 pStream = pAPTypeDict->GetStreamFor(sAPState);
jaepark27362762016-08-11 13:10:39 -0700317 }
318
319 if (!pStream) {
jaepark27362762016-08-11 13:10:39 -0700320 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
tsepez70c4afd2016-11-15 11:33:44 -0800321 pStream = pDoc->NewIndirect<CPDF_Stream>();
tsepez0e606b52016-11-18 16:22:41 -0800322 pParentDict->SetNewFor<CPDF_Reference>(sAPType, pDoc, pStream->GetObjNum());
jaepark27362762016-08-11 13:10:39 -0700323 }
324
325 CPDF_Dictionary* pStreamDict = pStream->GetDict();
326 if (!pStreamDict) {
tsepez9e05ee12016-11-21 13:19:10 -0800327 auto pNewDict = pdfium::MakeUnique<CPDF_Dictionary>(
328 m_pAnnot->GetDocument()->GetByteStringPool());
329 pStreamDict = pNewDict.get();
tsepez0e606b52016-11-18 16:22:41 -0800330 pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject");
331 pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form");
332 pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
tsepez9e05ee12016-11-21 13:19:10 -0800333 pStream->InitStream(nullptr, 0, std::move(pNewDict));
jaepark27362762016-08-11 13:10:39 -0700334 }
tsepez9e05ee12016-11-21 13:19:10 -0800335 pStreamDict->SetMatrixFor("Matrix", matrix);
336 pStreamDict->SetRectFor("BBox", rcBBox);
tsepeze6db16e2016-09-19 10:45:09 -0700337 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength());
jaepark27362762016-08-11 13:10:39 -0700338}
339
tsepez4cf55152016-11-02 14:37:54 -0700340bool CPDFSDK_BAAnnot::IsVisible() const {
jaepark27362762016-08-11 13:10:39 -0700341 uint32_t nFlags = GetFlags();
342 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
343 (nFlags & ANNOTFLAG_NOVIEW));
344}
345
346CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
dsinclair38fd8442016-09-15 10:15:32 -0700347 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A"));
jaepark27362762016-08-11 13:10:39 -0700348}
349
350void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
tsepezbb577af2016-09-21 19:10:19 -0700351 CPDF_Dictionary* pDict = action.GetDict();
352 if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) {
jaepark27362762016-08-11 13:10:39 -0700353 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
tsepez70c4afd2016-11-15 11:33:44 -0800354 if (pDict->IsInline())
355 pDict = pDoc->AddIndirectObject(pDict->Clone())->AsDictionary();
tsepez0e606b52016-11-18 16:22:41 -0800356 m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Reference>("A", pDoc,
357 pDict->GetObjNum());
jaepark27362762016-08-11 13:10:39 -0700358 }
359}
360
361void CPDFSDK_BAAnnot::RemoveAction() {
dsinclair38fd8442016-09-15 10:15:32 -0700362 m_pAnnot->GetAnnotDict()->RemoveFor("A");
jaepark27362762016-08-11 13:10:39 -0700363}
364
365CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
dsinclair38fd8442016-09-15 10:15:32 -0700366 return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA"));
jaepark27362762016-08-11 13:10:39 -0700367}
368
369void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
dsinclair38fd8442016-09-15 10:15:32 -0700370 if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA"))
tsepez0e606b52016-11-18 16:22:41 -0800371 m_pAnnot->GetAnnotDict()->SetFor("AA", pdfium::WrapUnique(aa.GetDict()));
jaepark27362762016-08-11 13:10:39 -0700372}
373
374void CPDFSDK_BAAnnot::RemoveAAction() {
dsinclair38fd8442016-09-15 10:15:32 -0700375 m_pAnnot->GetAnnotDict()->RemoveFor("AA");
jaepark27362762016-08-11 13:10:39 -0700376}
377
378CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
379 CPDF_AAction AAction = GetAAction();
jaepark27362762016-08-11 13:10:39 -0700380 if (AAction.ActionExist(eAAT))
381 return AAction.GetAction(eAAT);
382
383 if (eAAT == CPDF_AAction::ButtonUp)
384 return GetAction();
385
386 return CPDF_Action();
387}
388
jaepark35512aa2016-08-29 17:15:08 -0700389void CPDFSDK_BAAnnot::SetOpenState(bool bOpenState) {
390 if (CPDF_Annot* pAnnot = m_pAnnot->GetPopupAnnot())
391 pAnnot->SetOpenState(bOpenState);
392}