diff options
author | Lei Zhang <thestig@chromium.org> | 2016-02-25 14:35:23 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2016-02-25 14:35:23 -0800 |
commit | f8e21f34e9b67c5b9e754e949c58a5113ea4d746 (patch) | |
tree | d6d2c774ae099320c41fab43cfa4857f1274aa25 /core | |
parent | 198362223d2257ded96895bd91df2bea422f361e (diff) | |
download | pdfium-f8e21f34e9b67c5b9e754e949c58a5113ea4d746.tar.xz |
Use std::lower_bound() in a couple places.
Do some cleanups along the way.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1732223002 .
Diffstat (limited to 'core')
-rw-r--r-- | core/src/fxge/ge/fx_ge_fontmap.cpp | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp index b9850f85db..06b58ea3ab 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> @@ -197,17 +198,17 @@ const struct FX_FontStyle { {"Bold", 4}, {"Italic", 6}, {"BoldItalic", 10}, {"Reg", 3}, {"Regular", 7}, }; -const struct CHARSET_MAP { - uint8_t charset; +const struct CODEPAGE_MAP { FX_WORD codepage; + uint8_t charset; } g_Codepage2CharsetTable[] = { - {1, 0}, {2, 42}, {254, 437}, {255, 850}, {222, 874}, - {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}, + {0, 1}, {42, 2}, {437, 254}, {850, 255}, {874, 222}, + {932, 128}, {936, 134}, {949, 129}, {950, 136}, {1250, 238}, + {1251, 204}, {1252, 0}, {1253, 161}, {1254, 162}, {1255, 177}, + {1256, 178}, {1257, 186}, {1258, 163}, {1361, 130}, {10000, 77}, + {10001, 78}, {10002, 81}, {10003, 79}, {10004, 84}, {10005, 83}, + {10006, 85}, {10007, 89}, {10008, 80}, {10021, 87}, {10029, 88}, + {10081, 86}, }; 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 CODEPAGE_MAP* pEnd = + g_Codepage2CharsetTable + FX_ArraySize(g_Codepage2CharsetTable); + const CODEPAGE_MAP* pCharmap = + std::lower_bound(g_Codepage2CharsetTable, pEnd, codepage, + [](const CODEPAGE_MAP& charset, FX_WORD page) { + return charset.codepage < page; + }); + if (pCharmap < pEnd && codepage == pCharmap->codepage) + return pCharmap->charset; return 1; } |