blob: 83cd49858b588eaee8e21a4bc49bd58057ae598b [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07008#include "../include/fpdfxfa/fpdfxfa_doc.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_mgr.h"
10#include "../include/fsdk_baseannot.h"
11
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012//---------------------------------------------------------------------------
Tom Sepez2f2ffec2015-07-23 14:42:09 -070013// CPDFSDK_DateTime
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014//---------------------------------------------------------------------------
Nico Weber9d8ec5a2015-08-04 13:00:21 -070015int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, uint8_t tzminute) {
16 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017}
18
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019FX_BOOL _gAfxIsLeapYear(int16_t year) {
20 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021}
22
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023FX_WORD _gAfxGetYearDays(int16_t year) {
24 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025}
26
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) {
28 uint8_t mDays;
29 switch (month) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -070030 case 1:
31 case 3:
32 case 5:
33 case 7:
34 case 8:
35 case 10:
36 case 12:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 mDays = 31;
38 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
Tom Sepez2f2ffec2015-07-23 14:42:09 -070040 case 4:
41 case 6:
42 case 9:
43 case 11:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 mDays = 30;
45 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046
Tom Sepez2f2ffec2015-07-23 14:42:09 -070047 case 2:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 if (_gAfxIsLeapYear(year) == TRUE)
49 mDays = 29;
50 else
51 mDays = 28;
52 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053
Tom Sepez2f2ffec2015-07-23 14:42:09 -070054 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 mDays = 0;
56 break;
57 }
58
59 return mDays;
60}
61
62CPDFSDK_DateTime::CPDFSDK_DateTime() {
63 ResetDateTime();
64}
65
66CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) {
67 ResetDateTime();
68
69 FromPDFDateTimeString(dtStr);
70}
71
72CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime) {
73 operator=(datetime);
74}
75
76CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st) {
77 operator=(st);
78}
79
80void CPDFSDK_DateTime::ResetDateTime() {
81 tzset();
82
83 time_t curTime;
84 time(&curTime);
85 struct tm* newtime;
86 // newtime = gmtime(&curTime);
87 newtime = localtime(&curTime);
88
89 dt.year = newtime->tm_year + 1900;
90 dt.month = newtime->tm_mon + 1;
91 dt.day = newtime->tm_mday;
92 dt.hour = newtime->tm_hour;
93 dt.minute = newtime->tm_min;
94 dt.second = newtime->tm_sec;
95 // dt.tzHour = _timezone / 3600 * -1;
96 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
97}
98
99CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(
100 const CPDFSDK_DateTime& datetime) {
101 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
102 return *this;
103}
104
105CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(const FX_SYSTEMTIME& st) {
106 tzset();
107
108 dt.year = (int16_t)st.wYear;
109 dt.month = (uint8_t)st.wMonth;
110 dt.day = (uint8_t)st.wDay;
111 dt.hour = (uint8_t)st.wHour;
112 dt.minute = (uint8_t)st.wMinute;
113 dt.second = (uint8_t)st.wSecond;
114 // dt.tzHour = _timezone / 3600 * -1;
115 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
116 return *this;
117}
118
119FX_BOOL CPDFSDK_DateTime::operator==(CPDFSDK_DateTime& datetime) {
120 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0);
121}
122
123FX_BOOL CPDFSDK_DateTime::operator!=(CPDFSDK_DateTime& datetime) {
124 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
125}
126
127FX_BOOL CPDFSDK_DateTime::operator>(CPDFSDK_DateTime& datetime) {
128 CPDFSDK_DateTime dt1 = ToGMT();
129 CPDFSDK_DateTime dt2 = datetime.ToGMT();
130 int d1 =
131 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
132 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
133 (int)dt1.dt.second;
134 int d3 =
135 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
136 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
137 (int)dt2.dt.second;
138
139 if (d1 > d3)
140 return TRUE;
141 if (d2 > d4)
142 return TRUE;
143 return FALSE;
144}
145
146FX_BOOL CPDFSDK_DateTime::operator>=(CPDFSDK_DateTime& datetime) {
147 CPDFSDK_DateTime dt1 = ToGMT();
148 CPDFSDK_DateTime dt2 = datetime.ToGMT();
149 int d1 =
150 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
151 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
152 (int)dt1.dt.second;
153 int d3 =
154 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
155 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
156 (int)dt2.dt.second;
157
158 if (d1 >= d3)
159 return TRUE;
160 if (d2 >= d4)
161 return TRUE;
162 return FALSE;
163}
164
165FX_BOOL CPDFSDK_DateTime::operator<(CPDFSDK_DateTime& datetime) {
166 CPDFSDK_DateTime dt1 = ToGMT();
167 CPDFSDK_DateTime dt2 = datetime.ToGMT();
168 int d1 =
169 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
170 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
171 (int)dt1.dt.second;
172 int d3 =
173 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
174 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
175 (int)dt2.dt.second;
176
177 if (d1 < d3)
178 return TRUE;
179 if (d2 < d4)
180 return TRUE;
181 return FALSE;
182}
183
184FX_BOOL CPDFSDK_DateTime::operator<=(CPDFSDK_DateTime& datetime) {
185 CPDFSDK_DateTime dt1 = ToGMT();
186 CPDFSDK_DateTime dt2 = datetime.ToGMT();
187 int d1 =
188 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
189 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
190 (int)dt1.dt.second;
191 int d3 =
192 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
193 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
194 (int)dt2.dt.second;
195
196 if (d1 <= d3)
197 return TRUE;
198 if (d2 <= d4)
199 return TRUE;
200 return FALSE;
201}
202
203CPDFSDK_DateTime::operator time_t() {
204 struct tm newtime;
205
206 newtime.tm_year = dt.year - 1900;
207 newtime.tm_mon = dt.month - 1;
208 newtime.tm_mday = dt.day;
209 newtime.tm_hour = dt.hour;
210 newtime.tm_min = dt.minute;
211 newtime.tm_sec = dt.second;
212
213 return mktime(&newtime);
214}
215
216CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
217 const CFX_ByteString& dtStr) {
218 int strLength = dtStr.GetLength();
219 if (strLength > 0) {
220 int i = 0;
221 int j, k;
222 FX_CHAR ch;
223 while (i < strLength) {
224 ch = dtStr[i];
225 if (ch >= '0' && ch <= '9')
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700226 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700228 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 if (i >= strLength)
230 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700231
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 j = 0;
233 k = 0;
234 while (i < strLength && j < 4) {
235 ch = dtStr[i];
236 k = k * 10 + ch - '0';
237 j++;
238 if (ch < '0' || ch > '9')
239 break;
240 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700241 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 dt.year = (int16_t)k;
243 if (i >= strLength || j < 4)
244 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 j = 0;
247 k = 0;
248 while (i < strLength && j < 2) {
249 ch = dtStr[i];
250 k = k * 10 + ch - '0';
251 j++;
252 if (ch < '0' || ch > '9')
253 break;
254 i++;
255 }
256 dt.month = (uint8_t)k;
257 if (i >= strLength || j < 2)
258 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 j = 0;
261 k = 0;
262 while (i < strLength && j < 2) {
263 ch = dtStr[i];
264 k = k * 10 + ch - '0';
265 j++;
266 if (ch < '0' || ch > '9')
267 break;
268 i++;
269 }
270 dt.day = (uint8_t)k;
271 if (i >= strLength || j < 2)
272 return *this;
273
274 j = 0;
275 k = 0;
276 while (i < strLength && j < 2) {
277 ch = dtStr[i];
278 k = k * 10 + ch - '0';
279 j++;
280 if (ch < '0' || ch > '9')
281 break;
282 i++;
283 }
284 dt.hour = (uint8_t)k;
285 if (i >= strLength || j < 2)
286 return *this;
287
288 j = 0;
289 k = 0;
290 while (i < strLength && j < 2) {
291 ch = dtStr[i];
292 k = k * 10 + ch - '0';
293 j++;
294 if (ch < '0' || ch > '9')
295 break;
296 i++;
297 }
298 dt.minute = (uint8_t)k;
299 if (i >= strLength || j < 2)
300 return *this;
301
302 j = 0;
303 k = 0;
304 while (i < strLength && j < 2) {
305 ch = dtStr[i];
306 k = k * 10 + ch - '0';
307 j++;
308 if (ch < '0' || ch > '9')
309 break;
310 i++;
311 }
312 dt.second = (uint8_t)k;
313 if (i >= strLength || j < 2)
314 return *this;
315
316 ch = dtStr[i++];
317 if (ch != '-' && ch != '+')
318 return *this;
319 if (ch == '-')
320 dt.tzHour = -1;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700321 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322 dt.tzHour = 1;
323 j = 0;
324 k = 0;
325 while (i < strLength && j < 2) {
326 ch = dtStr[i];
327 k = k * 10 + ch - '0';
328 j++;
329 if (ch < '0' || ch > '9')
330 break;
331 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700332 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 dt.tzHour *= (FX_CHAR)k;
334 if (i >= strLength || j < 2)
335 return *this;
336
337 ch = dtStr[i++];
338 if (ch != '\'')
339 return *this;
340 j = 0;
341 k = 0;
342 while (i < strLength && j < 2) {
343 ch = dtStr[i];
344 k = k * 10 + ch - '0';
345 j++;
346 if (ch < '0' || ch > '9')
347 break;
348 i++;
349 }
350 dt.tzMinute = (uint8_t)k;
351 if (i >= strLength || j < 2)
352 return *this;
353 }
354
355 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356}
357
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() {
359 CFX_ByteString str1;
360 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day,
361 dt.hour, dt.minute, dt.second);
362 if (dt.tzHour < 0)
363 str1 += "-";
364 else
365 str1 += "+";
366 CFX_ByteString str2;
367 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
368 return str1 + str2;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369}
370
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() {
372 CFX_ByteString dtStr;
373 char tempStr[32];
374 memset(tempStr, 0, sizeof(tempStr));
375 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
376 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
377 dtStr = CFX_ByteString(tempStr);
378 if (dt.tzHour < 0)
379 dtStr += CFX_ByteString("-");
380 else
381 dtStr += CFX_ByteString("+");
382 memset(tempStr, 0, sizeof(tempStr));
383 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour),
384 dt.tzMinute);
385 dtStr += CFX_ByteString(tempStr);
386 return dtStr;
387}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700388
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) {
390 CPDFSDK_DateTime dt = *this;
391 time_t t = (time_t)dt;
392 struct tm* pTime = localtime(&t);
393 if (pTime) {
394 st.wYear = (FX_WORD)pTime->tm_year + 1900;
395 st.wMonth = (FX_WORD)pTime->tm_mon + 1;
396 st.wDay = (FX_WORD)pTime->tm_mday;
397 st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
398 st.wHour = (FX_WORD)pTime->tm_hour;
399 st.wMinute = (FX_WORD)pTime->tm_min;
400 st.wSecond = (FX_WORD)pTime->tm_sec;
401 st.wMilliseconds = 0;
402 }
403}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700404
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700405CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() {
406 CPDFSDK_DateTime dt = *this;
407 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
408 dt.dt.tzHour = 0;
409 dt.dt.tzMinute = 0;
410 return dt;
411}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700412
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) {
414 if (days == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700415 return *this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416
417 int16_t y = dt.year, yy;
418 uint8_t m = dt.month;
419 uint8_t d = dt.day;
420 int mdays, ydays, ldays;
421
422 ldays = days;
423 if (ldays > 0) {
424 yy = y;
425 if (((FX_WORD)m * 100 + d) > 300)
426 yy++;
427 ydays = _gAfxGetYearDays(yy);
428 while (ldays >= ydays) {
429 y++;
430 ldays -= ydays;
431 yy++;
432 mdays = _gAfxGetMonthDays(y, m);
433 if (d > mdays) {
434 m++;
435 d -= mdays;
436 }
437 ydays = _gAfxGetYearDays(yy);
438 }
439 mdays = _gAfxGetMonthDays(y, m) - d + 1;
440 while (ldays >= mdays) {
441 ldays -= mdays;
442 m++;
443 d = 1;
444 mdays = _gAfxGetMonthDays(y, m);
445 }
446 d += ldays;
447 } else {
448 ldays *= -1;
449 yy = y;
450 if (((FX_WORD)m * 100 + d) < 300)
451 yy--;
452 ydays = _gAfxGetYearDays(yy);
453 while (ldays >= ydays) {
454 y--;
455 ldays -= ydays;
456 yy--;
457 mdays = _gAfxGetMonthDays(y, m);
458 if (d > mdays) {
459 m++;
460 d -= mdays;
461 }
462 ydays = _gAfxGetYearDays(yy);
463 }
464 while (ldays >= d) {
465 ldays -= d;
466 m--;
467 mdays = _gAfxGetMonthDays(y, m);
468 d = mdays;
469 }
470 d -= ldays;
471 }
472
473 dt.year = y;
474 dt.month = m;
475 dt.day = d;
476
477 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478}
479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) {
481 if (seconds == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700482 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700483
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 int n;
485 int days;
486
487 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
488 if (n < 0) {
489 days = (n - 86399) / 86400;
490 n -= days * 86400;
491 } else {
492 days = n / 86400;
493 n %= 86400;
494 }
495 dt.hour = (uint8_t)(n / 3600);
496 dt.hour %= 24;
497 n %= 3600;
498 dt.minute = (uint8_t)(n / 60);
499 dt.second = (uint8_t)(n % 60);
500 if (days != 0)
501 AddDays(days);
502
503 return *this;
504}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700505
506//---------------------------------------------------------------------------
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700507// CPDFSDK_Annot
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508//---------------------------------------------------------------------------
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView)
510 : m_pPageView(pPageView), m_bSelected(FALSE), m_nTabOrder(-1) {}
511
512// CPDFSDK_BAAnnot
513CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
514 CPDFSDK_PageView* pPageView)
515 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {}
516
517CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {
518 m_pAnnot = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700519}
520
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() {
522 return m_pAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700523}
524
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525FX_BOOL CPDFSDK_Annot::IsSelected() {
526 return m_bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700527}
528
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) {
530 m_bSelected = bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700531}
532
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700533// Tab Order
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534int CPDFSDK_Annot::GetTabOrder() {
535 return m_nTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700536}
537
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538void CPDFSDK_Annot::SetTabOrder(int iTabOrder) {
539 m_nTabOrder = iTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540}
541
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
543 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700544
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 return m_pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700546}
547
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect) {
549 ASSERT(rect.right - rect.left >= GetMinWidth());
550 ASSERT(rect.top - rect.bottom >= GetMinHeight());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700551
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700553}
554
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555CPDF_Rect CPDFSDK_BAAnnot::GetRect() const {
556 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700557
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 CPDF_Rect rect;
559 m_pAnnot->GetRect(rect);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700560
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562}
563
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564CFX_ByteString CPDFSDK_BAAnnot::GetType() const {
565 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700566
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 return m_pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700568}
569
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const {
571 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700572}
573
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574void CPDFSDK_BAAnnot::ResetAppearance() {
575 ASSERT(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -0700576}
577
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
579 const CPDF_Matrix* pUser2Device,
580 CPDF_Annot::AppearanceMode mode,
581 const CPDF_RenderOptions* pOptions) {
582 ASSERT(m_pPageView != NULL);
583 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700584
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
586 mode, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700587}
588
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() {
590 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
594 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
595 if (pAP == NULL)
596 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700597
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 // Choose the right sub-ap
599 const FX_CHAR* ap_entry = "N";
600 if (mode == CPDF_Annot::Down)
601 ap_entry = "D";
602 else if (mode == CPDF_Annot::Rollover)
603 ap_entry = "R";
604 if (!pAP->KeyExist(ap_entry))
605 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700606
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 // Get the AP stream or subdirectory
608 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
609 if (psub == NULL)
610 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700611
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700613}
614
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
616 const CPDF_Matrix* pUser2Device,
617 const CPDF_RenderOptions* pOptions) {
618 ASSERT(m_pAnnot != NULL);
619 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620}
621
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622void CPDFSDK_BAAnnot::ClearCachedAP() {
623 ASSERT(m_pAnnot != NULL);
624 m_pAnnot->ClearCachedAP();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700625}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
628 if (sContents.IsEmpty())
629 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
630 else
631 m_pAnnot->GetAnnotDict()->SetAtString("Contents",
632 PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633}
634
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
636 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637}
638
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
640 if (sName.IsEmpty())
641 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
642 else
643 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644}
645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
647 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700648}
649
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
651 CPDFSDK_DateTime dt(st);
652 CFX_ByteString str = dt.ToPDFDateTimeString();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700653
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 if (str.IsEmpty())
655 m_pAnnot->GetAnnotDict()->RemoveAt("M");
656 else
657 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658}
659
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
661 FX_SYSTEMTIME systime;
662 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700663
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 CPDFSDK_DateTime dt(str);
665 dt.ToSystemTime(systime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700666
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 return systime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670void CPDFSDK_BAAnnot::SetFlags(int nFlags) {
671 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672}
673
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674int CPDFSDK_BAAnnot::GetFlags() const {
675 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676}
677
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
679 if (str.IsEmpty())
680 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
681 else
682 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683}
684
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
686 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687}
688
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689void CPDFSDK_BAAnnot::SetStructParent(int key) {
690 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691}
692
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693int CPDFSDK_BAAnnot::GetStructParent() const {
694 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695}
696
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697// border
698void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
699 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 if (pBorder) {
702 pBorder->SetAt(2, FX_NEW CPDF_Number(nWidth));
703 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700704 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705
706 if (!pBSDict) {
707 pBSDict = FX_NEW CPDF_Dictionary;
708 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700709 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700710
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 pBSDict->SetAtInteger("W", nWidth);
712 }
713}
714
715int CPDFSDK_BAAnnot::GetBorderWidth() const {
716 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) {
717 return pBorder->GetInteger(2);
718 }
719 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) {
720 return pBSDict->GetInteger("W", 1);
721 }
722 return 1;
723}
724
725void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) {
726 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
727 if (!pBSDict) {
728 pBSDict = new CPDF_Dictionary;
729 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
730 }
731
732 switch (nStyle) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700733 case BBS_SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 pBSDict->SetAtName("S", "S");
735 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700736 case BBS_DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 pBSDict->SetAtName("S", "D");
738 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700739 case BBS_BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 pBSDict->SetAtName("S", "B");
741 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700742 case BBS_INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 pBSDict->SetAtName("S", "I");
744 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700745 case BBS_UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 pBSDict->SetAtName("S", "U");
747 break;
748 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749}
750
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751int CPDFSDK_BAAnnot::GetBorderStyle() const {
752 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
753 if (pBSDict) {
754 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
755 if (sBorderStyle == "S")
756 return BBS_SOLID;
757 if (sBorderStyle == "D")
758 return BBS_DASH;
759 if (sBorderStyle == "B")
760 return BBS_BEVELED;
761 if (sBorderStyle == "I")
762 return BBS_INSET;
763 if (sBorderStyle == "U")
764 return BBS_UNDERLINE;
765 }
766
767 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
768 if (pBorder) {
769 if (pBorder->GetCount() >= 4) {
770 CPDF_Array* pDP = pBorder->GetArray(3);
771 if (pDP && pDP->GetCount() > 0)
772 return BBS_DASH;
773 }
774 }
775
776 return BBS_SOLID;
777}
778
779void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) {
780 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
781 if (!pBSDict) {
782 pBSDict = new CPDF_Dictionary;
783 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
784 }
785
786 CPDF_Array* pArray = FX_NEW CPDF_Array;
787 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
788 pArray->AddInteger(array[i]);
789 }
790
791 pBSDict->SetAt("D", pArray);
792}
793
794void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const {
795 CPDF_Array* pDash = NULL;
796
797 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
798 if (pBorder) {
799 pDash = pBorder->GetArray(3);
800 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700801 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 if (pBSDict) {
803 pDash = pBSDict->GetArray("D");
804 }
805 }
806
807 if (pDash) {
808 for (int i = 0, sz = pDash->GetCount(); i < sz; i++) {
809 array.Add(pDash->GetInteger(i));
810 }
811 }
812}
813
814void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
815 CPDF_Array* pArray = new CPDF_Array;
816 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
817 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
818 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
819 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
820}
821
822void CPDFSDK_BAAnnot::RemoveColor() {
823 m_pAnnot->GetAnnotDict()->RemoveAt("C");
824}
825
826FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
827 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) {
828 int nCount = pEntry->GetCount();
829 if (nCount == 1) {
830 FX_FLOAT g = pEntry->GetNumber(0) * 255;
831
832 color = FXSYS_RGB((int)g, (int)g, (int)g);
833
834 return TRUE;
835 } else if (nCount == 3) {
836 FX_FLOAT r = pEntry->GetNumber(0) * 255;
837 FX_FLOAT g = pEntry->GetNumber(1) * 255;
838 FX_FLOAT b = pEntry->GetNumber(2) * 255;
839
840 color = FXSYS_RGB((int)r, (int)g, (int)b);
841
842 return TRUE;
843 } else if (nCount == 4) {
844 FX_FLOAT c = pEntry->GetNumber(0);
845 FX_FLOAT m = pEntry->GetNumber(1);
846 FX_FLOAT y = pEntry->GetNumber(2);
847 FX_FLOAT k = pEntry->GetNumber(3);
848
849 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
850 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
851 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
852
853 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
854
855 return TRUE;
856 }
857 }
858
859 return FALSE;
860}
861
862void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
863 const CPDF_Rect& rcBBox,
864 const CPDF_Matrix& matrix,
865 const CFX_ByteString& sContents,
866 const CFX_ByteString& sAPState) {
867 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
868
869 if (!pAPDict) {
870 pAPDict = new CPDF_Dictionary;
871 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
872 }
873
874 CPDF_Stream* pStream = NULL;
875 CPDF_Dictionary* pParentDict = NULL;
876
877 if (sAPState.IsEmpty()) {
878 pParentDict = pAPDict;
879 pStream = pAPDict->GetStream(sAPType);
880 } else {
881 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
882 if (!pAPTypeDict) {
883 pAPTypeDict = FX_NEW CPDF_Dictionary;
884 pAPDict->SetAt(sAPType, pAPTypeDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700885 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700886
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887 pParentDict = pAPTypeDict;
888 pStream = pAPTypeDict->GetStream(sAPState);
889 }
890
891 if (!pStream) {
892 ASSERT(m_pPageView != NULL);
893 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
894 ASSERT(pDoc != NULL);
895
896 pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
897 int32_t objnum = pDoc->AddIndirectObject(pStream);
898 // pAPDict->SetAtReference(sAPType, pDoc, objnum);
899 ASSERT(pParentDict != NULL);
900 pParentDict->SetAtReference(sAPType, pDoc, objnum);
901 }
902
903 CPDF_Dictionary* pStreamDict = pStream->GetDict();
904
905 if (!pStreamDict) {
906 pStreamDict = FX_NEW CPDF_Dictionary;
907 pStreamDict->SetAtName("Type", "XObject");
908 pStreamDict->SetAtName("Subtype", "Form");
909 pStreamDict->SetAtInteger("FormType", 1);
910 pStream->InitStream(NULL, 0, pStreamDict);
911 }
912
913 if (pStreamDict) {
914 pStreamDict->SetAtMatrix("Matrix", matrix);
915 pStreamDict->SetAtRect("BBox", rcBBox);
916 }
917
918 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE,
919 FALSE);
920}
921
922#define BA_ANNOT_MINWIDTH 1
923#define BA_ANNOT_MINHEIGHT 1
924
925FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
926 return BA_ANNOT_MINWIDTH;
927}
928
929FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
930 return BA_ANNOT_MINHEIGHT;
931}
932
933FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() {
934 return TRUE;
935}
936FX_BOOL CPDFSDK_BAAnnot::IsVisible() const {
937 int nFlags = GetFlags();
938 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
939 (nFlags & ANNOTFLAG_NOVIEW));
940}
941
942CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
943 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
944}
945
946void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
947 ASSERT(action);
948 if ((CPDF_Action&)action !=
949 CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) {
950 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
951 CPDF_Dictionary* pDict = action.GetDict();
952 if (pDict && pDict->GetObjNum() == 0) {
953 pDoc->AddIndirectObject(pDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700954 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
956 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700957}
958
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700959void CPDFSDK_BAAnnot::RemoveAction() {
960 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700961}
962
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700963CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
964 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700965}
966
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
968 ASSERT(aa != NULL);
969
970 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
971 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700972}
973
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974void CPDFSDK_BAAnnot::RemoveAAction() {
975 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976}
977
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700978CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
979 CPDF_AAction AAction = GetAAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 if (AAction.ActionExist(eAAT))
982 return AAction.GetAction(eAAT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700983
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984 if (eAAT == CPDF_AAction::ButtonUp)
985 return GetAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700986
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700987 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700988}
989
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990FX_BOOL CPDFSDK_BAAnnot::IsXFAField() {
991 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700992}
993
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700994void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
995 CPDF_Matrix* pUser2Device,
996 CPDF_RenderOptions* pOptions) {
997 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
998 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
999 CPDF_Annot::Normal, NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001000
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001001 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001002}
1003
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001004CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
1005 if (m_pPageView)
1006 return m_pPageView->GetPDFPage();
1007 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001008}
1009
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001010CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
1011 if (m_pPageView)
1012 return m_pPageView->GetPDFXFAPage();
1013 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001014}