| 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 "core/fxcrt/include/fx_ext.h" | 7 #include "core/fxcrt/include/fx_ext.h" |
| 8 #include "xfa/fgas/crt/fgas_codepage.h" | 8 #include "xfa/fgas/crt/fgas_codepage.h" |
| 9 #include "xfa/fgas/crt/fgas_language.h" | 9 #include "xfa/fgas/crt/fgas_language.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { | 28 const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { |
| 29 {0, 1252}, {1, 0}, {2, 42}, {77, 10000}, {78, 10001}, | 29 {0, 1252}, {1, 0}, {2, 42}, {77, 10000}, {78, 10001}, |
| 30 {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, {84, 10004}, | 30 {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, {84, 10004}, |
| 31 {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, {89, 10007}, | 31 {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, {89, 10007}, |
| 32 {128, 932}, {129, 949}, {130, 1361}, {134, 936}, {136, 950}, | 32 {128, 932}, {129, 949}, {130, 1361}, {134, 936}, {136, 950}, |
| 33 {161, 1253}, {162, 1254}, {163, 1258}, {177, 1255}, {178, 1256}, | 33 {161, 1253}, {162, 1254}, {163, 1258}, {177, 1255}, {178, 1256}, |
| 34 {186, 1257}, {204, 1251}, {222, 874}, {238, 1250}, {254, 437}, | 34 {186, 1257}, {204, 1251}, {222, 874}, {238, 1250}, {254, 437}, |
| 35 {255, 850}, | 35 {255, 850}, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 const FX_CHARSET_MAP g_FXCodepage2CharsetTable[] = { | |
| 39 {1, 0}, {2, 42}, {254, 437}, {255, 850}, {222, 874}, | |
| 40 {128, 932}, {134, 936}, {129, 949}, {136, 950}, {238, 1250}, | |
| 41 {204, 1251}, {0, 1252}, {161, 1253}, {162, 1254}, {177, 1255}, | |
| 42 {178, 1256}, {186, 1257}, {163, 1258}, {130, 1361}, {77, 10000}, | |
| 43 {78, 10001}, {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, | |
| 44 {84, 10004}, {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, | |
| 45 {89, 10007}, | |
| 46 }; | |
| 47 | |
| 48 const FX_LANG2CPMAP g_FXLang2CodepageTable[] = { | 38 const FX_LANG2CPMAP g_FXLang2CodepageTable[] = { |
| 49 {FX_LANG_Arabic_SaudiArabia, FX_CODEPAGE_MSWin_Arabic}, | 39 {FX_LANG_Arabic_SaudiArabia, FX_CODEPAGE_MSWin_Arabic}, |
| 50 {FX_LANG_Bulgarian_Bulgaria, FX_CODEPAGE_MSWin_Cyrillic}, | 40 {FX_LANG_Bulgarian_Bulgaria, FX_CODEPAGE_MSWin_Cyrillic}, |
| 51 {FX_LANG_Catalan_Catalan, FX_CODEPAGE_MSWin_WesternEuropean}, | 41 {FX_LANG_Catalan_Catalan, FX_CODEPAGE_MSWin_WesternEuropean}, |
| 52 {FX_LANG_Chinese_Taiwan, FX_CODEPAGE_ChineseTraditional}, | 42 {FX_LANG_Chinese_Taiwan, FX_CODEPAGE_ChineseTraditional}, |
| 53 {FX_LANG_CzechRepublic, FX_CODEPAGE_MSWin_EasternEuropean}, | 43 {FX_LANG_CzechRepublic, FX_CODEPAGE_MSWin_EasternEuropean}, |
| 54 {FX_LANG_Danish_Denmark, FX_CODEPAGE_MSWin_WesternEuropean}, | 44 {FX_LANG_Danish_Denmark, FX_CODEPAGE_MSWin_WesternEuropean}, |
| 55 {FX_LANG_German_Germany, FX_CODEPAGE_MSWin_WesternEuropean}, | 45 {FX_LANG_German_Germany, FX_CODEPAGE_MSWin_WesternEuropean}, |
| 56 {FX_LANG_Greek_Greece, FX_CODEPAGE_MSWin_Greek}, | 46 {FX_LANG_Greek_Greece, FX_CODEPAGE_MSWin_Greek}, |
| 57 {FX_LANG_English_UnitedStates, FX_CODEPAGE_MSWin_WesternEuropean}, | 47 {FX_LANG_English_UnitedStates, FX_CODEPAGE_MSWin_WesternEuropean}, |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 return cp.codepage; | 300 return cp.codepage; |
| 311 } else if (charset < cp.charset) { | 301 } else if (charset < cp.charset) { |
| 312 iEnd = iMid - 1; | 302 iEnd = iMid - 1; |
| 313 } else { | 303 } else { |
| 314 iStart = iMid + 1; | 304 iStart = iMid + 1; |
| 315 } | 305 } |
| 316 } while (iStart <= iEnd); | 306 } while (iStart <= iEnd); |
| 317 return 0xFFFF; | 307 return 0xFFFF; |
| 318 } | 308 } |
| 319 | 309 |
| 320 uint16_t FX_GetCharsetFromCodePage(uint16_t codepage) { | |
| 321 int32_t iEnd = sizeof(g_FXCodepage2CharsetTable) / sizeof(FX_CHARSET_MAP) - 1; | |
| 322 ASSERT(iEnd >= 0); | |
| 323 int32_t iStart = 0, iMid; | |
| 324 do { | |
| 325 iMid = (iStart + iEnd) / 2; | |
| 326 const FX_CHARSET_MAP& cp = g_FXCodepage2CharsetTable[iMid]; | |
| 327 if (codepage == cp.codepage) { | |
| 328 return cp.charset; | |
| 329 } else if (codepage < cp.codepage) { | |
| 330 iEnd = iMid - 1; | |
| 331 } else { | |
| 332 iStart = iMid + 1; | |
| 333 } | |
| 334 } while (iStart <= iEnd); | |
| 335 return 0xFFFF; | |
| 336 } | |
| 337 | |
| 338 uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage) { | 310 uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage) { |
| 339 int32_t iEnd = sizeof(g_FXLang2CodepageTable) / sizeof(FX_LANG2CPMAP) - 1; | 311 int32_t iEnd = sizeof(g_FXLang2CodepageTable) / sizeof(FX_LANG2CPMAP) - 1; |
| 340 ASSERT(iEnd >= 0); | 312 ASSERT(iEnd >= 0); |
| 341 int32_t iStart = 0, iMid; | 313 int32_t iStart = 0, iMid; |
| 342 do { | 314 do { |
| 343 iMid = (iStart + iEnd) / 2; | 315 iMid = (iStart + iEnd) / 2; |
| 344 const FX_LANG2CPMAP& cp = g_FXLang2CodepageTable[iMid]; | 316 const FX_LANG2CPMAP& cp = g_FXLang2CodepageTable[iMid]; |
| 345 if (wLanguage == cp.wLanguage) { | 317 if (wLanguage == cp.wLanguage) { |
| 346 return cp.wCodepage; | 318 return cp.wCodepage; |
| 347 } else if (wLanguage < cp.wLanguage) { | 319 } else if (wLanguage < cp.wLanguage) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 if (sizeof(FX_WCHAR) == 2) { | 368 if (sizeof(FX_WCHAR) == 2) { |
| 397 return; | 369 return; |
| 398 } | 370 } |
| 399 uint16_t* pSrc = (uint16_t*)pBuffer; | 371 uint16_t* pSrc = (uint16_t*)pBuffer; |
| 400 FX_WCHAR* pDst = (FX_WCHAR*)pBuffer; | 372 FX_WCHAR* pDst = (FX_WCHAR*)pBuffer; |
| 401 while (--iLength >= 0) { | 373 while (--iLength >= 0) { |
| 402 pDst[iLength] = (FX_WCHAR)pSrc[iLength]; | 374 pDst[iLength] = (FX_WCHAR)pSrc[iLength]; |
| 403 } | 375 } |
| 404 } | 376 } |
| 405 | 377 |
| 406 void FX_WCharToUTF16(void* pBuffer, int32_t iLength) { | |
| 407 ASSERT(pBuffer && iLength > 0); | |
| 408 if (sizeof(FX_WCHAR) == 2) { | |
| 409 return; | |
| 410 } | |
| 411 const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer; | |
| 412 uint16_t* pDst = (uint16_t*)pBuffer; | |
| 413 while (--iLength >= 0) { | |
| 414 *pDst++ = (uint16_t)*pSrc++; | |
| 415 } | |
| 416 } | |
| 417 | |
| 418 int32_t FX_DecodeString(uint16_t wCodePage, | 378 int32_t FX_DecodeString(uint16_t wCodePage, |
| 419 const FX_CHAR* pSrc, | 379 const FX_CHAR* pSrc, |
| 420 int32_t* pSrcLen, | 380 int32_t* pSrcLen, |
| 421 FX_WCHAR* pDst, | 381 FX_WCHAR* pDst, |
| 422 int32_t* pDstLen, | 382 int32_t* pDstLen, |
| 423 FX_BOOL bErrBreak) { | 383 FX_BOOL bErrBreak) { |
| 424 if (wCodePage == FX_CODEPAGE_UTF8) { | 384 if (wCodePage == FX_CODEPAGE_UTF8) { |
| 425 return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen); | 385 return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen); |
| 426 } | 386 } |
| 427 return -1; | 387 return -1; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 dwCode = (byte & 0x01) << 30; | 457 dwCode = (byte & 0x01) << 30; |
| 498 } else { | 458 } else { |
| 499 break; | 459 break; |
| 500 } | 460 } |
| 501 iIndex++; | 461 iIndex++; |
| 502 } | 462 } |
| 503 *pSrcLen = iSrcNum; | 463 *pSrcLen = iSrcNum; |
| 504 *pDstLen = iDstNum; | 464 *pDstLen = iDstNum; |
| 505 return 1; | 465 return 1; |
| 506 } | 466 } |
| OLD | NEW |