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

Unified Diff: ui/gfx/font_list.cc

Issue 534713002: [Merge] [Win, Linux] Always display the avatar button text at the same size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2125
Patch Set: Created 6 years, 3 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') | ui/gfx/font_list_unittest.cc » ('j') | 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 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();
}
« no previous file with comments | « ui/gfx/font_list.h ('k') | ui/gfx/font_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698