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 "xfa/fxfa/fm2js/xfa_fm2jscontext.h" | 7 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h" |
8 | 8 |
9 #include <time.h> | 9 #include <time.h> |
10 | 10 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 {8800, L"ne"}, {8801, L"equiv"}, {8804, L"le"}, | 242 {8800, L"ne"}, {8801, L"equiv"}, {8804, L"le"}, |
243 {8805, L"ge"}, {8834, L"sub"}, {8835, L"sup"}, | 243 {8805, L"ge"}, {8834, L"sub"}, {8835, L"sup"}, |
244 {8836, L"nsub"}, {8838, L"sube"}, {8839, L"supe"}, | 244 {8836, L"nsub"}, {8838, L"sube"}, {8839, L"supe"}, |
245 {8853, L"oplus"}, {8855, L"otimes"}, {8869, L"perp"}, | 245 {8853, L"oplus"}, {8855, L"otimes"}, {8869, L"perp"}, |
246 {8901, L"sdot"}, {8968, L"lceil"}, {8969, L"rceil"}, | 246 {8901, L"sdot"}, {8968, L"lceil"}, {8969, L"rceil"}, |
247 {8970, L"lfloor"}, {8971, L"rfloor"}, {9001, L"lang"}, | 247 {8970, L"lfloor"}, {8971, L"rfloor"}, {9001, L"lang"}, |
248 {9002, L"rang"}, {9674, L"loz"}, {9824, L"spades"}, | 248 {9002, L"rang"}, {9674, L"loz"}, {9824, L"spades"}, |
249 {9827, L"clubs"}, {9829, L"hearts"}, {9830, L"diams"}, | 249 {9827, L"clubs"}, {9829, L"hearts"}, {9830, L"diams"}, |
250 }; | 250 }; |
251 | 251 |
| 252 const uint8_t g_sAltTable_Date[] = { |
| 253 255, 255, 255, 3, 9, 255, 255, 255, 255, 255, 255, 255, 2, |
| 254 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 255, |
| 255 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 256 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 257 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 258 }; |
| 259 |
| 260 const uint8_t g_sAltTable_Time[] = { |
| 261 14, 255, 255, 3, 9, 255, 255, 15, 255, 255, 255, 255, 6, |
| 262 255, 255, 255, 255, 255, 7, 255, 255, 255, 255, 255, 1, 17, |
| 263 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 264 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 265 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 266 }; |
| 267 |
| 268 void AlternateDateTimeSymbols(CFX_WideString& wsPattern, |
| 269 const CFX_WideString& wsAltSymbols, |
| 270 const uint8_t* pAltTable) { |
| 271 int32_t nLength = wsPattern.GetLength(); |
| 272 FX_BOOL bInConstRange = FALSE; |
| 273 FX_BOOL bEscape = FALSE; |
| 274 int32_t i = 0, n = 0; |
| 275 while (i < nLength) { |
| 276 FX_WCHAR wc = wsPattern[i]; |
| 277 if (wc == L'\'') { |
| 278 bInConstRange = !bInConstRange; |
| 279 if (bEscape) { |
| 280 i++; |
| 281 } else { |
| 282 wsPattern.Delete(i); |
| 283 nLength--; |
| 284 } |
| 285 bEscape = !bEscape; |
| 286 continue; |
| 287 } |
| 288 if (!bInConstRange && (n = wc - L'A') >= 0 && n <= (L'a' - L'A')) { |
| 289 int32_t nAlt = (int32_t)pAltTable[n]; |
| 290 if (nAlt != 255) { |
| 291 wsPattern.SetAt(i, wsAltSymbols[nAlt]); |
| 292 } |
| 293 } |
| 294 i++; |
| 295 bEscape = FALSE; |
| 296 } |
| 297 } |
| 298 |
252 } // namespace | 299 } // namespace |
253 | 300 |
254 void CXFA_FM2JSContext::Abs(FXJSE_HOBJECT hThis, | 301 void CXFA_FM2JSContext::Abs(FXJSE_HOBJECT hThis, |
255 const CFX_ByteStringC& szFuncName, | 302 const CFX_ByteStringC& szFuncName, |
256 CFXJSE_Arguments& args) { | 303 CFXJSE_Arguments& args) { |
257 if (args.GetLength() == 1) { | 304 if (args.GetLength() == 1) { |
258 FXJSE_HVALUE argOne = args.GetValue(0); | 305 FXJSE_HVALUE argOne = args.GetValue(0); |
259 if (HValueIsNull(hThis, argOne)) { | 306 if (HValueIsNull(hThis, argOne)) { |
260 FXJSE_Value_SetNull(args.GetReturnValue()); | 307 FXJSE_Value_SetNull(args.GetReturnValue()); |
261 } else { | 308 } else { |
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 i = 0; | 2315 i = 0; |
2269 while (iDay - i > 0) { | 2316 while (iDay - i > 0) { |
2270 dDays += 1; | 2317 dDays += 1; |
2271 ++i; | 2318 ++i; |
2272 } | 2319 } |
2273 } else { | 2320 } else { |
2274 dDays = 0; | 2321 dDays = 0; |
2275 } | 2322 } |
2276 return (int32_t)dDays; | 2323 return (int32_t)dDays; |
2277 } | 2324 } |
2278 #define XFA_N 19 | 2325 |
2279 static uint8_t g_sAltTable_Date[] = { | |
2280 XFA_N, XFA_N, XFA_N, 3, 9, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2281 XFA_N, 2, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2282 XFA_N, XFA_N, 1, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2283 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2284 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2285 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2286 }; | |
2287 static uint8_t g_sAltTable_Time[] = { | |
2288 14, XFA_N, XFA_N, 3, 9, XFA_N, XFA_N, 15, XFA_N, XFA_N, XFA_N, | |
2289 XFA_N, 6, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, 7, XFA_N, XFA_N, XFA_N, | |
2290 XFA_N, XFA_N, 1, 17, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2291 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, 15, XFA_N, XFA_N, XFA_N, XFA_N, | |
2292 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2293 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, | |
2294 }; | |
2295 static void XFA_FM_AlternateDateTimeSymbols(CFX_WideString& wsPattern, | |
2296 const CFX_WideString& wsAltSymbols, | |
2297 uint8_t* pAltTable) { | |
2298 int32_t nLength = wsPattern.GetLength(); | |
2299 FX_BOOL bInConstRange = FALSE; | |
2300 FX_BOOL bEscape = FALSE; | |
2301 int32_t i = 0, n = 0; | |
2302 while (i < nLength) { | |
2303 FX_WCHAR wc = wsPattern[i]; | |
2304 if (wc == L'\'') { | |
2305 bInConstRange = !bInConstRange; | |
2306 if (bEscape) { | |
2307 i++; | |
2308 } else { | |
2309 wsPattern.Delete(i); | |
2310 nLength--; | |
2311 } | |
2312 bEscape = !bEscape; | |
2313 continue; | |
2314 } | |
2315 if (!bInConstRange && (n = wc - L'A') >= 0 && n <= (L'a' - L'A')) { | |
2316 int32_t nAlt = (int32_t)pAltTable[n]; | |
2317 if (nAlt != XFA_N) { | |
2318 wsPattern.SetAt(i, wsAltSymbols[nAlt]); | |
2319 } | |
2320 } | |
2321 i++; | |
2322 bEscape = FALSE; | |
2323 } | |
2324 } | |
2325 #undef XFA_N | |
2326 void CXFA_FM2JSContext::GetLocalDateFormat(FXJSE_HOBJECT hThis, | 2326 void CXFA_FM2JSContext::GetLocalDateFormat(FXJSE_HOBJECT hThis, |
2327 int32_t iStyle, | 2327 int32_t iStyle, |
2328 const CFX_ByteStringC& szLocalStr, | 2328 const CFX_ByteStringC& szLocalStr, |
2329 CFX_ByteString& strFormat, | 2329 CFX_ByteString& strFormat, |
2330 FX_BOOL bStandard) { | 2330 FX_BOOL bStandard) { |
2331 FX_LOCALEDATETIMESUBCATEGORY strStyle; | 2331 FX_LOCALEDATETIMESUBCATEGORY strStyle; |
2332 switch (iStyle) { | 2332 switch (iStyle) { |
2333 case 0: | 2333 case 0: |
2334 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; | 2334 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
2335 break; | 2335 break; |
(...skipping 30 matching lines...) Expand all Loading... |
2366 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); | 2366 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); |
2367 } | 2367 } |
2368 if (!pLocale) { | 2368 if (!pLocale) { |
2369 return; | 2369 return; |
2370 } | 2370 } |
2371 CFX_WideString strRet; | 2371 CFX_WideString strRet; |
2372 pLocale->GetDatePattern(strStyle, strRet); | 2372 pLocale->GetDatePattern(strStyle, strRet); |
2373 if (!bStandard) { | 2373 if (!bStandard) { |
2374 CFX_WideString wsSymbols; | 2374 CFX_WideString wsSymbols; |
2375 pLocale->GetDateTimeSymbols(wsSymbols); | 2375 pLocale->GetDateTimeSymbols(wsSymbols); |
2376 XFA_FM_AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); | 2376 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); |
2377 } | 2377 } |
2378 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); | 2378 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); |
2379 } | 2379 } |
2380 void CXFA_FM2JSContext::GetLocalTimeFormat(FXJSE_HOBJECT hThis, | 2380 void CXFA_FM2JSContext::GetLocalTimeFormat(FXJSE_HOBJECT hThis, |
2381 int32_t iStyle, | 2381 int32_t iStyle, |
2382 const CFX_ByteStringC& szLocalStr, | 2382 const CFX_ByteStringC& szLocalStr, |
2383 CFX_ByteString& strFormat, | 2383 CFX_ByteString& strFormat, |
2384 FX_BOOL bStandard) { | 2384 FX_BOOL bStandard) { |
2385 FX_LOCALEDATETIMESUBCATEGORY strStyle; | 2385 FX_LOCALEDATETIMESUBCATEGORY strStyle; |
2386 switch (iStyle) { | 2386 switch (iStyle) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2420 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); | 2420 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); |
2421 } | 2421 } |
2422 if (!pLocale) { | 2422 if (!pLocale) { |
2423 return; | 2423 return; |
2424 } | 2424 } |
2425 CFX_WideString strRet; | 2425 CFX_WideString strRet; |
2426 pLocale->GetTimePattern(strStyle, strRet); | 2426 pLocale->GetTimePattern(strStyle, strRet); |
2427 if (!bStandard) { | 2427 if (!bStandard) { |
2428 CFX_WideString wsSymbols; | 2428 CFX_WideString wsSymbols; |
2429 pLocale->GetDateTimeSymbols(wsSymbols); | 2429 pLocale->GetDateTimeSymbols(wsSymbols); |
2430 XFA_FM_AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); | 2430 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); |
2431 } | 2431 } |
2432 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); | 2432 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); |
2433 } | 2433 } |
2434 void CXFA_FM2JSContext::GetStandardDateFormat(FXJSE_HOBJECT hThis, | 2434 void CXFA_FM2JSContext::GetStandardDateFormat(FXJSE_HOBJECT hThis, |
2435 int32_t iStyle, | 2435 int32_t iStyle, |
2436 const CFX_ByteStringC& szLocalStr, | 2436 const CFX_ByteStringC& szLocalStr, |
2437 CFX_ByteString& strFormat) { | 2437 CFX_ByteString& strFormat) { |
2438 GetLocalDateFormat(hThis, iStyle, szLocalStr, strFormat, TRUE); | 2438 GetLocalDateFormat(hThis, iStyle, szLocalStr, strFormat, TRUE); |
2439 } | 2439 } |
2440 void CXFA_FM2JSContext::GetStandardTimeFormat(FXJSE_HOBJECT hThis, | 2440 void CXFA_FM2JSContext::GetStandardTimeFormat(FXJSE_HOBJECT hThis, |
(...skipping 4770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7211 CFX_WideString wsFormat; | 7211 CFX_WideString wsFormat; |
7212 pAppProvider->LoadString(iStringID, wsFormat); | 7212 pAppProvider->LoadString(iStringID, wsFormat); |
7213 CFX_WideString wsMessage; | 7213 CFX_WideString wsMessage; |
7214 va_list arg_ptr; | 7214 va_list arg_ptr; |
7215 va_start(arg_ptr, iStringID); | 7215 va_start(arg_ptr, iStringID); |
7216 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 7216 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
7217 va_end(arg_ptr); | 7217 va_end(arg_ptr); |
7218 FXJSE_ThrowMessage( | 7218 FXJSE_ThrowMessage( |
7219 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 7219 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
7220 } | 7220 } |
OLD | NEW |