blob: 0f2aaf42cddde22b734c1e44bb529dc989acc98d [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
Dan Sinclair10cfea12015-11-16 13:09:00 -05007#include "core/include/fxcrt/fx_ext.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
Tom Sepez40e9ff32015-11-30 12:39:54 -080012#ifdef PDF_ENABLE_XFA
13#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
14#endif // PDF_ENABLE_XFA
15
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, uint8_t tzminute) {
17 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018}
19
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020FX_BOOL _gAfxIsLeapYear(int16_t year) {
21 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022}
23
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024FX_WORD _gAfxGetYearDays(int16_t year) {
25 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026}
27
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) {
29 uint8_t mDays;
30 switch (month) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -070031 case 1:
32 case 3:
33 case 5:
34 case 7:
35 case 8:
36 case 10:
37 case 12:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038 mDays = 31;
39 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040
Tom Sepez2f2ffec2015-07-23 14:42:09 -070041 case 4:
42 case 6:
43 case 9:
44 case 11:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 mDays = 30;
46 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047
Tom Sepez2f2ffec2015-07-23 14:42:09 -070048 case 2:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 if (_gAfxIsLeapYear(year) == TRUE)
50 mDays = 29;
51 else
52 mDays = 28;
53 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054
Tom Sepez2f2ffec2015-07-23 14:42:09 -070055 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 mDays = 0;
57 break;
58 }
59
60 return mDays;
61}
62
63CPDFSDK_DateTime::CPDFSDK_DateTime() {
64 ResetDateTime();
65}
66
67CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) {
68 ResetDateTime();
69
70 FromPDFDateTimeString(dtStr);
71}
72
73CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime) {
74 operator=(datetime);
75}
76
77CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st) {
78 operator=(st);
79}
80
81void CPDFSDK_DateTime::ResetDateTime() {
82 tzset();
83
84 time_t curTime;
85 time(&curTime);
86 struct tm* newtime;
87 // newtime = gmtime(&curTime);
88 newtime = localtime(&curTime);
89
90 dt.year = newtime->tm_year + 1900;
91 dt.month = newtime->tm_mon + 1;
92 dt.day = newtime->tm_mday;
93 dt.hour = newtime->tm_hour;
94 dt.minute = newtime->tm_min;
95 dt.second = newtime->tm_sec;
96 // dt.tzHour = _timezone / 3600 * -1;
97 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
98}
99
100CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(
101 const CPDFSDK_DateTime& datetime) {
102 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
103 return *this;
104}
105
106CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(const FX_SYSTEMTIME& st) {
107 tzset();
108
109 dt.year = (int16_t)st.wYear;
110 dt.month = (uint8_t)st.wMonth;
111 dt.day = (uint8_t)st.wDay;
112 dt.hour = (uint8_t)st.wHour;
113 dt.minute = (uint8_t)st.wMinute;
114 dt.second = (uint8_t)st.wSecond;
115 // dt.tzHour = _timezone / 3600 * -1;
116 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
117 return *this;
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 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
126}
127
128FX_BOOL CPDFSDK_DateTime::operator>(CPDFSDK_DateTime& datetime) {
129 CPDFSDK_DateTime dt1 = ToGMT();
130 CPDFSDK_DateTime dt2 = datetime.ToGMT();
131 int d1 =
132 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
133 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
134 (int)dt1.dt.second;
135 int d3 =
136 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
137 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
138 (int)dt2.dt.second;
139
140 if (d1 > d3)
141 return TRUE;
142 if (d2 > d4)
143 return TRUE;
144 return FALSE;
145}
146
147FX_BOOL CPDFSDK_DateTime::operator>=(CPDFSDK_DateTime& datetime) {
148 CPDFSDK_DateTime dt1 = ToGMT();
149 CPDFSDK_DateTime dt2 = datetime.ToGMT();
150 int d1 =
151 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
152 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
153 (int)dt1.dt.second;
154 int d3 =
155 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
156 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
157 (int)dt2.dt.second;
158
159 if (d1 >= d3)
160 return TRUE;
161 if (d2 >= d4)
162 return TRUE;
163 return FALSE;
164}
165
166FX_BOOL CPDFSDK_DateTime::operator<(CPDFSDK_DateTime& datetime) {
167 CPDFSDK_DateTime dt1 = ToGMT();
168 CPDFSDK_DateTime dt2 = datetime.ToGMT();
169 int d1 =
170 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
171 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
172 (int)dt1.dt.second;
173 int d3 =
174 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
175 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
176 (int)dt2.dt.second;
177
178 if (d1 < d3)
179 return TRUE;
180 if (d2 < d4)
181 return TRUE;
182 return FALSE;
183}
184
185FX_BOOL CPDFSDK_DateTime::operator<=(CPDFSDK_DateTime& datetime) {
186 CPDFSDK_DateTime dt1 = ToGMT();
187 CPDFSDK_DateTime dt2 = datetime.ToGMT();
188 int d1 =
189 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
190 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
191 (int)dt1.dt.second;
192 int d3 =
193 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
194 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
195 (int)dt2.dt.second;
196
197 if (d1 <= d3)
198 return TRUE;
199 if (d2 <= d4)
200 return TRUE;
201 return FALSE;
202}
203
204CPDFSDK_DateTime::operator time_t() {
205 struct tm newtime;
206
207 newtime.tm_year = dt.year - 1900;
208 newtime.tm_mon = dt.month - 1;
209 newtime.tm_mday = dt.day;
210 newtime.tm_hour = dt.hour;
211 newtime.tm_min = dt.minute;
212 newtime.tm_sec = dt.second;
213
214 return mktime(&newtime);
215}
216
217CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
218 const CFX_ByteString& dtStr) {
219 int strLength = dtStr.GetLength();
220 if (strLength > 0) {
221 int i = 0;
222 int j, k;
223 FX_CHAR ch;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500224 while (i < strLength && !std::isdigit(dtStr[i]))
225 ++i;
226
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 if (i >= strLength)
228 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 j = 0;
231 k = 0;
232 while (i < strLength && j < 4) {
233 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500234 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500236 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 break;
238 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700239 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 dt.year = (int16_t)k;
241 if (i >= strLength || j < 4)
242 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 j = 0;
245 k = 0;
246 while (i < strLength && j < 2) {
247 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500248 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500250 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 break;
252 i++;
253 }
254 dt.month = (uint8_t)k;
255 if (i >= strLength || j < 2)
256 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700257
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 j = 0;
259 k = 0;
260 while (i < strLength && j < 2) {
261 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500262 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500264 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265 break;
266 i++;
267 }
268 dt.day = (uint8_t)k;
269 if (i >= strLength || j < 2)
270 return *this;
271
272 j = 0;
273 k = 0;
274 while (i < strLength && j < 2) {
275 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500276 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500278 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279 break;
280 i++;
281 }
282 dt.hour = (uint8_t)k;
283 if (i >= strLength || j < 2)
284 return *this;
285
286 j = 0;
287 k = 0;
288 while (i < strLength && j < 2) {
289 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500290 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500292 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 break;
294 i++;
295 }
296 dt.minute = (uint8_t)k;
297 if (i >= strLength || j < 2)
298 return *this;
299
300 j = 0;
301 k = 0;
302 while (i < strLength && j < 2) {
303 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500304 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500306 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 break;
308 i++;
309 }
310 dt.second = (uint8_t)k;
311 if (i >= strLength || j < 2)
312 return *this;
313
314 ch = dtStr[i++];
315 if (ch != '-' && ch != '+')
316 return *this;
317 if (ch == '-')
318 dt.tzHour = -1;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700319 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 dt.tzHour = 1;
321 j = 0;
322 k = 0;
323 while (i < strLength && j < 2) {
324 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500325 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500327 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 break;
329 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700330 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331 dt.tzHour *= (FX_CHAR)k;
332 if (i >= strLength || j < 2)
333 return *this;
334
335 ch = dtStr[i++];
336 if (ch != '\'')
337 return *this;
338 j = 0;
339 k = 0;
340 while (i < strLength && j < 2) {
341 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500342 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500344 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 break;
346 i++;
347 }
348 dt.tzMinute = (uint8_t)k;
349 if (i >= strLength || j < 2)
350 return *this;
351 }
352
353 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354}
355
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() {
357 CFX_ByteString str1;
358 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day,
359 dt.hour, dt.minute, dt.second);
360 if (dt.tzHour < 0)
361 str1 += "-";
362 else
363 str1 += "+";
364 CFX_ByteString str2;
365 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
366 return str1 + str2;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367}
368
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() {
370 CFX_ByteString dtStr;
371 char tempStr[32];
372 memset(tempStr, 0, sizeof(tempStr));
373 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
374 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
375 dtStr = CFX_ByteString(tempStr);
376 if (dt.tzHour < 0)
377 dtStr += CFX_ByteString("-");
378 else
379 dtStr += CFX_ByteString("+");
380 memset(tempStr, 0, sizeof(tempStr));
381 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour),
382 dt.tzMinute);
383 dtStr += CFX_ByteString(tempStr);
384 return dtStr;
385}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700386
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) {
388 CPDFSDK_DateTime dt = *this;
389 time_t t = (time_t)dt;
390 struct tm* pTime = localtime(&t);
391 if (pTime) {
392 st.wYear = (FX_WORD)pTime->tm_year + 1900;
393 st.wMonth = (FX_WORD)pTime->tm_mon + 1;
394 st.wDay = (FX_WORD)pTime->tm_mday;
395 st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
396 st.wHour = (FX_WORD)pTime->tm_hour;
397 st.wMinute = (FX_WORD)pTime->tm_min;
398 st.wSecond = (FX_WORD)pTime->tm_sec;
399 st.wMilliseconds = 0;
400 }
401}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700402
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() {
404 CPDFSDK_DateTime dt = *this;
405 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
406 dt.dt.tzHour = 0;
407 dt.dt.tzMinute = 0;
408 return dt;
409}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700410
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) {
412 if (days == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700413 return *this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414
415 int16_t y = dt.year, yy;
416 uint8_t m = dt.month;
417 uint8_t d = dt.day;
418 int mdays, ydays, ldays;
419
420 ldays = days;
421 if (ldays > 0) {
422 yy = y;
423 if (((FX_WORD)m * 100 + d) > 300)
424 yy++;
425 ydays = _gAfxGetYearDays(yy);
426 while (ldays >= ydays) {
427 y++;
428 ldays -= ydays;
429 yy++;
430 mdays = _gAfxGetMonthDays(y, m);
431 if (d > mdays) {
432 m++;
433 d -= mdays;
434 }
435 ydays = _gAfxGetYearDays(yy);
436 }
437 mdays = _gAfxGetMonthDays(y, m) - d + 1;
438 while (ldays >= mdays) {
439 ldays -= mdays;
440 m++;
441 d = 1;
442 mdays = _gAfxGetMonthDays(y, m);
443 }
444 d += ldays;
445 } else {
446 ldays *= -1;
447 yy = y;
448 if (((FX_WORD)m * 100 + d) < 300)
449 yy--;
450 ydays = _gAfxGetYearDays(yy);
451 while (ldays >= ydays) {
452 y--;
453 ldays -= ydays;
454 yy--;
455 mdays = _gAfxGetMonthDays(y, m);
456 if (d > mdays) {
457 m++;
458 d -= mdays;
459 }
460 ydays = _gAfxGetYearDays(yy);
461 }
462 while (ldays >= d) {
463 ldays -= d;
464 m--;
465 mdays = _gAfxGetMonthDays(y, m);
466 d = mdays;
467 }
468 d -= ldays;
469 }
470
471 dt.year = y;
472 dt.month = m;
473 dt.day = d;
474
475 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700476}
477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) {
479 if (seconds == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700480 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700481
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 int n;
483 int days;
484
485 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
486 if (n < 0) {
487 days = (n - 86399) / 86400;
488 n -= days * 86400;
489 } else {
490 days = n / 86400;
491 n %= 86400;
492 }
493 dt.hour = (uint8_t)(n / 3600);
494 dt.hour %= 24;
495 n %= 3600;
496 dt.minute = (uint8_t)(n / 60);
497 dt.second = (uint8_t)(n % 60);
498 if (days != 0)
499 AddDays(days);
500
501 return *this;
502}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700503
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView)
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500505 : m_pPageView(pPageView), m_bSelected(FALSE), m_nTabOrder(-1) {
506}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
509 CPDFSDK_PageView* pPageView)
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500510 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700511}
512
Tom Sepez3343d142015-11-02 09:54:54 -0800513CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 return m_pAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700515}
516
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517FX_BOOL CPDFSDK_Annot::IsSelected() {
518 return m_bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700519}
520
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) {
522 m_bSelected = bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523}
524
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700525// Tab Order
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526int CPDFSDK_Annot::GetTabOrder() {
527 return m_nTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700528}
529
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530void CPDFSDK_Annot::SetTabOrder(int iTabOrder) {
531 m_nTabOrder = iTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700532}
533
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 return m_pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700536}
537
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect) {
539 ASSERT(rect.right - rect.left >= GetMinWidth());
540 ASSERT(rect.top - rect.bottom >= GetMinHeight());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700541
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543}
544
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545CPDF_Rect CPDFSDK_BAAnnot::GetRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546 CPDF_Rect rect;
547 m_pAnnot->GetRect(rect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700549}
550
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551CFX_ByteString CPDFSDK_BAAnnot::GetType() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 return m_pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700553}
554
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const {
556 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700557}
558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800560 const CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 CPDF_Annot::AppearanceMode mode,
562 const CPDF_RenderOptions* pOptions) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
564 mode, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700565}
566
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() {
568 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569}
570
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
572 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
573 if (pAP == NULL)
574 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700575
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 // Choose the right sub-ap
577 const FX_CHAR* ap_entry = "N";
578 if (mode == CPDF_Annot::Down)
579 ap_entry = "D";
580 else if (mode == CPDF_Annot::Rollover)
581 ap_entry = "R";
582 if (!pAP->KeyExist(ap_entry))
583 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700584
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 // Get the AP stream or subdirectory
586 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
587 if (psub == NULL)
588 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700589
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800594 const CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 const CPDF_RenderOptions* pOptions) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700597}
598
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599void CPDFSDK_BAAnnot::ClearCachedAP() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600 m_pAnnot->ClearCachedAP();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700601}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
604 if (sContents.IsEmpty())
605 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
606 else
607 m_pAnnot->GetAnnotDict()->SetAtString("Contents",
608 PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609}
610
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
612 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700613}
614
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
616 if (sName.IsEmpty())
617 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
618 else
619 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620}
621
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
623 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624}
625
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
627 CPDFSDK_DateTime dt(st);
628 CFX_ByteString str = dt.ToPDFDateTimeString();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 if (str.IsEmpty())
631 m_pAnnot->GetAnnotDict()->RemoveAt("M");
632 else
633 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634}
635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
637 FX_SYSTEMTIME systime;
638 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700639
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 CPDFSDK_DateTime dt(str);
641 dt.ToSystemTime(systime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700642
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643 return systime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644}
645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646void CPDFSDK_BAAnnot::SetFlags(int nFlags) {
647 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700648}
649
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650int CPDFSDK_BAAnnot::GetFlags() const {
651 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700652}
653
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
655 if (str.IsEmpty())
656 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
657 else
658 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659}
660
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
662 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663}
664
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665void CPDFSDK_BAAnnot::SetStructParent(int key) {
666 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669int CPDFSDK_BAAnnot::GetStructParent() const {
670 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700671}
672
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673// border
674void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
675 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677 if (pBorder) {
Tom Sepezae51c812015-08-05 12:34:06 -0700678 pBorder->SetAt(2, new CPDF_Number(nWidth));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700680 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681
682 if (!pBSDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700683 pBSDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700685 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 pBSDict->SetAtInteger("W", nWidth);
688 }
689}
690
691int CPDFSDK_BAAnnot::GetBorderWidth() const {
692 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) {
693 return pBorder->GetInteger(2);
694 }
695 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) {
696 return pBSDict->GetInteger("W", 1);
697 }
698 return 1;
699}
700
701void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) {
702 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
703 if (!pBSDict) {
704 pBSDict = new CPDF_Dictionary;
705 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
706 }
707
708 switch (nStyle) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700709 case BBS_SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 pBSDict->SetAtName("S", "S");
711 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700712 case BBS_DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713 pBSDict->SetAtName("S", "D");
714 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700715 case BBS_BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 pBSDict->SetAtName("S", "B");
717 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700718 case BBS_INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 pBSDict->SetAtName("S", "I");
720 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700721 case BBS_UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 pBSDict->SetAtName("S", "U");
723 break;
724 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700725}
726
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727int CPDFSDK_BAAnnot::GetBorderStyle() const {
728 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
729 if (pBSDict) {
730 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
731 if (sBorderStyle == "S")
732 return BBS_SOLID;
733 if (sBorderStyle == "D")
734 return BBS_DASH;
735 if (sBorderStyle == "B")
736 return BBS_BEVELED;
737 if (sBorderStyle == "I")
738 return BBS_INSET;
739 if (sBorderStyle == "U")
740 return BBS_UNDERLINE;
741 }
742
743 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
744 if (pBorder) {
745 if (pBorder->GetCount() >= 4) {
746 CPDF_Array* pDP = pBorder->GetArray(3);
747 if (pDP && pDP->GetCount() > 0)
748 return BBS_DASH;
749 }
750 }
751
752 return BBS_SOLID;
753}
754
755void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) {
756 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
757 if (!pBSDict) {
758 pBSDict = new CPDF_Dictionary;
759 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
760 }
761
Tom Sepezae51c812015-08-05 12:34:06 -0700762 CPDF_Array* pArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
764 pArray->AddInteger(array[i]);
765 }
766
767 pBSDict->SetAt("D", pArray);
768}
769
770void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const {
771 CPDF_Array* pDash = NULL;
772
773 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
774 if (pBorder) {
775 pDash = pBorder->GetArray(3);
776 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700777 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778 if (pBSDict) {
779 pDash = pBSDict->GetArray("D");
780 }
781 }
782
783 if (pDash) {
784 for (int i = 0, sz = pDash->GetCount(); i < sz; i++) {
785 array.Add(pDash->GetInteger(i));
786 }
787 }
788}
789
790void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
791 CPDF_Array* pArray = new CPDF_Array;
792 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
793 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
794 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
795 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
796}
797
798void CPDFSDK_BAAnnot::RemoveColor() {
799 m_pAnnot->GetAnnotDict()->RemoveAt("C");
800}
801
802FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
803 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) {
804 int nCount = pEntry->GetCount();
805 if (nCount == 1) {
806 FX_FLOAT g = pEntry->GetNumber(0) * 255;
807
808 color = FXSYS_RGB((int)g, (int)g, (int)g);
809
810 return TRUE;
811 } else if (nCount == 3) {
812 FX_FLOAT r = pEntry->GetNumber(0) * 255;
813 FX_FLOAT g = pEntry->GetNumber(1) * 255;
814 FX_FLOAT b = pEntry->GetNumber(2) * 255;
815
816 color = FXSYS_RGB((int)r, (int)g, (int)b);
817
818 return TRUE;
819 } else if (nCount == 4) {
820 FX_FLOAT c = pEntry->GetNumber(0);
821 FX_FLOAT m = pEntry->GetNumber(1);
822 FX_FLOAT y = pEntry->GetNumber(2);
823 FX_FLOAT k = pEntry->GetNumber(3);
824
825 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
826 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
827 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
828
829 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
830
831 return TRUE;
832 }
833 }
834
835 return FALSE;
836}
837
838void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
839 const CPDF_Rect& rcBBox,
Tom Sepez60d909e2015-12-10 15:34:55 -0800840 const CFX_Matrix& matrix,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 const CFX_ByteString& sContents,
842 const CFX_ByteString& sAPState) {
843 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
844
845 if (!pAPDict) {
846 pAPDict = new CPDF_Dictionary;
847 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
848 }
849
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500850 CPDF_Stream* pStream = nullptr;
851 CPDF_Dictionary* pParentDict = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700852
853 if (sAPState.IsEmpty()) {
854 pParentDict = pAPDict;
855 pStream = pAPDict->GetStream(sAPType);
856 } else {
857 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
858 if (!pAPTypeDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700859 pAPTypeDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700860 pAPDict->SetAt(sAPType, pAPTypeDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700861 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700862
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700863 pParentDict = pAPTypeDict;
864 pStream = pAPTypeDict->GetStream(sAPState);
865 }
866
867 if (!pStream) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500868 pStream = new CPDF_Stream(nullptr, 0, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500870 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871 int32_t objnum = pDoc->AddIndirectObject(pStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 pParentDict->SetAtReference(sAPType, pDoc, objnum);
873 }
874
875 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 if (!pStreamDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700877 pStreamDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 pStreamDict->SetAtName("Type", "XObject");
879 pStreamDict->SetAtName("Subtype", "Form");
880 pStreamDict->SetAtInteger("FormType", 1);
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500881 pStream->InitStream(nullptr, 0, pStreamDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 }
883
884 if (pStreamDict) {
885 pStreamDict->SetAtMatrix("Matrix", matrix);
886 pStreamDict->SetAtRect("BBox", rcBBox);
887 }
888
889 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE,
890 FALSE);
891}
892
893#define BA_ANNOT_MINWIDTH 1
894#define BA_ANNOT_MINHEIGHT 1
895
896FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
897 return BA_ANNOT_MINWIDTH;
898}
899
900FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
901 return BA_ANNOT_MINHEIGHT;
902}
903
904FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() {
905 return TRUE;
906}
907FX_BOOL CPDFSDK_BAAnnot::IsVisible() const {
908 int nFlags = GetFlags();
909 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
910 (nFlags & ANNOTFLAG_NOVIEW));
911}
912
913CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
914 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
915}
916
917void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
918 ASSERT(action);
919 if ((CPDF_Action&)action !=
920 CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) {
921 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
922 CPDF_Dictionary* pDict = action.GetDict();
923 if (pDict && pDict->GetObjNum() == 0) {
924 pDoc->AddIndirectObject(pDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700925 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
927 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700928}
929
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700930void CPDFSDK_BAAnnot::RemoveAction() {
931 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700932}
933
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
935 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700936}
937
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
940 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700941}
942
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943void CPDFSDK_BAAnnot::RemoveAAction() {
944 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945}
946
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
948 CPDF_AAction AAction = GetAAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700949
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 if (AAction.ActionExist(eAAT))
951 return AAction.GetAction(eAAT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700952
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953 if (eAAT == CPDF_AAction::ButtonUp)
954 return GetAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700957}
958
Tom Sepez51da0932015-11-25 16:05:49 -0800959#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960FX_BOOL CPDFSDK_BAAnnot::IsXFAField() {
961 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700962}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800963#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700964
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800966 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967 CPDF_RenderOptions* pOptions) {
968 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
969 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
970 CPDF_Annot::Normal, NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700971}
972
Tom Sepez50d12ad2015-11-24 09:50:51 -0800973UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800974#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800975 return GetPDFXFAPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800976#else // PDF_ENABLE_XFA
977 return GetPDFPage();
978#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800979}
980
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
982 if (m_pPageView)
983 return m_pPageView->GetPDFPage();
984 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985}
986
Tom Sepez40e9ff32015-11-30 12:39:54 -0800987#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700988CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
989 if (m_pPageView)
990 return m_pPageView->GetPDFXFAPage();
991 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700992}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800993#endif // PDF_ENABLE_XFA