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