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