Split m_InstalledTTFonts into two vectors to avoid sketchy logic.
Instead of relying on ' ' to determine whether the CFX_Bytestring
is added on one place or another, use another vector. When trying
to match fonts from the fontmapper, compare with both vectors.
BUG=pdfium:510
Review-Url: https://codereview.chromium.org/2395883002
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index 383550b..e59966a 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -45,6 +45,7 @@
}
std::vector<CFX_ByteString> m_InstalledTTFonts;
+ std::vector<std::pair<CFX_ByteString, CFX_ByteString>> m_LocalizedTTFonts;
private:
static const size_t MM_FACE_COUNT = 2;
diff --git a/core/fxge/ge/cfx_fontmapper.cpp b/core/fxge/ge/cfx_fontmapper.cpp
index 86dc238..b388545 100644
--- a/core/fxge/ge/cfx_fontmapper.cpp
+++ b/core/fxge/ge/cfx_fontmapper.cpp
@@ -347,10 +347,8 @@
}
CFX_ByteString new_name = GetPSNameFromTT(hFont);
- if (!new_name.IsEmpty()) {
- new_name.Insert(0, ' ');
- m_InstalledTTFonts.push_back(new_name);
- }
+ if (!new_name.IsEmpty())
+ m_LocalizedTTFonts.push_back(std::make_pair(new_name, name));
m_pFontInfo->DeleteFont(hFont);
}
m_InstalledTTFonts.push_back(name);
@@ -372,14 +370,15 @@
for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) {
CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str());
if (norm1 == norm_name)
- break;
+ return m_InstalledTTFonts[i];
}
- if (i < 0)
- return CFX_ByteString();
- CFX_ByteString match = m_InstalledTTFonts[i];
- if (match[0] == ' ')
- match = m_InstalledTTFonts[i + 1];
- return match;
+ for (i = pdfium::CollectionSize<int>(m_LocalizedTTFonts) - 1; i >= 0; i--) {
+ CFX_ByteString norm1 =
+ TT_NormalizeName(m_LocalizedTTFonts[i].first.c_str());
+ if (norm1 == norm_name)
+ return m_LocalizedTTFonts[i].second;
+ }
+ return CFX_ByteString();
}
FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont,
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index bc6817d..0ef7829 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -471,13 +471,13 @@
for (size_t i = 0; i < m_pMapper->m_InstalledTTFonts.size(); ++i) {
CFX_ByteString thisname = m_pMapper->m_InstalledTTFonts[i];
- if (thisname[0] == ' ') {
- if (thisname.Mid(1, name.GetLength()) == name) {
- return m_pMapper->m_InstalledTTFonts[i + 1];
- }
- } else if (thisname.Left(name.GetLength()) == name) {
+ if (thisname.Left(name.GetLength()) == name)
return m_pMapper->m_InstalledTTFonts[i];
- }
+ }
+ for (size_t i = 0; i < m_pMapper->m_LocalizedTTFonts.size(); ++i) {
+ CFX_ByteString thisname = m_pMapper->m_LocalizedTTFonts[i].first;
+ if (thisname.Left(name.GetLength()) == name)
+ return m_pMapper->m_LocalizedTTFonts[i].second;
}
return CFX_ByteString();
}
diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp
index bfa80df..72cb9f5 100644
--- a/fpdfsdk/cfx_systemhandler.cpp
+++ b/fpdfsdk/cfx_systemhandler.cpp
@@ -106,6 +106,10 @@
if (font.Compare(sFontFaceName.AsStringC()))
return true;
}
+ for (const auto& fontPair : pFontMapper->m_LocalizedTTFonts) {
+ if (fontPair.first.Compare(sFontFaceName.AsStringC()))
+ return true;
+ }
return false;
}