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

Unified Diff: ui/gfx/font_list.cc

Issue 124693003: Makes the default ctor of gfx::FontList copy the pre-calculated metrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/font_list.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/font_list.cc
diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc
index e977882bed90ea4d96a30e8e4859e4423839ca8e..c2a9927c3b9c89d0ed9e3864a51b3eba8c2669ac 100644
--- a/ui/gfx/font_list.cc
+++ b/ui/gfx/font_list.cc
@@ -18,6 +18,11 @@ namespace {
base::LazyInstance<std::string>::Leaky g_default_font_description =
LAZY_INSTANCE_INITIALIZER;
+// The default instance of gfx::FontList, whose metrics are pre-calculated.
+// The default ctor of gfx::FontList copies the metrics so it won't need to
+// scan the whole font list to calculate the metrics.
+const gfx::FontList* g_default_font_list = NULL;
+
// Parses font description into |font_names|, |font_style| and |font_size|.
void ParseFontDescriptionString(const std::string& font_description_string,
std::vector<std::string>* font_names,
@@ -85,9 +90,24 @@ FontList::FontList()
DCHECK(!(g_default_font_description == NULL)) // != is not overloaded.
<< "SetDefaultFontDescription has not been called.";
- font_description_string_ = g_default_font_description.Get();
- if (font_description_string_.empty())
- fonts_.push_back(Font());
+ // Allocate the global instance of FontList for |g_default_font_list| without
+ // calling the default ctor.
+ static FontList default_font_list((Font()));
+
+ if (!g_default_font_list) {
+ default_font_list = g_default_font_description.Get().empty() ?
+ FontList(Font()) : FontList(g_default_font_description.Get());
+ // Pre-calculate the metrics if the underlying PlatformFont is supported.
+ // Note that not all the platforms support PlatformFont.
msw 2014/01/10 17:54:51 What happens when the metics caching functions run
Yuki 2014/01/11 09:29:07 If PlatformFont::CreateDefault() returns NULL, all
+ if (default_font_list.GetPrimaryFont().platform_font()) {
+ default_font_list.CacheCommonFontHeightAndBaseline();
+ default_font_list.CacheFontStyleAndSize();
+ }
+ g_default_font_list = &default_font_list;
+ }
+
+ // Copy the default font list specification and its pre-calculated metrics.
+ *this = *g_default_font_list;
}
FontList::FontList(const std::string& font_description_string)
@@ -150,6 +170,7 @@ void FontList::SetDefaultFontDescription(const std::string& font_description) {
EndsWith(font_description, "px", true));
g_default_font_description.Get() = font_description;
+ g_default_font_list = NULL;
}
FontList FontList::DeriveFontList(int font_style) const {
« no previous file with comments | « ui/gfx/font_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698