Index: content/renderer/renderer_font_platform_win.cc |
diff --git a/content/renderer/renderer_font_platform_win.cc b/content/renderer/renderer_font_platform_win.cc |
index 089e876fb8959a7adc664d6d01b8b702ac3da21f..9828c1bd4ed3382e1d9514eed43b10aa5bec9c2b 100644 |
--- a/content/renderer/renderer_font_platform_win.cc |
+++ b/content/renderer/renderer_font_platform_win.cc |
@@ -49,6 +49,7 @@ class FontCollectionLoader |
std::wstring GetFontNameFromKey(UINT32 idx); |
bool LoadFontListFromRegistry(); |
+ bool LoadRestrictedFontList(); |
FontCollectionLoader() {}; |
virtual ~FontCollectionLoader() {}; |
@@ -283,6 +284,47 @@ bool FontCollectionLoader::LoadFontListFromRegistry() { |
return true; |
} |
+// This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults. |
+const wchar_t* kRestrictedFontSet[] = { |
+ L"times.ttf", |
+ L"timesbd.ttf", |
+ L"timesbi.ttf", |
+ L"timesi.ttf", |
+ L"cour.ttf", |
+ L"courbd.ttf", |
+ L"courbi.ttf", |
+ L"couri.ttf", |
+ L"consola.ttf", |
+ L"consolab.ttf", |
+ L"consolai.ttf", |
+ L"consolaz.ttf", |
+ L"arial.ttf", |
+ L"arialbd.ttf", |
+ L"arialbi.ttf", |
+ L"ariali.ttf", |
+ L"comic.ttf", |
+ L"comicbd.ttf", |
+ L"comici.ttf", |
+ L"comicz.ttf", |
+ L"impact.ttf", |
+ L"segoeui.ttf", |
+ L"segoeuib.ttf", |
+ L"segoeuii.ttf", |
+ L"msgothic.ttc", |
+ L"msmincho.ttc", |
+ L"gulim.ttc", |
+ L"batang.ttc", |
+ L"simsun.ttc", |
+ L"mingliu.ttc", |
cpu_(ooo_6.6-7.5)
2014/08/29 01:14:31
1) add a comment for each font that indicates whic
Shrikant Kelkar
2014/08/29 01:41:28
Done.
|
+}; |
+ |
+bool FontCollectionLoader::LoadRestrictedFontList() { |
+ reg_fonts_.clear(); |
+ reg_fonts_.assign(kRestrictedFontSet, |
+ kRestrictedFontSet + _countof(kRestrictedFontSet)); |
+ return true; |
+} |
+ |
} // namespace |
namespace content { |
@@ -297,8 +339,14 @@ IDWriteFontCollection* GetCustomFontCollection(IDWriteFactory* factory) { |
FontCollectionLoader::Initialize(factory); |
- HRESULT hr = factory->CreateCustomFontCollection( |
- g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); |
+ // We try here to put arbitrary limit on max number of fonts that could |
+ // be loaded, otherwise we fallback to restricted set of fonts. |
+ const UINT32 kMaxFontThreashold = 1000; |
cpu_(ooo_6.6-7.5)
2014/08/29 01:14:31
misspell --> threshold
Shrikant Kelkar
2014/08/29 01:41:28
Done.
|
+ HRESULT hr = E_FAIL; |
+ if (g_font_loader->GetFontMapSize() < kMaxFontThreashold) { |
+ hr = factory->CreateCustomFontCollection( |
+ g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); |
+ } |
cpu_(ooo_6.6-7.5)
2014/08/29 01:17:53
I rather have an "else" than rely on hr being e_fa
Shrikant Kelkar
2014/08/29 01:41:28
Idea is to execute it in both cases, try registry
|
base::TimeDelta time_delta = base::TimeTicks::Now() - start_tick; |
int64 delta = time_delta.ToInternalValue(); |
@@ -306,6 +354,13 @@ IDWriteFontCollection* GetCustomFontCollection(IDWriteFactory* factory) { |
UINT32 size = g_font_loader->GetFontMapSize(); |
base::debug::Alias(&size); |
+ if (FAILED(hr) || !g_font_collection.Get()) { |
+ // We will try here just one more time with restricted font set. |
+ g_font_loader->LoadRestrictedFontList(); |
+ hr = factory->CreateCustomFontCollection( |
+ g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); |
+ } |
+ |
CHECK(SUCCEEDED(hr)); |
CHECK(g_font_collection.Get() != NULL); |