| 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/fxcrt/include/fx_ext.h" | 13 #include "core/fxcrt/include/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/fpdfxfa/include/fpdfxfa_doc.h" | 19 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| 20 #endif // PDF_ENABLE_XFA | 20 #endif // PDF_ENABLE_XFA |
| 21 | 21 |
| 22 namespace { |
| 23 |
| 24 const float kMinWidth = 1.0f; |
| 25 const float kMinHeight = 1.0f; |
| 26 |
| 22 int gAfxGetTimeZoneInSeconds(int8_t tzhour, uint8_t tzminute) { | 27 int gAfxGetTimeZoneInSeconds(int8_t tzhour, uint8_t tzminute) { |
| 23 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60); | 28 return (int)tzhour * 3600 + (int)tzminute * (tzhour >= 0 ? 60 : -60); |
| 24 } | 29 } |
| 25 | 30 |
| 26 FX_BOOL _gAfxIsLeapYear(int16_t year) { | 31 bool gAfxIsLeapYear(int16_t year) { |
| 27 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))); | 32 return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))); |
| 28 } | 33 } |
| 29 | 34 |
| 30 uint16_t _gAfxGetYearDays(int16_t year) { | 35 uint16_t gAfxGetYearDays(int16_t year) { |
| 31 return (_gAfxIsLeapYear(year) == TRUE ? 366 : 365); | 36 return (gAfxIsLeapYear(year) ? 366 : 365); |
| 32 } | 37 } |
| 33 | 38 |
| 34 uint8_t _gAfxGetMonthDays(int16_t year, uint8_t month) { | 39 uint8_t gAfxGetMonthDays(int16_t year, uint8_t month) { |
| 35 uint8_t mDays; | 40 uint8_t mDays; |
| 36 switch (month) { | 41 switch (month) { |
| 37 case 1: | 42 case 1: |
| 38 case 3: | 43 case 3: |
| 39 case 5: | 44 case 5: |
| 40 case 7: | 45 case 7: |
| 41 case 8: | 46 case 8: |
| 42 case 10: | 47 case 10: |
| 43 case 12: | 48 case 12: |
| 44 mDays = 31; | 49 mDays = 31; |
| 45 break; | 50 break; |
| 46 | 51 |
| 47 case 4: | 52 case 4: |
| 48 case 6: | 53 case 6: |
| 49 case 9: | 54 case 9: |
| 50 case 11: | 55 case 11: |
| 51 mDays = 30; | 56 mDays = 30; |
| 52 break; | 57 break; |
| 53 | 58 |
| 54 case 2: | 59 case 2: |
| 55 if (_gAfxIsLeapYear(year) == TRUE) | 60 if (gAfxIsLeapYear(year)) |
| 56 mDays = 29; | 61 mDays = 29; |
| 57 else | 62 else |
| 58 mDays = 28; | 63 mDays = 28; |
| 59 break; | 64 break; |
| 60 | 65 |
| 61 default: | 66 default: |
| 62 mDays = 0; | 67 mDays = 0; |
| 63 break; | 68 break; |
| 64 } | 69 } |
| 65 | 70 |
| 66 return mDays; | 71 return mDays; |
| 67 } | 72 } |
| 68 | 73 |
| 74 } // namespace |
| 75 |
| 69 CPDFSDK_DateTime::CPDFSDK_DateTime() { | 76 CPDFSDK_DateTime::CPDFSDK_DateTime() { |
| 70 ResetDateTime(); | 77 ResetDateTime(); |
| 71 } | 78 } |
| 72 | 79 |
| 73 CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) { | 80 CPDFSDK_DateTime::CPDFSDK_DateTime(const CFX_ByteString& dtStr) { |
| 74 ResetDateTime(); | 81 ResetDateTime(); |
| 75 | 82 |
| 76 FromPDFDateTimeString(dtStr); | 83 FromPDFDateTimeString(dtStr); |
| 77 } | 84 } |
| 78 | 85 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 int16_t y = dt.year, yy; | 406 int16_t y = dt.year, yy; |
| 400 uint8_t m = dt.month; | 407 uint8_t m = dt.month; |
| 401 uint8_t d = dt.day; | 408 uint8_t d = dt.day; |
| 402 int mdays, ydays, ldays; | 409 int mdays, ydays, ldays; |
| 403 | 410 |
| 404 ldays = days; | 411 ldays = days; |
| 405 if (ldays > 0) { | 412 if (ldays > 0) { |
| 406 yy = y; | 413 yy = y; |
| 407 if (((uint16_t)m * 100 + d) > 300) | 414 if (((uint16_t)m * 100 + d) > 300) |
| 408 yy++; | 415 yy++; |
| 409 ydays = _gAfxGetYearDays(yy); | 416 ydays = gAfxGetYearDays(yy); |
| 410 while (ldays >= ydays) { | 417 while (ldays >= ydays) { |
| 411 y++; | 418 y++; |
| 412 ldays -= ydays; | 419 ldays -= ydays; |
| 413 yy++; | 420 yy++; |
| 414 mdays = _gAfxGetMonthDays(y, m); | 421 mdays = gAfxGetMonthDays(y, m); |
| 415 if (d > mdays) { | 422 if (d > mdays) { |
| 416 m++; | 423 m++; |
| 417 d -= mdays; | 424 d -= mdays; |
| 418 } | 425 } |
| 419 ydays = _gAfxGetYearDays(yy); | 426 ydays = gAfxGetYearDays(yy); |
| 420 } | 427 } |
| 421 mdays = _gAfxGetMonthDays(y, m) - d + 1; | 428 mdays = gAfxGetMonthDays(y, m) - d + 1; |
| 422 while (ldays >= mdays) { | 429 while (ldays >= mdays) { |
| 423 ldays -= mdays; | 430 ldays -= mdays; |
| 424 m++; | 431 m++; |
| 425 d = 1; | 432 d = 1; |
| 426 mdays = _gAfxGetMonthDays(y, m); | 433 mdays = gAfxGetMonthDays(y, m); |
| 427 } | 434 } |
| 428 d += ldays; | 435 d += ldays; |
| 429 } else { | 436 } else { |
| 430 ldays *= -1; | 437 ldays *= -1; |
| 431 yy = y; | 438 yy = y; |
| 432 if (((uint16_t)m * 100 + d) < 300) | 439 if (((uint16_t)m * 100 + d) < 300) |
| 433 yy--; | 440 yy--; |
| 434 ydays = _gAfxGetYearDays(yy); | 441 ydays = gAfxGetYearDays(yy); |
| 435 while (ldays >= ydays) { | 442 while (ldays >= ydays) { |
| 436 y--; | 443 y--; |
| 437 ldays -= ydays; | 444 ldays -= ydays; |
| 438 yy--; | 445 yy--; |
| 439 mdays = _gAfxGetMonthDays(y, m); | 446 mdays = gAfxGetMonthDays(y, m); |
| 440 if (d > mdays) { | 447 if (d > mdays) { |
| 441 m++; | 448 m++; |
| 442 d -= mdays; | 449 d -= mdays; |
| 443 } | 450 } |
| 444 ydays = _gAfxGetYearDays(yy); | 451 ydays = gAfxGetYearDays(yy); |
| 445 } | 452 } |
| 446 while (ldays >= d) { | 453 while (ldays >= d) { |
| 447 ldays -= d; | 454 ldays -= d; |
| 448 m--; | 455 m--; |
| 449 mdays = _gAfxGetMonthDays(y, m); | 456 mdays = gAfxGetMonthDays(y, m); |
| 450 d = mdays; | 457 d = mdays; |
| 451 } | 458 } |
| 452 d -= ldays; | 459 d -= ldays; |
| 453 } | 460 } |
| 454 | 461 |
| 455 dt.year = y; | 462 dt.year = y; |
| 456 dt.month = m; | 463 dt.month = m; |
| 457 dt.day = d; | 464 dt.day = d; |
| 458 | 465 |
| 459 return *this; | 466 return *this; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 int CPDFSDK_BAAnnot::GetBorderWidth() const { | 677 int CPDFSDK_BAAnnot::GetBorderWidth() const { |
| 671 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayBy("Border")) { | 678 if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayBy("Border")) { |
| 672 return pBorder->GetIntegerAt(2); | 679 return pBorder->GetIntegerAt(2); |
| 673 } | 680 } |
| 674 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS")) { | 681 if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS")) { |
| 675 return pBSDict->GetIntegerBy("W", 1); | 682 return pBSDict->GetIntegerBy("W", 1); |
| 676 } | 683 } |
| 677 return 1; | 684 return 1; |
| 678 } | 685 } |
| 679 | 686 |
| 680 void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle) { | 687 void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { |
| 681 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS"); | 688 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS"); |
| 682 if (!pBSDict) { | 689 if (!pBSDict) { |
| 683 pBSDict = new CPDF_Dictionary; | 690 pBSDict = new CPDF_Dictionary; |
| 684 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict); | 691 m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict); |
| 685 } | 692 } |
| 686 | 693 |
| 687 switch (nStyle) { | 694 switch (nStyle) { |
| 688 case BBS_SOLID: | 695 case BorderStyle::SOLID: |
| 689 pBSDict->SetAtName("S", "S"); | 696 pBSDict->SetAtName("S", "S"); |
| 690 break; | 697 break; |
| 691 case BBS_DASH: | 698 case BorderStyle::DASH: |
| 692 pBSDict->SetAtName("S", "D"); | 699 pBSDict->SetAtName("S", "D"); |
| 693 break; | 700 break; |
| 694 case BBS_BEVELED: | 701 case BorderStyle::BEVELED: |
| 695 pBSDict->SetAtName("S", "B"); | 702 pBSDict->SetAtName("S", "B"); |
| 696 break; | 703 break; |
| 697 case BBS_INSET: | 704 case BorderStyle::INSET: |
| 698 pBSDict->SetAtName("S", "I"); | 705 pBSDict->SetAtName("S", "I"); |
| 699 break; | 706 break; |
| 700 case BBS_UNDERLINE: | 707 case BorderStyle::UNDERLINE: |
| 701 pBSDict->SetAtName("S", "U"); | 708 pBSDict->SetAtName("S", "U"); |
| 702 break; | 709 break; |
| 710 default: |
| 711 break; |
| 703 } | 712 } |
| 704 } | 713 } |
| 705 | 714 |
| 706 int CPDFSDK_BAAnnot::GetBorderStyle() const { | 715 BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const { |
| 707 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS"); | 716 CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS"); |
| 708 if (pBSDict) { | 717 if (pBSDict) { |
| 709 CFX_ByteString sBorderStyle = pBSDict->GetStringBy("S", "S"); | 718 CFX_ByteString sBorderStyle = pBSDict->GetStringBy("S", "S"); |
| 710 if (sBorderStyle == "S") | 719 if (sBorderStyle == "S") |
| 711 return BBS_SOLID; | 720 return BorderStyle::SOLID; |
| 712 if (sBorderStyle == "D") | 721 if (sBorderStyle == "D") |
| 713 return BBS_DASH; | 722 return BorderStyle::DASH; |
| 714 if (sBorderStyle == "B") | 723 if (sBorderStyle == "B") |
| 715 return BBS_BEVELED; | 724 return BorderStyle::BEVELED; |
| 716 if (sBorderStyle == "I") | 725 if (sBorderStyle == "I") |
| 717 return BBS_INSET; | 726 return BorderStyle::INSET; |
| 718 if (sBorderStyle == "U") | 727 if (sBorderStyle == "U") |
| 719 return BBS_UNDERLINE; | 728 return BorderStyle::UNDERLINE; |
| 720 } | 729 } |
| 721 | 730 |
| 722 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayBy("Border"); | 731 CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayBy("Border"); |
| 723 if (pBorder) { | 732 if (pBorder) { |
| 724 if (pBorder->GetCount() >= 4) { | 733 if (pBorder->GetCount() >= 4) { |
| 725 CPDF_Array* pDP = pBorder->GetArrayAt(3); | 734 CPDF_Array* pDP = pBorder->GetArrayAt(3); |
| 726 if (pDP && pDP->GetCount() > 0) | 735 if (pDP && pDP->GetCount() > 0) |
| 727 return BBS_DASH; | 736 return BorderStyle::DASH; |
| 728 } | 737 } |
| 729 } | 738 } |
| 730 | 739 |
| 731 return BBS_SOLID; | 740 return BorderStyle::SOLID; |
| 732 } | 741 } |
| 733 | 742 |
| 734 void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) { | 743 void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) { |
| 735 CPDF_Array* pArray = new CPDF_Array; | 744 CPDF_Array* pArray = new CPDF_Array; |
| 736 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); | 745 pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f); |
| 737 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); | 746 pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f); |
| 738 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); | 747 pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f); |
| 739 m_pAnnot->GetAnnotDict()->SetAt("C", pArray); | 748 m_pAnnot->GetAnnotDict()->SetAt("C", pArray); |
| 740 } | 749 } |
| 741 | 750 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 834 |
| 826 if (pStreamDict) { | 835 if (pStreamDict) { |
| 827 pStreamDict->SetAtMatrix("Matrix", matrix); | 836 pStreamDict->SetAtMatrix("Matrix", matrix); |
| 828 pStreamDict->SetAtRect("BBox", rcBBox); | 837 pStreamDict->SetAtRect("BBox", rcBBox); |
| 829 } | 838 } |
| 830 | 839 |
| 831 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE, | 840 pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE, |
| 832 FALSE); | 841 FALSE); |
| 833 } | 842 } |
| 834 | 843 |
| 835 #define BA_ANNOT_MINWIDTH 1 | |
| 836 #define BA_ANNOT_MINHEIGHT 1 | |
| 837 | |
| 838 FX_FLOAT CPDFSDK_Annot::GetMinWidth() const { | 844 FX_FLOAT CPDFSDK_Annot::GetMinWidth() const { |
| 839 return BA_ANNOT_MINWIDTH; | 845 return kMinWidth; |
| 840 } | 846 } |
| 841 | 847 |
| 842 FX_FLOAT CPDFSDK_Annot::GetMinHeight() const { | 848 FX_FLOAT CPDFSDK_Annot::GetMinHeight() const { |
| 843 return BA_ANNOT_MINHEIGHT; | 849 return kMinHeight; |
| 844 } | 850 } |
| 845 | 851 |
| 846 FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() { | 852 FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller() { |
| 847 return TRUE; | 853 return TRUE; |
| 848 } | 854 } |
| 849 FX_BOOL CPDFSDK_BAAnnot::IsVisible() const { | 855 FX_BOOL CPDFSDK_BAAnnot::IsVisible() const { |
| 850 uint32_t nFlags = GetFlags(); | 856 uint32_t nFlags = GetFlags(); |
| 851 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || | 857 return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || |
| 852 (nFlags & ANNOTFLAG_NOVIEW)); | 858 (nFlags & ANNOTFLAG_NOVIEW)); |
| 853 } | 859 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 | 927 |
| 922 CPDF_Page* CPDFSDK_Annot::GetPDFPage() { | 928 CPDF_Page* CPDFSDK_Annot::GetPDFPage() { |
| 923 return m_pPageView ? m_pPageView->GetPDFPage() : nullptr; | 929 return m_pPageView ? m_pPageView->GetPDFPage() : nullptr; |
| 924 } | 930 } |
| 925 | 931 |
| 926 #ifdef PDF_ENABLE_XFA | 932 #ifdef PDF_ENABLE_XFA |
| 927 CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() { | 933 CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() { |
| 928 return m_pPageView ? m_pPageView->GetPDFXFAPage() : nullptr; | 934 return m_pPageView ? m_pPageView->GetPDFXFAPage() : nullptr; |
| 929 } | 935 } |
| 930 #endif // PDF_ENABLE_XFA | 936 #endif // PDF_ENABLE_XFA |
| OLD | NEW |