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/include/fxcrt/fx_ext.h" | 7 #include "core/include/fxcrt/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 |
11 static const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { | 11 static const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = { |
12 {0, 1252}, {1, 0}, {2, 42}, {77, 10000}, {78, 10001}, | 12 {0, 1252}, {1, 0}, {2, 42}, {77, 10000}, {78, 10001}, |
13 {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, {84, 10004}, | 13 {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, {84, 10004}, |
14 {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, {89, 10007}, | 14 {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, {89, 10007}, |
15 {128, 932}, {129, 949}, {130, 1361}, {134, 936}, {136, 950}, | 15 {128, 932}, {129, 949}, {130, 1361}, {134, 936}, {136, 950}, |
16 {161, 1253}, {162, 1254}, {163, 1258}, {177, 1255}, {178, 1256}, | 16 {161, 1253}, {162, 1254}, {163, 1258}, {177, 1255}, {178, 1256}, |
17 {186, 1257}, {204, 1251}, {222, 874}, {238, 1250}, {254, 437}, | 17 {186, 1257}, {204, 1251}, {222, 874}, {238, 1250}, {254, 437}, |
18 {255, 850}, | 18 {255, 850}, |
19 }; | 19 }; |
20 FX_WORD FX_GetCodePageFromCharset(uint8_t charset) { | 20 uint16_t FX_GetCodePageFromCharset(uint8_t charset) { |
21 int32_t iEnd = sizeof(g_FXCharset2CodePageTable) / sizeof(FX_CHARSET_MAP) - 1; | 21 int32_t iEnd = sizeof(g_FXCharset2CodePageTable) / sizeof(FX_CHARSET_MAP) - 1; |
22 FXSYS_assert(iEnd >= 0); | 22 FXSYS_assert(iEnd >= 0); |
23 int32_t iStart = 0, iMid; | 23 int32_t iStart = 0, iMid; |
24 do { | 24 do { |
25 iMid = (iStart + iEnd) / 2; | 25 iMid = (iStart + iEnd) / 2; |
26 const FX_CHARSET_MAP& cp = g_FXCharset2CodePageTable[iMid]; | 26 const FX_CHARSET_MAP& cp = g_FXCharset2CodePageTable[iMid]; |
27 if (charset == cp.charset) { | 27 if (charset == cp.charset) { |
28 return cp.codepage; | 28 return cp.codepage; |
29 } else if (charset < cp.charset) { | 29 } else if (charset < cp.charset) { |
30 iEnd = iMid - 1; | 30 iEnd = iMid - 1; |
31 } else { | 31 } else { |
32 iStart = iMid + 1; | 32 iStart = iMid + 1; |
33 } | 33 } |
34 } while (iStart <= iEnd); | 34 } while (iStart <= iEnd); |
35 return 0xFFFF; | 35 return 0xFFFF; |
36 } | 36 } |
37 static const FX_CHARSET_MAP g_FXCodepage2CharsetTable[] = { | 37 static const FX_CHARSET_MAP g_FXCodepage2CharsetTable[] = { |
38 {1, 0}, {2, 42}, {254, 437}, {255, 850}, {222, 874}, | 38 {1, 0}, {2, 42}, {254, 437}, {255, 850}, {222, 874}, |
39 {128, 932}, {134, 936}, {129, 949}, {136, 950}, {238, 1250}, | 39 {128, 932}, {134, 936}, {129, 949}, {136, 950}, {238, 1250}, |
40 {204, 1251}, {0, 1252}, {161, 1253}, {162, 1254}, {177, 1255}, | 40 {204, 1251}, {0, 1252}, {161, 1253}, {162, 1254}, {177, 1255}, |
41 {178, 1256}, {186, 1257}, {163, 1258}, {130, 1361}, {77, 10000}, | 41 {178, 1256}, {186, 1257}, {163, 1258}, {130, 1361}, {77, 10000}, |
42 {78, 10001}, {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, | 42 {78, 10001}, {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, |
43 {84, 10004}, {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, | 43 {84, 10004}, {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, |
44 {89, 10007}, | 44 {89, 10007}, |
45 }; | 45 }; |
46 FX_WORD FX_GetCharsetFromCodePage(FX_WORD codepage) { | 46 uint16_t FX_GetCharsetFromCodePage(uint16_t codepage) { |
47 int32_t iEnd = sizeof(g_FXCodepage2CharsetTable) / sizeof(FX_CHARSET_MAP) - 1; | 47 int32_t iEnd = sizeof(g_FXCodepage2CharsetTable) / sizeof(FX_CHARSET_MAP) - 1; |
48 FXSYS_assert(iEnd >= 0); | 48 FXSYS_assert(iEnd >= 0); |
49 int32_t iStart = 0, iMid; | 49 int32_t iStart = 0, iMid; |
50 do { | 50 do { |
51 iMid = (iStart + iEnd) / 2; | 51 iMid = (iStart + iEnd) / 2; |
52 const FX_CHARSET_MAP& cp = g_FXCodepage2CharsetTable[iMid]; | 52 const FX_CHARSET_MAP& cp = g_FXCodepage2CharsetTable[iMid]; |
53 if (codepage == cp.codepage) { | 53 if (codepage == cp.codepage) { |
54 return cp.charset; | 54 return cp.charset; |
55 } else if (codepage < cp.codepage) { | 55 } else if (codepage < cp.codepage) { |
56 iEnd = iMid - 1; | 56 iEnd = iMid - 1; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 {FX_LANG_Spanish_Uruguay, FX_CODEPAGE_MSWin_WesternEuropean}, | 190 {FX_LANG_Spanish_Uruguay, FX_CODEPAGE_MSWin_WesternEuropean}, |
191 {FX_LANG_Arabic_Bahrain, FX_CODEPAGE_MSWin_Arabic}, | 191 {FX_LANG_Arabic_Bahrain, FX_CODEPAGE_MSWin_Arabic}, |
192 {FX_LANG_Spanish_Paraguay, FX_CODEPAGE_MSWin_WesternEuropean}, | 192 {FX_LANG_Spanish_Paraguay, FX_CODEPAGE_MSWin_WesternEuropean}, |
193 {FX_LANG_Arabic_Qatar, FX_CODEPAGE_MSWin_Arabic}, | 193 {FX_LANG_Arabic_Qatar, FX_CODEPAGE_MSWin_Arabic}, |
194 {FX_LANG_Spanish_Bolivia, FX_CODEPAGE_MSWin_WesternEuropean}, | 194 {FX_LANG_Spanish_Bolivia, FX_CODEPAGE_MSWin_WesternEuropean}, |
195 {FX_LANG_Spanish_ElSalvador, FX_CODEPAGE_MSWin_WesternEuropean}, | 195 {FX_LANG_Spanish_ElSalvador, FX_CODEPAGE_MSWin_WesternEuropean}, |
196 {FX_LANG_Spanish_Honduras, FX_CODEPAGE_MSWin_WesternEuropean}, | 196 {FX_LANG_Spanish_Honduras, FX_CODEPAGE_MSWin_WesternEuropean}, |
197 {FX_LANG_Spanish_Nicaragua, FX_CODEPAGE_MSWin_WesternEuropean}, | 197 {FX_LANG_Spanish_Nicaragua, FX_CODEPAGE_MSWin_WesternEuropean}, |
198 {FX_LANG_Spanish_PuertoRico, FX_CODEPAGE_MSWin_WesternEuropean}, | 198 {FX_LANG_Spanish_PuertoRico, FX_CODEPAGE_MSWin_WesternEuropean}, |
199 }; | 199 }; |
200 FX_WORD FX_GetDefCodePageByLanguage(FX_WORD wLanguage) { | 200 uint16_t FX_GetDefCodePageByLanguage(uint16_t wLanguage) { |
201 int32_t iEnd = sizeof(g_FXLang2CodepageTable) / sizeof(FX_LANG2CPMAP) - 1; | 201 int32_t iEnd = sizeof(g_FXLang2CodepageTable) / sizeof(FX_LANG2CPMAP) - 1; |
202 FXSYS_assert(iEnd >= 0); | 202 FXSYS_assert(iEnd >= 0); |
203 int32_t iStart = 0, iMid; | 203 int32_t iStart = 0, iMid; |
204 do { | 204 do { |
205 iMid = (iStart + iEnd) / 2; | 205 iMid = (iStart + iEnd) / 2; |
206 const FX_LANG2CPMAP& cp = g_FXLang2CodepageTable[iMid]; | 206 const FX_LANG2CPMAP& cp = g_FXLang2CodepageTable[iMid]; |
207 if (wLanguage == cp.wLanguage) { | 207 if (wLanguage == cp.wLanguage) { |
208 return cp.wCodepage; | 208 return cp.wCodepage; |
209 } else if (wLanguage < cp.wLanguage) { | 209 } else if (wLanguage < cp.wLanguage) { |
210 iEnd = iMid - 1; | 210 iEnd = iMid - 1; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 {0xdd80a61a, 0x3b5}, {0xdd80c0f8, 0x4e9f}, {0xdf7e46ff, 0x4fc8}, | 294 {0xdd80a61a, 0x3b5}, {0xdd80c0f8, 0x4e9f}, {0xdf7e46ff, 0x4fc8}, |
295 {0xdf8680fd, 0x556a}, {0xdfb0bd6e, 0xc42d}, {0xdff05486, 0x2c4}, | 295 {0xdf8680fd, 0x556a}, {0xdfb0bd6e, 0xc42d}, {0xdff05486, 0x2c4}, |
296 {0xe3323399, 0x3a4}, {0xe60412dd, 0x3b5}, {0xeee47add, 0x4b0}, | 296 {0xe3323399, 0x3a4}, {0xe60412dd, 0x3b5}, {0xeee47add, 0x4b0}, |
297 {0xf021a186, 0x4e2}, {0xf021a187, 0x4e3}, {0xf021a188, 0x4e4}, | 297 {0xf021a186, 0x4e2}, {0xf021a187, 0x4e3}, {0xf021a188, 0x4e4}, |
298 {0xf021a189, 0x4e5}, {0xf021a18a, 0x4e6}, {0xf021a18b, 0x4e7}, | 298 {0xf021a189, 0x4e5}, {0xf021a18a, 0x4e6}, {0xf021a18b, 0x4e7}, |
299 {0xf021a18c, 0x4e8}, {0xf021a18d, 0x4e9}, {0xf021a18e, 0x4ea}, | 299 {0xf021a18c, 0x4e8}, {0xf021a18d, 0x4e9}, {0xf021a18e, 0x4ea}, |
300 {0xf0700456, 0x6fb3}, {0xf274f175, 0x3b5}, {0xf2a9730b, 0x3a8}, | 300 {0xf0700456, 0x6fb3}, {0xf274f175, 0x3b5}, {0xf2a9730b, 0x3a8}, |
301 {0xf3d463c2, 0x3a4}, {0xf52a70a3, 0xc42e}, {0xf5693147, 0x6fb3}, | 301 {0xf3d463c2, 0x3a4}, {0xf52a70a3, 0xc42e}, {0xf5693147, 0x6fb3}, |
302 {0xf637e157, 0x478}, {0xfc213f3a, 0x2717}, {0xff654d14, 0x3b5}, | 302 {0xf637e157, 0x478}, {0xfc213f3a, 0x2717}, {0xff654d14, 0x3b5}, |
303 }; | 303 }; |
304 FX_WORD FX_GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) { | 304 uint16_t FX_GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) { |
305 FXSYS_assert(pStr != NULL); | 305 FXSYS_assert(pStr != NULL); |
306 if (iLength < 0) { | 306 if (iLength < 0) { |
307 iLength = FXSYS_strlen(pStr); | 307 iLength = FXSYS_strlen(pStr); |
308 } | 308 } |
309 if (iLength == 0) { | 309 if (iLength == 0) { |
310 return 0xFFFF; | 310 return 0xFFFF; |
311 } | 311 } |
312 uint32_t uHash = FX_HashCode_String_GetA(pStr, iLength, TRUE); | 312 uint32_t uHash = FX_HashCode_String_GetA(pStr, iLength, TRUE); |
313 int32_t iStart = 0, iMid; | 313 int32_t iStart = 0, iMid; |
314 int32_t iEnd = sizeof(g_FXCPHashTable) / sizeof(FX_STR2CPHASH) - 1; | 314 int32_t iEnd = sizeof(g_FXCPHashTable) / sizeof(FX_STR2CPHASH) - 1; |
315 FXSYS_assert(iEnd >= 0); | 315 FXSYS_assert(iEnd >= 0); |
316 do { | 316 do { |
317 iMid = (iStart + iEnd) / 2; | 317 iMid = (iStart + iEnd) / 2; |
318 const FX_STR2CPHASH& cp = g_FXCPHashTable[iMid]; | 318 const FX_STR2CPHASH& cp = g_FXCPHashTable[iMid]; |
319 if (uHash == cp.uHash) { | 319 if (uHash == cp.uHash) { |
320 return (FX_WORD)cp.uCodePage; | 320 return (uint16_t)cp.uCodePage; |
321 } else if (uHash < cp.uHash) { | 321 } else if (uHash < cp.uHash) { |
322 iEnd = iMid - 1; | 322 iEnd = iMid - 1; |
323 } else { | 323 } else { |
324 iStart = iMid + 1; | 324 iStart = iMid + 1; |
325 } | 325 } |
326 } while (iStart <= iEnd); | 326 } while (iStart <= iEnd); |
327 return 0xFFFF; | 327 return 0xFFFF; |
328 } | 328 } |
329 FX_WORD FX_GetCodePageFormStringW(const FX_WCHAR* pStr, int32_t iLength) { | 329 uint16_t FX_GetCodePageFormStringW(const FX_WCHAR* pStr, int32_t iLength) { |
330 if (iLength < 0) { | 330 if (iLength < 0) { |
331 iLength = FXSYS_wcslen(pStr); | 331 iLength = FXSYS_wcslen(pStr); |
332 } | 332 } |
333 if (iLength == 0) { | 333 if (iLength == 0) { |
334 return 0xFFFF; | 334 return 0xFFFF; |
335 } | 335 } |
336 CFX_ByteString csStr; | 336 CFX_ByteString csStr; |
337 FX_CHAR* pBuf = csStr.GetBuffer(iLength + 1); | 337 FX_CHAR* pBuf = csStr.GetBuffer(iLength + 1); |
338 for (int32_t i = 0; i < iLength; ++i) { | 338 for (int32_t i = 0; i < iLength; ++i) { |
339 *pBuf++ = (FX_CHAR)*pStr++; | 339 *pBuf++ = (FX_CHAR)*pStr++; |
340 } | 340 } |
341 csStr.ReleaseBuffer(iLength); | 341 csStr.ReleaseBuffer(iLength); |
342 return FX_GetCodePageFromStringA(csStr, iLength); | 342 return FX_GetCodePageFromStringA(csStr, iLength); |
343 } | 343 } |
OLD | NEW |