blob: 1c96936f03af4ca66cc69fa9298eb3c39d6b8acb [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
Tom Sepez3343d142015-11-02 09:54:54 -0800521CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 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::DrawAppearance(CFX_RenderDevice* pDevice,
575 const CPDF_Matrix* pUser2Device,
576 CPDF_Annot::AppearanceMode mode,
577 const CPDF_RenderOptions* pOptions) {
578 ASSERT(m_pPageView != NULL);
579 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700580
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
582 mode, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() {
586 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700587}
588
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
590 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
591 if (pAP == NULL)
592 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700593
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 // Choose the right sub-ap
595 const FX_CHAR* ap_entry = "N";
596 if (mode == CPDF_Annot::Down)
597 ap_entry = "D";
598 else if (mode == CPDF_Annot::Rollover)
599 ap_entry = "R";
600 if (!pAP->KeyExist(ap_entry))
601 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700602
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 // Get the AP stream or subdirectory
604 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
605 if (psub == NULL)
606 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700607
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609}
610
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
612 const CPDF_Matrix* pUser2Device,
613 const CPDF_RenderOptions* pOptions) {
614 ASSERT(m_pAnnot != NULL);
615 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616}
617
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618void CPDFSDK_BAAnnot::ClearCachedAP() {
619 ASSERT(m_pAnnot != NULL);
620 m_pAnnot->ClearCachedAP();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700621}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
624 if (sContents.IsEmpty())
625 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
626 else
627 m_pAnnot->GetAnnotDict()->SetAtString("Contents",
628 PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629}
630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
632 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633}
634
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
636 if (sName.IsEmpty())
637 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
638 else
639 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700640}
641
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
643 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644}
645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
647 CPDFSDK_DateTime dt(st);
648 CFX_ByteString str = dt.ToPDFDateTimeString();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700649
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 if (str.IsEmpty())
651 m_pAnnot->GetAnnotDict()->RemoveAt("M");
652 else
653 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654}
655
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
657 FX_SYSTEMTIME systime;
658 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700659
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 CPDFSDK_DateTime dt(str);
661 dt.ToSystemTime(systime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700662
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 return systime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666void CPDFSDK_BAAnnot::SetFlags(int nFlags) {
667 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670int CPDFSDK_BAAnnot::GetFlags() const {
671 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672}
673
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
675 if (str.IsEmpty())
676 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
677 else
678 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700679}
680
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
682 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683}
684
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685void CPDFSDK_BAAnnot::SetStructParent(int key) {
686 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687}
688
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689int CPDFSDK_BAAnnot::GetStructParent() const {
690 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691}
692
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693// border
694void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
695 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700696
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 if (pBorder) {
Tom Sepezae51c812015-08-05 12:34:06 -0700698 pBorder->SetAt(2, new CPDF_Number(nWidth));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700700 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701
702 if (!pBSDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700703 pBSDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700705 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 pBSDict->SetAtInteger("W", nWidth);
708 }
709}
710
711int CPDFSDK_BAAnnot::GetBorderWidth() const {
712 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) {
713 return pBorder->GetInteger(2);
714 }
715 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) {
716 return pBSDict->GetInteger("W", 1);
717 }
718 return 1;
719}
720
721void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) {
722 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
723 if (!pBSDict) {
724 pBSDict = new CPDF_Dictionary;
725 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
726 }
727
728 switch (nStyle) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700729 case BBS_SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730 pBSDict->SetAtName("S", "S");
731 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700732 case BBS_DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733 pBSDict->SetAtName("S", "D");
734 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700735 case BBS_BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 pBSDict->SetAtName("S", "B");
737 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700738 case BBS_INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 pBSDict->SetAtName("S", "I");
740 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700741 case BBS_UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 pBSDict->SetAtName("S", "U");
743 break;
744 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745}
746
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747int CPDFSDK_BAAnnot::GetBorderStyle() const {
748 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
749 if (pBSDict) {
750 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
751 if (sBorderStyle == "S")
752 return BBS_SOLID;
753 if (sBorderStyle == "D")
754 return BBS_DASH;
755 if (sBorderStyle == "B")
756 return BBS_BEVELED;
757 if (sBorderStyle == "I")
758 return BBS_INSET;
759 if (sBorderStyle == "U")
760 return BBS_UNDERLINE;
761 }
762
763 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
764 if (pBorder) {
765 if (pBorder->GetCount() >= 4) {
766 CPDF_Array* pDP = pBorder->GetArray(3);
767 if (pDP && pDP->GetCount() > 0)
768 return BBS_DASH;
769 }
770 }
771
772 return BBS_SOLID;
773}
774
775void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) {
776 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
777 if (!pBSDict) {
778 pBSDict = new CPDF_Dictionary;
779 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
780 }
781
Tom Sepezae51c812015-08-05 12:34:06 -0700782 CPDF_Array* pArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
784 pArray->AddInteger(array[i]);
785 }
786
787 pBSDict->SetAt("D", pArray);
788}
789
790void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const {
791 CPDF_Array* pDash = NULL;
792
793 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
794 if (pBorder) {
795 pDash = pBorder->GetArray(3);
796 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700797 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 if (pBSDict) {
799 pDash = pBSDict->GetArray("D");
800 }
801 }
802
803 if (pDash) {
804 for (int i = 0, sz = pDash->GetCount(); i < sz; i++) {
805 array.Add(pDash->GetInteger(i));
806 }
807 }
808}
809
810void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
811 CPDF_Array* pArray = new CPDF_Array;
812 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
813 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
814 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
815 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
816}
817
818void CPDFSDK_BAAnnot::RemoveColor() {
819 m_pAnnot->GetAnnotDict()->RemoveAt("C");
820}
821
822FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
823 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) {
824 int nCount = pEntry->GetCount();
825 if (nCount == 1) {
826 FX_FLOAT g = pEntry->GetNumber(0) * 255;
827
828 color = FXSYS_RGB((int)g, (int)g, (int)g);
829
830 return TRUE;
831 } else if (nCount == 3) {
832 FX_FLOAT r = pEntry->GetNumber(0) * 255;
833 FX_FLOAT g = pEntry->GetNumber(1) * 255;
834 FX_FLOAT b = pEntry->GetNumber(2) * 255;
835
836 color = FXSYS_RGB((int)r, (int)g, (int)b);
837
838 return TRUE;
839 } else if (nCount == 4) {
840 FX_FLOAT c = pEntry->GetNumber(0);
841 FX_FLOAT m = pEntry->GetNumber(1);
842 FX_FLOAT y = pEntry->GetNumber(2);
843 FX_FLOAT k = pEntry->GetNumber(3);
844
845 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
846 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
847 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
848
849 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
850
851 return TRUE;
852 }
853 }
854
855 return FALSE;
856}
857
858void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
859 const CPDF_Rect& rcBBox,
860 const CPDF_Matrix& matrix,
861 const CFX_ByteString& sContents,
862 const CFX_ByteString& sAPState) {
863 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
864
865 if (!pAPDict) {
866 pAPDict = new CPDF_Dictionary;
867 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
868 }
869
870 CPDF_Stream* pStream = NULL;
871 CPDF_Dictionary* pParentDict = NULL;
872
873 if (sAPState.IsEmpty()) {
874 pParentDict = pAPDict;
875 pStream = pAPDict->GetStream(sAPType);
876 } else {
877 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
878 if (!pAPTypeDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700879 pAPTypeDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 pAPDict->SetAt(sAPType, pAPTypeDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700881 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700882
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 pParentDict = pAPTypeDict;
884 pStream = pAPTypeDict->GetStream(sAPState);
885 }
886
887 if (!pStream) {
888 ASSERT(m_pPageView != NULL);
889 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
890 ASSERT(pDoc != NULL);
891
Tom Sepezae51c812015-08-05 12:34:06 -0700892 pStream = new CPDF_Stream(NULL, 0, NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700893 int32_t objnum = pDoc->AddIndirectObject(pStream);
894 // pAPDict->SetAtReference(sAPType, pDoc, objnum);
895 ASSERT(pParentDict != NULL);
896 pParentDict->SetAtReference(sAPType, pDoc, objnum);
897 }
898
899 CPDF_Dictionary* pStreamDict = pStream->GetDict();
900
901 if (!pStreamDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700902 pStreamDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903 pStreamDict->SetAtName("Type", "XObject");
904 pStreamDict->SetAtName("Subtype", "Form");
905 pStreamDict->SetAtInteger("FormType", 1);
906 pStream->InitStream(NULL, 0, pStreamDict);
907 }
908
909 if (pStreamDict) {
910 pStreamDict->SetAtMatrix("Matrix", matrix);
911 pStreamDict->SetAtRect("BBox", rcBBox);
912 }
913
914 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE,
915 FALSE);
916}
917
918#define BA_ANNOT_MINWIDTH 1
919#define BA_ANNOT_MINHEIGHT 1
920
921FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
922 return BA_ANNOT_MINWIDTH;
923}
924
925FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
926 return BA_ANNOT_MINHEIGHT;
927}
928
929FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() {
930 return TRUE;
931}
932FX_BOOL CPDFSDK_BAAnnot::IsVisible() const {
933 int nFlags = GetFlags();
934 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
935 (nFlags & ANNOTFLAG_NOVIEW));
936}
937
938CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
939 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
940}
941
942void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
943 ASSERT(action);
944 if ((CPDF_Action&)action !=
945 CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) {
946 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
947 CPDF_Dictionary* pDict = action.GetDict();
948 if (pDict && pDict->GetObjNum() == 0) {
949 pDoc->AddIndirectObject(pDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700950 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
952 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700953}
954
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955void CPDFSDK_BAAnnot::RemoveAction() {
956 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700957}
958
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700959CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
960 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700961}
962
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700963void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
964 ASSERT(aa != NULL);
965
966 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
967 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700968}
969
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970void CPDFSDK_BAAnnot::RemoveAAction() {
971 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700972}
973
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
975 CPDF_AAction AAction = GetAAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 if (AAction.ActionExist(eAAT))
978 return AAction.GetAction(eAAT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700979
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700980 if (eAAT == CPDF_AAction::ButtonUp)
981 return GetAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700982
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700983 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984}
985
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986FX_BOOL CPDFSDK_BAAnnot::IsXFAField() {
987 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700988}
989
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
991 CPDF_Matrix* pUser2Device,
992 CPDF_RenderOptions* pOptions) {
993 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
994 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
995 CPDF_Annot::Normal, NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700996
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700998}
999
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
1001 if (m_pPageView)
1002 return m_pPageView->GetPDFPage();
1003 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001004}
1005
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001006CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
1007 if (m_pPageView)
1008 return m_pPageView->GetPDFXFAPage();
1009 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001010}