John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // 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 Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "../include/fsdk_define.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 8 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | #include "../include/fsdk_mgr.h" |
| 10 | #include "../include/fsdk_baseannot.h" |
| 11 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 12 | int _gAfxGetTimeZoneInSeconds(FX_CHAR tzhour, uint8_t tzminute) { |
| 13 | return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | } |
| 15 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 16 | FX_BOOL _gAfxIsLeapYear(int16_t year) { |
| 17 | return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 20 | FX_WORD _gAfxGetYearDays(int16_t year) { |
| 21 | return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) { |
| 25 | uint8_t mDays; |
| 26 | switch (month) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 27 | case 1: |
| 28 | case 3: |
| 29 | case 5: |
| 30 | case 7: |
| 31 | case 8: |
| 32 | case 10: |
| 33 | case 12: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | mDays = 31; |
| 35 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 37 | case 4: |
| 38 | case 6: |
| 39 | case 9: |
| 40 | case 11: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | mDays = 30; |
| 42 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 43 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 44 | case 2: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | if (_gAfxIsLeapYear(year) == TRUE) |
| 46 | mDays = 29; |
| 47 | else |
| 48 | mDays = 28; |
| 49 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 51 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | mDays = 0; |
| 53 | break; |
| 54 | } |
| 55 | |
| 56 | return mDays; |
| 57 | } |
| 58 | |
| 59 | CPDFSDK_DateTime::CPDFSDK_DateTime() { |
| 60 | ResetDateTime(); |
| 61 | } |
| 62 | |
| 63 | CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) { |
| 64 | ResetDateTime(); |
| 65 | |
| 66 | FromPDFDateTimeString(dtStr); |
| 67 | } |
| 68 | |
| 69 | CPDFSDK_DateTime::CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime) { |
| 70 | operator=(datetime); |
| 71 | } |
| 72 | |
| 73 | CPDFSDK_DateTime::CPDFSDK_DateTime(const FX_SYSTEMTIME& st) { |
| 74 | operator=(st); |
| 75 | } |
| 76 | |
| 77 | void CPDFSDK_DateTime::ResetDateTime() { |
| 78 | tzset(); |
| 79 | |
| 80 | time_t curTime; |
| 81 | time(&curTime); |
| 82 | struct tm* newtime; |
| 83 | // newtime = gmtime(&curTime); |
| 84 | newtime = localtime(&curTime); |
| 85 | |
| 86 | dt.year = newtime->tm_year + 1900; |
| 87 | dt.month = newtime->tm_mon + 1; |
| 88 | dt.day = newtime->tm_mday; |
| 89 | dt.hour = newtime->tm_hour; |
| 90 | dt.minute = newtime->tm_min; |
| 91 | dt.second = newtime->tm_sec; |
| 92 | // dt.tzHour = _timezone / 3600 * -1; |
| 93 | // dt.tzMinute = (abs(_timezone) % 3600) / 60; |
| 94 | } |
| 95 | |
| 96 | CPDFSDK_DateTime& CPDFSDK_DateTime::operator=( |
| 97 | const CPDFSDK_DateTime& datetime) { |
| 98 | FXSYS_memcpy(&dt, &datetime.dt, sizeof(FX_DATETIME)); |
| 99 | return *this; |
| 100 | } |
| 101 | |
| 102 | CPDFSDK_DateTime& CPDFSDK_DateTime::operator=(const FX_SYSTEMTIME& st) { |
| 103 | tzset(); |
| 104 | |
| 105 | dt.year = (int16_t)st.wYear; |
| 106 | dt.month = (uint8_t)st.wMonth; |
| 107 | dt.day = (uint8_t)st.wDay; |
| 108 | dt.hour = (uint8_t)st.wHour; |
| 109 | dt.minute = (uint8_t)st.wMinute; |
| 110 | dt.second = (uint8_t)st.wSecond; |
| 111 | // dt.tzHour = _timezone / 3600 * -1; |
| 112 | // dt.tzMinute = (abs(_timezone) % 3600) / 60; |
| 113 | return *this; |
| 114 | } |
| 115 | |
| 116 | FX_BOOL CPDFSDK_DateTime::operator==(CPDFSDK_DateTime& datetime) { |
| 117 | return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) == 0); |
| 118 | } |
| 119 | |
| 120 | FX_BOOL CPDFSDK_DateTime::operator!=(CPDFSDK_DateTime& datetime) { |
| 121 | return (FXSYS_memcmp(&dt, &datetime.dt, sizeof(FX_DATETIME)) != 0); |
| 122 | } |
| 123 | |
| 124 | FX_BOOL CPDFSDK_DateTime::operator>(CPDFSDK_DateTime& datetime) { |
| 125 | CPDFSDK_DateTime dt1 = ToGMT(); |
| 126 | CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
| 127 | int d1 = |
| 128 | (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
| 129 | int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
| 130 | (int)dt1.dt.second; |
| 131 | int d3 = |
| 132 | (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
| 133 | int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
| 134 | (int)dt2.dt.second; |
| 135 | |
| 136 | if (d1 > d3) |
| 137 | return TRUE; |
| 138 | if (d2 > d4) |
| 139 | return TRUE; |
| 140 | return FALSE; |
| 141 | } |
| 142 | |
| 143 | FX_BOOL CPDFSDK_DateTime::operator>=(CPDFSDK_DateTime& datetime) { |
| 144 | CPDFSDK_DateTime dt1 = ToGMT(); |
| 145 | CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
| 146 | int d1 = |
| 147 | (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
| 148 | int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
| 149 | (int)dt1.dt.second; |
| 150 | int d3 = |
| 151 | (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
| 152 | int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
| 153 | (int)dt2.dt.second; |
| 154 | |
| 155 | if (d1 >= d3) |
| 156 | return TRUE; |
| 157 | if (d2 >= d4) |
| 158 | return TRUE; |
| 159 | return FALSE; |
| 160 | } |
| 161 | |
| 162 | FX_BOOL CPDFSDK_DateTime::operator<(CPDFSDK_DateTime& datetime) { |
| 163 | CPDFSDK_DateTime dt1 = ToGMT(); |
| 164 | CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
| 165 | int d1 = |
| 166 | (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
| 167 | int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
| 168 | (int)dt1.dt.second; |
| 169 | int d3 = |
| 170 | (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
| 171 | int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
| 172 | (int)dt2.dt.second; |
| 173 | |
| 174 | if (d1 < d3) |
| 175 | return TRUE; |
| 176 | if (d2 < d4) |
| 177 | return TRUE; |
| 178 | return FALSE; |
| 179 | } |
| 180 | |
| 181 | FX_BOOL CPDFSDK_DateTime::operator<=(CPDFSDK_DateTime& datetime) { |
| 182 | CPDFSDK_DateTime dt1 = ToGMT(); |
| 183 | CPDFSDK_DateTime dt2 = datetime.ToGMT(); |
| 184 | int d1 = |
| 185 | (((int)dt1.dt.year) << 16) | (((int)dt1.dt.month) << 8) | (int)dt1.dt.day; |
| 186 | int d2 = (((int)dt1.dt.hour) << 16) | (((int)dt1.dt.minute) << 8) | |
| 187 | (int)dt1.dt.second; |
| 188 | int d3 = |
| 189 | (((int)dt2.dt.year) << 16) | (((int)dt2.dt.month) << 8) | (int)dt2.dt.day; |
| 190 | int d4 = (((int)dt2.dt.hour) << 16) | (((int)dt2.dt.minute) << 8) | |
| 191 | (int)dt2.dt.second; |
| 192 | |
| 193 | if (d1 <= d3) |
| 194 | return TRUE; |
| 195 | if (d2 <= d4) |
| 196 | return TRUE; |
| 197 | return FALSE; |
| 198 | } |
| 199 | |
| 200 | CPDFSDK_DateTime::operator time_t() { |
| 201 | struct tm newtime; |
| 202 | |
| 203 | newtime.tm_year = dt.year - 1900; |
| 204 | newtime.tm_mon = dt.month - 1; |
| 205 | newtime.tm_mday = dt.day; |
| 206 | newtime.tm_hour = dt.hour; |
| 207 | newtime.tm_min = dt.minute; |
| 208 | newtime.tm_sec = dt.second; |
| 209 | |
| 210 | return mktime(&newtime); |
| 211 | } |
| 212 | |
| 213 | CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( |
| 214 | const CFX_ByteString& dtStr) { |
| 215 | int strLength = dtStr.GetLength(); |
| 216 | if (strLength > 0) { |
| 217 | int i = 0; |
| 218 | int j, k; |
| 219 | FX_CHAR ch; |
| 220 | while (i < strLength) { |
| 221 | ch = dtStr[i]; |
| 222 | if (ch >= '0' && ch <= '9') |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 223 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 224 | i++; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 225 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | if (i >= strLength) |
| 227 | return *this; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 228 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | j = 0; |
| 230 | k = 0; |
| 231 | while (i < strLength && j < 4) { |
| 232 | ch = dtStr[i]; |
| 233 | k = k * 10 + ch - '0'; |
| 234 | j++; |
| 235 | if (ch < '0' || ch > '9') |
| 236 | break; |
| 237 | i++; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 238 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | dt.year = (int16_t)k; |
| 240 | if (i >= strLength || j < 4) |
| 241 | return *this; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 242 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | j = 0; |
| 244 | k = 0; |
| 245 | while (i < strLength && j < 2) { |
| 246 | ch = dtStr[i]; |
| 247 | k = k * 10 + ch - '0'; |
| 248 | j++; |
| 249 | if (ch < '0' || ch > '9') |
| 250 | break; |
| 251 | i++; |
| 252 | } |
| 253 | dt.month = (uint8_t)k; |
| 254 | if (i >= strLength || j < 2) |
| 255 | return *this; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 256 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | j = 0; |
| 258 | k = 0; |
| 259 | while (i < strLength && j < 2) { |
| 260 | ch = dtStr[i]; |
| 261 | k = k * 10 + ch - '0'; |
| 262 | j++; |
| 263 | if (ch < '0' || ch > '9') |
| 264 | break; |
| 265 | i++; |
| 266 | } |
| 267 | dt.day = (uint8_t)k; |
| 268 | if (i >= strLength || j < 2) |
| 269 | return *this; |
| 270 | |
| 271 | j = 0; |
| 272 | k = 0; |
| 273 | while (i < strLength && j < 2) { |
| 274 | ch = dtStr[i]; |
| 275 | k = k * 10 + ch - '0'; |
| 276 | j++; |
| 277 | if (ch < '0' || ch > '9') |
| 278 | break; |
| 279 | i++; |
| 280 | } |
| 281 | dt.hour = (uint8_t)k; |
| 282 | if (i >= strLength || j < 2) |
| 283 | return *this; |
| 284 | |
| 285 | j = 0; |
| 286 | k = 0; |
| 287 | while (i < strLength && j < 2) { |
| 288 | ch = dtStr[i]; |
| 289 | k = k * 10 + ch - '0'; |
| 290 | j++; |
| 291 | if (ch < '0' || ch > '9') |
| 292 | break; |
| 293 | i++; |
| 294 | } |
| 295 | dt.minute = (uint8_t)k; |
| 296 | if (i >= strLength || j < 2) |
| 297 | return *this; |
| 298 | |
| 299 | j = 0; |
| 300 | k = 0; |
| 301 | while (i < strLength && j < 2) { |
| 302 | ch = dtStr[i]; |
| 303 | k = k * 10 + ch - '0'; |
| 304 | j++; |
| 305 | if (ch < '0' || ch > '9') |
| 306 | break; |
| 307 | i++; |
| 308 | } |
| 309 | dt.second = (uint8_t)k; |
| 310 | if (i >= strLength || j < 2) |
| 311 | return *this; |
| 312 | |
| 313 | ch = dtStr[i++]; |
| 314 | if (ch != '-' && ch != '+') |
| 315 | return *this; |
| 316 | if (ch == '-') |
| 317 | dt.tzHour = -1; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 318 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | dt.tzHour = 1; |
| 320 | j = 0; |
| 321 | k = 0; |
| 322 | while (i < strLength && j < 2) { |
| 323 | ch = dtStr[i]; |
| 324 | k = k * 10 + ch - '0'; |
| 325 | j++; |
| 326 | if (ch < '0' || ch > '9') |
| 327 | break; |
| 328 | i++; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 329 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | dt.tzHour *= (FX_CHAR)k; |
| 331 | if (i >= strLength || j < 2) |
| 332 | return *this; |
| 333 | |
| 334 | ch = dtStr[i++]; |
| 335 | if (ch != '\'') |
| 336 | return *this; |
| 337 | j = 0; |
| 338 | k = 0; |
| 339 | while (i < strLength && j < 2) { |
| 340 | ch = dtStr[i]; |
| 341 | k = k * 10 + ch - '0'; |
| 342 | j++; |
| 343 | if (ch < '0' || ch > '9') |
| 344 | break; |
| 345 | i++; |
| 346 | } |
| 347 | dt.tzMinute = (uint8_t)k; |
| 348 | if (i >= strLength || j < 2) |
| 349 | return *this; |
| 350 | } |
| 351 | |
| 352 | return *this; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 355 | CFX_ByteString CPDFSDK_DateTime::ToCommonDateTimeString() { |
| 356 | CFX_ByteString str1; |
| 357 | str1.Format("%04d-%02d-%02d %02d:%02d:%02d ", dt.year, dt.month, dt.day, |
| 358 | dt.hour, dt.minute, dt.second); |
| 359 | if (dt.tzHour < 0) |
| 360 | str1 += "-"; |
| 361 | else |
| 362 | str1 += "+"; |
| 363 | CFX_ByteString str2; |
| 364 | str2.Format("%02d:%02d", abs(dt.tzHour), dt.tzMinute); |
| 365 | return str1 + str2; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 368 | CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() { |
| 369 | CFX_ByteString dtStr; |
| 370 | char tempStr[32]; |
| 371 | memset(tempStr, 0, sizeof(tempStr)); |
| 372 | FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d", |
| 373 | dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second); |
| 374 | dtStr = CFX_ByteString(tempStr); |
| 375 | if (dt.tzHour < 0) |
| 376 | dtStr += CFX_ByteString("-"); |
| 377 | else |
| 378 | dtStr += CFX_ByteString("+"); |
| 379 | memset(tempStr, 0, sizeof(tempStr)); |
| 380 | FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour), |
| 381 | dt.tzMinute); |
| 382 | dtStr += CFX_ByteString(tempStr); |
| 383 | return dtStr; |
| 384 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 385 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 386 | void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) { |
| 387 | CPDFSDK_DateTime dt = *this; |
| 388 | time_t t = (time_t)dt; |
| 389 | struct tm* pTime = localtime(&t); |
| 390 | if (pTime) { |
| 391 | st.wYear = (FX_WORD)pTime->tm_year + 1900; |
| 392 | st.wMonth = (FX_WORD)pTime->tm_mon + 1; |
| 393 | st.wDay = (FX_WORD)pTime->tm_mday; |
| 394 | st.wDayOfWeek = (FX_WORD)pTime->tm_wday; |
| 395 | st.wHour = (FX_WORD)pTime->tm_hour; |
| 396 | st.wMinute = (FX_WORD)pTime->tm_min; |
| 397 | st.wSecond = (FX_WORD)pTime->tm_sec; |
| 398 | st.wMilliseconds = 0; |
| 399 | } |
| 400 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 401 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 402 | CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() { |
| 403 | CPDFSDK_DateTime dt = *this; |
| 404 | dt.AddSeconds(-_gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute)); |
| 405 | dt.dt.tzHour = 0; |
| 406 | dt.dt.tzMinute = 0; |
| 407 | return dt; |
| 408 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 409 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) { |
| 411 | if (days == 0) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 412 | return *this; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | |
| 414 | int16_t y = dt.year, yy; |
| 415 | uint8_t m = dt.month; |
| 416 | uint8_t d = dt.day; |
| 417 | int mdays, ydays, ldays; |
| 418 | |
| 419 | ldays = days; |
| 420 | if (ldays > 0) { |
| 421 | yy = y; |
| 422 | if (((FX_WORD)m * 100 + d) > 300) |
| 423 | yy++; |
| 424 | ydays = _gAfxGetYearDays(yy); |
| 425 | while (ldays >= ydays) { |
| 426 | y++; |
| 427 | ldays -= ydays; |
| 428 | yy++; |
| 429 | mdays = _gAfxGetMonthDays(y, m); |
| 430 | if (d > mdays) { |
| 431 | m++; |
| 432 | d -= mdays; |
| 433 | } |
| 434 | ydays = _gAfxGetYearDays(yy); |
| 435 | } |
| 436 | mdays = _gAfxGetMonthDays(y, m) - d + 1; |
| 437 | while (ldays >= mdays) { |
| 438 | ldays -= mdays; |
| 439 | m++; |
| 440 | d = 1; |
| 441 | mdays = _gAfxGetMonthDays(y, m); |
| 442 | } |
| 443 | d += ldays; |
| 444 | } else { |
| 445 | ldays *= -1; |
| 446 | yy = y; |
| 447 | if (((FX_WORD)m * 100 + d) < 300) |
| 448 | yy--; |
| 449 | ydays = _gAfxGetYearDays(yy); |
| 450 | while (ldays >= ydays) { |
| 451 | y--; |
| 452 | ldays -= ydays; |
| 453 | yy--; |
| 454 | mdays = _gAfxGetMonthDays(y, m); |
| 455 | if (d > mdays) { |
| 456 | m++; |
| 457 | d -= mdays; |
| 458 | } |
| 459 | ydays = _gAfxGetYearDays(yy); |
| 460 | } |
| 461 | while (ldays >= d) { |
| 462 | ldays -= d; |
| 463 | m--; |
| 464 | mdays = _gAfxGetMonthDays(y, m); |
| 465 | d = mdays; |
| 466 | } |
| 467 | d -= ldays; |
| 468 | } |
| 469 | |
| 470 | dt.year = y; |
| 471 | dt.month = m; |
| 472 | dt.day = d; |
| 473 | |
| 474 | return *this; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds) { |
| 478 | if (seconds == 0) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 479 | return *this; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 480 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | int n; |
| 482 | int days; |
| 483 | |
| 484 | n = dt.hour * 3600 + dt.minute * 60 + dt.second + seconds; |
| 485 | if (n < 0) { |
| 486 | days = (n - 86399) / 86400; |
| 487 | n -= days * 86400; |
| 488 | } else { |
| 489 | days = n / 86400; |
| 490 | n %= 86400; |
| 491 | } |
| 492 | dt.hour = (uint8_t)(n / 3600); |
| 493 | dt.hour %= 24; |
| 494 | n %= 3600; |
| 495 | dt.minute = (uint8_t)(n / 60); |
| 496 | dt.second = (uint8_t)(n % 60); |
| 497 | if (days != 0) |
| 498 | AddDays(days); |
| 499 | |
| 500 | return *this; |
| 501 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 502 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame^] | 504 | : m_pPageView(pPageView), m_bSelected(FALSE), m_nTabOrder(-1) { |
| 505 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 506 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 507 | CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, |
| 508 | CPDFSDK_PageView* pPageView) |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame^] | 509 | : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Tom Sepez | 3343d14 | 2015-11-02 09:54:54 -0800 | [diff] [blame] | 512 | CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | return m_pAnnot; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 516 | FX_BOOL CPDFSDK_Annot::IsSelected() { |
| 517 | return m_bSelected; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 520 | void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) { |
| 521 | m_bSelected = bSelected; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 524 | // Tab Order |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | int CPDFSDK_Annot::GetTabOrder() { |
| 526 | return m_nTabOrder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 529 | void CPDFSDK_Annot::SetTabOrder(int iTabOrder) { |
| 530 | m_nTabOrder = iTabOrder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 533 | CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const { |
| 534 | ASSERT(m_pAnnot != NULL); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 535 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | return m_pAnnot->GetAnnotDict(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect) { |
| 540 | ASSERT(rect.right - rect.left >= GetMinWidth()); |
| 541 | ASSERT(rect.top - rect.bottom >= GetMinHeight()); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 542 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 543 | m_pAnnot->GetAnnotDict()->SetAtRect("Rect", rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | CPDF_Rect CPDFSDK_BAAnnot::GetRect() const { |
| 547 | ASSERT(m_pAnnot != NULL); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 548 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 549 | CPDF_Rect rect; |
| 550 | m_pAnnot->GetRect(rect); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 551 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | return rect; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | CFX_ByteString CPDFSDK_BAAnnot::GetType() const { |
| 556 | ASSERT(m_pAnnot != NULL); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 557 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 558 | return m_pAnnot->GetSubType(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const { |
| 562 | return ""; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, |
| 566 | const CPDF_Matrix* pUser2Device, |
| 567 | CPDF_Annot::AppearanceMode mode, |
| 568 | const CPDF_RenderOptions* pOptions) { |
| 569 | ASSERT(m_pPageView != NULL); |
| 570 | ASSERT(m_pAnnot != NULL); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 571 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, |
| 573 | mode, pOptions); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 576 | FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid() { |
| 577 | return m_pAnnot->GetAnnotDict()->GetDict("AP") != NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 580 | FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) { |
| 581 | CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP"); |
| 582 | if (pAP == NULL) |
| 583 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 584 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 585 | // Choose the right sub-ap |
| 586 | const FX_CHAR* ap_entry = "N"; |
| 587 | if (mode == CPDF_Annot::Down) |
| 588 | ap_entry = "D"; |
| 589 | else if (mode == CPDF_Annot::Rollover) |
| 590 | ap_entry = "R"; |
| 591 | if (!pAP->KeyExist(ap_entry)) |
| 592 | ap_entry = "N"; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 593 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | // Get the AP stream or subdirectory |
| 595 | CPDF_Object* psub = pAP->GetElementValue(ap_entry); |
| 596 | if (psub == NULL) |
| 597 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 598 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 599 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 602 | void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice, |
| 603 | const CPDF_Matrix* pUser2Device, |
| 604 | const CPDF_RenderOptions* pOptions) { |
| 605 | ASSERT(m_pAnnot != NULL); |
| 606 | m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 609 | void CPDFSDK_BAAnnot::ClearCachedAP() { |
| 610 | ASSERT(m_pAnnot != NULL); |
| 611 | m_pAnnot->ClearCachedAP(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 612 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 613 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) { |
| 615 | if (sContents.IsEmpty()) |
| 616 | m_pAnnot->GetAnnotDict()->RemoveAt("Contents"); |
| 617 | else |
| 618 | m_pAnnot->GetAnnotDict()->SetAtString("Contents", |
| 619 | PDF_EncodeText(sContents)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | CFX_WideString CPDFSDK_BAAnnot::GetContents() const { |
| 623 | return m_pAnnot->GetAnnotDict()->GetUnicodeText("Contents"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) { |
| 627 | if (sName.IsEmpty()) |
| 628 | m_pAnnot->GetAnnotDict()->RemoveAt("NM"); |
| 629 | else |
| 630 | m_pAnnot->GetAnnotDict()->SetAtString("NM", PDF_EncodeText(sName)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const { |
| 634 | return m_pAnnot->GetAnnotDict()->GetUnicodeText("NM"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) { |
| 638 | CPDFSDK_DateTime dt(st); |
| 639 | CFX_ByteString str = dt.ToPDFDateTimeString(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 640 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 641 | if (str.IsEmpty()) |
| 642 | m_pAnnot->GetAnnotDict()->RemoveAt("M"); |
| 643 | else |
| 644 | m_pAnnot->GetAnnotDict()->SetAtString("M", str); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 647 | FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const { |
| 648 | FX_SYSTEMTIME systime; |
| 649 | CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetString("M"); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 650 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 651 | CPDFSDK_DateTime dt(str); |
| 652 | dt.ToSystemTime(systime); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 653 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | return systime; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 657 | void CPDFSDK_BAAnnot::SetFlags(int nFlags) { |
| 658 | m_pAnnot->GetAnnotDict()->SetAtInteger("F", nFlags); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 661 | int CPDFSDK_BAAnnot::GetFlags() const { |
| 662 | return m_pAnnot->GetAnnotDict()->GetInteger("F"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 665 | void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) { |
| 666 | if (str.IsEmpty()) |
| 667 | m_pAnnot->GetAnnotDict()->RemoveAt("AS"); |
| 668 | else |
| 669 | m_pAnnot->GetAnnotDict()->SetAtString("AS", str); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 672 | CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const { |
| 673 | return m_pAnnot->GetAnnotDict()->GetString("AS"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | void CPDFSDK_BAAnnot::SetStructParent(int key) { |
| 677 | m_pAnnot->GetAnnotDict()->SetAtInteger("StructParent", key); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 680 | int CPDFSDK_BAAnnot::GetStructParent() const { |
| 681 | return m_pAnnot->GetAnnotDict()->GetInteger("StructParent"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 684 | // border |
| 685 | void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) { |
| 686 | CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 687 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 688 | if (pBorder) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 689 | pBorder->SetAt(2, new CPDF_Number(nWidth)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | } else { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 691 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | |
| 693 | if (!pBSDict) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 694 | pBSDict = new CPDF_Dictionary; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 695 | m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 696 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 697 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | pBSDict->SetAtInteger("W", nWidth); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | int CPDFSDK_BAAnnot::GetBorderWidth() const { |
| 703 | if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border")) { |
| 704 | return pBorder->GetInteger(2); |
| 705 | } |
| 706 | if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS")) { |
| 707 | return pBSDict->GetInteger("W", 1); |
| 708 | } |
| 709 | return 1; |
| 710 | } |
| 711 | |
| 712 | void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) { |
| 713 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); |
| 714 | if (!pBSDict) { |
| 715 | pBSDict = new CPDF_Dictionary; |
| 716 | m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict); |
| 717 | } |
| 718 | |
| 719 | switch (nStyle) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 720 | case BBS_SOLID: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | pBSDict->SetAtName("S", "S"); |
| 722 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 723 | case BBS_DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 724 | pBSDict->SetAtName("S", "D"); |
| 725 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 726 | case BBS_BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 727 | pBSDict->SetAtName("S", "B"); |
| 728 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 729 | case BBS_INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 730 | pBSDict->SetAtName("S", "I"); |
| 731 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 732 | case BBS_UNDERLINE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 733 | pBSDict->SetAtName("S", "U"); |
| 734 | break; |
| 735 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 738 | int CPDFSDK_BAAnnot::GetBorderStyle() const { |
| 739 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); |
| 740 | if (pBSDict) { |
| 741 | CFX_ByteString sBorderStyle = pBSDict->GetString("S", "S"); |
| 742 | if (sBorderStyle == "S") |
| 743 | return BBS_SOLID; |
| 744 | if (sBorderStyle == "D") |
| 745 | return BBS_DASH; |
| 746 | if (sBorderStyle == "B") |
| 747 | return BBS_BEVELED; |
| 748 | if (sBorderStyle == "I") |
| 749 | return BBS_INSET; |
| 750 | if (sBorderStyle == "U") |
| 751 | return BBS_UNDERLINE; |
| 752 | } |
| 753 | |
| 754 | CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border"); |
| 755 | if (pBorder) { |
| 756 | if (pBorder->GetCount() >= 4) { |
| 757 | CPDF_Array* pDP = pBorder->GetArray(3); |
| 758 | if (pDP && pDP->GetCount() > 0) |
| 759 | return BBS_DASH; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | return BBS_SOLID; |
| 764 | } |
| 765 | |
| 766 | void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) { |
| 767 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); |
| 768 | if (!pBSDict) { |
| 769 | pBSDict = new CPDF_Dictionary; |
| 770 | m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict); |
| 771 | } |
| 772 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 773 | CPDF_Array* pArray = new CPDF_Array; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 774 | for (int i = 0, sz = array.GetSize(); i < sz; i++) { |
| 775 | pArray->AddInteger(array[i]); |
| 776 | } |
| 777 | |
| 778 | pBSDict->SetAt("D", pArray); |
| 779 | } |
| 780 | |
| 781 | void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const { |
| 782 | CPDF_Array* pDash = NULL; |
| 783 | |
| 784 | CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArray("Border"); |
| 785 | if (pBorder) { |
| 786 | pDash = pBorder->GetArray(3); |
| 787 | } else { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 788 | CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 789 | if (pBSDict) { |
| 790 | pDash = pBSDict->GetArray("D"); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | if (pDash) { |
| 795 | for (int i = 0, sz = pDash->GetCount(); i < sz; i++) { |
| 796 | array.Add(pDash->GetInteger(i)); |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) { |
| 802 | CPDF_Array* pArray = new CPDF_Array; |
| 803 | pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); |
| 804 | pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); |
| 805 | pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); |
| 806 | m_pAnnot->GetAnnotDict()->SetAt("C", pArray); |
| 807 | } |
| 808 | |
| 809 | void CPDFSDK_BAAnnot::RemoveColor() { |
| 810 | m_pAnnot->GetAnnotDict()->RemoveAt("C"); |
| 811 | } |
| 812 | |
| 813 | FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const { |
| 814 | if (CPDF_Array* pEntry = m_pAnnot->GetAnnotDict()->GetArray("C")) { |
| 815 | int nCount = pEntry->GetCount(); |
| 816 | if (nCount == 1) { |
| 817 | FX_FLOAT g = pEntry->GetNumber(0) * 255; |
| 818 | |
| 819 | color = FXSYS_RGB((int)g, (int)g, (int)g); |
| 820 | |
| 821 | return TRUE; |
| 822 | } else if (nCount == 3) { |
| 823 | FX_FLOAT r = pEntry->GetNumber(0) * 255; |
| 824 | FX_FLOAT g = pEntry->GetNumber(1) * 255; |
| 825 | FX_FLOAT b = pEntry->GetNumber(2) * 255; |
| 826 | |
| 827 | color = FXSYS_RGB((int)r, (int)g, (int)b); |
| 828 | |
| 829 | return TRUE; |
| 830 | } else if (nCount == 4) { |
| 831 | FX_FLOAT c = pEntry->GetNumber(0); |
| 832 | FX_FLOAT m = pEntry->GetNumber(1); |
| 833 | FX_FLOAT y = pEntry->GetNumber(2); |
| 834 | FX_FLOAT k = pEntry->GetNumber(3); |
| 835 | |
| 836 | FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); |
| 837 | FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); |
| 838 | FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); |
| 839 | |
| 840 | color = FXSYS_RGB((int)(r * 255), (int)(g * 255), (int)(b * 255)); |
| 841 | |
| 842 | return TRUE; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | return FALSE; |
| 847 | } |
| 848 | |
| 849 | void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, |
| 850 | const CPDF_Rect& rcBBox, |
| 851 | const CPDF_Matrix& matrix, |
| 852 | const CFX_ByteString& sContents, |
| 853 | const CFX_ByteString& sAPState) { |
| 854 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP"); |
| 855 | |
| 856 | if (!pAPDict) { |
| 857 | pAPDict = new CPDF_Dictionary; |
| 858 | m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict); |
| 859 | } |
| 860 | |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame^] | 861 | CPDF_Stream* pStream = nullptr; |
| 862 | CPDF_Dictionary* pParentDict = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 863 | |
| 864 | if (sAPState.IsEmpty()) { |
| 865 | pParentDict = pAPDict; |
| 866 | pStream = pAPDict->GetStream(sAPType); |
| 867 | } else { |
| 868 | CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType); |
| 869 | if (!pAPTypeDict) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 870 | pAPTypeDict = new CPDF_Dictionary; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 871 | pAPDict->SetAt(sAPType, pAPTypeDict); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 872 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 873 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 874 | pParentDict = pAPTypeDict; |
| 875 | pStream = pAPTypeDict->GetStream(sAPState); |
| 876 | } |
| 877 | |
| 878 | if (!pStream) { |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame^] | 879 | pStream = new CPDF_Stream(nullptr, 0, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 880 | |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame^] | 881 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 882 | int32_t objnum = pDoc->AddIndirectObject(pStream); |
| 883 | // pAPDict->SetAtReference(sAPType, pDoc, objnum); |
| 884 | ASSERT(pParentDict != NULL); |
| 885 | pParentDict->SetAtReference(sAPType, pDoc, objnum); |
| 886 | } |
| 887 | |
| 888 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 889 | if (!pStreamDict) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 890 | pStreamDict = new CPDF_Dictionary; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 891 | pStreamDict->SetAtName("Type", "XObject"); |
| 892 | pStreamDict->SetAtName("Subtype", "Form"); |
| 893 | pStreamDict->SetAtInteger("FormType", 1); |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame^] | 894 | pStream->InitStream(nullptr, 0, pStreamDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | if (pStreamDict) { |
| 898 | pStreamDict->SetAtMatrix("Matrix", matrix); |
| 899 | pStreamDict->SetAtRect("BBox", rcBBox); |
| 900 | } |
| 901 | |
| 902 | pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE, |
| 903 | FALSE); |
| 904 | } |
| 905 | |
| 906 | #define BA_ANNOT_MINWIDTH 1 |
| 907 | #define BA_ANNOT_MINHEIGHT 1 |
| 908 | |
| 909 | FX_FLOAT CPDFSDK_Annot::GetMinWidth() const { |
| 910 | return BA_ANNOT_MINWIDTH; |
| 911 | } |
| 912 | |
| 913 | FX_FLOAT CPDFSDK_Annot::GetMinHeight() const { |
| 914 | return BA_ANNOT_MINHEIGHT; |
| 915 | } |
| 916 | |
| 917 | FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() { |
| 918 | return TRUE; |
| 919 | } |
| 920 | FX_BOOL CPDFSDK_BAAnnot::IsVisible() const { |
| 921 | int nFlags = GetFlags(); |
| 922 | return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || |
| 923 | (nFlags & ANNOTFLAG_NOVIEW)); |
| 924 | } |
| 925 | |
| 926 | CPDF_Action CPDFSDK_BAAnnot::GetAction() const { |
| 927 | return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A")); |
| 928 | } |
| 929 | |
| 930 | void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) { |
| 931 | ASSERT(action); |
| 932 | if ((CPDF_Action&)action != |
| 933 | CPDF_Action(m_pAnnot->GetAnnotDict()->GetDict("A"))) { |
| 934 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
| 935 | CPDF_Dictionary* pDict = action.GetDict(); |
| 936 | if (pDict && pDict->GetObjNum() == 0) { |
| 937 | pDoc->AddIndirectObject(pDict); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 938 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 939 | m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum()); |
| 940 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 943 | void CPDFSDK_BAAnnot::RemoveAction() { |
| 944 | m_pAnnot->GetAnnotDict()->RemoveAt("A"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 947 | CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const { |
| 948 | return m_pAnnot->GetAnnotDict()->GetDict("AA"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 951 | void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) { |
| 952 | ASSERT(aa != NULL); |
| 953 | |
| 954 | if ((CPDF_AAction&)aa != m_pAnnot->GetAnnotDict()->GetDict("AA")) |
| 955 | m_pAnnot->GetAnnotDict()->SetAt("AA", (CPDF_AAction&)aa); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 958 | void CPDFSDK_BAAnnot::RemoveAAction() { |
| 959 | m_pAnnot->GetAnnotDict()->RemoveAt("AA"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 962 | CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 963 | CPDF_AAction AAction = GetAAction(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 964 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 965 | if (AAction.ActionExist(eAAT)) |
| 966 | return AAction.GetAction(eAAT); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 967 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 968 | if (eAAT == CPDF_AAction::ButtonUp) |
| 969 | return GetAction(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 970 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 971 | return CPDF_Action(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 974 | FX_BOOL CPDFSDK_BAAnnot::IsXFAField() { |
| 975 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 978 | void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, |
| 979 | CPDF_Matrix* pUser2Device, |
| 980 | CPDF_RenderOptions* pOptions) { |
| 981 | m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal); |
| 982 | m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, |
| 983 | CPDF_Annot::Normal, NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 984 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 985 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 988 | CPDF_Page* CPDFSDK_Annot::GetPDFPage() { |
| 989 | if (m_pPageView) |
| 990 | return m_pPageView->GetPDFPage(); |
| 991 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 994 | CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() { |
| 995 | if (m_pPageView) |
| 996 | return m_pPageView->GetPDFXFAPage(); |
| 997 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 998 | } |