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 <iomanip> | 10 #include <iomanip> |
| 11 #include <limits> |
11 #include <sstream> | 12 #include <sstream> |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "core/fpdfdoc/cpdf_interform.h" | 16 #include "core/fpdfdoc/cpdf_interform.h" |
16 #include "core/fxcrt/fx_ext.h" | 17 #include "core/fxcrt/fx_ext.h" |
17 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 18 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
18 #include "fpdfsdk/cpdfsdk_interform.h" | 19 #include "fpdfsdk/cpdfsdk_interform.h" |
19 #include "fpdfsdk/javascript/Field.h" | 20 #include "fpdfsdk/javascript/Field.h" |
20 #include "fpdfsdk/javascript/JS_Define.h" | 21 #include "fpdfsdk/javascript/JS_Define.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 89 } |
89 | 90 |
90 #if _FX_OS_ != _FX_ANDROID_ | 91 #if _FX_OS_ != _FX_ANDROID_ |
91 CFX_ByteString CalculateString(double dValue, | 92 CFX_ByteString CalculateString(double dValue, |
92 int iDec, | 93 int iDec, |
93 int* iDec2, | 94 int* iDec2, |
94 bool* bNegative) { | 95 bool* bNegative) { |
95 *bNegative = dValue < 0; | 96 *bNegative = dValue < 0; |
96 if (*bNegative) | 97 if (*bNegative) |
97 dValue = -dValue; | 98 dValue = -dValue; |
| 99 |
| 100 // Make sure the number of precision characters will fit. |
| 101 if (iDec > std::numeric_limits<double>::digits10) |
| 102 iDec = std::numeric_limits<double>::digits10; |
| 103 |
98 std::stringstream ss; | 104 std::stringstream ss; |
99 ss << std::fixed << std::setprecision(iDec) << dValue; | 105 ss << std::fixed << std::setprecision(iDec) << dValue; |
100 std::string stringValue = ss.str(); | 106 std::string stringValue = ss.str(); |
101 size_t iDecimalPos = stringValue.find("."); | 107 size_t iDecimalPos = stringValue.find("."); |
102 *iDec2 = iDecimalPos == std::string::npos ? stringValue.size() | 108 *iDec2 = iDecimalPos == std::string::npos ? stringValue.size() |
103 : static_cast<int>(iDecimalPos); | 109 : static_cast<int>(iDecimalPos); |
104 return CFX_ByteString(stringValue.c_str()); | 110 return CFX_ByteString(stringValue.c_str()); |
105 } | 111 } |
106 #endif | 112 #endif |
107 | 113 |
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1819 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); |
1814 } | 1820 } |
1815 | 1821 |
1816 if (nums.GetLength(pRuntime) > 0) | 1822 if (nums.GetLength(pRuntime) > 0) |
1817 vRet = CJS_Value(pRuntime, nums); | 1823 vRet = CJS_Value(pRuntime, nums); |
1818 else | 1824 else |
1819 vRet.SetNull(pRuntime); | 1825 vRet.SetNull(pRuntime); |
1820 | 1826 |
1821 return true; | 1827 return true; |
1822 } | 1828 } |
OLD | NEW |