Index: ui/gfx/font_list.cc |
diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc |
index 93bf73e834a0bd5bbeed9c2670e64aaeb7f86add..bbf79afe6e81530d20b0d457e39663d7cda5ec4d 100644 |
--- a/ui/gfx/font_list.cc |
+++ b/ui/gfx/font_list.cc |
@@ -69,19 +69,21 @@ std::string BuildFontDescription(const std::vector<std::string>& font_names, |
namespace gfx { |
-FontList::FontList() { |
+FontList::FontList() : common_height_(-1), common_baseline_(-1) { |
fonts_.push_back(Font()); |
} |
FontList::FontList(const std::string& font_description_string) |
- : font_description_string_(font_description_string) { |
+ : font_description_string_(font_description_string), |
+ common_height_(-1), |
+ common_baseline_(-1) { |
DCHECK(!font_description_string.empty()); |
// DCHECK description string ends with "px" for size in pixel. |
DCHECK(EndsWith(font_description_string, "px", true)); |
} |
FontList::FontList(const std::vector<Font>& fonts) |
- : fonts_(fonts) { |
+ : fonts_(fonts), common_height_(-1), common_baseline_(-1) { |
DCHECK(!fonts.empty()); |
if (DCHECK_IS_ON()) { |
int style = fonts[0].GetStyle(); |
@@ -93,7 +95,8 @@ FontList::FontList(const std::vector<Font>& fonts) |
} |
} |
-FontList::FontList(const Font& font) { |
+FontList::FontList(const Font& font) |
+ : common_height_(-1), common_baseline_(-1) { |
fonts_.push_back(font); |
} |
@@ -146,6 +149,34 @@ FontList FontList::DeriveFontListWithSize(int size) const { |
return FontList(BuildFontDescription(font_names, font_style, size)); |
} |
+int FontList::GetHeight() const { |
+ if (common_height_ < 0) { |
+ int ascent = 0; |
+ int descent = 0; |
+ const std::vector<Font>& fonts = GetFonts(); |
+ for (std::vector<Font>::const_iterator i = fonts.begin(); |
+ i != fonts.end(); ++i) { |
+ ascent = std::max(ascent, i->GetBaseline()); |
+ descent = std::max(descent, i->GetHeight() - i->GetBaseline()); |
+ } |
+ common_height_ = ascent + descent; |
+ } |
+ return common_height_; |
+} |
+ |
+int FontList::GetBaseline() const { |
+ if (common_baseline_ < 0) { |
+ int baseline = 0; |
+ const std::vector<Font>& fonts = GetFonts(); |
+ for (std::vector<Font>::const_iterator i = fonts.begin(); |
+ i != fonts.end(); ++i) { |
+ baseline = std::max(baseline, i->GetBaseline()); |
+ } |
+ common_baseline_ = baseline; |
+ } |
+ return common_baseline_; |
+} |
+ |
int FontList::GetFontStyle() const { |
if (!fonts_.empty()) |
return fonts_[0].GetStyle(); |