Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: core/src/fxge/ge/fx_ge_fontmap.cpp

Issue 1732223002: Use std::lower_bound() in a couple places. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | xfa/src/fgas/src/localization/fx_locale.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm>
7 #include <limits> 8 #include <limits>
8 #include <vector> 9 #include <vector>
9 10
10 #include "core/include/fxge/fx_freetype.h" 11 #include "core/include/fxge/fx_freetype.h"
11 #include "core/include/fxge/fx_ge.h" 12 #include "core/include/fxge/fx_ge.h"
12 #include "core/src/fxge/fontdata/chromefontdata/chromefontdata.h" 13 #include "core/src/fxge/fontdata/chromefontdata/chromefontdata.h"
13 #include "core/src/fxge/ge/fx_text_int.h" 14 #include "core/src/fxge/ge/fx_text_int.h"
14 #include "third_party/base/stl_util.h" 15 #include "third_party/base/stl_util.h"
15 16
16 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1]) 17 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1])
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 {"ForteMT", "Forte"}, 191 {"ForteMT", "Forte"},
191 }; 192 };
192 193
193 const struct FX_FontStyle { 194 const struct FX_FontStyle {
194 const FX_CHAR* style; 195 const FX_CHAR* style;
195 int32_t len; 196 int32_t len;
196 } g_FontStyles[] = { 197 } g_FontStyles[] = {
197 {"Bold", 4}, {"Italic", 6}, {"BoldItalic", 10}, {"Reg", 3}, {"Regular", 7}, 198 {"Bold", 4}, {"Italic", 6}, {"BoldItalic", 10}, {"Reg", 3}, {"Regular", 7},
198 }; 199 };
199 200
200 const struct CHARSET_MAP { 201 const struct CODEPAGE_MAP {
202 FX_WORD codepage;
201 uint8_t charset; 203 uint8_t charset;
202 FX_WORD codepage;
203 } g_Codepage2CharsetTable[] = { 204 } g_Codepage2CharsetTable[] = {
204 {1, 0}, {2, 42}, {254, 437}, {255, 850}, {222, 874}, 205 {0, 1}, {42, 2}, {437, 254}, {850, 255}, {874, 222},
205 {128, 932}, {134, 936}, {129, 949}, {136, 950}, {238, 1250}, 206 {932, 128}, {936, 134}, {949, 129}, {950, 136}, {1250, 238},
206 {204, 1251}, {0, 1252}, {161, 1253}, {162, 1254}, {177, 1255}, 207 {1251, 204}, {1252, 0}, {1253, 161}, {1254, 162}, {1255, 177},
207 {178, 1256}, {186, 1257}, {163, 1258}, {130, 1361}, {77, 10000}, 208 {1256, 178}, {1257, 186}, {1258, 163}, {1361, 130}, {10000, 77},
208 {78, 10001}, {79, 10003}, {80, 10008}, {81, 10002}, {83, 10005}, 209 {10001, 78}, {10002, 81}, {10003, 79}, {10004, 84}, {10005, 83},
209 {84, 10004}, {85, 10006}, {86, 10081}, {87, 10021}, {88, 10029}, 210 {10006, 85}, {10007, 89}, {10008, 80}, {10021, 87}, {10029, 88},
210 {89, 10007}, 211 {10081, 86},
211 }; 212 };
212 213
213 const FX_DWORD kTableNAME = FXDWORD_GET_MSBFIRST("name"); 214 const FX_DWORD kTableNAME = FXDWORD_GET_MSBFIRST("name");
214 const FX_DWORD kTableTTCF = FXDWORD_GET_MSBFIRST("ttcf"); 215 const FX_DWORD kTableTTCF = FXDWORD_GET_MSBFIRST("ttcf");
215 216
216 int CompareFontFamilyString(const void* key, const void* element) { 217 int CompareFontFamilyString(const void* key, const void* element) {
217 CFX_ByteString str_key((const FX_CHAR*)key); 218 CFX_ByteString str_key((const FX_CHAR*)key);
218 if (str_key.Find(((AltFontFamily*)element)->m_pFontName) != -1) { 219 if (str_key.Find(((AltFontFamily*)element)->m_pFontName) != -1) {
219 return 0; 220 return 0;
220 } 221 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 FX_DWORD offset = GET_TT_LONG(p + 8); 275 FX_DWORD offset = GET_TT_LONG(p + 8);
275 FX_DWORD size = GET_TT_LONG(p + 12); 276 FX_DWORD size = GET_TT_LONG(p + 12);
276 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); 277 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
277 return FPDF_ReadStringFromFile(pFile, size); 278 return FPDF_ReadStringFromFile(pFile, size);
278 } 279 }
279 } 280 }
280 return CFX_ByteString(); 281 return CFX_ByteString();
281 } 282 }
282 283
283 uint8_t GetCharsetFromCodePage(FX_WORD codepage) { 284 uint8_t GetCharsetFromCodePage(FX_WORD codepage) {
284 int32_t iEnd = sizeof(g_Codepage2CharsetTable) / sizeof(CHARSET_MAP) - 1; 285 const CODEPAGE_MAP* pEnd =
285 FXSYS_assert(iEnd >= 0); 286 g_Codepage2CharsetTable + FX_ArraySize(g_Codepage2CharsetTable);
286 int32_t iStart = 0, iMid; 287 const CODEPAGE_MAP* pCharmap =
287 do { 288 std::lower_bound(g_Codepage2CharsetTable, pEnd, codepage,
288 iMid = (iStart + iEnd) / 2; 289 [](const CODEPAGE_MAP& charset, FX_WORD page) {
289 const CHARSET_MAP& cp = g_Codepage2CharsetTable[iMid]; 290 return charset.codepage < page;
290 if (codepage == cp.codepage) { 291 });
291 return cp.charset; 292 if (pCharmap < pEnd && codepage == pCharmap->codepage)
292 } 293 return pCharmap->charset;
293 if (codepage < cp.codepage) {
294 iEnd = iMid - 1;
295 } else {
296 iStart = iMid + 1;
297 }
298 } while (iStart <= iEnd);
299 return 1; 294 return 1;
300 } 295 }
301 296
302 CFX_ByteString GetFontFamily(CFX_ByteString fontName, int nStyle) { 297 CFX_ByteString GetFontFamily(CFX_ByteString fontName, int nStyle) {
303 if (fontName.Find("Script") >= 0) { 298 if (fontName.Find("Script") >= 0) {
304 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) { 299 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) {
305 fontName = "ScriptMTBold"; 300 fontName = "ScriptMTBold";
306 } else if (fontName.Find("Palace") >= 0) { 301 } else if (fontName.Find("Palace") >= 0) {
307 fontName = "PalaceScriptMT"; 302 fontName = "PalaceScriptMT";
308 } else if (fontName.Find("French") >= 0) { 303 } else if (fontName.Find("French") >= 0) {
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 int PDF_GetStandardFontName(CFX_ByteString* name) { 1593 int PDF_GetStandardFontName(CFX_ByteString* name) {
1599 AltFontName* found = static_cast<AltFontName*>( 1594 AltFontName* found = static_cast<AltFontName*>(
1600 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), 1595 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
1601 sizeof(AltFontName), CompareString)); 1596 sizeof(AltFontName), CompareString));
1602 if (!found) 1597 if (!found)
1603 return -1; 1598 return -1;
1604 1599
1605 *name = g_Base14FontNames[found->m_Index]; 1600 *name = g_Base14FontNames[found->m_Index];
1606 return found->m_Index; 1601 return found->m_Index;
1607 } 1602 }
OLDNEW
« no previous file with comments | « no previous file | xfa/src/fgas/src/localization/fx_locale.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698