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