blob: ccb20ba8e95217390ad2b01e305f9ebd357eadbb [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"
8#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
Lei Zhangbde53d22015-11-12 22:21:30 -08009#include "fpdfsdk/include/fsdk_baseannot.h"
10#include "fpdfsdk/include/fsdk_define.h"
11#include "fpdfsdk/include/fsdk_mgr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
Nico Weber9d8ec5a2015-08-04 13:00:21 -070013int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, uint8_t tzminute) {
14 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015}
16
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017FX_BOOL _gAfxIsLeapYear(int16_t year) {
18 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019}
20
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021FX_WORD _gAfxGetYearDays(int16_t year) {
22 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023}
24
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) {
26 uint8_t mDays;
27 switch (month) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -070028 case 1:
29 case 3:
30 case 5:
31 case 7:
32 case 8:
33 case 10:
34 case 12:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 mDays = 31;
36 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037
Tom Sepez2f2ffec2015-07-23 14:42:09 -070038 case 4:
39 case 6:
40 case 9:
41 case 11:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 mDays = 30;
43 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Tom Sepez2f2ffec2015-07-23 14:42:09 -070045 case 2:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 if (_gAfxIsLeapYear(year) == TRUE)
47 mDays = 29;
48 else
49 mDays = 28;
50 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Tom Sepez2f2ffec2015-07-23 14:42:09 -070052 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 mDays = 0;
54 break;
55 }
56
57 return mDays;
58}
59
60CPDFSDK_DateTime::CPDFSDK_DateTime() {
61 ResetDateTime();
62}
63
64CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) {
65 ResetDateTime();
66
67 FromPDFDateTimeString(dtStr);
68}
69
70CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime) {
71 operator=(datetime);
72}
73
74CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st) {
75 operator=(st);
76}
77
78void CPDFSDK_DateTime::ResetDateTime() {
79 tzset();
80
81 time_t curTime;
82 time(&curTime);
83 struct tm* newtime;
84 // newtime = gmtime(&curTime);
85 newtime = localtime(&curTime);
86
87 dt.year = newtime->tm_year + 1900;
88 dt.month = newtime->tm_mon + 1;
89 dt.day = newtime->tm_mday;
90 dt.hour = newtime->tm_hour;
91 dt.minute = newtime->tm_min;
92 dt.second = newtime->tm_sec;
93 // dt.tzHour = _timezone / 3600 * -1;
94 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
95}
96
97CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(
98 const CPDFSDK_DateTime& datetime) {
99 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
100 return *this;
101}
102
103CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(const FX_SYSTEMTIME& st) {
104 tzset();
105
106 dt.year = (int16_t)st.wYear;
107 dt.month = (uint8_t)st.wMonth;
108 dt.day = (uint8_t)st.wDay;
109 dt.hour = (uint8_t)st.wHour;
110 dt.minute = (uint8_t)st.wMinute;
111 dt.second = (uint8_t)st.wSecond;
112 // dt.tzHour = _timezone / 3600 * -1;
113 // dt.tzMinute = (abs(_timezone) % 3600) / 60;
114 return *this;
115}
116
117FX_BOOL CPDFSDK_DateTime::operator==(CPDFSDK_DateTime& datetime) {
118 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0);
119}
120
121FX_BOOL CPDFSDK_DateTime::operator!=(CPDFSDK_DateTime& datetime) {
122 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
123}
124
125FX_BOOL CPDFSDK_DateTime::operator>(CPDFSDK_DateTime& datetime) {
126 CPDFSDK_DateTime dt1 = ToGMT();
127 CPDFSDK_DateTime dt2 = datetime.ToGMT();
128 int d1 =
129 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
130 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
131 (int)dt1.dt.second;
132 int d3 =
133 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
134 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
135 (int)dt2.dt.second;
136
137 if (d1 > d3)
138 return TRUE;
139 if (d2 > d4)
140 return TRUE;
141 return FALSE;
142}
143
144FX_BOOL CPDFSDK_DateTime::operator>=(CPDFSDK_DateTime& datetime) {
145 CPDFSDK_DateTime dt1 = ToGMT();
146 CPDFSDK_DateTime dt2 = datetime.ToGMT();
147 int d1 =
148 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
149 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
150 (int)dt1.dt.second;
151 int d3 =
152 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
153 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
154 (int)dt2.dt.second;
155
156 if (d1 >= d3)
157 return TRUE;
158 if (d2 >= d4)
159 return TRUE;
160 return FALSE;
161}
162
163FX_BOOL CPDFSDK_DateTime::operator<(CPDFSDK_DateTime& datetime) {
164 CPDFSDK_DateTime dt1 = ToGMT();
165 CPDFSDK_DateTime dt2 = datetime.ToGMT();
166 int d1 =
167 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
168 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
169 (int)dt1.dt.second;
170 int d3 =
171 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
172 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
173 (int)dt2.dt.second;
174
175 if (d1 < d3)
176 return TRUE;
177 if (d2 < d4)
178 return TRUE;
179 return FALSE;
180}
181
182FX_BOOL CPDFSDK_DateTime::operator<=(CPDFSDK_DateTime& datetime) {
183 CPDFSDK_DateTime dt1 = ToGMT();
184 CPDFSDK_DateTime dt2 = datetime.ToGMT();
185 int d1 =
186 (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
187 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) |
188 (int)dt1.dt.second;
189 int d3 =
190 (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
191 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) |
192 (int)dt2.dt.second;
193
194 if (d1 <= d3)
195 return TRUE;
196 if (d2 <= d4)
197 return TRUE;
198 return FALSE;
199}
200
201CPDFSDK_DateTime::operator time_t() {
202 struct tm newtime;
203
204 newtime.tm_year = dt.year - 1900;
205 newtime.tm_mon = dt.month - 1;
206 newtime.tm_mday = dt.day;
207 newtime.tm_hour = dt.hour;
208 newtime.tm_min = dt.minute;
209 newtime.tm_sec = dt.second;
210
211 return mktime(&newtime);
212}
213
214CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(
215 const CFX_ByteString& dtStr) {
216 int strLength = dtStr.GetLength();
217 if (strLength > 0) {
218 int i = 0;
219 int j, k;
220 FX_CHAR ch;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500221 while (i < strLength && !std::isdigit(dtStr[i]))
222 ++i;
223
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 if (i >= strLength)
225 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700226
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 j = 0;
228 k = 0;
229 while (i < strLength && j < 4) {
230 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500231 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500233 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 break;
235 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700236 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 dt.year = (int16_t)k;
238 if (i >= strLength || j < 4)
239 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700240
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 j = 0;
242 k = 0;
243 while (i < strLength && j < 2) {
244 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500245 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500247 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 break;
249 i++;
250 }
251 dt.month = (uint8_t)k;
252 if (i >= strLength || j < 2)
253 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700254
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 j = 0;
256 k = 0;
257 while (i < strLength && j < 2) {
258 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500259 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500261 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 break;
263 i++;
264 }
265 dt.day = (uint8_t)k;
266 if (i >= strLength || j < 2)
267 return *this;
268
269 j = 0;
270 k = 0;
271 while (i < strLength && j < 2) {
272 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500273 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500275 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 break;
277 i++;
278 }
279 dt.hour = (uint8_t)k;
280 if (i >= strLength || j < 2)
281 return *this;
282
283 j = 0;
284 k = 0;
285 while (i < strLength && j < 2) {
286 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500287 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500289 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 break;
291 i++;
292 }
293 dt.minute = (uint8_t)k;
294 if (i >= strLength || j < 2)
295 return *this;
296
297 j = 0;
298 k = 0;
299 while (i < strLength && j < 2) {
300 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500301 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500303 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 break;
305 i++;
306 }
307 dt.second = (uint8_t)k;
308 if (i >= strLength || j < 2)
309 return *this;
310
311 ch = dtStr[i++];
312 if (ch != '-' && ch != '+')
313 return *this;
314 if (ch == '-')
315 dt.tzHour = -1;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700316 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 dt.tzHour = 1;
318 j = 0;
319 k = 0;
320 while (i < strLength && j < 2) {
321 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500322 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500324 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 break;
326 i++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700327 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 dt.tzHour *= (FX_CHAR)k;
329 if (i >= strLength || j < 2)
330 return *this;
331
332 ch = dtStr[i++];
333 if (ch != '\'')
334 return *this;
335 j = 0;
336 k = 0;
337 while (i < strLength && j < 2) {
338 ch = dtStr[i];
Dan Sinclair10cfea12015-11-16 13:09:00 -0500339 k = k * 10 + FXSYS_toDecimalDigit(ch);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 j++;
Dan Sinclair10cfea12015-11-16 13:09:00 -0500341 if (!std::isdigit(ch))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 break;
343 i++;
344 }
345 dt.tzMinute = (uint8_t)k;
346 if (i >= strLength || j < 2)
347 return *this;
348 }
349
350 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700351}
352
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() {
354 CFX_ByteString str1;
355 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day,
356 dt.hour, dt.minute, dt.second);
357 if (dt.tzHour < 0)
358 str1 += "-";
359 else
360 str1 += "+";
361 CFX_ByteString str2;
362 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
363 return str1 + str2;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364}
365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() {
367 CFX_ByteString dtStr;
368 char tempStr[32];
369 memset(tempStr, 0, sizeof(tempStr));
370 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
371 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
372 dtStr = CFX_ByteString(tempStr);
373 if (dt.tzHour < 0)
374 dtStr += CFX_ByteString("-");
375 else
376 dtStr += CFX_ByteString("+");
377 memset(tempStr, 0, sizeof(tempStr));
378 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour),
379 dt.tzMinute);
380 dtStr += CFX_ByteString(tempStr);
381 return dtStr;
382}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) {
385 CPDFSDK_DateTime dt = *this;
386 time_t t = (time_t)dt;
387 struct tm* pTime = localtime(&t);
388 if (pTime) {
389 st.wYear = (FX_WORD)pTime->tm_year + 1900;
390 st.wMonth = (FX_WORD)pTime->tm_mon + 1;
391 st.wDay = (FX_WORD)pTime->tm_mday;
392 st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
393 st.wHour = (FX_WORD)pTime->tm_hour;
394 st.wMinute = (FX_WORD)pTime->tm_min;
395 st.wSecond = (FX_WORD)pTime->tm_sec;
396 st.wMilliseconds = 0;
397 }
398}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700399
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() {
401 CPDFSDK_DateTime dt = *this;
402 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
403 dt.dt.tzHour = 0;
404 dt.dt.tzMinute = 0;
405 return dt;
406}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700407
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) {
409 if (days == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700410 return *this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411
412 int16_t y = dt.year, yy;
413 uint8_t m = dt.month;
414 uint8_t d = dt.day;
415 int mdays, ydays, ldays;
416
417 ldays = days;
418 if (ldays > 0) {
419 yy = y;
420 if (((FX_WORD)m * 100 + d) > 300)
421 yy++;
422 ydays = _gAfxGetYearDays(yy);
423 while (ldays >= ydays) {
424 y++;
425 ldays -= ydays;
426 yy++;
427 mdays = _gAfxGetMonthDays(y, m);
428 if (d > mdays) {
429 m++;
430 d -= mdays;
431 }
432 ydays = _gAfxGetYearDays(yy);
433 }
434 mdays = _gAfxGetMonthDays(y, m) - d + 1;
435 while (ldays >= mdays) {
436 ldays -= mdays;
437 m++;
438 d = 1;
439 mdays = _gAfxGetMonthDays(y, m);
440 }
441 d += ldays;
442 } else {
443 ldays *= -1;
444 yy = y;
445 if (((FX_WORD)m * 100 + d) < 300)
446 yy--;
447 ydays = _gAfxGetYearDays(yy);
448 while (ldays >= ydays) {
449 y--;
450 ldays -= ydays;
451 yy--;
452 mdays = _gAfxGetMonthDays(y, m);
453 if (d > mdays) {
454 m++;
455 d -= mdays;
456 }
457 ydays = _gAfxGetYearDays(yy);
458 }
459 while (ldays >= d) {
460 ldays -= d;
461 m--;
462 mdays = _gAfxGetMonthDays(y, m);
463 d = mdays;
464 }
465 d -= ldays;
466 }
467
468 dt.year = y;
469 dt.month = m;
470 dt.day = d;
471
472 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473}
474
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) {
476 if (seconds == 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700477 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 int n;
480 int days;
481
482 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
483 if (n < 0) {
484 days = (n - 86399) / 86400;
485 n -= days * 86400;
486 } else {
487 days = n / 86400;
488 n %= 86400;
489 }
490 dt.hour = (uint8_t)(n / 3600);
491 dt.hour %= 24;
492 n %= 3600;
493 dt.minute = (uint8_t)(n / 60);
494 dt.second = (uint8_t)(n % 60);
495 if (days != 0)
496 AddDays(days);
497
498 return *this;
499}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700500
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView)
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500502 : m_pPageView(pPageView), m_bSelected(FALSE), m_nTabOrder(-1) {
503}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot,
506 CPDFSDK_PageView* pPageView)
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500507 : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508}
509
Tom Sepez3343d142015-11-02 09:54:54 -0800510CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 return m_pAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700512}
513
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514FX_BOOL CPDFSDK_Annot::IsSelected() {
515 return m_bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700516}
517
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) {
519 m_bSelected = bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700520}
521
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700522// Tab Order
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523int CPDFSDK_Annot::GetTabOrder() {
524 return m_nTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700525}
526
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527void CPDFSDK_Annot::SetTabOrder(int iTabOrder) {
528 m_nTabOrder = iTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700529}
530
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const {
532 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700533
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 return m_pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700535}
536
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect) {
538 ASSERT(rect.right - rect.left >= GetMinWidth());
539 ASSERT(rect.top - rect.bottom >= GetMinHeight());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700540
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700542}
543
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544CPDF_Rect CPDFSDK_BAAnnot::GetRect() const {
545 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700546
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 CPDF_Rect rect;
548 m_pAnnot->GetRect(rect);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700549
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700551}
552
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553CFX_ByteString CPDFSDK_BAAnnot::GetType() const {
554 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700555
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 return m_pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700557}
558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const {
560 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700561}
562
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice,
564 const CPDF_Matrix* pUser2Device,
565 CPDF_Annot::AppearanceMode mode,
566 const CPDF_RenderOptions* pOptions) {
567 ASSERT(m_pPageView != NULL);
568 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700569
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
571 mode, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700572}
573
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() {
575 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576}
577
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
579 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
580 if (pAP == NULL)
581 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700582
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 // Choose the right sub-ap
584 const FX_CHAR* ap_entry = "N";
585 if (mode == CPDF_Annot::Down)
586 ap_entry = "D";
587 else if (mode == CPDF_Annot::Rollover)
588 ap_entry = "R";
589 if (!pAP->KeyExist(ap_entry))
590 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700591
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 // Get the AP stream or subdirectory
593 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
594 if (psub == NULL)
595 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700596
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700598}
599
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice,
601 const CPDF_Matrix* pUser2Device,
602 const CPDF_RenderOptions* pOptions) {
603 ASSERT(m_pAnnot != NULL);
604 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700605}
606
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607void CPDFSDK_BAAnnot::ClearCachedAP() {
608 ASSERT(m_pAnnot != NULL);
609 m_pAnnot->ClearCachedAP();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700610}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
613 if (sContents.IsEmpty())
614 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
615 else
616 m_pAnnot->GetAnnotDict()->SetAtString("Contents",
617 PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700618}
619
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
621 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622}
623
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
625 if (sName.IsEmpty())
626 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
627 else
628 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629}
630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
632 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633}
634
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
636 CPDFSDK_DateTime dt(st);
637 CFX_ByteString str = dt.ToPDFDateTimeString();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700638
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 if (str.IsEmpty())
640 m_pAnnot->GetAnnotDict()->RemoveAt("M");
641 else
642 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700643}
644
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
646 FX_SYSTEMTIME systime;
647 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700648
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 CPDFSDK_DateTime dt(str);
650 dt.ToSystemTime(systime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700651
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 return systime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653}
654
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655void CPDFSDK_BAAnnot::SetFlags(int nFlags) {
656 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700657}
658
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659int CPDFSDK_BAAnnot::GetFlags() const {
660 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661}
662
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
664 if (str.IsEmpty())
665 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
666 else
667 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
671 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672}
673
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674void CPDFSDK_BAAnnot::SetStructParent(int key) {
675 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676}
677
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678int CPDFSDK_BAAnnot::GetStructParent() const {
679 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700680}
681
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682// border
683void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
684 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 if (pBorder) {
Tom Sepezae51c812015-08-05 12:34:06 -0700687 pBorder->SetAt(2, new CPDF_Number(nWidth));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700689 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690
691 if (!pBSDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700692 pBSDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700694 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 pBSDict->SetAtInteger("W", nWidth);
697 }
698}
699
700int CPDFSDK_BAAnnot::GetBorderWidth() const {
701 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) {
702 return pBorder->GetInteger(2);
703 }
704 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) {
705 return pBSDict->GetInteger("W", 1);
706 }
707 return 1;
708}
709
710void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) {
711 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
712 if (!pBSDict) {
713 pBSDict = new CPDF_Dictionary;
714 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
715 }
716
717 switch (nStyle) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700718 case BBS_SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 pBSDict->SetAtName("S", "S");
720 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700721 case BBS_DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 pBSDict->SetAtName("S", "D");
723 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700724 case BBS_BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 pBSDict->SetAtName("S", "B");
726 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700727 case BBS_INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 pBSDict->SetAtName("S", "I");
729 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700730 case BBS_UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 pBSDict->SetAtName("S", "U");
732 break;
733 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734}
735
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736int CPDFSDK_BAAnnot::GetBorderStyle() const {
737 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
738 if (pBSDict) {
739 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
740 if (sBorderStyle == "S")
741 return BBS_SOLID;
742 if (sBorderStyle == "D")
743 return BBS_DASH;
744 if (sBorderStyle == "B")
745 return BBS_BEVELED;
746 if (sBorderStyle == "I")
747 return BBS_INSET;
748 if (sBorderStyle == "U")
749 return BBS_UNDERLINE;
750 }
751
752 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
753 if (pBorder) {
754 if (pBorder->GetCount() >= 4) {
755 CPDF_Array* pDP = pBorder->GetArray(3);
756 if (pDP && pDP->GetCount() > 0)
757 return BBS_DASH;
758 }
759 }
760
761 return BBS_SOLID;
762}
763
764void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) {
765 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
766 if (!pBSDict) {
767 pBSDict = new CPDF_Dictionary;
768 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
769 }
770
Tom Sepezae51c812015-08-05 12:34:06 -0700771 CPDF_Array* pArray = new CPDF_Array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
773 pArray->AddInteger(array[i]);
774 }
775
776 pBSDict->SetAt("D", pArray);
777}
778
779void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const {
780 CPDF_Array* pDash = NULL;
781
782 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
783 if (pBorder) {
784 pDash = pBorder->GetArray(3);
785 } else {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700786 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700787 if (pBSDict) {
788 pDash = pBSDict->GetArray("D");
789 }
790 }
791
792 if (pDash) {
793 for (int i = 0, sz = pDash->GetCount(); i < sz; i++) {
794 array.Add(pDash->GetInteger(i));
795 }
796 }
797}
798
799void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
800 CPDF_Array* pArray = new CPDF_Array;
801 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
802 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
803 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
804 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
805}
806
807void CPDFSDK_BAAnnot::RemoveColor() {
808 m_pAnnot->GetAnnotDict()->RemoveAt("C");
809}
810
811FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const {
812 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) {
813 int nCount = pEntry->GetCount();
814 if (nCount == 1) {
815 FX_FLOAT g = pEntry->GetNumber(0) * 255;
816
817 color = FXSYS_RGB((int)g, (int)g, (int)g);
818
819 return TRUE;
820 } else if (nCount == 3) {
821 FX_FLOAT r = pEntry->GetNumber(0) * 255;
822 FX_FLOAT g = pEntry->GetNumber(1) * 255;
823 FX_FLOAT b = pEntry->GetNumber(2) * 255;
824
825 color = FXSYS_RGB((int)r, (int)g, (int)b);
826
827 return TRUE;
828 } else if (nCount == 4) {
829 FX_FLOAT c = pEntry->GetNumber(0);
830 FX_FLOAT m = pEntry->GetNumber(1);
831 FX_FLOAT y = pEntry->GetNumber(2);
832 FX_FLOAT k = pEntry->GetNumber(3);
833
834 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
835 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
836 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
837
838 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
839
840 return TRUE;
841 }
842 }
843
844 return FALSE;
845}
846
847void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
848 const CPDF_Rect& rcBBox,
849 const CPDF_Matrix& matrix,
850 const CFX_ByteString& sContents,
851 const CFX_ByteString& sAPState) {
852 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
853
854 if (!pAPDict) {
855 pAPDict = new CPDF_Dictionary;
856 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
857 }
858
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500859 CPDF_Stream* pStream = nullptr;
860 CPDF_Dictionary* pParentDict = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861
862 if (sAPState.IsEmpty()) {
863 pParentDict = pAPDict;
864 pStream = pAPDict->GetStream(sAPType);
865 } else {
866 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
867 if (!pAPTypeDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700868 pAPTypeDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869 pAPDict->SetAt(sAPType, pAPTypeDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700870 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 pParentDict = pAPTypeDict;
873 pStream = pAPTypeDict->GetStream(sAPState);
874 }
875
876 if (!pStream) {
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500877 pStream = new CPDF_Stream(nullptr, 0, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500879 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 int32_t objnum = pDoc->AddIndirectObject(pStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881 pParentDict->SetAtReference(sAPType, pDoc, objnum);
882 }
883
884 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700885 if (!pStreamDict) {
Tom Sepezae51c812015-08-05 12:34:06 -0700886 pStreamDict = new CPDF_Dictionary;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887 pStreamDict->SetAtName("Type", "XObject");
888 pStreamDict->SetAtName("Subtype", "Form");
889 pStreamDict->SetAtInteger("FormType", 1);
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500890 pStream->InitStream(nullptr, 0, pStreamDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891 }
892
893 if (pStreamDict) {
894 pStreamDict->SetAtMatrix("Matrix", matrix);
895 pStreamDict->SetAtRect("BBox", rcBBox);
896 }
897
898 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE,
899 FALSE);
900}
901
902#define BA_ANNOT_MINWIDTH 1
903#define BA_ANNOT_MINHEIGHT 1
904
905FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
906 return BA_ANNOT_MINWIDTH;
907}
908
909FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
910 return BA_ANNOT_MINHEIGHT;
911}
912
913FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() {
914 return TRUE;
915}
916FX_BOOL CPDFSDK_BAAnnot::IsVisible() const {
917 int nFlags = GetFlags();
918 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) ||
919 (nFlags & ANNOTFLAG_NOVIEW));
920}
921
922CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
923 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
924}
925
926void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
927 ASSERT(action);
928 if ((CPDF_Action&)action !=
929 CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) {
930 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
931 CPDF_Dictionary* pDict = action.GetDict();
932 if (pDict && pDict->GetObjNum() == 0) {
933 pDoc->AddIndirectObject(pDict);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700934 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700935 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
936 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700937}
938
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939void CPDFSDK_BAAnnot::RemoveAction() {
940 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700941}
942
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
944 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945}
946
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
948 ASSERT(aa != NULL);
949
950 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
951 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700952}
953
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954void CPDFSDK_BAAnnot::RemoveAAction() {
955 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700956}
957
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
959 CPDF_AAction AAction = GetAAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700960
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961 if (AAction.ActionExist(eAAT))
962 return AAction.GetAction(eAAT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700963
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 if (eAAT == CPDF_AAction::ButtonUp)
965 return GetAction();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700966
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700968}
969
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970FX_BOOL CPDFSDK_BAAnnot::IsXFAField() {
971 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700972}
973
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice,
975 CPDF_Matrix* pUser2Device,
976 CPDF_RenderOptions* pOptions) {
977 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
978 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device,
979 CPDF_Annot::Normal, NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700982}
983
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
985 if (m_pPageView)
986 return m_pPageView->GetPDFPage();
987 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700988}
989
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
991 if (m_pPageView)
992 return m_pPageView->GetPDFXFAPage();
993 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700994}