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