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 "PublicMethods.h" | 7 #include "PublicMethods.h" |
8 | 8 |
9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. | 9 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. |
10 #include "../../include/javascript/IJavaScript.h" | 10 #include "../../include/javascript/IJavaScript.h" |
11 #include "Field.h" | 11 #include "Field.h" |
12 #include "JS_Context.h" | 12 #include "JS_Context.h" |
13 #include "JS_Define.h" | 13 #include "JS_Define.h" |
14 #include "JS_EventHandler.h" | 14 #include "JS_EventHandler.h" |
15 #include "JS_Object.h" | 15 #include "JS_Object.h" |
16 #include "JS_Runtime.h" | 16 #include "JS_Runtime.h" |
17 #include "JS_Value.h" | 17 #include "JS_Value.h" |
18 #include "color.h" | 18 #include "color.h" |
19 #include "resource.h" | 19 #include "resource.h" |
20 #include "util.h" | 20 #include "util.h" |
21 | 21 |
22 static v8::Isolate* GetIsolate(IJS_Context* cc) { | |
23 CJS_Context* pContext = (CJS_Context*)cc; | |
24 ASSERT(pContext != NULL); | |
25 | |
26 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
27 ASSERT(pRuntime != NULL); | |
28 | |
29 return pRuntime->GetIsolate(); | |
30 } | |
31 | |
32 /* -------------------------------- CJS_PublicMethods | |
33 * -------------------------------- */ | |
34 | |
35 #define DOUBLE_CORRECT 0.000000000000001 | 22 #define DOUBLE_CORRECT 0.000000000000001 |
36 | 23 |
37 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) | 24 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) |
38 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) | 25 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) |
39 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) | 26 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) |
40 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) | 27 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) |
41 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke) | 28 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke) |
42 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx) | 29 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx) |
43 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx) | 30 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx) |
44 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format) | 31 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format) |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 FX_BOOL& bDot) { | 326 FX_BOOL& bDot) { |
340 FX_BOOL bAllDigits = FALSE; | 327 FX_BOOL bAllDigits = FALSE; |
341 FX_BOOL bSign = FALSE; | 328 FX_BOOL bSign = FALSE; |
342 FX_BOOL bKXJS = FALSE; | 329 FX_BOOL bKXJS = FALSE; |
343 | 330 |
344 dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); | 331 dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); |
345 | 332 |
346 return bAllDigits; | 333 return bAllDigits; |
347 } | 334 } |
348 | 335 |
349 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, | 336 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, |
350 CJS_Value val) { | 337 CJS_Value val) { |
351 CJS_Array StrArray(isolate); | 338 CJS_Array StrArray(pRuntime); |
352 if (val.IsArrayObject()) { | 339 if (val.IsArrayObject()) { |
353 val.ConvertToArray(StrArray); | 340 val.ConvertToArray(StrArray); |
354 return StrArray; | 341 return StrArray; |
355 } | 342 } |
356 CFX_WideString wsStr = val.ToCFXWideString(); | 343 CFX_WideString wsStr = val.ToCFXWideString(); |
357 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); | 344 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); |
358 const char* p = (const char*)t; | 345 const char* p = (const char*)t; |
359 | 346 |
360 int ch = ','; | 347 int ch = ','; |
361 int nIndex = 0; | 348 int nIndex = 0; |
362 | 349 |
363 while (*p) { | 350 while (*p) { |
364 const char* pTemp = strchr(p, ch); | 351 const char* pTemp = strchr(p, ch); |
365 if (pTemp == NULL) { | 352 if (pTemp == NULL) { |
366 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str())); | 353 StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(p).c_str())); |
367 break; | 354 break; |
368 } else { | 355 } else { |
369 char* pSub = new char[pTemp - p + 1]; | 356 char* pSub = new char[pTemp - p + 1]; |
370 strncpy(pSub, p, pTemp - p); | 357 strncpy(pSub, p, pTemp - p); |
371 *(pSub + (pTemp - p)) = '\0'; | 358 *(pSub + (pTemp - p)) = '\0'; |
372 | 359 |
373 StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str())); | 360 StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str())); |
374 delete[] pSub; | 361 delete[] pSub; |
375 | 362 |
376 nIndex++; | 363 nIndex++; |
377 p = ++pTemp; | 364 p = ++pTemp; |
378 } | 365 } |
379 } | 366 } |
380 return StrArray; | 367 return StrArray; |
381 } | 368 } |
382 | 369 |
383 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string, | 370 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string, |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 | 891 |
905 /* -------------------------------------------------------------------------- */ | 892 /* -------------------------------------------------------------------------- */ |
906 | 893 |
907 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, | 894 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, |
908 // bCurrencyPrepend) | 895 // bCurrencyPrepend) |
909 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, | 896 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, |
910 const CJS_Parameters& params, | 897 const CJS_Parameters& params, |
911 CJS_Value& vRet, | 898 CJS_Value& vRet, |
912 CFX_WideString& sError) { | 899 CFX_WideString& sError) { |
913 #if _FX_OS_ != _FX_ANDROID_ | 900 #if _FX_OS_ != _FX_ANDROID_ |
914 v8::Isolate* isolate = ::GetIsolate(cc); | |
915 CJS_Context* pContext = (CJS_Context*)cc; | 901 CJS_Context* pContext = (CJS_Context*)cc; |
916 ASSERT(pContext != NULL); | |
917 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | |
918 ASSERT(pEvent != NULL); | |
919 | |
920 if (params.size() != 6) { | 902 if (params.size() != 6) { |
921 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 903 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
922 return FALSE; | 904 return FALSE; |
923 } | 905 } |
| 906 |
| 907 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 908 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
924 if (!pEvent->m_pValue) | 909 if (!pEvent->m_pValue) |
925 return FALSE; | 910 return FALSE; |
| 911 |
926 CFX_WideString& Value = pEvent->Value(); | 912 CFX_WideString& Value = pEvent->Value(); |
927 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 913 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
928 | |
929 if (strValue.IsEmpty()) | 914 if (strValue.IsEmpty()) |
930 return TRUE; | 915 return TRUE; |
931 | 916 |
932 int iDec = params[0].ToInt(); | 917 int iDec = params[0].ToInt(); |
933 int iSepStyle = params[1].ToInt(); | 918 int iSepStyle = params[1].ToInt(); |
934 int iNegStyle = params[2].ToInt(); | 919 int iNegStyle = params[2].ToInt(); |
935 // params[3] is iCurrStyle, it's not used. | 920 // params[3] is iCurrStyle, it's not used. |
936 std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); | 921 std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); |
937 FX_BOOL bCurrencyPrepend = params[5].ToBool(); | 922 FX_BOOL bCurrencyPrepend = params[5].ToBool(); |
938 | 923 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 if (iNegative) { | 1010 if (iNegative) { |
1026 if (iNegStyle == 0) { | 1011 if (iNegStyle == 0) { |
1027 strValue2.insert(0, L"-"); | 1012 strValue2.insert(0, L"-"); |
1028 } | 1013 } |
1029 if (iNegStyle == 2 || iNegStyle == 3) { | 1014 if (iNegStyle == 2 || iNegStyle == 3) { |
1030 strValue2.insert(0, L"("); | 1015 strValue2.insert(0, L"("); |
1031 strValue2.insert(strValue2.length(), L")"); | 1016 strValue2.insert(strValue2.length(), L")"); |
1032 } | 1017 } |
1033 if (iNegStyle == 1 || iNegStyle == 3) { | 1018 if (iNegStyle == 1 || iNegStyle == 3) { |
1034 if (Field* fTarget = pEvent->Target_Field()) { | 1019 if (Field* fTarget = pEvent->Target_Field()) { |
1035 CJS_Array arColor(isolate); | 1020 CJS_Array arColor(pRuntime); |
1036 CJS_Value vColElm(isolate); | 1021 CJS_Value vColElm(pRuntime); |
1037 vColElm = L"RGB"; | 1022 vColElm = L"RGB"; |
1038 arColor.SetElement(0, vColElm); | 1023 arColor.SetElement(0, vColElm); |
1039 vColElm = 1; | 1024 vColElm = 1; |
1040 arColor.SetElement(1, vColElm); | 1025 arColor.SetElement(1, vColElm); |
1041 vColElm = 0; | 1026 vColElm = 0; |
1042 arColor.SetElement(2, vColElm); | 1027 arColor.SetElement(2, vColElm); |
1043 | 1028 |
1044 arColor.SetElement(3, vColElm); | 1029 arColor.SetElement(3, vColElm); |
1045 | 1030 |
1046 CJS_PropValue vProp(isolate); | 1031 CJS_PropValue vProp(pRuntime); |
1047 vProp.StartGetting(); | 1032 vProp.StartGetting(); |
1048 vProp << arColor; | 1033 vProp << arColor; |
1049 vProp.StartSetting(); | 1034 vProp.StartSetting(); |
1050 fTarget->textColor(cc, vProp, sError); // red | 1035 fTarget->textColor(cc, vProp, sError); // red |
1051 } | 1036 } |
1052 } | 1037 } |
1053 } else { | 1038 } else { |
1054 if (iNegStyle == 1 || iNegStyle == 3) { | 1039 if (iNegStyle == 1 || iNegStyle == 3) { |
1055 if (Field* fTarget = pEvent->Target_Field()) { | 1040 if (Field* fTarget = pEvent->Target_Field()) { |
1056 CJS_Array arColor(isolate); | 1041 CJS_Array arColor(pRuntime); |
1057 CJS_Value vColElm(isolate); | 1042 CJS_Value vColElm(pRuntime); |
1058 vColElm = L"RGB"; | 1043 vColElm = L"RGB"; |
1059 arColor.SetElement(0, vColElm); | 1044 arColor.SetElement(0, vColElm); |
1060 vColElm = 0; | 1045 vColElm = 0; |
1061 arColor.SetElement(1, vColElm); | 1046 arColor.SetElement(1, vColElm); |
1062 arColor.SetElement(2, vColElm); | 1047 arColor.SetElement(2, vColElm); |
1063 arColor.SetElement(3, vColElm); | 1048 arColor.SetElement(3, vColElm); |
1064 | 1049 |
1065 CJS_PropValue vProp(isolate); | 1050 CJS_PropValue vProp(pRuntime); |
1066 vProp.StartGetting(); | 1051 vProp.StartGetting(); |
1067 fTarget->textColor(cc, vProp, sError); | 1052 fTarget->textColor(cc, vProp, sError); |
1068 | 1053 |
1069 CJS_Array aProp(isolate); | 1054 CJS_Array aProp(pRuntime); |
1070 vProp.ConvertToArray(aProp); | 1055 vProp.ConvertToArray(aProp); |
1071 | 1056 |
1072 CPWL_Color crProp; | 1057 CPWL_Color crProp; |
1073 CPWL_Color crColor; | 1058 CPWL_Color crColor; |
1074 color::ConvertArrayToPWLColor(aProp, crProp); | 1059 color::ConvertArrayToPWLColor(aProp, crProp); |
1075 color::ConvertArrayToPWLColor(arColor, crColor); | 1060 color::ConvertArrayToPWLColor(arColor, crColor); |
1076 | 1061 |
1077 if (crColor != crProp) { | 1062 if (crColor != crProp) { |
1078 CJS_PropValue vProp2(isolate); | 1063 CJS_PropValue vProp2(pRuntime); |
1079 vProp2.StartGetting(); | 1064 vProp2.StartGetting(); |
1080 vProp2 << arColor; | 1065 vProp2 << arColor; |
1081 vProp2.StartSetting(); | 1066 vProp2.StartSetting(); |
1082 fTarget->textColor(cc, vProp2, sError); | 1067 fTarget->textColor(cc, vProp2, sError); |
1083 } | 1068 } |
1084 } | 1069 } |
1085 } | 1070 } |
1086 } | 1071 } |
1087 Value = strValue2.c_str(); | 1072 Value = strValue2.c_str(); |
1088 #endif | 1073 #endif |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 return TRUE; | 1450 return TRUE; |
1466 } | 1451 } |
1467 } | 1452 } |
1468 return TRUE; | 1453 return TRUE; |
1469 } | 1454 } |
1470 | 1455 |
1471 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, | 1456 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, |
1472 const CJS_Parameters& params, | 1457 const CJS_Parameters& params, |
1473 CJS_Value& vRet, | 1458 CJS_Value& vRet, |
1474 CFX_WideString& sError) { | 1459 CFX_WideString& sError) { |
1475 v8::Isolate* isolate = ::GetIsolate(cc); | 1460 CJS_Context* pContext = (CJS_Context*)cc; |
1476 | |
1477 if (params.size() != 1) { | 1461 if (params.size() != 1) { |
1478 CJS_Context* pContext = (CJS_Context*)cc; | |
1479 ASSERT(pContext != NULL); | |
1480 | |
1481 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1462 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1482 return FALSE; | 1463 return FALSE; |
1483 } | 1464 } |
1484 | 1465 |
1485 int iIndex = params[0].ToInt(); | 1466 int iIndex = params[0].ToInt(); |
1486 const FX_WCHAR* cFormats[] = {L"m/d", | 1467 const FX_WCHAR* cFormats[] = {L"m/d", |
1487 L"m/d/yy", | 1468 L"m/d/yy", |
1488 L"mm/dd/yy", | 1469 L"mm/dd/yy", |
1489 L"mm/yy", | 1470 L"mm/yy", |
1490 L"d-mmm", | 1471 L"d-mmm", |
1491 L"d-mmm-yy", | 1472 L"d-mmm-yy", |
1492 L"dd-mmm-yy", | 1473 L"dd-mmm-yy", |
1493 L"yy-mm-dd", | 1474 L"yy-mm-dd", |
1494 L"mmm-yy", | 1475 L"mmm-yy", |
1495 L"mmmm-yy", | 1476 L"mmmm-yy", |
1496 L"mmm d, yyyy", | 1477 L"mmm d, yyyy", |
1497 L"mmmm d, yyyy", | 1478 L"mmmm d, yyyy", |
1498 L"m/d/yy h:MM tt", | 1479 L"m/d/yy h:MM tt", |
1499 L"m/d/yy HH:MM"}; | 1480 L"m/d/yy HH:MM"}; |
1500 | 1481 |
1501 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1482 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1502 iIndex = 0; | 1483 iIndex = 0; |
1503 | 1484 |
1504 CJS_Parameters newParams; | 1485 CJS_Parameters newParams; |
1505 CJS_Value val(isolate, cFormats[iIndex]); | 1486 newParams.push_back( |
1506 newParams.push_back(val); | 1487 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1507 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1488 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1508 } | 1489 } |
1509 | 1490 |
1510 // AFDate_KeystrokeEx(cFormat) | 1491 // AFDate_KeystrokeEx(cFormat) |
1511 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc, | 1492 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc, |
1512 const CJS_Parameters& params, | 1493 const CJS_Parameters& params, |
1513 CJS_Value& vRet, | 1494 CJS_Value& vRet, |
1514 CFX_WideString& sError) { | 1495 CFX_WideString& sError) { |
1515 v8::Isolate* isolate = ::GetIsolate(cc); | 1496 CJS_Context* pContext = (CJS_Context*)cc; |
1516 | |
1517 if (params.size() != 1) { | 1497 if (params.size() != 1) { |
1518 CJS_Context* pContext = (CJS_Context*)cc; | |
1519 ASSERT(pContext != NULL); | |
1520 | |
1521 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1498 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1522 return FALSE; | 1499 return FALSE; |
1523 } | 1500 } |
1524 | 1501 |
1525 int iIndex = params[0].ToInt(); | 1502 int iIndex = params[0].ToInt(); |
1526 const FX_WCHAR* cFormats[] = {L"m/d", | 1503 const FX_WCHAR* cFormats[] = {L"m/d", |
1527 L"m/d/yy", | 1504 L"m/d/yy", |
1528 L"mm/dd/yy", | 1505 L"mm/dd/yy", |
1529 L"mm/yy", | 1506 L"mm/yy", |
1530 L"d-mmm", | 1507 L"d-mmm", |
1531 L"d-mmm-yy", | 1508 L"d-mmm-yy", |
1532 L"dd-mmm-yy", | 1509 L"dd-mmm-yy", |
1533 L"yy-mm-dd", | 1510 L"yy-mm-dd", |
1534 L"mmm-yy", | 1511 L"mmm-yy", |
1535 L"mmmm-yy", | 1512 L"mmmm-yy", |
1536 L"mmm d, yyyy", | 1513 L"mmm d, yyyy", |
1537 L"mmmm d, yyyy", | 1514 L"mmmm d, yyyy", |
1538 L"m/d/yy h:MM tt", | 1515 L"m/d/yy h:MM tt", |
1539 L"m/d/yy HH:MM"}; | 1516 L"m/d/yy HH:MM"}; |
1540 | 1517 |
1541 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1518 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1542 iIndex = 0; | 1519 iIndex = 0; |
1543 | 1520 |
1544 CJS_Parameters newParams; | 1521 CJS_Parameters newParams; |
1545 CJS_Value val(isolate, cFormats[iIndex]); | 1522 newParams.push_back( |
1546 newParams.push_back(val); | 1523 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1547 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1524 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1548 } | 1525 } |
1549 | 1526 |
1550 // function AFTime_Format(ptf) | 1527 // function AFTime_Format(ptf) |
1551 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, | 1528 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, |
1552 const CJS_Parameters& params, | 1529 const CJS_Parameters& params, |
1553 CJS_Value& vRet, | 1530 CJS_Value& vRet, |
1554 CFX_WideString& sError) { | 1531 CFX_WideString& sError) { |
1555 v8::Isolate* isolate = ::GetIsolate(cc); | 1532 CJS_Context* pContext = (CJS_Context*)cc; |
1556 | |
1557 if (params.size() != 1) { | 1533 if (params.size() != 1) { |
1558 CJS_Context* pContext = (CJS_Context*)cc; | |
1559 ASSERT(pContext != NULL); | |
1560 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1534 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1561 return FALSE; | 1535 return FALSE; |
1562 } | 1536 } |
1563 | 1537 |
1564 int iIndex = params[0].ToInt(); | 1538 int iIndex = params[0].ToInt(); |
1565 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1539 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1566 L"h:MM:ss tt"}; | 1540 L"h:MM:ss tt"}; |
1567 | 1541 |
1568 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1542 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1569 iIndex = 0; | 1543 iIndex = 0; |
1570 | 1544 |
1571 CJS_Parameters newParams; | 1545 CJS_Parameters newParams; |
1572 CJS_Value val(isolate, cFormats[iIndex]); | 1546 newParams.push_back( |
1573 newParams.push_back(val); | 1547 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1574 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1548 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1575 } | 1549 } |
1576 | 1550 |
1577 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc, | 1551 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc, |
1578 const CJS_Parameters& params, | 1552 const CJS_Parameters& params, |
1579 CJS_Value& vRet, | 1553 CJS_Value& vRet, |
1580 CFX_WideString& sError) { | 1554 CFX_WideString& sError) { |
1581 v8::Isolate* isolate = ::GetIsolate(cc); | 1555 CJS_Context* pContext = (CJS_Context*)cc; |
1582 if (params.size() != 1) { | 1556 if (params.size() != 1) { |
1583 CJS_Context* pContext = (CJS_Context*)cc; | |
1584 ASSERT(pContext != NULL); | |
1585 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1557 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1586 return FALSE; | 1558 return FALSE; |
1587 } | 1559 } |
1588 | 1560 |
1589 int iIndex = params[0].ToInt(); | 1561 int iIndex = params[0].ToInt(); |
1590 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1562 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1591 L"h:MM:ss tt"}; | 1563 L"h:MM:ss tt"}; |
1592 | 1564 |
1593 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1565 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1594 iIndex = 0; | 1566 iIndex = 0; |
1595 | 1567 |
1596 CJS_Parameters newParams; | 1568 CJS_Parameters newParams; |
1597 CJS_Value val(isolate, cFormats[iIndex]); | 1569 newParams.push_back( |
1598 newParams.push_back(val); | 1570 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1599 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1571 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1600 } | 1572 } |
1601 | 1573 |
1602 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IJS_Context* cc, | 1574 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IJS_Context* cc, |
1603 const CJS_Parameters& params, | 1575 const CJS_Parameters& params, |
1604 CJS_Value& vRet, | 1576 CJS_Value& vRet, |
1605 CFX_WideString& sError) { | 1577 CFX_WideString& sError) { |
1606 return AFDate_FormatEx(cc, params, vRet, sError); | 1578 return AFDate_FormatEx(cc, params, vRet, sError); |
1607 } | 1579 } |
1608 | 1580 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 | 1727 |
1756 wideChange = wChange.c_str(); | 1728 wideChange = wChange.c_str(); |
1757 return TRUE; | 1729 return TRUE; |
1758 } | 1730 } |
1759 | 1731 |
1760 // function AFSpecial_Keystroke(psf) | 1732 // function AFSpecial_Keystroke(psf) |
1761 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc, | 1733 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc, |
1762 const CJS_Parameters& params, | 1734 const CJS_Parameters& params, |
1763 CJS_Value& vRet, | 1735 CJS_Value& vRet, |
1764 CFX_WideString& sError) { | 1736 CFX_WideString& sError) { |
1765 v8::Isolate* isolate = ::GetIsolate(cc); | |
1766 | |
1767 CJS_Context* pContext = (CJS_Context*)cc; | 1737 CJS_Context* pContext = (CJS_Context*)cc; |
1768 ASSERT(pContext != NULL); | |
1769 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | |
1770 ASSERT(pEvent != NULL); | |
1771 | |
1772 if (params.size() != 1) { | 1738 if (params.size() != 1) { |
1773 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1739 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1774 return FALSE; | 1740 return FALSE; |
1775 } | 1741 } |
1776 | 1742 |
| 1743 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1744 if (!pEvent->m_pValue) |
| 1745 return FALSE; |
| 1746 |
1777 std::string cFormat; | 1747 std::string cFormat; |
1778 int iIndex = params[0].ToInt(); | 1748 int iIndex = params[0].ToInt(); |
1779 | |
1780 if (!pEvent->m_pValue) | |
1781 return FALSE; | |
1782 // CJS_Value val = pEvent->Value(); | |
1783 CFX_WideString& val = pEvent->Value(); | 1749 CFX_WideString& val = pEvent->Value(); |
1784 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); | 1750 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); |
1785 std::wstring wstrChange = pEvent->Change().c_str(); | 1751 std::wstring wstrChange = pEvent->Change().c_str(); |
1786 | 1752 |
1787 switch (iIndex) { | 1753 switch (iIndex) { |
1788 case 0: | 1754 case 0: |
1789 cFormat = "99999"; | 1755 cFormat = "99999"; |
1790 break; | 1756 break; |
1791 case 1: | 1757 case 1: |
1792 // cFormat = "99999-9999"; | 1758 // cFormat = "99999-9999"; |
(...skipping 10 matching lines...) Expand all Loading... |
1803 cFormat = "9999999"; | 1769 cFormat = "9999999"; |
1804 break; | 1770 break; |
1805 } | 1771 } |
1806 case 3: | 1772 case 3: |
1807 // cFormat = "999-99-9999"; | 1773 // cFormat = "999-99-9999"; |
1808 cFormat = "999999999"; | 1774 cFormat = "999999999"; |
1809 break; | 1775 break; |
1810 } | 1776 } |
1811 | 1777 |
1812 CJS_Parameters params2; | 1778 CJS_Parameters params2; |
1813 CJS_Value vMask(isolate, cFormat.c_str()); | 1779 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str())); |
1814 params2.push_back(vMask); | |
1815 | |
1816 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); | 1780 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); |
1817 } | 1781 } |
1818 | 1782 |
1819 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, | 1783 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
1820 const CJS_Parameters& params, | 1784 const CJS_Parameters& params, |
1821 CJS_Value& vRet, | 1785 CJS_Value& vRet, |
1822 CFX_WideString& sError) { | 1786 CFX_WideString& sError) { |
1823 CJS_Context* pContext = (CJS_Context*)cc; | 1787 CJS_Context* pContext = (CJS_Context*)cc; |
1824 ASSERT(pContext != NULL); | 1788 ASSERT(pContext != NULL); |
1825 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); | 1789 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1917 return FALSE; | 1881 return FALSE; |
1918 } | 1882 } |
1919 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); | 1883 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); |
1920 return TRUE; | 1884 return TRUE; |
1921 } | 1885 } |
1922 | 1886 |
1923 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc, | 1887 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc, |
1924 const CJS_Parameters& params, | 1888 const CJS_Parameters& params, |
1925 CJS_Value& vRet, | 1889 CJS_Value& vRet, |
1926 CFX_WideString& sError) { | 1890 CFX_WideString& sError) { |
1927 v8::Isolate* isolate = ::GetIsolate(cc); | |
1928 | |
1929 CJS_Context* pContext = (CJS_Context*)cc; | 1891 CJS_Context* pContext = (CJS_Context*)cc; |
1930 ASSERT(pContext != NULL); | |
1931 | |
1932 if (params.size() != 2) { | 1892 if (params.size() != 2) { |
1933 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1893 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1934 return FALSE; | 1894 return FALSE; |
1935 } | 1895 } |
1936 | 1896 |
1937 CJS_Value params1 = params[1]; | 1897 CJS_Value params1 = params[1]; |
1938 | |
1939 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { | 1898 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { |
1940 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1899 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1941 return FALSE; | 1900 return FALSE; |
1942 } | 1901 } |
1943 | 1902 |
1944 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); | 1903 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); |
1945 ASSERT(pReaderDoc != NULL); | 1904 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); |
| 1905 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
1946 | 1906 |
1947 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); | 1907 CFX_WideString sFunction = params[0].ToCFXWideString(); |
1948 ASSERT(pReaderInterForm != NULL); | 1908 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; |
1949 | 1909 |
1950 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); | 1910 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1951 ASSERT(pInterForm != NULL); | 1911 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); |
1952 | |
1953 double dValue; | |
1954 CFX_WideString sFunction = params[0].ToCFXWideString(); | |
1955 if (wcscmp(sFunction.c_str(), L"PRD") == 0) | |
1956 dValue = 1.0; | |
1957 else | |
1958 dValue = 0.0; | |
1959 | |
1960 CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate, params1); | |
1961 | |
1962 int nFieldsCount = 0; | 1912 int nFieldsCount = 0; |
1963 | 1913 |
1964 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { | 1914 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { |
1965 CJS_Value jsValue(isolate); | 1915 CJS_Value jsValue(pRuntime); |
1966 FieldNameArray.GetElement(i, jsValue); | 1916 FieldNameArray.GetElement(i, jsValue); |
1967 CFX_WideString wsFieldName = jsValue.ToCFXWideString(); | 1917 CFX_WideString wsFieldName = jsValue.ToCFXWideString(); |
1968 | 1918 |
1969 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { | 1919 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { |
1970 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { | 1920 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { |
1971 double dTemp = 0.0; | 1921 double dTemp = 0.0; |
1972 | 1922 |
1973 switch (pFormField->GetFieldType()) { | 1923 switch (pFormField->GetFieldType()) { |
1974 case FIELDTYPE_TEXTFIELD: | 1924 case FIELDTYPE_TEXTFIELD: |
1975 case FIELDTYPE_COMBOBOX: { | 1925 case FIELDTYPE_COMBOBOX: { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 nFieldsCount++; | 1967 nFieldsCount++; |
2018 } | 1968 } |
2019 } | 1969 } |
2020 } | 1970 } |
2021 | 1971 |
2022 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) | 1972 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) |
2023 dValue /= nFieldsCount; | 1973 dValue /= nFieldsCount; |
2024 | 1974 |
2025 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / | 1975 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / |
2026 FXSYS_pow((double)10, (double)6); | 1976 FXSYS_pow((double)10, (double)6); |
2027 CJS_Value jsValue(isolate, dValue); | 1977 CJS_Value jsValue(pRuntime, dValue); |
2028 if (pContext->GetEventHandler()->m_pValue) | 1978 if (pContext->GetEventHandler()->m_pValue) |
2029 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(); | 1979 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(); |
2030 | 1980 |
2031 return TRUE; | 1981 return TRUE; |
2032 } | 1982 } |
2033 | 1983 |
2034 /* This function validates the current event to ensure that its value is | 1984 /* This function validates the current event to ensure that its value is |
2035 ** within the specified range. */ | 1985 ** within the specified range. */ |
2036 | 1986 |
2037 FX_BOOL CJS_PublicMethods::AFRange_Validate(IJS_Context* cc, | 1987 FX_BOOL CJS_PublicMethods::AFRange_Validate(IJS_Context* cc, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 Alert(pContext, swMsg.c_str()); | 2028 Alert(pContext, swMsg.c_str()); |
2079 pEvent->Rc() = FALSE; | 2029 pEvent->Rc() = FALSE; |
2080 } | 2030 } |
2081 return TRUE; | 2031 return TRUE; |
2082 } | 2032 } |
2083 | 2033 |
2084 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, | 2034 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
2085 const CJS_Parameters& params, | 2035 const CJS_Parameters& params, |
2086 CJS_Value& vRet, | 2036 CJS_Value& vRet, |
2087 CFX_WideString& sError) { | 2037 CFX_WideString& sError) { |
2088 v8::Isolate* isolate = ::GetIsolate(cc); | |
2089 CJS_Context* pContext = (CJS_Context*)cc; | 2038 CJS_Context* pContext = (CJS_Context*)cc; |
2090 ASSERT(pContext != NULL); | |
2091 | |
2092 if (params.size() != 1) { | 2039 if (params.size() != 1) { |
2093 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 2040 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
2094 return FALSE; | 2041 return FALSE; |
2095 } | 2042 } |
2096 | 2043 |
2097 CJS_Array nums(isolate); | 2044 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 2045 CJS_Array nums(pRuntime); |
2098 | 2046 |
2099 CFX_WideString str = params[0].ToCFXWideString(); | 2047 CFX_WideString str = params[0].ToCFXWideString(); |
2100 CFX_WideString sPart; | 2048 CFX_WideString sPart; |
2101 | 2049 |
2102 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 2050 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
2103 str = L"0" + str; | 2051 str = L"0" + str; |
2104 | 2052 |
2105 int nIndex = 0; | 2053 int nIndex = 0; |
2106 for (int i = 0, sz = str.GetLength(); i < sz; i++) { | 2054 for (int i = 0, sz = str.GetLength(); i < sz; i++) { |
2107 FX_WCHAR wc = str.GetAt(i); | 2055 FX_WCHAR wc = str.GetAt(i); |
2108 if (IsDigit((wchar_t)wc)) { | 2056 if (IsDigit((wchar_t)wc)) { |
2109 sPart += wc; | 2057 sPart += wc; |
2110 } else { | 2058 } else { |
2111 if (sPart.GetLength() > 0) { | 2059 if (sPart.GetLength() > 0) { |
2112 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); | 2060 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
2113 sPart = L""; | 2061 sPart = L""; |
2114 nIndex++; | 2062 nIndex++; |
2115 } | 2063 } |
2116 } | 2064 } |
2117 } | 2065 } |
2118 | 2066 |
2119 if (sPart.GetLength() > 0) { | 2067 if (sPart.GetLength() > 0) { |
2120 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); | 2068 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
2121 } | 2069 } |
2122 | 2070 |
2123 if (nums.GetLength() > 0) | 2071 if (nums.GetLength() > 0) |
2124 vRet = nums; | 2072 vRet = nums; |
2125 else | 2073 else |
2126 vRet.SetNull(); | 2074 vRet.SetNull(); |
2127 | 2075 |
2128 return TRUE; | 2076 return TRUE; |
2129 } | 2077 } |
OLD | NEW |