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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return; | 270 return; |
271 | 271 |
272 m_pFormDict = pRoot->GetDictBy("AcroForm"); | 272 m_pFormDict = pRoot->GetDictBy("AcroForm"); |
273 if (!m_pFormDict) | 273 if (!m_pFormDict) |
274 return; | 274 return; |
275 | 275 |
276 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields"); | 276 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields"); |
277 if (!pFields) | 277 if (!pFields) |
278 return; | 278 return; |
279 | 279 |
280 int count = pFields->GetCount(); | 280 for (size_t i = 0; i < pFields->GetCount(); i++) |
281 for (int i = 0; i < count; i++) { | |
282 LoadField(pFields->GetDictAt(i)); | 281 LoadField(pFields->GetDictAt(i)); |
283 } | |
284 } | 282 } |
285 | 283 |
286 CPDF_InterForm::~CPDF_InterForm() { | 284 CPDF_InterForm::~CPDF_InterForm() { |
287 for (auto it : m_ControlMap) | 285 for (auto it : m_ControlMap) |
288 delete it.second; | 286 delete it.second; |
289 | 287 |
290 int nCount = m_pFieldTree->m_Root.CountFields(); | 288 int nCount = m_pFieldTree->m_Root.CountFields(); |
291 for (int i = 0; i < nCount; ++i) { | 289 for (int i = 0; i < nCount; ++i) { |
292 delete m_pFieldTree->m_Root.GetField(i); | 290 delete m_pFieldTree->m_Root.GetField(i); |
293 } | 291 } |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } | 694 } |
697 | 695 |
698 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, | 696 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, |
699 FX_FLOAT pdf_x, | 697 FX_FLOAT pdf_x, |
700 FX_FLOAT pdf_y, | 698 FX_FLOAT pdf_y, |
701 int* z_order) const { | 699 int* z_order) const { |
702 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); | 700 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); |
703 if (!pAnnotList) | 701 if (!pAnnotList) |
704 return nullptr; | 702 return nullptr; |
705 | 703 |
706 for (uint32_t i = pAnnotList->GetCount(); i > 0; --i) { | 704 for (size_t i = pAnnotList->GetCount(); i > 0; --i) { |
707 uint32_t annot_index = i - 1; | 705 size_t annot_index = i - 1; |
708 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index); | 706 CPDF_Dictionary* pAnnot = pAnnotList->GetDictAt(annot_index); |
709 if (!pAnnot) | 707 if (!pAnnot) |
710 continue; | 708 continue; |
711 | 709 |
712 const auto it = m_ControlMap.find(pAnnot); | 710 const auto it = m_ControlMap.find(pAnnot); |
713 if (it == m_ControlMap.end()) | 711 if (it == m_ControlMap.end()) |
714 continue; | 712 continue; |
715 | 713 |
716 CPDF_FormControl* pControl = it->second; | 714 CPDF_FormControl* pControl = it->second; |
717 CFX_FloatRect rect = pControl->GetRect(); | 715 CFX_FloatRect rect = pControl->GetRect(); |
718 if (!rect.Contains(pdf_x, pdf_y)) | 716 if (!rect.Contains(pdf_x, pdf_y)) |
719 continue; | 717 continue; |
720 | 718 |
721 if (z_order) | 719 if (z_order) |
722 *z_order = annot_index; | 720 *z_order = static_cast<int>(annot_index); |
723 return pControl; | 721 return pControl; |
724 } | 722 } |
725 return nullptr; | 723 return nullptr; |
726 } | 724 } |
727 | 725 |
728 CPDF_FormControl* CPDF_InterForm::GetControlByDict( | 726 CPDF_FormControl* CPDF_InterForm::GetControlByDict( |
729 const CPDF_Dictionary* pWidgetDict) const { | 727 const CPDF_Dictionary* pWidgetDict) const { |
730 const auto it = m_ControlMap.find(pWidgetDict); | 728 const auto it = m_ControlMap.find(pWidgetDict); |
731 return it != m_ControlMap.end() ? it->second : nullptr; | 729 return it != m_ControlMap.end() ? it->second : nullptr; |
732 } | 730 } |
733 | 731 |
734 FX_BOOL CPDF_InterForm::NeedConstructAP() { | 732 FX_BOOL CPDF_InterForm::NeedConstructAP() { |
735 return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances"); | 733 return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances"); |
736 } | 734 } |
737 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { | 735 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { |
738 if (!m_pFormDict) { | 736 if (!m_pFormDict) { |
739 InitInterFormDict(m_pFormDict, m_pDocument); | 737 InitInterFormDict(m_pFormDict, m_pDocument); |
740 } | 738 } |
741 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); | 739 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); |
742 m_bGenerateAP = bNeedAP; | 740 m_bGenerateAP = bNeedAP; |
743 } | 741 } |
| 742 |
744 int CPDF_InterForm::CountFieldsInCalculationOrder() { | 743 int CPDF_InterForm::CountFieldsInCalculationOrder() { |
745 if (!m_pFormDict) { | 744 if (!m_pFormDict) { |
746 return 0; | 745 return 0; |
747 } | 746 } |
748 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 747 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
749 return pArray ? pArray->GetCount() : 0; | 748 return pArray ? pArray->GetCount() : 0; |
750 } | 749 } |
| 750 |
751 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { | 751 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { |
752 if (!m_pFormDict || index < 0) { | 752 if (!m_pFormDict || index < 0) { |
753 return NULL; | 753 return NULL; |
754 } | 754 } |
755 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 755 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
756 if (!pArray) { | 756 if (!pArray) { |
757 return NULL; | 757 return NULL; |
758 } | 758 } |
759 if (CPDF_Dictionary* pElement = | 759 if (CPDF_Dictionary* pElement = |
760 ToDictionary(pArray->GetDirectObjectAt(index))) { | 760 ToDictionary(pArray->GetDirectObjectAt(index))) { |
761 return GetFieldByDict(pElement); | 761 return GetFieldByDict(pElement); |
762 } | 762 } |
763 return NULL; | 763 return NULL; |
764 } | 764 } |
765 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { | 765 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { |
766 if (!m_pFormDict || !pField) { | 766 if (!m_pFormDict || !pField) { |
767 return -1; | 767 return -1; |
768 } | 768 } |
769 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 769 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
770 if (!pArray) { | 770 if (!pArray) { |
771 return -1; | 771 return -1; |
772 } | 772 } |
773 for (uint32_t i = 0; i < pArray->GetCount(); i++) { | 773 for (size_t i = 0; i < pArray->GetCount(); i++) { |
774 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); | 774 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); |
775 if (pElement == pField->m_pDict) { | 775 if (pElement == pField->m_pDict) { |
776 return i; | 776 return i; |
777 } | 777 } |
778 } | 778 } |
779 return -1; | 779 return -1; |
780 } | 780 } |
781 uint32_t CPDF_InterForm::CountFormFonts() { | 781 uint32_t CPDF_InterForm::CountFormFonts() { |
782 return CountInterFormFonts(m_pFormDict); | 782 return CountInterFormFonts(m_pFormDict); |
783 } | 783 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); | 893 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); |
894 if (!pKids) { | 894 if (!pKids) { |
895 AddTerminalField(pFieldDict); | 895 AddTerminalField(pFieldDict); |
896 return; | 896 return; |
897 } | 897 } |
898 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0); | 898 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0); |
899 if (!pFirstKid) { | 899 if (!pFirstKid) { |
900 return; | 900 return; |
901 } | 901 } |
902 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { | 902 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { |
903 for (uint32_t i = 0; i < pKids->GetCount(); i++) { | 903 for (size_t i = 0; i < pKids->GetCount(); i++) { |
904 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i); | 904 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i); |
905 if (pChildDict) { | 905 if (pChildDict) { |
906 if (pChildDict->GetObjNum() != dwParentObjNum) { | 906 if (pChildDict->GetObjNum() != dwParentObjNum) { |
907 LoadField(pChildDict, nLevel + 1); | 907 LoadField(pChildDict, nLevel + 1); |
908 } | 908 } |
909 } | 909 } |
910 } | 910 } |
911 } else { | 911 } else { |
912 AddTerminalField(pFieldDict); | 912 AddTerminalField(pFieldDict); |
913 } | 913 } |
914 } | 914 } |
915 FX_BOOL CPDF_InterForm::HasXFAForm() const { | 915 FX_BOOL CPDF_InterForm::HasXFAForm() const { |
916 return m_pFormDict && m_pFormDict->GetArrayBy("XFA"); | 916 return m_pFormDict && m_pFormDict->GetArrayBy("XFA"); |
917 } | 917 } |
918 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { | 918 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { |
919 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 919 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
920 if (!pPageDict) { | 920 if (!pPageDict) { |
921 return; | 921 return; |
922 } | 922 } |
923 CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots"); | 923 CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots"); |
924 if (!pAnnots) { | 924 if (!pAnnots) { |
925 return; | 925 return; |
926 } | 926 } |
927 int iAnnotCount = pAnnots->GetCount(); | 927 for (size_t i = 0; i < pAnnots->GetCount(); i++) { |
928 for (int i = 0; i < iAnnotCount; i++) { | |
929 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); | 928 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); |
930 if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget") { | 929 if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget") { |
931 LoadField(pAnnot); | 930 LoadField(pAnnot); |
932 } | 931 } |
933 } | 932 } |
934 } | 933 } |
935 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { | 934 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { |
936 if (!pFieldDict->KeyExist("T")) { | 935 if (!pFieldDict->KeyExist("T")) { |
937 return NULL; | 936 return NULL; |
938 } | 937 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 pDict->SetAtName("T", ""); | 975 pDict->SetAtName("T", ""); |
977 } | 976 } |
978 m_pFieldTree->SetField(csWName, pField); | 977 m_pFieldTree->SetField(csWName, pField); |
979 } | 978 } |
980 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); | 979 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); |
981 if (!pKids) { | 980 if (!pKids) { |
982 if (pFieldDict->GetStringBy("Subtype") == "Widget") { | 981 if (pFieldDict->GetStringBy("Subtype") == "Widget") { |
983 AddControl(pField, pFieldDict); | 982 AddControl(pField, pFieldDict); |
984 } | 983 } |
985 } else { | 984 } else { |
986 for (uint32_t i = 0; i < pKids->GetCount(); i++) { | 985 for (size_t i = 0; i < pKids->GetCount(); i++) { |
987 CPDF_Dictionary* pKid = pKids->GetDictAt(i); | 986 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
988 if (!pKid) { | 987 if (!pKid) { |
989 continue; | 988 continue; |
990 } | 989 } |
991 if (pKid->GetStringBy("Subtype") != "Widget") { | 990 if (pKid->GetStringBy("Subtype") != "Widget") { |
992 continue; | 991 continue; |
993 } | 992 } |
994 AddControl(pField, pKid); | 993 AddControl(pField, pKid); |
995 } | 994 } |
996 } | 995 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 const CFX_WideString& parent_name, | 1113 const CFX_WideString& parent_name, |
1115 FX_BOOL bNotify, | 1114 FX_BOOL bNotify, |
1116 int nLevel) { | 1115 int nLevel) { |
1117 CFX_WideString name; | 1116 CFX_WideString name; |
1118 if (!parent_name.IsEmpty()) { | 1117 if (!parent_name.IsEmpty()) { |
1119 name = parent_name + L"."; | 1118 name = parent_name + L"."; |
1120 } | 1119 } |
1121 name += pFieldDict->GetUnicodeTextBy("T"); | 1120 name += pFieldDict->GetUnicodeTextBy("T"); |
1122 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); | 1121 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); |
1123 if (pKids) { | 1122 if (pKids) { |
1124 for (uint32_t i = 0; i < pKids->GetCount(); i++) { | 1123 for (size_t i = 0; i < pKids->GetCount(); i++) { |
1125 CPDF_Dictionary* pKid = pKids->GetDictAt(i); | 1124 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
1126 if (!pKid) { | 1125 if (!pKid) { |
1127 continue; | 1126 continue; |
1128 } | 1127 } |
1129 if (nLevel <= nMaxRecursion) { | 1128 if (nLevel <= nMaxRecursion) { |
1130 FDF_ImportField(pKid, name, bNotify, nLevel + 1); | 1129 FDF_ImportField(pKid, name, bNotify, nLevel + 1); |
1131 } | 1130 } |
1132 } | 1131 } |
1133 return; | 1132 return; |
1134 } | 1133 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 if (!pFields) { | 1185 if (!pFields) { |
1187 return FALSE; | 1186 return FALSE; |
1188 } | 1187 } |
1189 m_bsEncoding = pMainDict->GetStringBy("Encoding"); | 1188 m_bsEncoding = pMainDict->GetStringBy("Encoding"); |
1190 if (bNotify && m_pFormNotify) { | 1189 if (bNotify && m_pFormNotify) { |
1191 int iRet = m_pFormNotify->BeforeFormImportData(this); | 1190 int iRet = m_pFormNotify->BeforeFormImportData(this); |
1192 if (iRet < 0) { | 1191 if (iRet < 0) { |
1193 return FALSE; | 1192 return FALSE; |
1194 } | 1193 } |
1195 } | 1194 } |
1196 for (uint32_t i = 0; i < pFields->GetCount(); i++) { | 1195 for (size_t i = 0; i < pFields->GetCount(); i++) { |
1197 CPDF_Dictionary* pField = pFields->GetDictAt(i); | 1196 CPDF_Dictionary* pField = pFields->GetDictAt(i); |
1198 if (!pField) { | 1197 if (!pField) { |
1199 continue; | 1198 continue; |
1200 } | 1199 } |
1201 FDF_ImportField(pField, L"", bNotify); | 1200 FDF_ImportField(pField, L"", bNotify); |
1202 } | 1201 } |
1203 if (bNotify && m_pFormNotify) { | 1202 if (bNotify && m_pFormNotify) { |
1204 m_pFormNotify->AfterFormImportData(this); | 1203 m_pFormNotify->AfterFormImportData(this); |
1205 } | 1204 } |
1206 return TRUE; | 1205 return TRUE; |
1207 } | 1206 } |
1208 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { | 1207 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { |
1209 m_pFormNotify = (CPDF_FormNotify*)pNotify; | 1208 m_pFormNotify = (CPDF_FormNotify*)pNotify; |
1210 } | 1209 } |
OLD | NEW |