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