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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 const std::vector<Font>& FontList::GetFonts() const { | 101 const std::vector<Font>& FontList::GetFonts() const { |
102 return impl_->GetFonts(); | 102 return impl_->GetFonts(); |
103 } | 103 } |
104 | 104 |
105 const Font& FontList::GetPrimaryFont() const { | 105 const Font& FontList::GetPrimaryFont() const { |
106 return impl_->GetPrimaryFont(); | 106 return impl_->GetPrimaryFont(); |
107 } | 107 } |
108 | 108 |
| 109 gfx::FontList FontList::GetLargestFontListWithHeightBound(int height) const { |
| 110 gfx::FontList font_list(*this); |
| 111 for (int font_size = font_list.GetFontSize(); font_size > 1; --font_size) { |
| 112 const int internal_leading = |
| 113 font_list.GetBaseline() - font_list.GetCapHeight(); |
| 114 // Some platforms don't support getting the cap height, and simply return |
| 115 // the entire font ascent from GetCapHeight(). Centering the ascent makes |
| 116 // the font look too low, so if GetCapHeight() returns the ascent, center |
| 117 // the entire font height instead. |
| 118 const int space = |
| 119 height - ((internal_leading != 0) ? |
| 120 font_list.GetCapHeight() : font_list.GetHeight()); |
| 121 const int y_offset = space / 2 - internal_leading; |
| 122 const int space_at_bottom = height - (y_offset + font_list.GetHeight()); |
| 123 if ((y_offset >= 0) && (space_at_bottom >= 0)) |
| 124 break; |
| 125 font_list = font_list.DeriveWithSizeDelta(-1); |
| 126 } |
| 127 return font_list; |
| 128 } |
| 129 |
109 FontList::FontList(FontListImpl* impl) : impl_(impl) {} | 130 FontList::FontList(FontListImpl* impl) : impl_(impl) {} |
110 | 131 |
111 // static | 132 // static |
112 const scoped_refptr<FontListImpl>& FontList::GetDefaultImpl() { | 133 const scoped_refptr<FontListImpl>& FontList::GetDefaultImpl() { |
113 // SetDefaultFontDescription() must be called and the default font description | 134 // SetDefaultFontDescription() must be called and the default font description |
114 // must be set earlier than any call of this function. | 135 // must be set earlier than any call of this function. |
115 DCHECK(!(g_default_font_description == NULL)) // != is not overloaded. | 136 DCHECK(!(g_default_font_description == NULL)) // != is not overloaded. |
116 << "SetDefaultFontDescription has not been called."; | 137 << "SetDefaultFontDescription has not been called."; |
117 | 138 |
118 if (!g_default_impl_initialized) { | 139 if (!g_default_impl_initialized) { |
119 g_default_impl.Get() = | 140 g_default_impl.Get() = |
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 |