Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: fpdfsdk/javascript/PublicMethods.cpp

Issue 1847583004: Move the fpdfsdk/include/javascript folder (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/javascript/JS_Value.cpp ('k') | fpdfsdk/javascript/app.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "core/fxcrt/include/fx_ext.h" 13 #include "core/fxcrt/include/fx_ext.h"
14 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. 14 #include "fpdfsdk/include/fsdk_mgr.h"
15 #include "fpdfsdk/include/javascript/IJavaScript.h"
16 #include "fpdfsdk/javascript/Field.h" 15 #include "fpdfsdk/javascript/Field.h"
17 #include "fpdfsdk/javascript/JS_Context.h"
18 #include "fpdfsdk/javascript/JS_Define.h" 16 #include "fpdfsdk/javascript/JS_Define.h"
19 #include "fpdfsdk/javascript/JS_EventHandler.h" 17 #include "fpdfsdk/javascript/JS_EventHandler.h"
20 #include "fpdfsdk/javascript/JS_Object.h" 18 #include "fpdfsdk/javascript/JS_Object.h"
21 #include "fpdfsdk/javascript/JS_Runtime.h"
22 #include "fpdfsdk/javascript/JS_Value.h" 19 #include "fpdfsdk/javascript/JS_Value.h"
20 #include "fpdfsdk/javascript/cjs_context.h"
21 #include "fpdfsdk/javascript/cjs_runtime.h"
23 #include "fpdfsdk/javascript/color.h" 22 #include "fpdfsdk/javascript/color.h"
24 #include "fpdfsdk/javascript/resource.h" 23 #include "fpdfsdk/javascript/resource.h"
25 #include "fpdfsdk/javascript/util.h" 24 #include "fpdfsdk/javascript/util.h"
26 25
27 #define DOUBLE_CORRECT 0.000000000000001 26 #define DOUBLE_CORRECT 0.000000000000001
28 27
29 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) 28 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
30 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) 29 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format)
31 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) 30 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke)
32 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) 31 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format)
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 sPart += c; 731 sPart += c;
733 break; 732 break;
734 } 733 }
735 734
736 sRet += sPart; 735 sRet += sPart;
737 } 736 }
738 737
739 return sRet; 738 return sRet;
740 } 739 }
741 740
742 /* -------------------------------------------------------------------------- */
743
744 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, 741 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency,
745 // bCurrencyPrepend) 742 // bCurrencyPrepend)
746 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, 743 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
747 const std::vector<CJS_Value>& params, 744 const std::vector<CJS_Value>& params,
748 CJS_Value& vRet, 745 CJS_Value& vRet,
749 CFX_WideString& sError) { 746 CFX_WideString& sError) {
750 #if _FX_OS_ != _FX_ANDROID_ 747 #if _FX_OS_ != _FX_ANDROID_
751 CJS_Context* pContext = (CJS_Context*)cc; 748 CJS_Context* pContext = (CJS_Context*)cc;
752 if (params.size() != 6) { 749 if (params.size() != 6) {
753 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 750 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
(...skipping 19 matching lines...) Expand all
773 770
774 if (iDec < 0) 771 if (iDec < 0)
775 iDec = -iDec; 772 iDec = -iDec;
776 773
777 if (iSepStyle < 0 || iSepStyle > 3) 774 if (iSepStyle < 0 || iSepStyle > 3)
778 iSepStyle = 0; 775 iSepStyle = 0;
779 776
780 if (iNegStyle < 0 || iNegStyle > 3) 777 if (iNegStyle < 0 || iNegStyle > 3)
781 iNegStyle = 0; 778 iNegStyle = 0;
782 779
783 //////////////////////////////////////////////////////
784 // for processing decimal places 780 // for processing decimal places
785 strValue.Replace(",", "."); 781 strValue.Replace(",", ".");
786 double dValue = atof(strValue); 782 double dValue = atof(strValue);
787 if (iDec > 0) 783 if (iDec > 0)
788 dValue += DOUBLE_CORRECT; 784 dValue += DOUBLE_CORRECT;
789 785
790 int iDec2; 786 int iDec2;
791 int iNegative = 0; 787 int iNegative = 0;
792 788
793 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); 789 strValue = fcvt(dValue, iDec, &iDec2, &iNegative);
(...skipping 12 matching lines...) Expand all
806 } 802 }
807 iDec2 = 0; 803 iDec2 = 0;
808 } 804 }
809 int iMax = strValue.GetLength(); 805 int iMax = strValue.GetLength();
810 if (iDec2 > iMax) { 806 if (iDec2 > iMax) {
811 for (int iNum = 0; iNum <= iDec2 - iMax; iNum++) { 807 for (int iNum = 0; iNum <= iDec2 - iMax; iNum++) {
812 strValue += "0"; 808 strValue += "0";
813 } 809 }
814 iMax = iDec2 + 1; 810 iMax = iDec2 + 1;
815 } 811 }
816 /////////////////////////////////////////////////////// 812
817 // for processing seperator style 813 // for processing seperator style
818 if (iDec2 < iMax) { 814 if (iDec2 < iMax) {
819 if (iSepStyle == 0 || iSepStyle == 1) { 815 if (iSepStyle == 0 || iSepStyle == 1) {
820 strValue.Insert(iDec2, '.'); 816 strValue.Insert(iDec2, '.');
821 iMax++; 817 iMax++;
822 } else if (iSepStyle == 2 || iSepStyle == 3) { 818 } else if (iSepStyle == 2 || iSepStyle == 3) {
823 strValue.Insert(iDec2, ','); 819 strValue.Insert(iDec2, ',');
824 iMax++; 820 iMax++;
825 } 821 }
826 822
827 if (iDec2 == 0) 823 if (iDec2 == 0)
828 strValue.Insert(iDec2, '0'); 824 strValue.Insert(iDec2, '0');
829 } 825 }
830 if (iSepStyle == 0 || iSepStyle == 2) { 826 if (iSepStyle == 0 || iSepStyle == 2) {
831 char cSeperator; 827 char cSeperator;
832 if (iSepStyle == 0) 828 if (iSepStyle == 0)
833 cSeperator = ','; 829 cSeperator = ',';
834 else 830 else
835 cSeperator = '.'; 831 cSeperator = '.';
836 832
837 for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) { 833 for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) {
838 strValue.Insert(iDecPositive, cSeperator); 834 strValue.Insert(iDecPositive, cSeperator);
839 iMax++; 835 iMax++;
840 } 836 }
841 } 837 }
842 838
843 //////////////////////////////////////////////////////////////////////
844 // for processing currency string 839 // for processing currency string
845
846 Value = CFX_WideString::FromLocal(strValue); 840 Value = CFX_WideString::FromLocal(strValue);
847 std::wstring strValue2 = Value.c_str(); 841 std::wstring strValue2 = Value.c_str();
848 842
849 if (bCurrencyPrepend) 843 if (bCurrencyPrepend)
850 strValue2 = wstrCurrency + strValue2; 844 strValue2 = wstrCurrency + strValue2;
851 else 845 else
852 strValue2 = strValue2 + wstrCurrency; 846 strValue2 = strValue2 + wstrCurrency;
853 847
854 /////////////////////////////////////////////////////////////////////////
855 // for processing negative style 848 // for processing negative style
856 if (iNegative) { 849 if (iNegative) {
857 if (iNegStyle == 0) { 850 if (iNegStyle == 0) {
858 strValue2.insert(0, L"-"); 851 strValue2.insert(0, L"-");
859 } 852 }
860 if (iNegStyle == 2 || iNegStyle == 3) { 853 if (iNegStyle == 2 || iNegStyle == 3) {
861 strValue2.insert(0, L"("); 854 strValue2.insert(0, L"(");
862 strValue2.insert(strValue2.length(), L")"); 855 strValue2.insert(strValue2.length(), L")");
863 } 856 }
864 if (iNegStyle == 1 || iNegStyle == 3) { 857 if (iNegStyle == 1 || iNegStyle == 3) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 return TRUE; 1055 return TRUE;
1063 1056
1064 int iDec = params[0].ToInt(); 1057 int iDec = params[0].ToInt();
1065 if (iDec < 0) 1058 if (iDec < 0)
1066 iDec = -iDec; 1059 iDec = -iDec;
1067 1060
1068 int iSepStyle = params[1].ToInt(); 1061 int iSepStyle = params[1].ToInt();
1069 if (iSepStyle < 0 || iSepStyle > 3) 1062 if (iSepStyle < 0 || iSepStyle > 3)
1070 iSepStyle = 0; 1063 iSepStyle = 0;
1071 1064
1072 //////////////////////////////////////////////////////
1073 // for processing decimal places 1065 // for processing decimal places
1074 double dValue = atof(strValue); 1066 double dValue = atof(strValue);
1075 dValue *= 100; 1067 dValue *= 100;
1076 if (iDec > 0) 1068 if (iDec > 0)
1077 dValue += DOUBLE_CORRECT; 1069 dValue += DOUBLE_CORRECT;
1078 1070
1079 int iDec2; 1071 int iDec2;
1080 int iNegative = 0; 1072 int iNegative = 0;
1081 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); 1073 strValue = fcvt(dValue, iDec, &iDec2, &iNegative);
1082 if (strValue.IsEmpty()) { 1074 if (strValue.IsEmpty()) {
1083 dValue = 0; 1075 dValue = 0;
1084 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); 1076 strValue = fcvt(dValue, iDec, &iDec2, &iNegative);
1085 } 1077 }
1086 1078
1087 if (iDec2 < 0) { 1079 if (iDec2 < 0) {
1088 for (int iNum = 0; iNum < abs(iDec2); iNum++) { 1080 for (int iNum = 0; iNum < abs(iDec2); iNum++) {
1089 strValue = "0" + strValue; 1081 strValue = "0" + strValue;
1090 } 1082 }
1091 iDec2 = 0; 1083 iDec2 = 0;
1092 } 1084 }
1093 int iMax = strValue.GetLength(); 1085 int iMax = strValue.GetLength();
1094 if (iDec2 > iMax) { 1086 if (iDec2 > iMax) {
1095 for (int iNum = 0; iNum <= iDec2 - iMax; iNum++) { 1087 for (int iNum = 0; iNum <= iDec2 - iMax; iNum++) {
1096 strValue += "0"; 1088 strValue += "0";
1097 } 1089 }
1098 iMax = iDec2 + 1; 1090 iMax = iDec2 + 1;
1099 } 1091 }
1100 /////////////////////////////////////////////////////// 1092
1101 // for processing seperator style 1093 // for processing seperator style
1102 if (iDec2 < iMax) { 1094 if (iDec2 < iMax) {
1103 if (iSepStyle == 0 || iSepStyle == 1) { 1095 if (iSepStyle == 0 || iSepStyle == 1) {
1104 strValue.Insert(iDec2, '.'); 1096 strValue.Insert(iDec2, '.');
1105 iMax++; 1097 iMax++;
1106 } else if (iSepStyle == 2 || iSepStyle == 3) { 1098 } else if (iSepStyle == 2 || iSepStyle == 3) {
1107 strValue.Insert(iDec2, ','); 1099 strValue.Insert(iDec2, ',');
1108 iMax++; 1100 iMax++;
1109 } 1101 }
1110 1102
1111 if (iDec2 == 0) 1103 if (iDec2 == 0)
1112 strValue.Insert(iDec2, '0'); 1104 strValue.Insert(iDec2, '0');
1113 } 1105 }
1114 if (iSepStyle == 0 || iSepStyle == 2) { 1106 if (iSepStyle == 0 || iSepStyle == 2) {
1115 char cSeperator; 1107 char cSeperator;
1116 if (iSepStyle == 0) 1108 if (iSepStyle == 0)
1117 cSeperator = ','; 1109 cSeperator = ',';
1118 else 1110 else
1119 cSeperator = '.'; 1111 cSeperator = '.';
1120 1112
1121 for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) { 1113 for (int iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) {
1122 strValue.Insert(iDecPositive, cSeperator); 1114 strValue.Insert(iDecPositive, cSeperator);
1123 iMax++; 1115 iMax++;
1124 } 1116 }
1125 } 1117 }
1126 //////////////////////////////////////////////////////////////////// 1118
1127 // negative mark 1119 // negative mark
1128 if (iNegative) 1120 if (iNegative)
1129 strValue = "-" + strValue; 1121 strValue = "-" + strValue;
1130 strValue += "%"; 1122 strValue += "%";
1131 Value = CFX_WideString::FromLocal(strValue); 1123 Value = CFX_WideString::FromLocal(strValue);
1132 #endif 1124 #endif
1133 return TRUE; 1125 return TRUE;
1134 } 1126 }
1135 // AFPercent_Keystroke(nDec, sepStyle) 1127 // AFPercent_Keystroke(nDec, sepStyle)
1136 FX_BOOL CJS_PublicMethods::AFPercent_Keystroke( 1128 FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); 1867 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
1876 } 1868 }
1877 1869
1878 if (nums.GetLength() > 0) 1870 if (nums.GetLength() > 0)
1879 vRet = nums; 1871 vRet = nums;
1880 else 1872 else
1881 vRet.SetNull(); 1873 vRet.SetNull();
1882 1874
1883 return TRUE; 1875 return TRUE;
1884 } 1876 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/JS_Value.cpp ('k') | fpdfsdk/javascript/app.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698