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

Side by Side Diff: ui/gfx/font_list.cc

Issue 470053004: [Win, Linux] Always display the avatar button text at the same size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits part 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/font_list.h ('k') | ui/gfx/font_list_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/font_list.h" 5 #include "ui/gfx/font_list.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "ui/gfx/font_list_impl.h" 9 #include "ui/gfx/font_list_impl.h"
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 FontList FontList::DeriveWithSizeDelta(int size_delta) const { 65 FontList FontList::DeriveWithSizeDelta(int size_delta) const {
66 return Derive(size_delta, GetFontStyle()); 66 return Derive(size_delta, GetFontStyle());
67 } 67 }
68 68
69 FontList FontList::DeriveWithStyle(int font_style) const { 69 FontList FontList::DeriveWithStyle(int font_style) const {
70 return Derive(0, font_style); 70 return Derive(0, font_style);
71 } 71 }
72 72
73 gfx::FontList FontList::DeriveWithHeightUpperBound(int height) const {
74 gfx::FontList font_list(*this);
75 for (int font_size = font_list.GetFontSize(); font_size > 1; --font_size) {
76 const int internal_leading =
77 font_list.GetBaseline() - font_list.GetCapHeight();
78 // Some platforms don't support getting the cap height, and simply return
79 // the entire font ascent from GetCapHeight(). Centering the ascent makes
80 // the font look too low, so if GetCapHeight() returns the ascent, center
81 // the entire font height instead.
82 const int space =
83 height - ((internal_leading != 0) ?
84 font_list.GetCapHeight() : font_list.GetHeight());
85 const int y_offset = space / 2 - internal_leading;
86 const int space_at_bottom = height - (y_offset + font_list.GetHeight());
87 if ((y_offset >= 0) && (space_at_bottom >= 0))
88 break;
89 font_list = font_list.DeriveWithSizeDelta(-1);
90 }
91 return font_list;
92 }
93
73 int FontList::GetHeight() const { 94 int FontList::GetHeight() const {
74 return impl_->GetHeight(); 95 return impl_->GetHeight();
75 } 96 }
76 97
77 int FontList::GetBaseline() const { 98 int FontList::GetBaseline() const {
78 return impl_->GetBaseline(); 99 return impl_->GetBaseline();
79 } 100 }
80 101
81 int FontList::GetCapHeight() const { 102 int FontList::GetCapHeight() const {
82 return impl_->GetCapHeight(); 103 return impl_->GetCapHeight();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 g_default_font_description.Get().empty() ? 141 g_default_font_description.Get().empty() ?
121 new FontListImpl(Font()) : 142 new FontListImpl(Font()) :
122 new FontListImpl(g_default_font_description.Get()); 143 new FontListImpl(g_default_font_description.Get());
123 g_default_impl_initialized = true; 144 g_default_impl_initialized = true;
124 } 145 }
125 146
126 return g_default_impl.Get(); 147 return g_default_impl.Get();
127 } 148 }
128 149
129 } // namespace gfx 150 } // namespace gfx
OLDNEW
« 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