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

Side by Side Diff: content/renderer/renderer_font_platform_win.cc

Issue 521483002: Added restricted font fallback to custom font collection loader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Further restricting max number of fonts that we can load, if not we will go to fallback list. Created 6 years, 3 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 | no next file » | 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 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium 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 #include "content/renderer/renderer_font_platform_win.h" 5 #include "content/renderer/renderer_font_platform_win.h"
6 6
7 #include <dwrite.h> 7 #include <dwrite.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include <wrl/implements.h> 10 #include <wrl/implements.h>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 UINT32 key_size, 42 UINT32 key_size,
43 IDWriteFontFileEnumerator** file_enumerator); 43 IDWriteFontFileEnumerator** file_enumerator);
44 44
45 static HRESULT Initialize(IDWriteFactory* factory); 45 static HRESULT Initialize(IDWriteFactory* factory);
46 46
47 UINT32 GetFontMapSize(); 47 UINT32 GetFontMapSize();
48 48
49 std::wstring GetFontNameFromKey(UINT32 idx); 49 std::wstring GetFontNameFromKey(UINT32 idx);
50 50
51 bool LoadFontListFromRegistry(); 51 bool LoadFontListFromRegistry();
52 bool LoadRestrictedFontList();
52 53
53 FontCollectionLoader() {}; 54 FontCollectionLoader() {};
54 virtual ~FontCollectionLoader() {}; 55 virtual ~FontCollectionLoader() {};
55 56
56 private: 57 private:
57 mswr::ComPtr<IDWriteFontFileLoader> file_loader_; 58 mswr::ComPtr<IDWriteFontFileLoader> file_loader_;
58 59
59 std::vector<std::wstring> reg_fonts_; 60 std::vector<std::wstring> reg_fonts_;
60 }; 61 };
61 62
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 std::vector<base::FilePath::StringType> components; 277 std::vector<base::FilePath::StringType> components;
277 path.GetComponents(&components); 278 path.GetComponents(&components);
278 if (components.size() == 1) { 279 if (components.size() == 1) {
279 reg_fonts_.push_back(value.c_str()); 280 reg_fonts_.push_back(value.c_str());
280 } 281 }
281 } 282 }
282 } 283 }
283 return true; 284 return true;
284 } 285 }
285 286
287 // This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults.
288 const wchar_t* kRestrictedFontSet[] = {
289 L"times.ttf",
290 L"timesbd.ttf",
291 L"timesbi.ttf",
292 L"timesi.ttf",
293 L"cour.ttf",
294 L"courbd.ttf",
295 L"courbi.ttf",
296 L"couri.ttf",
297 L"consola.ttf",
298 L"consolab.ttf",
299 L"consolai.ttf",
300 L"consolaz.ttf",
301 L"arial.ttf",
302 L"arialbd.ttf",
303 L"arialbi.ttf",
304 L"ariali.ttf",
305 L"comic.ttf",
306 L"comicbd.ttf",
307 L"comici.ttf",
308 L"comicz.ttf",
309 L"impact.ttf",
310 L"segoeui.ttf",
311 L"segoeuib.ttf",
312 L"segoeuii.ttf",
313 L"msgothic.ttc",
314 L"msmincho.ttc",
315 L"gulim.ttc",
316 L"batang.ttc",
317 L"simsun.ttc",
318 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.
319 };
320
321 bool FontCollectionLoader::LoadRestrictedFontList() {
322 reg_fonts_.clear();
323 reg_fonts_.assign(kRestrictedFontSet,
324 kRestrictedFontSet + _countof(kRestrictedFontSet));
325 return true;
326 }
327
286 } // namespace 328 } // namespace
287 329
288 namespace content { 330 namespace content {
289 331
290 mswr::ComPtr<IDWriteFontCollection> g_font_collection; 332 mswr::ComPtr<IDWriteFontCollection> g_font_collection;
291 333
292 IDWriteFontCollection* GetCustomFontCollection(IDWriteFactory* factory) { 334 IDWriteFontCollection* GetCustomFontCollection(IDWriteFactory* factory) {
293 if (g_font_collection.Get() != NULL) 335 if (g_font_collection.Get() != NULL)
294 return g_font_collection.Get(); 336 return g_font_collection.Get();
295 337
296 base::TimeTicks start_tick = base::TimeTicks::Now(); 338 base::TimeTicks start_tick = base::TimeTicks::Now();
297 339
298 FontCollectionLoader::Initialize(factory); 340 FontCollectionLoader::Initialize(factory);
299 341
300 HRESULT hr = factory->CreateCustomFontCollection( 342 // We try here to put arbitrary limit on max number of fonts that could
301 g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); 343 // be loaded, otherwise we fallback to restricted set of fonts.
344 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.
345 HRESULT hr = E_FAIL;
346 if (g_font_loader->GetFontMapSize() < kMaxFontThreashold) {
347 hr = factory->CreateCustomFontCollection(
348 g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf());
349 }
302 350
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
303 base::TimeDelta time_delta = base::TimeTicks::Now() - start_tick; 351 base::TimeDelta time_delta = base::TimeTicks::Now() - start_tick;
304 int64 delta = time_delta.ToInternalValue(); 352 int64 delta = time_delta.ToInternalValue();
305 base::debug::Alias(&delta); 353 base::debug::Alias(&delta);
306 UINT32 size = g_font_loader->GetFontMapSize(); 354 UINT32 size = g_font_loader->GetFontMapSize();
307 base::debug::Alias(&size); 355 base::debug::Alias(&size);
308 356
357 if (FAILED(hr) || !g_font_collection.Get()) {
358 // We will try here just one more time with restricted font set.
359 g_font_loader->LoadRestrictedFontList();
360 hr = factory->CreateCustomFontCollection(
361 g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf());
362 }
363
309 CHECK(SUCCEEDED(hr)); 364 CHECK(SUCCEEDED(hr));
310 CHECK(g_font_collection.Get() != NULL); 365 CHECK(g_font_collection.Get() != NULL);
311 366
312 base::debug::ClearCrashKey(kFontKeyName); 367 base::debug::ClearCrashKey(kFontKeyName);
313 368
314 return g_font_collection.Get(); 369 return g_font_collection.Get();
315 } 370 }
316 371
317 } // namespace content 372 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698