Index: ui/gfx/font_list.cc |
diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc |
index 920204bf7a74dcc0c7bd58e73242846852b989d0..ca0c8ade58410c5604dbde0de45f5539439ded6e 100644 |
--- a/ui/gfx/font_list.cc |
+++ b/ui/gfx/font_list.cc |
@@ -70,6 +70,27 @@ FontList FontList::DeriveWithStyle(int font_style) const { |
return Derive(0, font_style); |
} |
+gfx::FontList FontList::DeriveWithHeightUpperBound(int height) const { |
+ gfx::FontList font_list(*this); |
+ for (int font_size = font_list.GetFontSize(); font_size > 1; --font_size) { |
+ const int internal_leading = |
+ font_list.GetBaseline() - font_list.GetCapHeight(); |
+ // Some platforms don't support getting the cap height, and simply return |
+ // the entire font ascent from GetCapHeight(). Centering the ascent makes |
+ // the font look too low, so if GetCapHeight() returns the ascent, center |
+ // the entire font height instead. |
+ const int space = |
+ height - ((internal_leading != 0) ? |
+ font_list.GetCapHeight() : font_list.GetHeight()); |
+ const int y_offset = space / 2 - internal_leading; |
+ const int space_at_bottom = height - (y_offset + font_list.GetHeight()); |
+ if ((y_offset >= 0) && (space_at_bottom >= 0)) |
+ break; |
+ font_list = font_list.DeriveWithSizeDelta(-1); |
+ } |
+ return font_list; |
+} |
+ |
int FontList::GetHeight() const { |
return impl_->GetHeight(); |
} |