blob: 090a50fe620105feebdc13b9d29ac6e4e2e14563 [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
Bo Xufdc00a72014-10-28 23:03:33 -07007#include "../include/fpdfxfa/fpdfxfa_doc.h"
Lei Zhangbde53d22015-11-12 22:21:30 -08008#include "fpdfsdk/include/fsdk_baseannot.h"
9#include "fpdfsdk/include/fsdk_define.h"
10#include "fpdfsdk/include/fsdk_mgr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070011
Nico Weber9d8ec5a2015-08-04 13:00:21 -070012int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, uint8_t tzminute) {
13 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014}
15
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016FX_BOOL _gAfxIsLeapYear(int16_t year) {
17 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018}
19
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020FX_WORD _gAfxGetYearDays(int16_t year) {
21 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022}
23
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) {
25 uint8_t mDays;
26 switch (month) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -070027 case 1:
28 case 3:
29 case 5:
30 case 7:
31 case 8:
32 case 10:
33 case 12:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 mDays = 31;
35 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
Tom Sepez2f2ffec2015-07-23 14:42:09 -070037 case 4:
38 case 6:
39 case 9:
40 case 11:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 mDays = 30;
42 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043
Tom Sepez2f2ffec2015-07-23 14:42:09 -070044 case 2:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 if (_gAfxIsLeapYear(year) == TRUE)
46 mDays = 29;
47 else
48 mDays = 28;
49 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050
Tom Sepez2f2ffec2015-07-23 14:42:09 -070051 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 mDays = 0;
53 break;
54 }
55
56 return mDays;
57}
58
59CPDFSDK_DateTime::CPDFSDK_DateTime() {
60 ResetDateTime();
61}
62
63CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) {
64 ResetDateTime();
65
66 FromPDFDateTimeString(dtStr);
67}
68
69CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime) {
70 operator=(datetime);
71}
72
73CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st) {
74 operator=(st);
75}
76
77void CPDFSDK_DateTime::ResetDateTime() {
78 tzset();
79
80 time_t curTime;
81 time(&curTime);
82 struct tm* newtime;
83 // newtime = gmtime(&curTime);
84 newtime = localtime(&curTime);
85
86 dt.year = newtime->tm_year + 1900;
87 dt.month = newtime->tm_mon + 1;
88 dt.day = newtime->tm_mday;
89 dt.hour = newtime->tm_hour;
90 dt.minute = newtime->tm_min;
91 dt.second = newtime->tm_sec;
92 // dt.tzHour = _timezone / 3600 * -1;
93 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
94}
95
96CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(
97 const CPDFSDK_DateTime& datetime) {
98 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
99 return *this;
100}
101
102CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(const FX_SYSTEMTIME& st) {
103 tzset();
104
105 dt.year = (int16_t)st.wYear;
106 dt.month = (uint8_t)st.wMonth;
107 dt.day = (uint8_t)st.wDay;
108 dt.hour = (uint8_t)st.wHour;
109 dt.minute = (uint8_t)st.wMinute;
110 dt.second = (uint8_t)st.wSecond;
111 // dt.tzHour = _timezone / 3600 * -1;
112 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
113 return *this;
114}
115
116FX_BOOL CPDFSDK_DateTime::operator==(CPDFSDK_DateTime& datetime) {
117 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0);
118}
119
120FX_BOOL CPDFSDK_DateTime::operator!=(CPDFSDK_DateTime& datetime) {
121 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
122}
123
124FX_BOOL CPDFSDK_DateTime::operator>(CPDFSDK_DateTime& datetime) {
125 CPDFSDK_DateTime dt1 = ToGMT();
126 CPDFSDK_DateTime dt2 = datetime.ToGMT();
127 int d1 =
128 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
129 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
130 (int)dt1.dt.second;
131 int d3 =
132 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
133 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
134 (int)dt2.dt.second;
135
136 if (d1 > d3)
137 return TRUE;
138 if (d2 > d4)
139 return TRUE;
140 return FALSE;
141}
142
143FX_BOOL CPDFSDK_DateTime::operator>=(CPDFSDK_DateTime& datetime) {
144 CPDFSDK_DateTime dt1 = ToGMT();
145 CPDFSDK_DateTime dt2 = datetime.ToGMT();
146 int d1 =
147 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
148 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
149 (int)dt1.dt.second;
150 int d3 =
151 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
152 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
153 (int)dt2.dt.second;
154
155 if (d1 >= d3)
156 return TRUE;
157 if (d2 >= d4)
158 return TRUE;
159 return FALSE;
160}
161
162FX_BOOL CPDFSDK_DateTime::operator<(CPDFSDK_DateTime& datetime) {
163 CPDFSDK_DateTime dt1 = ToGMT();
164 CPDFSDK_DateTime dt2 = datetime.ToGMT();
165 int d1 =
166 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
167 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
168 (int)dt1.dt.second;
169 int d3 =
170 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
171 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
172 (int)dt2.dt.second;
173
174 if (d1 < d3)
175 return TRUE;
176 if (d2 < d4)
177 return TRUE;
178 return FALSE;
179}
180
181FX_BOOL CPDFSDK_DateTime::operator<=(CPDFSDK_DateTime& datetime) {
182 CPDFSDK_DateTime dt1 = ToGMT();
183 CPDFSDK_DateTime dt2 = datetime.ToGMT();
184 int d1 =
185 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
186 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
187 (int)dt1.dt.second;
188 int d3 =
189 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
190 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
191 (int)dt2.dt.second;
192
193 if (d1 <= d3)
194 return TRUE;
195 if (d2 <= d4)
196 return TRUE;
197 return FALSE;
198}
199
200CPDFSDK_DateTime::operator time_t() {
201 struct tm newtime;
202
203 newtime.tm_year = dt.year - 1900;
204 newtime.tm_mon = dt.month - 1;
205 newtime.tm_mday = dt.day;
206 newtime.tm_hour = dt.hour;
207 newtime.tm_min = dt.minute;
208 newtime.tm_sec = dt.second;
209
210 return mktime(&newtime);
211}
212
213CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
214 const CFX_ByteString& dtStr) {
215 int strLength = dtStr.GetLength();
216 if (strLength > 0) {
217 int i = 0;
218 int j, k;
219 FX_CHAR ch;
220 while (i < strLength) {
221 ch = dtStr[i];
222 if (ch >= '0' && ch <= '9')
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700223 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700225 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 if (i >= strLength)
227 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700228
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 j = 0;
230 k = 0;
231 while (i < strLength && j < 4) {
232 ch = dtStr[i];
233 k = k * 10 + ch - '0';
234 j++;
235 if (ch < '0' || ch > '9')
236 break;
237 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700238 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 dt.year = (int16_t)k;
240 if (i >= strLength || j < 4)
241 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 j = 0;
244 k = 0;
245 while (i < strLength && j < 2) {
246 ch = dtStr[i];
247 k = k * 10 + ch - '0';
248 j++;
249 if (ch < '0' || ch > '9')
250 break;
251 i++;
252 }
253 dt.month = (uint8_t)k;
254 if (i >= strLength || j < 2)
255 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 j = 0;
258 k = 0;
259 while (i < strLength && j < 2) {
260 ch = dtStr[i];
261 k = k * 10 + ch - '0';
262 j++;
263 if (ch < '0' || ch > '9')
264 break;
265 i++;
266 }
267 dt.day = (uint8_t)k;
268 if (i >= strLength || j < 2)
269 return *this;
270
271 j = 0;
272 k = 0;
273 while (i < strLength && j < 2) {
274 ch = dtStr[i];
275 k = k * 10 + ch - '0';
276 j++;
277 if (ch < '0' || ch > '9')
278 break;
279 i++;
280 }
281 dt.hour = (uint8_t)k;
282 if (i >= strLength || j < 2)
283 return *this;
284
285 j = 0;
286 k = 0;
287 while (i < strLength && j < 2) {
288 ch = dtStr[i];
289 k = k * 10 + ch - '0';
290 j++;
291 if (ch < '0' || ch > '9')
292 break;
293 i++;
294 }
295 dt.minute = (uint8_t)k;
296 if (i >= strLength || j < 2)
297 return *this;
298
299 j = 0;
300 k = 0;
301 while (i < strLength && j < 2) {
302 ch = dtStr[i];
303 k = k * 10 + ch - '0';
304 j++;
305 if (ch < '0' || ch > '9')
306 break;
307 i++;
308 }
309 dt.second = (uint8_t)k;
310 if (i >= strLength || j < 2)
311 return *this;
312
313 ch = dtStr[i++];
314 if (ch != '-' && ch != '+')
315 return *this;
316 if (ch == '-')
317 dt.tzHour = -1;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700318 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 dt.tzHour = 1;
320 j = 0;
321 k = 0;
322 while (i < strLength && j < 2) {
323 ch = dtStr[i];
324 k = k * 10 + ch - '0';
325 j++;
326 if (ch < '0' || ch > '9')
327 break;
328 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700329 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330 dt.tzHour *= (FX_CHAR)k;
331 if (i >= strLength || j < 2)
332 return *this;
333
334 ch = dtStr[i++];
335 if (ch != '\'')
336 return *this;
337 j = 0;
338 k = 0;
339 while (i < strLength && j < 2) {
340 ch = dtStr[i];
341 k = k * 10 + ch - '0';
342 j++;
343 if (ch < '0' || ch > '9')
344 break;
345 i++;
346 }
347 dt.tzMinute = (uint8_t)k;
348 if (i >= strLength || j < 2)
349 return *this;
350 }
351
352 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353}
354
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() {
356 CFX_ByteString str1;
357 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day,
358 dt.hour, dt.minute, dt.second);
359 if (dt.tzHour < 0)
360 str1 += "-";
361 else
362 str1 += "+";
363 CFX_ByteString str2;
364 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
365 return str1 + str2;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366}
367
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() {
369 CFX_ByteString dtStr;
370 char tempStr[32];
371 memset(tempStr, 0, sizeof(tempStr));
372 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
373 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
374 dtStr = CFX_ByteString(tempStr);
375 if (dt.tzHour < 0)
376 dtStr += CFX_ByteString("-");
377 else
378 dtStr += CFX_ByteString("+");
379 memset(tempStr, 0, sizeof(tempStr));
380 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour),
381 dt.tzMinute);
382 dtStr += CFX_ByteString(tempStr);
383 return dtStr;
384}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) {
387 CPDFSDK_DateTime dt = *this;
388 time_t t = (time_t)dt;
389 struct tm* pTime = localtime(&t);
390 if (pTime) {
391 st.wYear = (FX_WORD)pTime->tm_year + 1900;
392 st.wMonth = (FX_WORD)pTime->tm_mon + 1;
393 st.wDay = (FX_WORD)pTime->tm_mday;
394 st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
395 st.wHour = (FX_WORD)pTime->tm_hour;
396 st.wMinute = (FX_WORD)pTime->tm_min;
397 st.wSecond = (FX_WORD)pTime->tm_sec;
398 st.wMilliseconds = 0;
399 }
400}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() {
403 CPDFSDK_DateTime dt = *this;
404 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
405 dt.dt.tzHour = 0;
406 dt.dt.tzMinute = 0;
407 return dt;
408}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700409
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) {
411 if (days == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700412 return *this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413
414 int16_t y = dt.year, yy;
415 uint8_t m = dt.month;
416 uint8_t d = dt.day;
417 int mdays, ydays, ldays;
418
419 ldays = days;
420 if (ldays > 0) {
421 yy = y;
422 if (((FX_WORD)m * 100 + d) > 300)
423 yy++;
424 ydays = _gAfxGetYearDays(yy);
425 while (ldays >= ydays) {
426 y++;
427 ldays -= ydays;
428 yy++;
429 mdays = _gAfxGetMonthDays(y, m);
430 if (d > mdays) {
431 m++;
432 d -= mdays;
433 }
434 ydays = _gAfxGetYearDays(yy);
435 }
436 mdays = _gAfxGetMonthDays(y, m) - d + 1;
437 while (ldays >= mdays) {
438 ldays -= mdays;
439 m++;
440 d = 1;
441 mdays = _gAfxGetMonthDays(y, m);
442 }
443 d += ldays;
444 } else {
445 ldays *= -1;
446 yy = y;
447 if (((FX_WORD)m * 100 + d) < 300)
448 yy--;
449 ydays = _gAfxGetYearDays(yy);
450 while (ldays >= ydays) {
451 y--;
452 ldays -= ydays;
453 yy--;
454 mdays = _gAfxGetMonthDays(y, m);
455 if (d > mdays) {
456 m++;
457 d -= mdays;
458 }
459 ydays = _gAfxGetYearDays(yy);
460 }
461 while (ldays >= d) {
462 ldays -= d;
463 m--;
464 mdays = _gAfxGetMonthDays(y, m);
465 d = mdays;
466 }
467 d -= ldays;
468 }
469
470 dt.year = y;
471 dt.month = m;
472 dt.day = d;
473
474 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700475}
476
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) {
478 if (seconds == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700479 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 int n;
482 int days;
483
484 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
485 if (n < 0) {
486 days = (n - 86399) / 86400;
487 n -= days * 86400;
488 } else {
489 days = n / 86400;
490 n %= 86400;
491 }
492 dt.hour = (uint8_t)(n / 3600);
493 dt.hour %= 24;
494 n %= 3600;
495 dt.minute = (uint8_t)(n / 60);
496 dt.second = (uint8_t)(n % 60);
497 if (days != 0)
498 AddDays(days);
499
500 return *this;
501}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700502
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView)
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500504 : m_pPageView(pPageView), m_bSelected(FALSE), m_nTabOrder(-1) {
505}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
508 CPDFSDK_PageView* pPageView)
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500509 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700510}
511
Tom Sepez3343d142015-11-02 09:54:54 -0800512CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 return m_pAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700514}
515
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516FX_BOOL CPDFSDK_Annot::IsSelected() {
517 return m_bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700518}
519
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) {
521 m_bSelected = bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700522}
523
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700524// Tab Order
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525int CPDFSDK_Annot::GetTabOrder() {
526 return m_nTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700527}
528
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529void CPDFSDK_Annot::SetTabOrder(int iTabOrder) {
530 m_nTabOrder = iTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700531}
532
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
534 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700535
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 return m_pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700537}
538
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect) {
540 ASSERT(rect.right - rect.left >= GetMinWidth());
541 ASSERT(rect.top - rect.bottom >= GetMinHeight());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700542
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700544}
545
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546CPDF_Rect CPDFSDK_BAAnnot::GetRect() const {
547 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700548
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 CPDF_Rect rect;
550 m_pAnnot->GetRect(rect);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700551
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700553}
554
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555CFX_ByteString CPDFSDK_BAAnnot::GetType() const {
556 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700557
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 return m_pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700559}
560
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const {
562 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700563}
564
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
566 const CPDF_Matrix* pUser2Device,
567 CPDF_Annot::AppearanceMode mode,
568 const CPDF_RenderOptions* pOptions) {
569 ASSERT(m_pPageView != NULL);
570 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700571
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
573 mode, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700574}
575
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() {
577 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700578}
579
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
581 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
582 if (pAP == NULL)
583 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700584
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 // Choose the right sub-ap
586 const FX_CHAR* ap_entry = "N";
587 if (mode == CPDF_Annot::Down)
588 ap_entry = "D";
589 else if (mode == CPDF_Annot::Rollover)
590 ap_entry = "R";
591 if (!pAP->KeyExist(ap_entry))
592 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700593
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 // Get the AP stream or subdirectory
595 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
596 if (psub == NULL)
597 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700598
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700600}
601
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700602void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
603 const CPDF_Matrix* pUser2Device,
604 const CPDF_RenderOptions* pOptions) {
605 ASSERT(m_pAnnot != NULL);
606 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609void CPDFSDK_BAAnnot::ClearCachedAP() {
610 ASSERT(m_pAnnot != NULL);
611 m_pAnnot->ClearCachedAP();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700612}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700613
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
615 if (sContents.IsEmpty())
616 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
617 else
618 m_pAnnot->GetAnnotDict()->SetAtString("Contents",
619 PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620}
621
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
623 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624}
625
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
627 if (sName.IsEmpty())
628 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
629 else
630 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700631}
632
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
634 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
638 CPDFSDK_DateTime dt(st);
639 CFX_ByteString str = dt.ToPDFDateTimeString();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700640
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641 if (str.IsEmpty())
642 m_pAnnot->GetAnnotDict()->RemoveAt("M");
643 else
644 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
648 FX_SYSTEMTIME systime;
649 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700650
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651 CPDFSDK_DateTime dt(str);
652 dt.ToSystemTime(systime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700653
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 return systime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700655}
656
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657void CPDFSDK_BAAnnot::SetFlags(int nFlags) {
658 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659}
660
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661int CPDFSDK_BAAnnot::GetFlags() const {
662 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663}
664
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
666 if (str.IsEmpty())
667 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
668 else
669 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670}
671
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
673 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700674}
675
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676void CPDFSDK_BAAnnot::SetStructParent(int key) {
677 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700678}
679
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680int CPDFSDK_BAAnnot::GetStructParent() const {
681 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682}
683
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684// border
685void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
686 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 if (pBorder) {
Tom Sepezae51c812015-08-05 12:34:06 -0700689 pBorder->SetAt(2, new CPDF_Number(nWidth));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700691 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692
693 if (!pBSDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700694 pBSDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700696 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 pBSDict->SetAtInteger("W", nWidth);
699 }
700}
701
702int CPDFSDK_BAAnnot::GetBorderWidth() const {
703 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) {
704 return pBorder->GetInteger(2);
705 }
706 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) {
707 return pBSDict->GetInteger("W", 1);
708 }
709 return 1;
710}
711
712void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) {
713 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
714 if (!pBSDict) {
715 pBSDict = new CPDF_Dictionary;
716 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
717 }
718
719 switch (nStyle) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700720 case BBS_SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 pBSDict->SetAtName("S", "S");
722 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700723 case BBS_DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 pBSDict->SetAtName("S", "D");
725 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700726 case BBS_BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 pBSDict->SetAtName("S", "B");
728 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700729 case BBS_INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730 pBSDict->SetAtName("S", "I");
731 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700732 case BBS_UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733 pBSDict->SetAtName("S", "U");
734 break;
735 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736}
737
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738int CPDFSDK_BAAnnot::GetBorderStyle() const {
739 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
740 if (pBSDict) {
741 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
742 if (sBorderStyle == "S")
743 return BBS_SOLID;
744 if (sBorderStyle == "D")
745 return BBS_DASH;
746 if (sBorderStyle == "B")
747 return BBS_BEVELED;
748 if (sBorderStyle == "I")
749 return BBS_INSET;
750 if (sBorderStyle == "U")
751 return BBS_UNDERLINE;
752 }
753
754 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
755 if (pBorder) {
756 if (pBorder->GetCount() >= 4) {
757 CPDF_Array* pDP = pBorder->GetArray(3);
758 if (pDP && pDP->GetCount() > 0)
759 return BBS_DASH;
760 }
761 }
762
763 return BBS_SOLID;
764}
765
766void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) {
767 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
768 if (!pBSDict) {
769 pBSDict = new CPDF_Dictionary;
770 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
771 }
772
Tom Sepezae51c812015-08-05 12:34:06 -0700773 CPDF_Array* pArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
775 pArray->AddInteger(array[i]);
776 }
777
778 pBSDict->SetAt("D", pArray);
779}
780
781void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const {
782 CPDF_Array* pDash = NULL;
783
784 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
785 if (pBorder) {
786 pDash = pBorder->GetArray(3);
787 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700788 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789 if (pBSDict) {
790 pDash = pBSDict->GetArray("D");
791 }
792 }
793
794 if (pDash) {
795 for (int i = 0, sz = pDash->GetCount(); i < sz; i++) {
796 array.Add(pDash->GetInteger(i));
797 }
798 }
799}
800
801void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
802 CPDF_Array* pArray = new CPDF_Array;
803 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
804 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
805 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
806 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
807}
808
809void CPDFSDK_BAAnnot::RemoveColor() {
810 m_pAnnot->GetAnnotDict()->RemoveAt("C");
811}
812
813FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
814 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) {
815 int nCount = pEntry->GetCount();
816 if (nCount == 1) {
817 FX_FLOAT g = pEntry->GetNumber(0) * 255;
818
819 color = FXSYS_RGB((int)g, (int)g, (int)g);
820
821 return TRUE;
822 } else if (nCount == 3) {
823 FX_FLOAT r = pEntry->GetNumber(0) * 255;
824 FX_FLOAT g = pEntry->GetNumber(1) * 255;
825 FX_FLOAT b = pEntry->GetNumber(2) * 255;
826
827 color = FXSYS_RGB((int)r, (int)g, (int)b);
828
829 return TRUE;
830 } else if (nCount == 4) {
831 FX_FLOAT c = pEntry->GetNumber(0);
832 FX_FLOAT m = pEntry->GetNumber(1);
833 FX_FLOAT y = pEntry->GetNumber(2);
834 FX_FLOAT k = pEntry->GetNumber(3);
835
836 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
837 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
838 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
839
840 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
841
842 return TRUE;
843 }
844 }
845
846 return FALSE;
847}
848
849void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
850 const CPDF_Rect& rcBBox,
851 const CPDF_Matrix& matrix,
852 const CFX_ByteString& sContents,
853 const CFX_ByteString& sAPState) {
854 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
855
856 if (!pAPDict) {
857 pAPDict = new CPDF_Dictionary;
858 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
859 }
860
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500861 CPDF_Stream* pStream = nullptr;
862 CPDF_Dictionary* pParentDict = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700863
864 if (sAPState.IsEmpty()) {
865 pParentDict = pAPDict;
866 pStream = pAPDict->GetStream(sAPType);
867 } else {
868 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
869 if (!pAPTypeDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700870 pAPTypeDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871 pAPDict->SetAt(sAPType, pAPTypeDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700872 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700873
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874 pParentDict = pAPTypeDict;
875 pStream = pAPTypeDict->GetStream(sAPState);
876 }
877
878 if (!pStream) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500879 pStream = new CPDF_Stream(nullptr, 0, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500881 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 int32_t objnum = pDoc->AddIndirectObject(pStream);
883 // pAPDict->SetAtReference(sAPType, pDoc, objnum);
884 ASSERT(pParentDict != NULL);
885 pParentDict->SetAtReference(sAPType, pDoc, objnum);
886 }
887
888 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 if (!pStreamDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700890 pStreamDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891 pStreamDict->SetAtName("Type", "XObject");
892 pStreamDict->SetAtName("Subtype", "Form");
893 pStreamDict->SetAtInteger("FormType", 1);
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500894 pStream->InitStream(nullptr, 0, pStreamDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 }
896
897 if (pStreamDict) {
898 pStreamDict->SetAtMatrix("Matrix", matrix);
899 pStreamDict->SetAtRect("BBox", rcBBox);
900 }
901
902 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE,
903 FALSE);
904}
905
906#define BA_ANNOT_MINWIDTH 1
907#define BA_ANNOT_MINHEIGHT 1
908
909FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
910 return BA_ANNOT_MINWIDTH;
911}
912
913FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
914 return BA_ANNOT_MINHEIGHT;
915}
916
917FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() {
918 return TRUE;
919}
920FX_BOOL CPDFSDK_BAAnnot::IsVisible() const {
921 int nFlags = GetFlags();
922 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
923 (nFlags & ANNOTFLAG_NOVIEW));
924}
925
926CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
927 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
928}
929
930void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
931 ASSERT(action);
932 if ((CPDF_Action&)action !=
933 CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) {
934 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
935 CPDF_Dictionary* pDict = action.GetDict();
936 if (pDict && pDict->GetObjNum() == 0) {
937 pDoc->AddIndirectObject(pDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700938 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
940 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700941}
942
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943void CPDFSDK_BAAnnot::RemoveAction() {
944 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945}
946
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
948 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700949}
950
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
952 ASSERT(aa != NULL);
953
954 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
955 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700956}
957
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958void CPDFSDK_BAAnnot::RemoveAAction() {
959 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700960}
961
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700962CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
963 CPDF_AAction AAction = GetAAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700964
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965 if (AAction.ActionExist(eAAT))
966 return AAction.GetAction(eAAT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700967
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968 if (eAAT == CPDF_AAction::ButtonUp)
969 return GetAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700970
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700971 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700972}
973
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974FX_BOOL CPDFSDK_BAAnnot::IsXFAField() {
975 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976}
977
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700978void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
979 CPDF_Matrix* pUser2Device,
980 CPDF_RenderOptions* pOptions) {
981 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
982 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
983 CPDF_Annot::Normal, NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700986}
987
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700988CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
989 if (m_pPageView)
990 return m_pPageView->GetPDFPage();
991 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700992}
993
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700994CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
995 if (m_pPageView)
996 return m_pPageView->GetPDFXFAPage();
997 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700998}