blob: a862ea77239e541493d25bd2534c3cdb311e56e4 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07008#include "../include/fpdfxfa/fpdfxfa_doc.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_mgr.h"
10#include "../include/fsdk_baseannot.h"
11
12
13//---------------------------------------------------------------------------
Tom Sepez2f2ffec2015-07-23 14:42:09 -070014// CPDFSDK_DateTime
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015//---------------------------------------------------------------------------
Tom Sepezbfa9a822015-06-09 13:24:12 -070016int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, uint8_t tzminute)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070018 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019}
20
Tom Sepezbfa9a822015-06-09 13:24:12 -070021FX_BOOL _gAfxIsLeapYear(int16_t year)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070023 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024}
25
Tom Sepezbfa9a822015-06-09 13:24:12 -070026FX_WORD _gAfxGetYearDays(int16_t year)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070028 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029}
30
Tom Sepezbfa9a822015-06-09 13:24:12 -070031uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070033 uint8_t mDays;
34 switch (month)
35 {
36 case 1:
37 case 3:
38 case 5:
39 case 7:
40 case 8:
41 case 10:
42 case 12:
43 mDays = 31;
44 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045
Tom Sepez2f2ffec2015-07-23 14:42:09 -070046 case 4:
47 case 6:
48 case 9:
49 case 11:
50 mDays = 30;
51 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
Tom Sepez2f2ffec2015-07-23 14:42:09 -070053 case 2:
54 if (_gAfxIsLeapYear(year) == TRUE)
55 mDays = 29;
56 else
57 mDays = 28;
58 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059
Tom Sepez2f2ffec2015-07-23 14:42:09 -070060 default:
61 mDays = 0;
62 break;
63 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070064
Tom Sepez2f2ffec2015-07-23 14:42:09 -070065 return mDays;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066}
67
68CPDFSDK_DateTime::CPDFSDK_DateTime()
69{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070070 ResetDateTime();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
73CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr)
74{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070075 ResetDateTime();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076
Tom Sepez2f2ffec2015-07-23 14:42:09 -070077 FromPDFDateTimeString(dtStr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078}
79
80CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime)
81{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070082 operator = (datetime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070083}
84
85CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st)
86{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070087 operator = (st) ;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070088}
89
90
91void CPDFSDK_DateTime::ResetDateTime()
92{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070093 tzset();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070094
Tom Sepez2f2ffec2015-07-23 14:42:09 -070095 time_t curTime;
96 time(&curTime);
97 struct tm* newtime;
98 //newtime = gmtime(&curTime);
99 newtime = localtime(&curTime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700101 dt.year = newtime->tm_year + 1900;
102 dt.month = newtime->tm_mon + 1;
103 dt.day = newtime->tm_mday;
104 dt.hour = newtime->tm_hour;
105 dt.minute = newtime->tm_min;
106 dt.second = newtime->tm_sec;
107// dt.tzHour = _timezone / 3600 * -1;
108// dt.tzMinute = (abs(_timezone) % 3600) / 60;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109}
110
111CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const CPDFSDK_DateTime& datetime)
112{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700113 FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME));
114 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115}
116
117CPDFSDK_DateTime& CPDFSDK_DateTime::operator = (const FX_SYSTEMTIME& st)
118{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700119 tzset();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700121 dt.year = (int16_t)st.wYear;
122 dt.month = (uint8_t)st.wMonth;
123 dt.day = (uint8_t)st.wDay;
124 dt.hour = (uint8_t)st.wHour;
125 dt.minute = (uint8_t)st.wMinute;
126 dt.second = (uint8_t)st.wSecond;
127// dt.tzHour = _timezone / 3600 * -1;
128// dt.tzMinute = (abs(_timezone) % 3600) / 60;
129 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130}
131
132FX_BOOL CPDFSDK_DateTime::operator == (CPDFSDK_DateTime& datetime)
133{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700134 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135}
136
137FX_BOOL CPDFSDK_DateTime::operator != (CPDFSDK_DateTime& datetime)
138{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700139 return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140}
141
142FX_BOOL CPDFSDK_DateTime::operator > (CPDFSDK_DateTime& datetime)
143{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700144 CPDFSDK_DateTime dt1 = ToGMT();
145 CPDFSDK_DateTime dt2 = datetime.ToGMT();
146 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
147 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
148 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
149 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700151 if (d1 > d3) return TRUE;
152 if (d2 > d4) return TRUE;
153 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154}
155
156FX_BOOL CPDFSDK_DateTime::operator >= (CPDFSDK_DateTime& datetime)
157{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700158 CPDFSDK_DateTime dt1 = ToGMT();
159 CPDFSDK_DateTime dt2 = datetime.ToGMT();
160 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
161 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
162 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
163 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700165 if (d1 >= d3) return TRUE;
166 if (d2 >= d4) return TRUE;
167 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168}
169
170FX_BOOL CPDFSDK_DateTime::operator < (CPDFSDK_DateTime& datetime)
171{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700172 CPDFSDK_DateTime dt1 = ToGMT();
173 CPDFSDK_DateTime dt2 = datetime.ToGMT();
174 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
175 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
176 int d3 = (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day;
177 int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | (int)dt2.dt.second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700179 if (d1 < d3) return TRUE;
180 if (d2 < d4) return TRUE;
181 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182}
183
184FX_BOOL CPDFSDK_DateTime::operator <= (CPDFSDK_DateTime& datetime)
185{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700186 CPDFSDK_DateTime dt1 = ToGMT();
187 CPDFSDK_DateTime dt2 = datetime.ToGMT();
188 int d1 = (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day;
189 int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | (int)dt1.dt.second;
190 int d3 = (((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) | (int)dt2.dt.second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700193 if (d1 <= d3) return TRUE;
194 if (d2 <= d4) return TRUE;
195 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196}
197
198CPDFSDK_DateTime::operator time_t()
199{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700200 struct tm newtime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700202 newtime.tm_year = dt.year - 1900;
203 newtime.tm_mon = dt.month - 1;
204 newtime.tm_mday = dt.day;
205 newtime.tm_hour = dt.hour;
206 newtime.tm_min = dt.minute;
207 newtime.tm_sec = dt.second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700209 return mktime(&newtime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210}
211
212CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString(const CFX_ByteString& dtStr)
213{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700214 int strLength = dtStr.GetLength();
215 if (strLength > 0)
216 {
217 int i = 0;
218 int j, k;
219 FX_CHAR ch;
220 while (i < strLength)
221 {
222 ch = dtStr[i];
223 if (ch >= '0' && ch <= '9') break;
224 i ++;
225 }
226 if (i >= strLength) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700228 j = 0;
229 k = 0;
230 while (i < strLength && j < 4)
231 {
232 ch = dtStr[i];
233 k = k * 10 + ch - '0';
234 j ++;
235 if (ch < '0' || ch > '9') break;
236 i ++;
237 }
238 dt.year = (int16_t)k;
239 if (i >= strLength || j < 4) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700240
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700241 j = 0;
242 k = 0;
243 while (i < strLength && j < 2)
244 {
245 ch = dtStr[i];
246 k = k * 10 + ch - '0';
247 j ++;
248 if (ch < '0' || ch > '9') break;
249 i ++;
250 }
251 dt.month = (uint8_t)k;
252 if (i >= strLength || j < 2) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700254 j = 0;
255 k = 0;
256 while (i < strLength && j < 2)
257 {
258 ch = dtStr[i];
259 k = k * 10 + ch - '0';
260 j ++;
261 if (ch < '0' || ch > '9') break;
262 i ++;
263 }
264 dt.day = (uint8_t)k;
265 if (i >= strLength || j < 2) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700266
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700267 j = 0;
268 k = 0;
269 while (i < strLength && j < 2)
270 {
271 ch = dtStr[i];
272 k = k * 10 + ch - '0';
273 j ++;
274 if (ch < '0' || ch > '9') break;
275 i ++;
276 }
277 dt.hour = (uint8_t)k;
278 if (i >= strLength || j < 2) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700280 j = 0;
281 k = 0;
282 while (i < strLength && j < 2)
283 {
284 ch = dtStr[i];
285 k = k * 10 + ch - '0';
286 j ++;
287 if (ch < '0' || ch > '9') break;
288 i ++;
289 }
290 dt.minute = (uint8_t)k;
291 if (i >= strLength || j < 2) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700293 j = 0;
294 k = 0;
295 while (i < strLength && j < 2)
296 {
297 ch = dtStr[i];
298 k = k * 10 + ch - '0';
299 j ++;
300 if (ch < '0' || ch > '9') break;
301 i ++;
302 }
303 dt.second = (uint8_t)k;
304 if (i >= strLength || j < 2) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700305
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700306 ch = dtStr[i ++];
307 if (ch != '-' && ch != '+') return *this;
308 if (ch == '-')
309 dt.tzHour = -1;
310 else
311 dt.tzHour = 1;
312 j = 0;
313 k = 0;
314 while (i < strLength && j < 2)
315 {
316 ch = dtStr[i];
317 k = k * 10 + ch - '0';
318 j ++;
319 if (ch < '0' || ch > '9') break;
320 i ++;
321 }
322 dt.tzHour *= (FX_CHAR)k;
323 if (i >= strLength || j < 2) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700324
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700325 ch = dtStr[i ++];
326 if (ch != '\'') return *this;
327 j = 0;
328 k = 0;
329 while (i < strLength && j < 2)
330 {
331 ch = dtStr[i];
332 k = k * 10 + ch - '0';
333 j ++;
334 if (ch < '0' || ch > '9') break;
335 i ++;
336 }
337 dt.tzMinute = (uint8_t)k;
338 if (i >= strLength || j < 2) return *this;
339 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700340
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700341 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700342}
343
344CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString()
345{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700346 CFX_ByteString str1;
347 str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
348 if (dt.tzHour < 0)
349 str1 += "-";
350 else
351 str1 += "+";
352 CFX_ByteString str2;
353 str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute);
354 return str1 + str2;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355}
356
357CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString()
358{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700359 CFX_ByteString dtStr;
360 char tempStr[32];
361 memset(tempStr, 0, sizeof(tempStr));
362 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
Tom Sepez2080b3e2015-03-11 14:25:05 -0700363 dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700364 dtStr = CFX_ByteString(tempStr);
365 if (dt.tzHour < 0)
366 dtStr += CFX_ByteString("-");
367 else
368 dtStr += CFX_ByteString("+");
369 memset(tempStr, 0, sizeof(tempStr));
370 FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute);
371 dtStr += CFX_ByteString(tempStr);
372 return dtStr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373}
374
375void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st)
376{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700377 CPDFSDK_DateTime dt = *this;
378 time_t t = (time_t)dt;
379 struct tm* pTime = localtime(&t);
380 if(pTime){
381 st.wYear = (FX_WORD)pTime->tm_year + 1900;
382 st.wMonth = (FX_WORD)pTime->tm_mon + 1;
383 st.wDay = (FX_WORD)pTime->tm_mday;
384 st.wDayOfWeek = (FX_WORD)pTime->tm_wday;
385 st.wHour = (FX_WORD)pTime->tm_hour;
386 st.wMinute = (FX_WORD)pTime->tm_min;
387 st.wSecond = (FX_WORD)pTime->tm_sec;
388 st.wMilliseconds = 0;
389 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390}
391
392CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT()
393{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700394 CPDFSDK_DateTime dt = *this;
395 dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute));
396 dt.dt.tzHour = 0;
397 dt.dt.tzMinute = 0;
398 return dt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700399}
400
401CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days)
402{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700403 if (days == 0) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700404
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700405 int16_t y = dt.year, yy;
406 uint8_t m = dt.month;
407 uint8_t d = dt.day;
408 int mdays, ydays, ldays;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700409
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700410 ldays = days;
411 if (ldays > 0)
412 {
413 yy = y;
414 if (((FX_WORD)m * 100 + d) > 300) yy ++;
415 ydays = _gAfxGetYearDays(yy);
416 while (ldays >= ydays)
417 {
418 y ++;
419 ldays -= ydays;
420 yy ++;
421 mdays = _gAfxGetMonthDays(y, m);
422 if (d > mdays)
423 {
424 m ++;
425 d -= mdays;
426 }
427 ydays = _gAfxGetYearDays(yy);
428 }
429 mdays = _gAfxGetMonthDays(y, m) - d + 1;
430 while (ldays >= mdays)
431 {
432 ldays -= mdays;
433 m ++;
434 d = 1;
435 mdays = _gAfxGetMonthDays(y, m);
436 }
437 d += ldays;
438 }
439 else
440 {
441 ldays *= -1;
442 yy = y;
443 if (((FX_WORD)m * 100 + d) < 300) yy --;
444 ydays = _gAfxGetYearDays(yy);
445 while (ldays >= ydays)
446 {
447 y --;
448 ldays -= ydays;
449 yy --;
450 mdays = _gAfxGetMonthDays(y, m);
451 if (d > mdays)
452 {
453 m ++;
454 d -= mdays;
455 }
456 ydays = _gAfxGetYearDays(yy);
457 }
458 while (ldays >= d)
459 {
460 ldays -= d;
461 m --;
462 mdays = _gAfxGetMonthDays(y, m);
463 d = mdays;
464 }
465 d -= ldays;
466 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700467
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700468 dt.year = y;
469 dt.month = m;
470 dt.day = d;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700471
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700472 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473}
474
475CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds)
476{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700477 if (seconds == 0) return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700479 int n;
480 int days;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700481
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700482 n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds;
483 if (n < 0)
484 {
485 days = (n - 86399) / 86400;
486 n -= days * 86400;
487 }
488 else
489 {
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) AddDays(days);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700500 return *this;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700501}
502
503
504//---------------------------------------------------------------------------
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700505// CPDFSDK_Annot
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700506//---------------------------------------------------------------------------
Bo Xufdc00a72014-10-28 23:03:33 -0700507CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) :
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508m_pPageView(pPageView),
509m_bSelected(FALSE),
510m_nTabOrder(-1)
511{
512}
513
Bo Xufdc00a72014-10-28 23:03:33 -0700514
515//CPDFSDK_BAAnnot
516CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) :
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700517 CPDFSDK_Annot(pPageView),
518 m_pAnnot(pAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700519{
Bo Xufdc00a72014-10-28 23:03:33 -0700520}
521
522CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700524 m_pAnnot = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700525}
526
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700527CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700528{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700529 return m_pAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700530}
531
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700532FX_BOOL CPDFSDK_Annot::IsSelected()
533{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700534 return m_bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700535}
536
537void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected)
538{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700539 m_bSelected = bSelected;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540}
541
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700542// Tab Order
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543int CPDFSDK_Annot::GetTabOrder()
544{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700545 return m_nTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700546}
547
548void CPDFSDK_Annot::SetTabOrder(int iTabOrder)
549{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700550 m_nTabOrder = iTabOrder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700551}
552
Bo Xufdc00a72014-10-28 23:03:33 -0700553CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700555 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700556
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700557 return m_pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700558}
559
Bo Xufdc00a72014-10-28 23:03:33 -0700560void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700561{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700562 ASSERT(rect.right - rect.left >= GetMinWidth());
563 ASSERT(rect.top - rect.bottom >= GetMinHeight());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700564
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700565 m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700566}
567
Bo Xufdc00a72014-10-28 23:03:33 -0700568CPDF_Rect CPDFSDK_BAAnnot::GetRect() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700570 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700571
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700572 CPDF_Rect rect;
573 m_pAnnot->GetRect(rect);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700574
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700575 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576}
577
Bo Xufdc00a72014-10-28 23:03:33 -0700578CFX_ByteString CPDFSDK_BAAnnot::GetType() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700579{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700580 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700581
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700582 return m_pAnnot->GetSubType();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
Bo Xufdc00a72014-10-28 23:03:33 -0700585CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700586{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700587 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700588}
589
Bo Xufdc00a72014-10-28 23:03:33 -0700590void CPDFSDK_BAAnnot::ResetAppearance()
591{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700592 ASSERT(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -0700593}
594
595void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700596 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700597{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700598 ASSERT(m_pPageView != NULL);
599 ASSERT(m_pAnnot != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700600
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700601 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, mode, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602}
603
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700604FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700605{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700606 return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700609FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700610{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700611 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
612 if (pAP == NULL) return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700613
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700614 // Choose the right sub-ap
615 const FX_CHAR* ap_entry = "N";
616 if (mode == CPDF_Annot::Down)
617 ap_entry = "D";
618 else if (mode == CPDF_Annot::Rollover)
619 ap_entry = "R";
620 if (!pAP->KeyExist(ap_entry))
621 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700622
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700623 // Get the AP stream or subdirectory
624 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
625 if (psub == NULL) return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700626
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700627 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628}
629
Bo Xufdc00a72014-10-28 23:03:33 -0700630void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700631 const CPDF_RenderOptions* pOptions)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700633 ASSERT(m_pAnnot != NULL);
634 m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Bo Xufdc00a72014-10-28 23:03:33 -0700637void CPDFSDK_BAAnnot::ClearCachedAP()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700638{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700639 ASSERT(m_pAnnot != NULL);
640 m_pAnnot->ClearCachedAP();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700641}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700642
Bo Xufdc00a72014-10-28 23:03:33 -0700643void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700645 if (sContents.IsEmpty())
646 m_pAnnot->GetAnnotDict()->RemoveAt("Contents");
647 else
648 m_pAnnot->GetAnnotDict()->SetAtString("Contents", PDF_EncodeText(sContents));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700649}
650
Bo Xufdc00a72014-10-28 23:03:33 -0700651CFX_WideString CPDFSDK_BAAnnot::GetContents() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700652{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700653 return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654}
655
Bo Xufdc00a72014-10-28 23:03:33 -0700656void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700657{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700658 if (sName.IsEmpty())
659 m_pAnnot->GetAnnotDict()->RemoveAt("NM");
660 else
661 m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700662}
663
Bo Xufdc00a72014-10-28 23:03:33 -0700664CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700665{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700666 return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
Bo Xufdc00a72014-10-28 23:03:33 -0700669void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700671 CPDFSDK_DateTime dt(st);
672 CFX_ByteString str = dt.ToPDFDateTimeString();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700673
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700674 if (str.IsEmpty())
675 m_pAnnot->GetAnnotDict()->RemoveAt("M");
676 else
677 m_pAnnot->GetAnnotDict()->SetAtString("M", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700678}
679
Bo Xufdc00a72014-10-28 23:03:33 -0700680FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700682 FX_SYSTEMTIME systime;
683 CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700684
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700685 CPDFSDK_DateTime dt(str);
686 dt.ToSystemTime(systime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700687
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700688 return systime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
Bo Xufdc00a72014-10-28 23:03:33 -0700691void CPDFSDK_BAAnnot::SetFlags(int nFlags)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700693 m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
Bo Xufdc00a72014-10-28 23:03:33 -0700696int CPDFSDK_BAAnnot::GetFlags() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700698 return m_pAnnot->GetAnnotDict()->GetInteger("F");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700699}
700
Bo Xufdc00a72014-10-28 23:03:33 -0700701void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700702{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700703 if (str.IsEmpty())
704 m_pAnnot->GetAnnotDict()->RemoveAt("AS");
705 else
706 m_pAnnot->GetAnnotDict()->SetAtString("AS", str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
708
Bo Xufdc00a72014-10-28 23:03:33 -0700709CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700710{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700711 return m_pAnnot->GetAnnotDict()->GetString("AS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712}
713
Bo Xufdc00a72014-10-28 23:03:33 -0700714void CPDFSDK_BAAnnot::SetStructParent(int key)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700715{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700716 m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700717}
718
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700719int CPDFSDK_BAAnnot::GetStructParent() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700721 return m_pAnnot->GetAnnotDict()->GetInteger("StructParent");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700722}
723
724//border
Bo Xufdc00a72014-10-28 23:03:33 -0700725void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700727 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700729 if (pBorder)
730 {
731 pBorder->SetAt(2, FX_NEW CPDF_Number(nWidth));
732 }
733 else
734 {
735 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700737 if (!pBSDict)
738 {
739 pBSDict = FX_NEW CPDF_Dictionary;
740 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
741 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700743 pBSDict->SetAtInteger("W", nWidth);
744 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745}
746
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700747int CPDFSDK_BAAnnot::GetBorderWidth() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700749 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) {
750 return pBorder->GetInteger(2);
751 }
752 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) {
753 return pBSDict->GetInteger("W", 1);
754 }
755 return 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756}
757
Bo Xufdc00a72014-10-28 23:03:33 -0700758void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700760 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
761 if (!pBSDict)
762 {
763 pBSDict = new CPDF_Dictionary;
764 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
765 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700767 switch (nStyle)
768 {
769 case BBS_SOLID:
770 pBSDict->SetAtName("S", "S");
771 break;
772 case BBS_DASH:
773 pBSDict->SetAtName("S", "D");
774 break;
775 case BBS_BEVELED:
776 pBSDict->SetAtName("S", "B");
777 break;
778 case BBS_INSET:
779 pBSDict->SetAtName("S", "I");
780 break;
781 case BBS_UNDERLINE:
782 pBSDict->SetAtName("S", "U");
783 break;
784 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700785}
786
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700787int CPDFSDK_BAAnnot::GetBorderStyle() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700789 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
790 if (pBSDict)
791 {
792 CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S");
793 if (sBorderStyle == "S") return BBS_SOLID;
794 if (sBorderStyle == "D") return BBS_DASH;
795 if (sBorderStyle == "B") return BBS_BEVELED;
796 if (sBorderStyle == "I") return BBS_INSET;
797 if (sBorderStyle == "U") return BBS_UNDERLINE;
798 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700799
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700800 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
801 if (pBorder)
802 {
803 if (pBorder->GetCount() >= 4)
804 {
805 CPDF_Array *pDP = pBorder->GetArray(3);
806 if (pDP && pDP->GetCount() > 0)
807 return BBS_DASH;
808 }
809 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700810
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700811 return BBS_SOLID;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700812}
813
Bo Xufdc00a72014-10-28 23:03:33 -0700814void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700816 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
817 if (!pBSDict)
818 {
819 pBSDict = new CPDF_Dictionary;
820 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
821 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700823 CPDF_Array* pArray = FX_NEW CPDF_Array;
824 for (int i=0,sz=array.GetSize(); i<sz; i++)
825 {
826 pArray->AddInteger(array[i]);
827 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700828
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700829 pBSDict->SetAt("D", pArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700830}
831
Bo Xufdc00a72014-10-28 23:03:33 -0700832void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700833{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700834 CPDF_Array* pDash = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700835
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700836 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border");
837 if (pBorder)
838 {
839 pDash = pBorder->GetArray(3);
840 }
841 else
842 {
843 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
844 if (pBSDict)
845 {
846 pDash = pBSDict->GetArray("D");
847 }
848 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700849
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700850 if (pDash)
851 {
852 for (int i=0,sz=pDash->GetCount(); i<sz; i++)
853 {
854 array.Add(pDash->GetInteger(i));
855 }
856 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700857}
858
Bo Xufdc00a72014-10-28 23:03:33 -0700859void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700860{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700861 CPDF_Array* pArray = new CPDF_Array;
862 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
863 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
864 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
865 m_pAnnot->GetAnnotDict()->SetAt("C", pArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866}
867
Bo Xufdc00a72014-10-28 23:03:33 -0700868void CPDFSDK_BAAnnot::RemoveColor()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700869{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700870 m_pAnnot->GetAnnotDict()->RemoveAt("C");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871}
872
Bo Xufdc00a72014-10-28 23:03:33 -0700873FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700874{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700875 if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C"))
876 {
877 int nCount = pEntry->GetCount();
878 if (nCount == 1)
879 {
880 FX_FLOAT g = pEntry->GetNumber(0) * 255;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700882 color = FXSYS_RGB((int)g, (int)g, (int)g);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700883
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700884 return TRUE;
885 }
886 else if (nCount == 3)
887 {
888 FX_FLOAT r = pEntry->GetNumber(0) * 255;
889 FX_FLOAT g = pEntry->GetNumber(1) * 255;
890 FX_FLOAT b = pEntry->GetNumber(2) * 255;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700892 color = FXSYS_RGB((int)r, (int)g, (int)b);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700893
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700894 return TRUE;
895 }
896 else if (nCount == 4)
897 {
898 FX_FLOAT c = pEntry->GetNumber(0);
899 FX_FLOAT m = pEntry->GetNumber(1);
900 FX_FLOAT y = pEntry->GetNumber(2);
901 FX_FLOAT k = pEntry->GetNumber(3);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700902
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700903 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
904 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
905 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700907 color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700908
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700909 return TRUE;
910 }
911 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700912
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700913 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700914}
915
916
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700917void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox,
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700918 const CPDF_Matrix& matrix, const CFX_ByteString& sContents,
919 const CFX_ByteString& sAPState)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700920{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700921 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700922
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700923 if (!pAPDict)
924 {
925 pAPDict = new CPDF_Dictionary;
926 m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
927 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700928
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700929 CPDF_Stream* pStream = NULL;
930 CPDF_Dictionary* pParentDict = NULL;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700931
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700932 if (sAPState.IsEmpty())
933 {
934 pParentDict = pAPDict;
935 pStream = pAPDict->GetStream(sAPType);
936 }
937 else
938 {
939 CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
940 if (!pAPTypeDict)
941 {
942 pAPTypeDict = FX_NEW CPDF_Dictionary;
943 pAPDict->SetAt(sAPType, pAPTypeDict);
944 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700945
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700946 pParentDict = pAPTypeDict;
947 pStream = pAPTypeDict->GetStream(sAPState);
948 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700949
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700950 if (!pStream)
951 {
952 ASSERT(m_pPageView != NULL);
953 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
954 ASSERT(pDoc != NULL);
Tom Sepezbfa9a822015-06-09 13:24:12 -0700955
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700956 pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
957 int32_t objnum = pDoc->AddIndirectObject(pStream);
958 //pAPDict->SetAtReference(sAPType, pDoc, objnum);
959 ASSERT(pParentDict != NULL);
960 pParentDict->SetAtReference(sAPType, pDoc, objnum);
961 }
Tom Sepezbfa9a822015-06-09 13:24:12 -0700962
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700963 CPDF_Dictionary * pStreamDict = pStream->GetDict();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700964
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700965 if (!pStreamDict)
966 {
967 pStreamDict = FX_NEW CPDF_Dictionary;
968 pStreamDict->SetAtName("Type", "XObject");
969 pStreamDict->SetAtName("Subtype", "Form");
970 pStreamDict->SetAtInteger("FormType", 1);
971 pStream->InitStream(NULL,0,pStreamDict);
972 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700973
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700974 if (pStreamDict)
975 {
976 pStreamDict->SetAtMatrix("Matrix",matrix);
977 pStreamDict->SetAtRect("BBox", rcBBox);
978 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700979
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700980 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700981}
982
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700983#define BA_ANNOT_MINWIDTH 1
984#define BA_ANNOT_MINHEIGHT 1
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
986FX_FLOAT CPDFSDK_Annot::GetMinWidth() const
987{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700988 return BA_ANNOT_MINWIDTH;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700989}
990
991FX_FLOAT CPDFSDK_Annot::GetMinHeight() const
992{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700993 return BA_ANNOT_MINHEIGHT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700994}
995
Bo Xufdc00a72014-10-28 23:03:33 -0700996FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700997{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700998 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700999}
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001000FX_BOOL CPDFSDK_BAAnnot::IsVisible() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001001{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001002 int nFlags = GetFlags();
1003 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || (nFlags & ANNOTFLAG_NOVIEW));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001004}
1005
Bo Xufdc00a72014-10-28 23:03:33 -07001006CPDF_Action CPDFSDK_BAAnnot::GetAction() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001007{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001008 return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001009}
1010
Bo Xufdc00a72014-10-28 23:03:33 -07001011void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001012{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001013 ASSERT(action);
1014 if ((CPDF_Action&)action != CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A")))
1015 {
1016 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
1017 CPDF_Dictionary* pDict = action.GetDict();
1018 if (pDict && pDict->GetObjNum() == 0) {
1019 pDoc->AddIndirectObject(pDict);
1020 }
1021 m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
1022 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001023}
1024
Bo Xufdc00a72014-10-28 23:03:33 -07001025void CPDFSDK_BAAnnot::RemoveAction()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001026{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001027 m_pAnnot->GetAnnotDict()->RemoveAt("A");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001028}
1029
Bo Xufdc00a72014-10-28 23:03:33 -07001030CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001031{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001032 return m_pAnnot->GetAnnotDict()->GetDict("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001033}
1034
Bo Xufdc00a72014-10-28 23:03:33 -07001035void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001036{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001037 ASSERT(aa != NULL);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001038
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001039 if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA"))
1040 m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001041}
1042
Bo Xufdc00a72014-10-28 23:03:33 -07001043void CPDFSDK_BAAnnot::RemoveAAction()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001044{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001045 m_pAnnot->GetAnnotDict()->RemoveAt("AA");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001046}
1047
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001048CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001049{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001050 CPDF_AAction AAction = GetAAction();
Tom Sepez7b5bc262015-03-05 16:44:22 -08001051
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001052 if (AAction.ActionExist(eAAT))
1053 return AAction.GetAction(eAAT);
Tom Sepez7b5bc262015-03-05 16:44:22 -08001054
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001055 if (eAAT == CPDF_AAction::ButtonUp)
1056 return GetAction();
Tom Sepez7b5bc262015-03-05 16:44:22 -08001057
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001058 return CPDF_Action();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001059}
1060
Bo Xufdc00a72014-10-28 23:03:33 -07001061FX_BOOL CPDFSDK_BAAnnot::IsXFAField()
1062{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001063 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -07001064}
1065
1066void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001067{
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001068
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001069 m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
1070 m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001071
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001072 return ;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001073}
1074
1075CPDF_Page* CPDFSDK_Annot::GetPDFPage()
1076{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001077 if(m_pPageView)
1078 return m_pPageView->GetPDFPage();
1079 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001080}
1081
Bo Xufdc00a72014-10-28 23:03:33 -07001082CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage()
1083{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001084 if (m_pPageView)
1085 return m_pPageView->GetPDFXFAPage();
1086 return NULL;
Bo Xufdc00a72014-10-28 23:03:33 -07001087}
1088