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 "core/fpdfapi/fpdf_parser/include/cfdf_document.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 } | 886 } |
887 if (bNotify && m_pForm->m_pFormNotify) { | 887 if (bNotify && m_pForm->m_pFormNotify) { |
888 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 888 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
889 } | 889 } |
890 m_pForm->m_bUpdated = TRUE; | 890 m_pForm->m_bUpdated = TRUE; |
891 return TRUE; | 891 return TRUE; |
892 } | 892 } |
893 | 893 |
894 int CPDF_FormField::GetTopVisibleIndex() { | 894 int CPDF_FormField::GetTopVisibleIndex() { |
895 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); | 895 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); |
896 if (!pObj) { | 896 return pObj ? pObj->GetInteger() : 0; |
897 return 0; | |
898 } | |
899 return pObj->GetInteger(); | |
900 } | 897 } |
901 | 898 |
902 int CPDF_FormField::CountSelectedOptions() { | 899 int CPDF_FormField::CountSelectedOptions() { |
903 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); | 900 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); |
904 if (!pObj) { | 901 return pArray ? pArray->GetCount() : 0; |
905 return 0; | |
906 } | |
907 CPDF_Array* pArray = pObj->GetArray(); | |
908 if (!pArray) { | |
909 return 0; | |
910 } | |
911 return static_cast<int>(pArray->GetCount()); | |
912 } | 902 } |
913 | 903 |
914 int CPDF_FormField::GetSelectedOptionIndex(int index) { | 904 int CPDF_FormField::GetSelectedOptionIndex(int index) { |
915 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); | 905 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); |
916 if (!pObj) { | 906 if (!pArray) |
917 return -1; | 907 return -1; |
918 } | 908 |
919 CPDF_Array* pArray = pObj->GetArray(); | 909 int iCount = pArray->GetCount(); |
920 if (!pArray) { | 910 if (iCount < 0 || index >= iCount) |
921 return -1; | 911 return -1; |
922 } | 912 return pArray->GetIntegerAt(index); |
923 int iCount = static_cast<int>(pArray->GetCount()); | |
924 if (iCount > 0 && index < iCount) { | |
925 return pArray->GetIntegerAt(index); | |
926 } | |
927 return -1; | |
928 } | 913 } |
| 914 |
929 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) { | 915 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) { |
930 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); | 916 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); |
931 if (!pObj) { | 917 if (!pArray) |
932 return FALSE; | 918 return FALSE; |
933 } | 919 |
934 CPDF_Array* pArray = pObj->GetArray(); | 920 for (CPDF_Object* pObj : *pArray) { |
935 if (!pArray) { | 921 if (pObj->GetInteger() == iOptIndex) |
936 return FALSE; | |
937 } | |
938 size_t iCount = pArray->GetCount(); | |
939 for (size_t i = 0; i < iCount; i++) { | |
940 if (pArray->GetIntegerAt(i) == iOptIndex) { | |
941 return TRUE; | 922 return TRUE; |
942 } | |
943 } | 923 } |
944 return FALSE; | 924 return FALSE; |
945 } | 925 } |
| 926 |
946 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, | 927 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, |
947 FX_BOOL bSelected, | 928 FX_BOOL bSelected, |
948 FX_BOOL bNotify) { | 929 FX_BOOL bNotify) { |
949 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); | 930 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); |
950 if (!pArray) { | 931 if (!pArray) { |
951 if (!bSelected) { | 932 if (!bSelected) { |
952 return TRUE; | 933 return TRUE; |
953 } | 934 } |
954 pArray = new CPDF_Array; | 935 pArray = new CPDF_Array; |
955 m_pDict->SetAt("I", pArray); | 936 m_pDict->SetAt("I", pArray); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") | 1050 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") |
1070 ->GetDictBy("Font") | 1051 ->GetDictBy("Font") |
1071 ->GetDictBy(font_name); | 1052 ->GetDictBy(font_name); |
1072 } | 1053 } |
1073 if (!pFontDict) { | 1054 if (!pFontDict) { |
1074 return; | 1055 return; |
1075 } | 1056 } |
1076 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 1057 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
1077 m_FontSize = FX_atof(syntax.GetWord()); | 1058 m_FontSize = FX_atof(syntax.GetWord()); |
1078 } | 1059 } |
OLD | NEW |