Chromium Code Reviews| Index: ui/gfx/font_list.cc |
| diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc |
| index e977882bed90ea4d96a30e8e4859e4423839ca8e..ff1daf780d5763c08e11d2a4a85400705b03a402 100644 |
| --- a/ui/gfx/font_list.cc |
| +++ b/ui/gfx/font_list.cc |
| @@ -6,7 +6,6 @@ |
| #include <algorithm> |
| -#include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| @@ -14,9 +13,10 @@ |
| namespace { |
| -// Font description of the default font set. |
| -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. |
| +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, |
| @@ -80,14 +80,14 @@ FontList::FontList() |
| common_baseline_(-1), |
| font_style_(-1), |
| font_size_(-1) { |
| - // SetDefaultFontDescription() must be called and the default font description |
| - // must be set earlier than any call of the default constructor. |
| - DCHECK(!(g_default_font_description == NULL)) // != is not overloaded. |
| + // SetDefaultFontDescription() must be called earlier than any call of the |
| + // default constructor. |
| + DCHECK(g_default_font_list) |
| << "SetDefaultFontDescription has not been called."; |
| - font_description_string_ = g_default_font_description.Get(); |
| - if (font_description_string_.empty()) |
| - fonts_.push_back(Font()); |
| + // Copy the default font list specification as well as the pre-calculated |
|
msw
2014/01/07 17:51:38
nit: s/as well as the/and its/
Yuki
2014/01/08 06:32:19
Done.
|
| + // metrics. |
| + *this = *g_default_font_list; |
| } |
| FontList::FontList(const std::string& font_description_string) |
| @@ -144,12 +144,14 @@ FontList::~FontList() { |
| // static |
| void FontList::SetDefaultFontDescription(const std::string& font_description) { |
| - // The description string must end with "px" for size in pixel, or must be |
| - // the empty string, which specifies to use a single default font. |
| - DCHECK(font_description.empty() || |
| - EndsWith(font_description, "px", true)); |
| - |
| - g_default_font_description.Get() = font_description; |
| + static FontList default_font_list((Font())); |
|
msw
2014/01/07 17:51:38
nit: remove extra parens around Font().
Yuki
2014/01/08 06:32:19
This is necessary. Without them, it's ambiguous i
|
| + g_default_font_list = &default_font_list; |
| + |
| + default_font_list = font_description.empty() ? |
|
msw
2014/01/07 17:51:38
nit: make this if (!font_description.empty()) defa
Yuki
2014/01/08 06:32:19
When ui::ResourceBundle reloads the resources incl
|
| + FontList(Font()) : FontList(font_description); |
| + // Pre-calculate the metrics. |
| + default_font_list.CacheCommonFontHeightAndBaseline(); |
| + default_font_list.CacheFontStyleAndSize(); |
| } |
| FontList FontList::DeriveFontList(int font_style) const { |