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