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 19, 19, 19, 3, 9, 19, 19, 19, 19, 19, 19, 19, 2, 19, 19, 19, | |
Tom Sepez
2016/05/17 20:08:30
How about using 255 instead of 19? That might mak
dsinclair
2016/05/17 20:13:28
Done.
| |
254 19, 19, 19, 19, 19, 19, 19, 19, 1, 19, 19, 19, 19, 19, 19, 19, | |
255 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, | |
256 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, | |
257 }; | |
258 | |
259 const uint8_t g_sAltTable_Time[] = { | |
260 14, 19, 19, 3, 9, 19, 19, 15, 19, 19, 19, 19, 6, 19, 19, 19, | |
261 19, 19, 7, 19, 19, 19, 19, 19, 1, 17, 19, 19, 19, 19, 19, 19, | |
262 19, 19, 19, 19, 19, 19, 19, 15, 19, 19, 19, 19, 19, 19, 19, 19, | |
263 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, | |
264 }; | |
265 | |
266 void AlternateDateTimeSymbols(CFX_WideString& wsPattern, | |
267 const CFX_WideString& wsAltSymbols, | |
268 const uint8_t* pAltTable) { | |
269 int32_t nLength = wsPattern.GetLength(); | |
270 FX_BOOL bInConstRange = FALSE; | |
271 FX_BOOL bEscape = FALSE; | |
272 int32_t i = 0, n = 0; | |
273 while (i < nLength) { | |
274 FX_WCHAR wc = wsPattern[i]; | |
275 if (wc == L'\'') { | |
276 bInConstRange = !bInConstRange; | |
277 if (bEscape) { | |
278 i++; | |
279 } else { | |
280 wsPattern.Delete(i); | |
281 nLength--; | |
282 } | |
283 bEscape = !bEscape; | |
284 continue; | |
285 } | |
286 if (!bInConstRange && (n = wc - L'A') >= 0 && n <= (L'a' - L'A')) { | |
287 int32_t nAlt = (int32_t)pAltTable[n]; | |
288 if (nAlt != 19) { | |
289 wsPattern.SetAt(i, wsAltSymbols[nAlt]); | |
290 } | |
291 } | |
292 i++; | |
293 bEscape = FALSE; | |
294 } | |
295 } | |
296 | |
252 } // namespace | 297 } // namespace |
253 | 298 |
254 void CXFA_FM2JSContext::Abs(FXJSE_HOBJECT hThis, | 299 void CXFA_FM2JSContext::Abs(FXJSE_HOBJECT hThis, |
255 const CFX_ByteStringC& szFuncName, | 300 const CFX_ByteStringC& szFuncName, |
256 CFXJSE_Arguments& args) { | 301 CFXJSE_Arguments& args) { |
257 if (args.GetLength() == 1) { | 302 if (args.GetLength() == 1) { |
258 FXJSE_HVALUE argOne = args.GetValue(0); | 303 FXJSE_HVALUE argOne = args.GetValue(0); |
259 if (HValueIsNull(hThis, argOne)) { | 304 if (HValueIsNull(hThis, argOne)) { |
260 FXJSE_Value_SetNull(args.GetReturnValue()); | 305 FXJSE_Value_SetNull(args.GetReturnValue()); |
261 } else { | 306 } else { |
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2268 i = 0; | 2313 i = 0; |
2269 while (iDay - i > 0) { | 2314 while (iDay - i > 0) { |
2270 dDays += 1; | 2315 dDays += 1; |
2271 ++i; | 2316 ++i; |
2272 } | 2317 } |
2273 } else { | 2318 } else { |
2274 dDays = 0; | 2319 dDays = 0; |
2275 } | 2320 } |
2276 return (int32_t)dDays; | 2321 return (int32_t)dDays; |
2277 } | 2322 } |
2278 #define XFA_N 19 | 2323 |
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, | 2324 void CXFA_FM2JSContext::GetLocalDateFormat(FXJSE_HOBJECT hThis, |
2327 int32_t iStyle, | 2325 int32_t iStyle, |
2328 const CFX_ByteStringC& szLocalStr, | 2326 const CFX_ByteStringC& szLocalStr, |
2329 CFX_ByteString& strFormat, | 2327 CFX_ByteString& strFormat, |
2330 FX_BOOL bStandard) { | 2328 FX_BOOL bStandard) { |
2331 FX_LOCALEDATETIMESUBCATEGORY strStyle; | 2329 FX_LOCALEDATETIMESUBCATEGORY strStyle; |
2332 switch (iStyle) { | 2330 switch (iStyle) { |
2333 case 0: | 2331 case 0: |
2334 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; | 2332 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
2335 break; | 2333 break; |
(...skipping 30 matching lines...) Expand all Loading... | |
2366 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); | 2364 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); |
2367 } | 2365 } |
2368 if (!pLocale) { | 2366 if (!pLocale) { |
2369 return; | 2367 return; |
2370 } | 2368 } |
2371 CFX_WideString strRet; | 2369 CFX_WideString strRet; |
2372 pLocale->GetDatePattern(strStyle, strRet); | 2370 pLocale->GetDatePattern(strStyle, strRet); |
2373 if (!bStandard) { | 2371 if (!bStandard) { |
2374 CFX_WideString wsSymbols; | 2372 CFX_WideString wsSymbols; |
2375 pLocale->GetDateTimeSymbols(wsSymbols); | 2373 pLocale->GetDateTimeSymbols(wsSymbols); |
2376 XFA_FM_AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); | 2374 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); |
2377 } | 2375 } |
2378 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); | 2376 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); |
2379 } | 2377 } |
2380 void CXFA_FM2JSContext::GetLocalTimeFormat(FXJSE_HOBJECT hThis, | 2378 void CXFA_FM2JSContext::GetLocalTimeFormat(FXJSE_HOBJECT hThis, |
2381 int32_t iStyle, | 2379 int32_t iStyle, |
2382 const CFX_ByteStringC& szLocalStr, | 2380 const CFX_ByteStringC& szLocalStr, |
2383 CFX_ByteString& strFormat, | 2381 CFX_ByteString& strFormat, |
2384 FX_BOOL bStandard) { | 2382 FX_BOOL bStandard) { |
2385 FX_LOCALEDATETIMESUBCATEGORY strStyle; | 2383 FX_LOCALEDATETIMESUBCATEGORY strStyle; |
2386 switch (iStyle) { | 2384 switch (iStyle) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2420 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); | 2418 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); |
2421 } | 2419 } |
2422 if (!pLocale) { | 2420 if (!pLocale) { |
2423 return; | 2421 return; |
2424 } | 2422 } |
2425 CFX_WideString strRet; | 2423 CFX_WideString strRet; |
2426 pLocale->GetTimePattern(strStyle, strRet); | 2424 pLocale->GetTimePattern(strStyle, strRet); |
2427 if (!bStandard) { | 2425 if (!bStandard) { |
2428 CFX_WideString wsSymbols; | 2426 CFX_WideString wsSymbols; |
2429 pLocale->GetDateTimeSymbols(wsSymbols); | 2427 pLocale->GetDateTimeSymbols(wsSymbols); |
2430 XFA_FM_AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); | 2428 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); |
2431 } | 2429 } |
2432 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); | 2430 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); |
2433 } | 2431 } |
2434 void CXFA_FM2JSContext::GetStandardDateFormat(FXJSE_HOBJECT hThis, | 2432 void CXFA_FM2JSContext::GetStandardDateFormat(FXJSE_HOBJECT hThis, |
2435 int32_t iStyle, | 2433 int32_t iStyle, |
2436 const CFX_ByteStringC& szLocalStr, | 2434 const CFX_ByteStringC& szLocalStr, |
2437 CFX_ByteString& strFormat) { | 2435 CFX_ByteString& strFormat) { |
2438 GetLocalDateFormat(hThis, iStyle, szLocalStr, strFormat, TRUE); | 2436 GetLocalDateFormat(hThis, iStyle, szLocalStr, strFormat, TRUE); |
2439 } | 2437 } |
2440 void CXFA_FM2JSContext::GetStandardTimeFormat(FXJSE_HOBJECT hThis, | 2438 void CXFA_FM2JSContext::GetStandardTimeFormat(FXJSE_HOBJECT hThis, |
(...skipping 4770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7211 CFX_WideString wsFormat; | 7209 CFX_WideString wsFormat; |
7212 pAppProvider->LoadString(iStringID, wsFormat); | 7210 pAppProvider->LoadString(iStringID, wsFormat); |
7213 CFX_WideString wsMessage; | 7211 CFX_WideString wsMessage; |
7214 va_list arg_ptr; | 7212 va_list arg_ptr; |
7215 va_start(arg_ptr, iStringID); | 7213 va_start(arg_ptr, iStringID); |
7216 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 7214 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
7217 va_end(arg_ptr); | 7215 va_end(arg_ptr); |
7218 FXJSE_ThrowMessage( | 7216 FXJSE_ThrowMessage( |
7219 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 7217 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
7220 } | 7218 } |
OLD | NEW |