Index: core/src/fxge/ge/fx_ge_fontmap.cpp |
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp |
index b9850f85db810e7afc9638f522ce0d1ffe8a1015..3d8b7a77b3bae605a810463fb31ec63a1fb15a09 100644 |
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp |
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp |
@@ -4,6 +4,7 @@ |
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
+#include <algorithm> |
#include <limits> |
#include <vector> |
@@ -205,9 +206,9 @@ const struct CHARSET_MAP { |
{128, 932}, {134, 936}, {129, 949}, {136, 950}, {238, 1250}, |
{204, 1251}, {0, 1252}, {161, 1253}, {162, 1254}, {177, 1255}, |
{178, 1256}, {186, 1257}, {163, 1258}, {130, 1361}, {77, 10000}, |
- {78, 10001}, {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, |
- {84, 10004}, {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, |
- {89, 10007}, |
+ {78, 10001}, {81, 10002}, {79, 10003}, {84, 10004}, {83, 10005}, |
Lei Zhang
2016/02/25 20:11:27
Uhh, these weren't sorted by |codepage| value.
Tom Sepez
2016/02/25 20:32:53
But they were sorted by the wrong index value due
Lei Zhang
2016/02/25 20:48:16
No they weren't sorted by |charset| either.
|
+ {85, 10006}, {89, 10007}, {80, 10008}, {87, 10021}, {88, 10029}, |
+ {86, 10081}, |
}; |
const FX_DWORD kTableNAME = FXDWORD_GET_MSBFIRST("name"); |
@@ -281,21 +282,15 @@ CFX_ByteString FPDF_LoadTableFromTT(FXSYS_FILE* pFile, |
} |
uint8_t GetCharsetFromCodePage(FX_WORD codepage) { |
- int32_t iEnd = sizeof(g_Codepage2CharsetTable) / sizeof(CHARSET_MAP) - 1; |
- FXSYS_assert(iEnd >= 0); |
- int32_t iStart = 0, iMid; |
- do { |
- iMid = (iStart + iEnd) / 2; |
- const CHARSET_MAP& cp = g_Codepage2CharsetTable[iMid]; |
- if (codepage == cp.codepage) { |
- return cp.charset; |
- } |
- if (codepage < cp.codepage) { |
- iEnd = iMid - 1; |
- } else { |
- iStart = iMid + 1; |
- } |
- } while (iStart <= iEnd); |
+ const CHARSET_MAP* pEnd = |
+ g_Codepage2CharsetTable + FX_ArraySize(g_Codepage2CharsetTable); |
+ const CHARSET_MAP* pCharmap = |
+ std::lower_bound(g_Codepage2CharsetTable, pEnd, codepage, |
Tom Sepez
2016/02/25 20:32:53
std::binary_search() for an exact hit and avoid th
Lei Zhang
2016/02/25 20:48:16
std::binary_search() returns a bool, not an iterat
Tom Sepez
2016/02/25 22:20:13
Ah, Carry on.
|
+ [](const CHARSET_MAP& charset, FX_WORD page) { |
+ return charset.codepage < page; |
+ }); |
+ if (pCharmap < pEnd && codepage == pCharmap->codepage) |
+ return pCharmap->charset; |
return 1; |
} |