From 1d10a165c5962a744eeca7a72a0c1fa087cc6ba9 Mon Sep 17 00:00:00 2001 From: "asvitkine@chromium.org" Date: Thu, 3 May 2012 20:19:30 +0000 Subject: Cache successful substitute fonts in RenderTextWin. This is both a performance win (avoids trying all fonts in the chain in the common case) and fixes the issue in http://crbug.com/126109. BUG=126109, 105550 TEST=Set Chrome's UI language to Chinese and restart Chrome. Look through various text in the UI. The font used for all Chinese text should be the same. Review URL: http://codereview.chromium.org/10342018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135200 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/gfx/render_text_win.cc | 21 ++++++++++++++++++++- ui/gfx/render_text_win.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index c0a8277..4093047 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -191,6 +191,9 @@ HDC RenderTextWin::cached_hdc_ = NULL; // static std::map > RenderTextWin::cached_linked_fonts_; +// static +std::map RenderTextWin::successful_substitute_fonts_; + RenderTextWin::RenderTextWin() : RenderText(), common_baseline_(0), @@ -608,6 +611,7 @@ void RenderTextWin::LayoutVisualText() { internal::TextRun* run = runs_[i]; size_t run_length = run->range.length(); const wchar_t* run_text = &(text()[run->range.start()]); + bool tried_cached_font = false; bool tried_fallback = false; size_t linked_font_index = 0; const std::vector* linked_fonts = NULL; @@ -656,8 +660,23 @@ void RenderTextWin::LayoutVisualText() { } // Skip font substitution if there are no missing glyphs. - if (!glyphs_missing) + if (!glyphs_missing) { + // Save the successful fallback font that was chosen. + if (tried_fallback) + successful_substitute_fonts_[original_font.GetFontName()] = run->font; break; + } + + // First, try the cached font from previous runs, if any. + if (!tried_cached_font) { + tried_cached_font = true; + std::map::const_iterator it = + successful_substitute_fonts_.find(original_font.GetFontName()); + if (it != successful_substitute_fonts_.end()) { + ApplySubstituteFont(run, it->second); + continue; + } + } // If there are missing glyphs, first try finding a fallback font using a // meta file, if it hasn't yet been attempted for this run. diff --git a/ui/gfx/render_text_win.h b/ui/gfx/render_text_win.h index 6e9059e..7fb8d86 100644 --- a/ui/gfx/render_text_win.h +++ b/ui/gfx/render_text_win.h @@ -118,6 +118,9 @@ class RenderTextWin : public RenderText { // Cached map from font names to vectors of linked fonts. static std::map > cached_linked_fonts_; + // Cached map from font name to the last successful substitute font used. + static std::map successful_substitute_fonts_; + SCRIPT_CONTROL script_control_; SCRIPT_STATE script_state_; -- cgit v1.1