blob: c2036a5ba8e7599d62fc255867c10cfc1d91e20d [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 {
535 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700536
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 return m_pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700538}
539
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect) {
541 ASSERT(rect.right - rect.left >= GetMinWidth());
542 ASSERT(rect.top - rect.bottom >= GetMinHeight());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700543
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700545}
546
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547CPDF_Rect CPDFSDK_BAAnnot::GetRect() const {
548 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700549
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 CPDF_Rect rect;
551 m_pAnnot->GetRect(rect);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700552
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554}
555
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556CFX_ByteString CPDFSDK_BAAnnot::GetType() const {
557 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 return m_pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560}
561
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const {
563 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700564}
565
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
567 const CPDF_Matrix* pUser2Device,
568 CPDF_Annot::AppearanceMode mode,
569 const CPDF_RenderOptions* pOptions) {
570 ASSERT(m_pPageView != NULL);
571 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700572
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
574 mode, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700575}
576
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() {
578 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700579}
580
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
582 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
583 if (pAP == NULL)
584 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700585
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 // Choose the right sub-ap
587 const FX_CHAR* ap_entry = "N";
588 if (mode == CPDF_Annot::Down)
589 ap_entry = "D";
590 else if (mode == CPDF_Annot::Rollover)
591 ap_entry = "R";
592 if (!pAP->KeyExist(ap_entry))
593 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700594
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 // Get the AP stream or subdirectory
596 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
597 if (psub == NULL)
598 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700599
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700601}
602
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
604 const CPDF_Matrix* pUser2Device,
605 const CPDF_RenderOptions* pOptions) {
606 ASSERT(m_pAnnot != NULL);
607 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700608}
609
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610void CPDFSDK_BAAnnot::ClearCachedAP() {
611 ASSERT(m_pAnnot != NULL);
612 m_pAnnot->ClearCachedAP();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700613}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
616 if (sContents.IsEmpty())
617 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
618 else
619 m_pAnnot->GetAnnotDict()->SetAtString("Contents",
620 PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700621}
622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
624 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625}
626
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
628 if (sName.IsEmpty())
629 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
630 else
631 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632}
633
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
635 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700636}
637
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
639 CPDFSDK_DateTime dt(st);
640 CFX_ByteString str = dt.ToPDFDateTimeString();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700641
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642 if (str.IsEmpty())
643 m_pAnnot->GetAnnotDict()->RemoveAt("M");
644 else
645 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646}
647
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
649 FX_SYSTEMTIME systime;
650 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700651
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 CPDFSDK_DateTime dt(str);
653 dt.ToSystemTime(systime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700654
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655 return systime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
657
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658void CPDFSDK_BAAnnot::SetFlags(int nFlags) {
659 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660}
661
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662int CPDFSDK_BAAnnot::GetFlags() const {
663 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
667 if (str.IsEmpty())
668 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
669 else
670 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700671}
672
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
674 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700675}
676
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677void CPDFSDK_BAAnnot::SetStructParent(int key) {
678 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700679}
680
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681int CPDFSDK_BAAnnot::GetStructParent() const {
682 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683}
684
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685// border
686void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
687 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 if (pBorder) {
Tom Sepezae51c812015-08-05 12:34:06 -0700690 pBorder->SetAt(2, new CPDF_Number(nWidth));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700692 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693
694 if (!pBSDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700695 pBSDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700697 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700698
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 pBSDict->SetAtInteger("W", nWidth);
700 }
701}
702
703int CPDFSDK_BAAnnot::GetBorderWidth() const {
704 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) {
705 return pBorder->GetInteger(2);
706 }
707 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) {
708 return pBSDict->GetInteger("W", 1);
709 }
710 return 1;
711}
712
713void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) {
714 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
715 if (!pBSDict) {
716 pBSDict = new CPDF_Dictionary;
717 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
718 }
719
720 switch (nStyle) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700721 case BBS_SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 pBSDict->SetAtName("S", "S");
723 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700724 case BBS_DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 pBSDict->SetAtName("S", "D");
726 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700727 case BBS_BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 pBSDict->SetAtName("S", "B");
729 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700730 case BBS_INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 pBSDict->SetAtName("S", "I");
732 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700733 case BBS_UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 pBSDict->SetAtName("S", "U");
735 break;
736 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737}
738
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739int CPDFSDK_BAAnnot::GetBorderStyle() const {
740 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
741 if (pBSDict) {
742 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
743 if (sBorderStyle == "S")
744 return BBS_SOLID;
745 if (sBorderStyle == "D")
746 return BBS_DASH;
747 if (sBorderStyle == "B")
748 return BBS_BEVELED;
749 if (sBorderStyle == "I")
750 return BBS_INSET;
751 if (sBorderStyle == "U")
752 return BBS_UNDERLINE;
753 }
754
755 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
756 if (pBorder) {
757 if (pBorder->GetCount() >= 4) {
758 CPDF_Array* pDP = pBorder->GetArray(3);
759 if (pDP && pDP->GetCount() > 0)
760 return BBS_DASH;
761 }
762 }
763
764 return BBS_SOLID;
765}
766
767void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) {
768 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
769 if (!pBSDict) {
770 pBSDict = new CPDF_Dictionary;
771 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
772 }
773
Tom Sepezae51c812015-08-05 12:34:06 -0700774 CPDF_Array* pArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
776 pArray->AddInteger(array[i]);
777 }
778
779 pBSDict->SetAt("D", pArray);
780}
781
782void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const {
783 CPDF_Array* pDash = NULL;
784
785 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
786 if (pBorder) {
787 pDash = pBorder->GetArray(3);
788 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700789 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 if (pBSDict) {
791 pDash = pBSDict->GetArray("D");
792 }
793 }
794
795 if (pDash) {
796 for (int i = 0, sz = pDash->GetCount(); i < sz; i++) {
797 array.Add(pDash->GetInteger(i));
798 }
799 }
800}
801
802void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
803 CPDF_Array* pArray = new CPDF_Array;
804 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
805 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
806 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
807 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
808}
809
810void CPDFSDK_BAAnnot::RemoveColor() {
811 m_pAnnot->GetAnnotDict()->RemoveAt("C");
812}
813
814FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
815 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) {
816 int nCount = pEntry->GetCount();
817 if (nCount == 1) {
818 FX_FLOAT g = pEntry->GetNumber(0) * 255;
819
820 color = FXSYS_RGB((int)g, (int)g, (int)g);
821
822 return TRUE;
823 } else if (nCount == 3) {
824 FX_FLOAT r = pEntry->GetNumber(0) * 255;
825 FX_FLOAT g = pEntry->GetNumber(1) * 255;
826 FX_FLOAT b = pEntry->GetNumber(2) * 255;
827
828 color = FXSYS_RGB((int)r, (int)g, (int)b);
829
830 return TRUE;
831 } else if (nCount == 4) {
832 FX_FLOAT c = pEntry->GetNumber(0);
833 FX_FLOAT m = pEntry->GetNumber(1);
834 FX_FLOAT y = pEntry->GetNumber(2);
835 FX_FLOAT k = pEntry->GetNumber(3);
836
837 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
838 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
839 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
840
841 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
842
843 return TRUE;
844 }
845 }
846
847 return FALSE;
848}
849
850void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
851 const CPDF_Rect& rcBBox,
852 const CPDF_Matrix& matrix,
853 const CFX_ByteString& sContents,
854 const CFX_ByteString& sAPState) {
855 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
856
857 if (!pAPDict) {
858 pAPDict = new CPDF_Dictionary;
859 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
860 }
861
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500862 CPDF_Stream* pStream = nullptr;
863 CPDF_Dictionary* pParentDict = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864
865 if (sAPState.IsEmpty()) {
866 pParentDict = pAPDict;
867 pStream = pAPDict->GetStream(sAPType);
868 } else {
869 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
870 if (!pAPTypeDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700871 pAPTypeDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 pAPDict->SetAt(sAPType, pAPTypeDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700873 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700874
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700875 pParentDict = pAPTypeDict;
876 pStream = pAPTypeDict->GetStream(sAPState);
877 }
878
879 if (!pStream) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500880 pStream = new CPDF_Stream(nullptr, 0, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500882 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 int32_t objnum = pDoc->AddIndirectObject(pStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884 pParentDict->SetAtReference(sAPType, pDoc, objnum);
885 }
886
887 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888 if (!pStreamDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700889 pStreamDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890 pStreamDict->SetAtName("Type", "XObject");
891 pStreamDict->SetAtName("Subtype", "Form");
892 pStreamDict->SetAtInteger("FormType", 1);
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500893 pStream->InitStream(nullptr, 0, pStreamDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 }
895
896 if (pStreamDict) {
897 pStreamDict->SetAtMatrix("Matrix", matrix);
898 pStreamDict->SetAtRect("BBox", rcBBox);
899 }
900
901 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE,
902 FALSE);
903}
904
905#define BA_ANNOT_MINWIDTH 1
906#define BA_ANNOT_MINHEIGHT 1
907
908FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
909 return BA_ANNOT_MINWIDTH;
910}
911
912FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
913 return BA_ANNOT_MINHEIGHT;
914}
915
916FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() {
917 return TRUE;
918}
919FX_BOOL CPDFSDK_BAAnnot::IsVisible() const {
920 int nFlags = GetFlags();
921 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
922 (nFlags & ANNOTFLAG_NOVIEW));
923}
924
925CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
926 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
927}
928
929void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
930 ASSERT(action);
931 if ((CPDF_Action&)action !=
932 CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) {
933 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
934 CPDF_Dictionary* pDict = action.GetDict();
935 if (pDict && pDict->GetObjNum() == 0) {
936 pDoc->AddIndirectObject(pDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700937 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
939 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700940}
941
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942void CPDFSDK_BAAnnot::RemoveAction() {
943 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700944}
945
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
947 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700948}
949
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
951 ASSERT(aa != NULL);
952
953 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
954 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955}
956
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700957void CPDFSDK_BAAnnot::RemoveAAction() {
958 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700959}
960
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
962 CPDF_AAction AAction = GetAAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700963
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 if (AAction.ActionExist(eAAT))
965 return AAction.GetAction(eAAT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700966
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967 if (eAAT == CPDF_AAction::ButtonUp)
968 return GetAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700969
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700971}
972
Tom Sepez51da0932015-11-25 16:05:49 -0800973#ifdef PDF_ENABLE_XFA
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}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800977#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700978
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
980 CPDF_Matrix* pUser2Device,
981 CPDF_RenderOptions* pOptions) {
982 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
983 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
984 CPDF_Annot::Normal, NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985}
986
Tom Sepez50d12ad2015-11-24 09:50:51 -0800987UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800988#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800989 return GetPDFXFAPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800990#else // PDF_ENABLE_XFA
991 return GetPDFPage();
992#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800993}
994
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
996 if (m_pPageView)
997 return m_pPageView->GetPDFPage();
998 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700999}
1000
Tom Sepez40e9ff32015-11-30 12:39:54 -08001001#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
1003 if (m_pPageView)
1004 return m_pPageView->GetPDFXFAPage();
1005 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001006}
Tom Sepez40e9ff32015-11-30 12:39:54 -08001007#endif // PDF_ENABLE_XFA