summaryrefslogtreecommitdiffstats
path: root/ui/gfx/render_text_win.cc
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-03 20:19:30 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-03 20:19:30 +0000
commit1d10a165c5962a744eeca7a72a0c1fa087cc6ba9 (patch)
tree6a936f12b77f46cd56a40a8ce373e53e348670a8 /ui/gfx/render_text_win.cc
parent1f4c2abb3829eb68a4363f83a75c3382acaaed42 (diff)
downloadchromium_src-1d10a165c5962a744eeca7a72a0c1fa087cc6ba9.zip
chromium_src-1d10a165c5962a744eeca7a72a0c1fa087cc6ba9.tar.gz
chromium_src-1d10a165c5962a744eeca7a72a0c1fa087cc6ba9.tar.bz2
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
Diffstat (limited to 'ui/gfx/render_text_win.cc')
-rw-r--r--ui/gfx/render_text_win.cc21
1 files changed, 20 insertions, 1 deletions
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<std::string, std::vector<Font> > RenderTextWin::cached_linked_fonts_;
+// static
+std::map<std::string, Font> 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<Font>* 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<std::string, Font>::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.