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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
13 #include "core/include/fxcrt/fx_ext.h" | 13 #include "core/include/fxcrt/fx_ext.h" |
14 #include "fpdfsdk/include/fsdk_baseannot.h" | 14 #include "fpdfsdk/include/fsdk_baseannot.h" |
15 #include "fpdfsdk/include/fsdk_define.h" | 15 #include "fpdfsdk/include/fsdk_define.h" |
16 #include "fpdfsdk/include/fsdk_mgr.h" | 16 #include "fpdfsdk/include/fsdk_mgr.h" |
17 | 17 |
18 #ifdef PDF_ENABLE_XFA | 18 #ifdef PDF_ENABLE_XFA |
19 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" | 19 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
20 #endif // PDF_ENABLE_XFA | 20 #endif // PDF_ENABLE_XFA |
21 | 21 |
22 int gAfxGetTimeZoneInSeconds(int8_t tzhour, uint8_t tzminute) { | 22 int gAfxGetTimeZoneInSeconds(int8_t tzhour, uint8_t tzminute) { |
23 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60); | 23 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60); |
24 } | 24 } |
25 | 25 |
26 FX_BOOL _gAfxIsLeapYear(int16_t year) { | 26 FX_BOOL _gAfxIsLeapYear(int16_t year) { |
27 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))); | 27 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))); |
28 } | 28 } |
29 | 29 |
30 FX_WORD _gAfxGetYearDays(int16_t year) { | 30 uint16_t _gAfxGetYearDays(int16_t year) { |
31 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365); | 31 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365); |
32 } | 32 } |
33 | 33 |
34 uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) { | 34 uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) { |
35 uint8_t mDays; | 35 uint8_t mDays; |
36 switch (month) { | 36 switch (month) { |
37 case 1: | 37 case 1: |
38 case 3: | 38 case 3: |
39 case 5: | 39 case 5: |
40 case 7: | 40 case 7: |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 dt.tzMinute); | 366 dt.tzMinute); |
367 dtStr += CFX_ByteString(tempStr); | 367 dtStr += CFX_ByteString(tempStr); |
368 return dtStr; | 368 return dtStr; |
369 } | 369 } |
370 | 370 |
371 void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) { | 371 void CPDFSDK_DateTime::ToSystemTime(FX_SYSTEMTIME& st) { |
372 CPDFSDK_DateTime dt = *this; | 372 CPDFSDK_DateTime dt = *this; |
373 time_t t = (time_t)dt; | 373 time_t t = (time_t)dt; |
374 struct tm* pTime = localtime(&t); | 374 struct tm* pTime = localtime(&t); |
375 if (pTime) { | 375 if (pTime) { |
376 st.wYear = (FX_WORD)pTime->tm_year + 1900; | 376 st.wYear = (uint16_t)pTime->tm_year + 1900; |
377 st.wMonth = (FX_WORD)pTime->tm_mon + 1; | 377 st.wMonth = (uint16_t)pTime->tm_mon + 1; |
378 st.wDay = (FX_WORD)pTime->tm_mday; | 378 st.wDay = (uint16_t)pTime->tm_mday; |
379 st.wDayOfWeek = (FX_WORD)pTime->tm_wday; | 379 st.wDayOfWeek = (uint16_t)pTime->tm_wday; |
380 st.wHour = (FX_WORD)pTime->tm_hour; | 380 st.wHour = (uint16_t)pTime->tm_hour; |
381 st.wMinute = (FX_WORD)pTime->tm_min; | 381 st.wMinute = (uint16_t)pTime->tm_min; |
382 st.wSecond = (FX_WORD)pTime->tm_sec; | 382 st.wSecond = (uint16_t)pTime->tm_sec; |
383 st.wMilliseconds = 0; | 383 st.wMilliseconds = 0; |
384 } | 384 } |
385 } | 385 } |
386 | 386 |
387 CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() const { | 387 CPDFSDK_DateTime CPDFSDK_DateTime::ToGMT() const { |
388 CPDFSDK_DateTime dt = *this; | 388 CPDFSDK_DateTime dt = *this; |
389 dt.AddSeconds(-gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute)); | 389 dt.AddSeconds(-gAfxGetTimeZoneInSeconds(dt.dt.tzHour, dt.dt.tzMinute)); |
390 dt.dt.tzHour = 0; | 390 dt.dt.tzHour = 0; |
391 dt.dt.tzMinute = 0; | 391 dt.dt.tzMinute = 0; |
392 return dt; | 392 return dt; |
393 } | 393 } |
394 | 394 |
395 CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) { | 395 CPDFSDK_DateTime& CPDFSDK_DateTime::AddDays(short days) { |
396 if (days == 0) | 396 if (days == 0) |
397 return *this; | 397 return *this; |
398 | 398 |
399 int16_t y = dt.year, yy; | 399 int16_t y = dt.year, yy; |
400 uint8_t m = dt.month; | 400 uint8_t m = dt.month; |
401 uint8_t d = dt.day; | 401 uint8_t d = dt.day; |
402 int mdays, ydays, ldays; | 402 int mdays, ydays, ldays; |
403 | 403 |
404 ldays = days; | 404 ldays = days; |
405 if (ldays > 0) { | 405 if (ldays > 0) { |
406 yy = y; | 406 yy = y; |
407 if (((FX_WORD)m * 100 + d) > 300) | 407 if (((uint16_t)m * 100 + d) > 300) |
408 yy++; | 408 yy++; |
409 ydays = _gAfxGetYearDays(yy); | 409 ydays = _gAfxGetYearDays(yy); |
410 while (ldays >= ydays) { | 410 while (ldays >= ydays) { |
411 y++; | 411 y++; |
412 ldays -= ydays; | 412 ldays -= ydays; |
413 yy++; | 413 yy++; |
414 mdays = _gAfxGetMonthDays(y, m); | 414 mdays = _gAfxGetMonthDays(y, m); |
415 if (d > mdays) { | 415 if (d > mdays) { |
416 m++; | 416 m++; |
417 d -= mdays; | 417 d -= mdays; |
418 } | 418 } |
419 ydays = _gAfxGetYearDays(yy); | 419 ydays = _gAfxGetYearDays(yy); |
420 } | 420 } |
421 mdays = _gAfxGetMonthDays(y, m) - d + 1; | 421 mdays = _gAfxGetMonthDays(y, m) - d + 1; |
422 while (ldays >= mdays) { | 422 while (ldays >= mdays) { |
423 ldays -= mdays; | 423 ldays -= mdays; |
424 m++; | 424 m++; |
425 d = 1; | 425 d = 1; |
426 mdays = _gAfxGetMonthDays(y, m); | 426 mdays = _gAfxGetMonthDays(y, m); |
427 } | 427 } |
428 d += ldays; | 428 d += ldays; |
429 } else { | 429 } else { |
430 ldays *= -1; | 430 ldays *= -1; |
431 yy = y; | 431 yy = y; |
432 if (((FX_WORD)m * 100 + d) < 300) | 432 if (((uint16_t)m * 100 + d) < 300) |
433 yy--; | 433 yy--; |
434 ydays = _gAfxGetYearDays(yy); | 434 ydays = _gAfxGetYearDays(yy); |
435 while (ldays >= ydays) { | 435 while (ldays >= ydays) { |
436 y--; | 436 y--; |
437 ldays -= ydays; | 437 ldays -= ydays; |
438 yy--; | 438 yy--; |
439 mdays = _gAfxGetMonthDays(y, m); | 439 mdays = _gAfxGetMonthDays(y, m); |
440 if (d > mdays) { | 440 if (d > mdays) { |
441 m++; | 441 m++; |
442 d -= mdays; | 442 d -= mdays; |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 | 958 |
959 CPDF_Page* CPDFSDK_Annot::GetPDFPage() { | 959 CPDF_Page* CPDFSDK_Annot::GetPDFPage() { |
960 return m_pPageView ? m_pPageView->GetPDFPage() : nullptr; | 960 return m_pPageView ? m_pPageView->GetPDFPage() : nullptr; |
961 } | 961 } |
962 | 962 |
963 #ifdef PDF_ENABLE_XFA | 963 #ifdef PDF_ENABLE_XFA |
964 CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() { | 964 CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() { |
965 return m_pPageView ? m_pPageView->GetPDFXFAPage() : nullptr; | 965 return m_pPageView ? m_pPageView->GetPDFXFAPage() : nullptr; |
966 } | 966 } |
967 #endif // PDF_ENABLE_XFA | 967 #endif // PDF_ENABLE_XFA |
OLD | NEW |