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