OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |