Update the list of Traditional Chinese fonts to try on Windows.
When trying to select a Traditional Chinese substitute font on Windows,
currently the only font being considered is MingLiu/PMingLiu. This font
is not installed by default on Windows 10 in many non-Chinese locales,
so font substitution will most likely fail. Work around this by also
considering the Microsoft YaHei/JHengHei fonts. This is the same
strategy used in Chromium in their
third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc.
Bug: chromium:908691
Change-Id: Id036b81b38028e62b83f26dd46e6d76540ab9194
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/95352
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/win32/cwin32_platform.cpp b/core/fxge/win32/cwin32_platform.cpp
index 1f3f7b7..ced4ba1 100644
--- a/core/fxge/win32/cwin32_platform.cpp
+++ b/core/fxge/win32/cwin32_platform.cpp
@@ -13,7 +13,9 @@
#include "core/fxcrt/fx_codepage.h"
#include "core/fxge/cfx_folderfontinfo.h"
#include "core/fxge/cfx_gemodule.h"
+#include "third_party/base/check.h"
#include "third_party/base/numerics/safe_conversions.h"
+#include "third_party/base/span.h"
#include "third_party/base/win/scoped_select_object.h"
#include "third_party/base/win/win_util.h"
@@ -123,6 +125,11 @@
void GetGBPreference(ByteString& face, int weight, int pitch_family);
void GetJapanesePreference(ByteString& face, int weight, int pitch_family);
ByteString FindFont(const ByteString& name);
+ void* GetFontFromList(int weight,
+ bool italic,
+ FX_Charset charset,
+ int pitch_family,
+ pdfium::span<const char* const> font_faces);
const HDC m_hDC;
UnownedPtr<CFX_FontMapper> m_pMapper;
@@ -214,6 +221,26 @@
return ByteString();
}
+void* CFX_Win32FontInfo::GetFontFromList(
+ int weight,
+ bool italic,
+ FX_Charset charset,
+ int pitch_family,
+ pdfium::span<const char* const> font_faces) {
+ DCHECK(!font_faces.empty());
+
+ // Initialization not needed because of DCHECK() above and the assignment in
+ // the for-loop below.
+ HFONT font;
+ for (const char* face : font_faces) {
+ font = Win32CreateFont(weight, italic, charset, pitch_family, face);
+ ByteString actual_face;
+ if (GetFaceName(font, &actual_face) && actual_face.EqualNoCase(face))
+ break;
+ }
+ return font;
+}
+
void* CFX_Win32FallbackFontInfo::MapFont(int weight,
bool bItalic,
FX_Charset charset,
@@ -367,12 +394,14 @@
new_face = "Gulim";
break;
case FX_Charset::kChineseTraditional:
- if (new_face.Contains("MSung")) {
- new_face = "MingLiU";
- } else {
- new_face = "PMingLiU";
- }
- break;
+ static const char* const kMonospaceFonts[] = {"Microsoft YaHei",
+ "MingLiU"};
+ static const char* const kProportionalFonts[] = {"Microsoft JHengHei",
+ "PMingLiU"};
+ pdfium::span<const char* const> candidate_fonts =
+ new_face.Contains("MSung") ? kMonospaceFonts : kProportionalFonts;
+ return GetFontFromList(weight, bItalic, charset, subst_pitch_family,
+ candidate_fonts);
}
return Win32CreateFont(weight, bItalic, charset, subst_pitch_family,
new_face.c_str());