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 "fpdfsdk/javascript/PublicMethods.h" | 7 #include "fpdfsdk/javascript/PublicMethods.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 return std::min(dValue1, dValue2); | 148 return std::min(dValue1, dValue2); |
149 } | 149 } |
150 if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { | 150 if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { |
151 return std::max(dValue1, dValue2); | 151 return std::max(dValue1, dValue2); |
152 } | 152 } |
153 return dValue1; | 153 return dValue1; |
154 } | 154 } |
155 | 155 |
156 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, | 156 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, |
157 CJS_Value val) { | 157 CJS_Value val) { |
158 CJS_Array StrArray(pRuntime); | 158 CJS_Array StrArray; |
159 if (val.IsArrayObject()) { | 159 if (val.IsArrayObject()) { |
160 val.ConvertToArray(StrArray); | 160 val.ConvertToArray(StrArray); |
161 return StrArray; | 161 return StrArray; |
162 } | 162 } |
163 CFX_WideString wsStr = val.ToCFXWideString(); | 163 CFX_WideString wsStr = val.ToCFXWideString(); |
164 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); | 164 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); |
165 const char* p = t.c_str(); | 165 const char* p = t.c_str(); |
166 | 166 |
167 int ch = ','; | 167 int ch = ','; |
168 int nIndex = 0; | 168 int nIndex = 0; |
169 | 169 |
170 while (*p) { | 170 while (*p) { |
171 const char* pTemp = strchr(p, ch); | 171 const char* pTemp = strchr(p, ch); |
172 if (!pTemp) { | 172 if (!pTemp) { |
173 StrArray.SetElement( | 173 StrArray.SetElement( |
174 nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str())); | 174 pRuntime->GetIsolate(), nIndex, |
| 175 CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str())); |
175 break; | 176 break; |
176 } | 177 } |
177 | 178 |
178 char* pSub = new char[pTemp - p + 1]; | 179 char* pSub = new char[pTemp - p + 1]; |
179 strncpy(pSub, p, pTemp - p); | 180 strncpy(pSub, p, pTemp - p); |
180 *(pSub + (pTemp - p)) = '\0'; | 181 *(pSub + (pTemp - p)) = '\0'; |
181 | 182 |
182 StrArray.SetElement( | 183 StrArray.SetElement( |
183 nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str())); | 184 pRuntime->GetIsolate(), nIndex, |
| 185 CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str())); |
184 delete[] pSub; | 186 delete[] pSub; |
185 | 187 |
186 nIndex++; | 188 nIndex++; |
187 p = ++pTemp; | 189 p = ++pTemp; |
188 } | 190 } |
189 return StrArray; | 191 return StrArray; |
190 } | 192 } |
191 | 193 |
192 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, | 194 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, |
193 int nStart, | 195 int nStart, |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 822 |
821 // for processing negative style | 823 // for processing negative style |
822 if (iNegative) { | 824 if (iNegative) { |
823 if (iNegStyle == 0) { | 825 if (iNegStyle == 0) { |
824 Value = L"-" + Value; | 826 Value = L"-" + Value; |
825 } else if (iNegStyle == 2 || iNegStyle == 3) { | 827 } else if (iNegStyle == 2 || iNegStyle == 3) { |
826 Value = L"(" + Value + L")"; | 828 Value = L"(" + Value + L")"; |
827 } | 829 } |
828 if (iNegStyle == 1 || iNegStyle == 3) { | 830 if (iNegStyle == 1 || iNegStyle == 3) { |
829 if (Field* fTarget = pEvent->Target_Field()) { | 831 if (Field* fTarget = pEvent->Target_Field()) { |
830 CJS_Array arColor(pRuntime); | 832 CJS_Array arColor; |
831 CJS_Value vColElm(pRuntime); | 833 CJS_Value vColElm(pRuntime); |
832 vColElm = L"RGB"; | 834 vColElm = L"RGB"; |
833 arColor.SetElement(0, vColElm); | 835 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); |
834 vColElm = 1; | 836 vColElm = 1; |
835 arColor.SetElement(1, vColElm); | 837 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); |
836 vColElm = 0; | 838 vColElm = 0; |
837 arColor.SetElement(2, vColElm); | 839 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); |
838 | 840 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); |
839 arColor.SetElement(3, vColElm); | |
840 | 841 |
841 CJS_PropValue vProp(pRuntime); | 842 CJS_PropValue vProp(pRuntime); |
842 vProp.StartGetting(); | 843 vProp.StartGetting(); |
843 vProp << arColor; | 844 vProp << arColor; |
844 vProp.StartSetting(); | 845 vProp.StartSetting(); |
845 fTarget->textColor(cc, vProp, sError); // red | 846 fTarget->textColor(cc, vProp, sError); // red |
846 } | 847 } |
847 } | 848 } |
848 } else { | 849 } else { |
849 if (iNegStyle == 1 || iNegStyle == 3) { | 850 if (iNegStyle == 1 || iNegStyle == 3) { |
850 if (Field* fTarget = pEvent->Target_Field()) { | 851 if (Field* fTarget = pEvent->Target_Field()) { |
851 CJS_Array arColor(pRuntime); | 852 CJS_Array arColor; |
852 CJS_Value vColElm(pRuntime); | 853 CJS_Value vColElm(pRuntime); |
853 vColElm = L"RGB"; | 854 vColElm = L"RGB"; |
854 arColor.SetElement(0, vColElm); | 855 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); |
855 vColElm = 0; | 856 vColElm = 0; |
856 arColor.SetElement(1, vColElm); | 857 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); |
857 arColor.SetElement(2, vColElm); | 858 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); |
858 arColor.SetElement(3, vColElm); | 859 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); |
859 | 860 |
860 CJS_PropValue vProp(pRuntime); | 861 CJS_PropValue vProp(pRuntime); |
861 vProp.StartGetting(); | 862 vProp.StartGetting(); |
862 fTarget->textColor(cc, vProp, sError); | 863 fTarget->textColor(cc, vProp, sError); |
863 | 864 |
864 CJS_Array aProp(pRuntime); | 865 CJS_Array aProp; |
865 vProp.ConvertToArray(aProp); | 866 vProp.ConvertToArray(aProp); |
866 | 867 |
867 CPWL_Color crProp; | 868 CPWL_Color crProp; |
868 CPWL_Color crColor; | 869 CPWL_Color crColor; |
869 color::ConvertArrayToPWLColor(aProp, crProp); | 870 color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp); |
870 color::ConvertArrayToPWLColor(arColor, crColor); | 871 color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor); |
871 | 872 |
872 if (crColor != crProp) { | 873 if (crColor != crProp) { |
873 CJS_PropValue vProp2(pRuntime); | 874 CJS_PropValue vProp2(pRuntime); |
874 vProp2.StartGetting(); | 875 vProp2.StartGetting(); |
875 vProp2 << arColor; | 876 vProp2 << arColor; |
876 vProp2.StartSetting(); | 877 vProp2.StartSetting(); |
877 fTarget->textColor(cc, vProp2, sError); | 878 fTarget->textColor(cc, vProp2, sError); |
878 } | 879 } |
879 } | 880 } |
880 } | 881 } |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 | 1650 |
1650 CFX_WideString sFunction = params[0].ToCFXWideString(); | 1651 CFX_WideString sFunction = params[0].ToCFXWideString(); |
1651 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; | 1652 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; |
1652 | 1653 |
1653 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1654 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1654 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); | 1655 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); |
1655 int nFieldsCount = 0; | 1656 int nFieldsCount = 0; |
1656 | 1657 |
1657 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { | 1658 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { |
1658 CJS_Value jsValue(pRuntime); | 1659 CJS_Value jsValue(pRuntime); |
1659 FieldNameArray.GetElement(i, jsValue); | 1660 FieldNameArray.GetElement(pRuntime->GetIsolate(), i, jsValue); |
1660 CFX_WideString wsFieldName = jsValue.ToCFXWideString(); | 1661 CFX_WideString wsFieldName = jsValue.ToCFXWideString(); |
1661 | 1662 |
1662 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { | 1663 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { |
1663 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { | 1664 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { |
1664 double dTemp = 0.0; | 1665 double dTemp = 0.0; |
1665 switch (pFormField->GetFieldType()) { | 1666 switch (pFormField->GetFieldType()) { |
1666 case FIELDTYPE_TEXTFIELD: | 1667 case FIELDTYPE_TEXTFIELD: |
1667 case FIELDTYPE_COMBOBOX: { | 1668 case FIELDTYPE_COMBOBOX: { |
1668 CFX_WideString trimmed = pFormField->GetValue(); | 1669 CFX_WideString trimmed = pFormField->GetValue(); |
1669 trimmed.TrimRight(); | 1670 trimmed.TrimRight(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 const std::vector<CJS_Value>& params, | 1778 const std::vector<CJS_Value>& params, |
1778 CJS_Value& vRet, | 1779 CJS_Value& vRet, |
1779 CFX_WideString& sError) { | 1780 CFX_WideString& sError) { |
1780 CJS_Context* pContext = (CJS_Context*)cc; | 1781 CJS_Context* pContext = (CJS_Context*)cc; |
1781 if (params.size() != 1) { | 1782 if (params.size() != 1) { |
1782 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1783 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1783 return FALSE; | 1784 return FALSE; |
1784 } | 1785 } |
1785 | 1786 |
1786 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1787 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1787 CJS_Array nums(pRuntime); | 1788 CJS_Array nums; |
1788 | 1789 |
1789 CFX_WideString str = params[0].ToCFXWideString(); | 1790 CFX_WideString str = params[0].ToCFXWideString(); |
1790 CFX_WideString sPart; | 1791 CFX_WideString sPart; |
1791 | 1792 |
1792 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 1793 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
1793 str = L"0" + str; | 1794 str = L"0" + str; |
1794 | 1795 |
1795 int nIndex = 0; | 1796 int nIndex = 0; |
1796 for (int i = 0, sz = str.GetLength(); i < sz; i++) { | 1797 for (int i = 0, sz = str.GetLength(); i < sz; i++) { |
1797 FX_WCHAR wc = str.GetAt(i); | 1798 FX_WCHAR wc = str.GetAt(i); |
1798 if (FXSYS_iswdigit(wc)) { | 1799 if (FXSYS_iswdigit(wc)) { |
1799 sPart += wc; | 1800 sPart += wc; |
1800 } else { | 1801 } else { |
1801 if (sPart.GetLength() > 0) { | 1802 if (sPart.GetLength() > 0) { |
1802 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1803 nums.SetElement(pRuntime->GetIsolate(), nIndex, |
| 1804 CJS_Value(pRuntime, sPart.c_str())); |
1803 sPart = L""; | 1805 sPart = L""; |
1804 nIndex++; | 1806 nIndex++; |
1805 } | 1807 } |
1806 } | 1808 } |
1807 } | 1809 } |
1808 | 1810 |
1809 if (sPart.GetLength() > 0) { | 1811 if (sPart.GetLength() > 0) { |
1810 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1812 nums.SetElement(pRuntime->GetIsolate(), nIndex, |
| 1813 CJS_Value(pRuntime, sPart.c_str())); |
1811 } | 1814 } |
1812 | 1815 |
1813 if (nums.GetLength() > 0) | 1816 if (nums.GetLength() > 0) |
1814 vRet = nums; | 1817 vRet = CJS_Value(pRuntime, nums); |
1815 else | 1818 else |
1816 vRet.SetNull(); | 1819 vRet.SetNull(); |
1817 | 1820 |
1818 return TRUE; | 1821 return TRUE; |
1819 } | 1822 } |
OLD | NEW |