summaryrefslogtreecommitdiff
path: root/core/fxge/cfx_fontmapper.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-05 20:34:36 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-05 20:34:36 +0000
commit6eda94d78313f18a8f0708c4492d0962649fa709 (patch)
tree29e0e340e47865b3ee2f2f3f45e40a606ec46198 /core/fxge/cfx_fontmapper.cpp
parentc5352efd9c0f86a189181f93405ee10919915841 (diff)
downloadpdfium-6eda94d78313f18a8f0708c4492d0962649fa709.tar.xz
Replace uses of bsearch().chromium/3286
Either switch to std::lower_bound(), or brute force when the search space is very small. Change-Id: I54db346aeb6f2e8000e95a6a9c8fbdd512df500a Reviewed-on: https://pdfium-review.googlesource.com/20431 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxge/cfx_fontmapper.cpp')
-rw-r--r--core/fxge/cfx_fontmapper.cpp58
1 files changed, 25 insertions, 33 deletions
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index bb80c27d51..406a8222db 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -158,19 +158,6 @@ const struct CODEPAGE_MAP {
{10081, 86},
};
-int CompareFontFamilyString(const void* key, const void* element) {
- ByteString str_key((const char*)key);
- const AltFontFamily* family = reinterpret_cast<const AltFontFamily*>(element);
- if (str_key.Contains(family->m_pFontName))
- return 0;
- return FXSYS_stricmp(reinterpret_cast<const char*>(key), family->m_pFontName);
-}
-
-int CompareString(const void* key, const void* element) {
- return FXSYS_stricmp(reinterpret_cast<const char*>(key),
- reinterpret_cast<const AltFontName*>(element)->m_pName);
-}
-
ByteString TT_NormalizeName(const char* family) {
ByteString norm(family);
norm.Remove(' ');
@@ -196,22 +183,24 @@ uint8_t GetCharsetFromCodePage(uint16_t codepage) {
return FX_CHARSET_Default;
}
-ByteString GetFontFamily(ByteString fontName, uint32_t nStyle) {
- if (fontName.Contains("Script")) {
+void GetFontFamily(uint32_t nStyle, ByteString* fontName) {
+ if (fontName->Contains("Script")) {
if (FontStyleIsBold(nStyle))
- fontName = "ScriptMTBold";
- else if (fontName.Contains("Palace"))
- fontName = "PalaceScriptMT";
- else if (fontName.Contains("French"))
- fontName = "FrenchScriptMT";
- else if (fontName.Contains("FreeStyle"))
- fontName = "FreeStyleScript";
- return fontName;
- }
- AltFontFamily* found = reinterpret_cast<AltFontFamily*>(bsearch(
- fontName.c_str(), g_AltFontFamilies, FX_ArraySize(g_AltFontFamilies),
- sizeof(AltFontFamily), CompareFontFamilyString));
- return found ? ByteString(found->m_pFontFamily) : fontName;
+ *fontName = "ScriptMTBold";
+ else if (fontName->Contains("Palace"))
+ *fontName = "PalaceScriptMT";
+ else if (fontName->Contains("French"))
+ *fontName = "FrenchScriptMT";
+ else if (fontName->Contains("FreeStyle"))
+ *fontName = "FreeStyleScript";
+ return;
+ }
+ for (const auto& alternate : g_AltFontFamilies) {
+ if (fontName->Contains(alternate.m_pFontName)) {
+ *fontName = alternate.m_pFontFamily;
+ return;
+ }
+ }
}
ByteString ParseStyle(const char* pStyle, int iLen, int iIndex) {
@@ -566,7 +555,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight,
PitchFamily);
}
- family = GetFontFamily(family, nStyle);
+ GetFontFamily(nStyle, &family);
ByteString match = MatchInstalledFonts(TT_NormalizeName(family.c_str()));
if (match.IsEmpty() && family != SubstName &&
(!bHasComma && (!bHasHyphen || (bHasHyphen && !bStyleAvail)))) {
@@ -800,10 +789,13 @@ FXFT_Face CFX_FontMapper::GetCachedFace(void* hFont,
}
int PDF_GetStandardFontName(ByteString* name) {
- AltFontName* found = static_cast<AltFontName*>(
- bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
- sizeof(AltFontName), CompareString));
- if (!found)
+ const auto* end = std::end(g_AltFontNames);
+ const auto* found =
+ std::lower_bound(std::begin(g_AltFontNames), end, name->c_str(),
+ [](const AltFontName& element, const char* name) {
+ return FXSYS_stricmp(element.m_pName, name) < 0;
+ });
+ if (found == end || FXSYS_stricmp(found->m_pName, name->c_str()))
return -1;
*name = g_Base14FontNames[found->m_Index];