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

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

Issue 142523003: Renames gfx::FontList::Derive* family. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void FontList::SetDefaultFontDescription(const std::string& font_description) { 166 void FontList::SetDefaultFontDescription(const std::string& font_description) {
167 // The description string must end with "px" for size in pixel, or must be 167 // The description string must end with "px" for size in pixel, or must be
168 // the empty string, which specifies to use a single default font. 168 // the empty string, which specifies to use a single default font.
169 DCHECK(font_description.empty() || 169 DCHECK(font_description.empty() ||
170 EndsWith(font_description, "px", true)); 170 EndsWith(font_description, "px", true));
171 171
172 g_default_font_description.Get() = font_description; 172 g_default_font_description.Get() = font_description;
173 g_default_font_list = NULL; 173 g_default_font_list = NULL;
174 } 174 }
175 175
176 FontList FontList::DeriveFontList(int font_style) const { 176 FontList FontList::Derive(int size_delta, int font_style) const {
177 return DeriveFontListWithSizeDeltaAndStyle(0, font_style);
178 }
179
180 FontList FontList::DeriveFontListWithSize(int size) const {
181 DCHECK_GT(size, 0);
182 return DeriveFontListWithSizeDeltaAndStyle(size - GetFontSize(),
183 GetFontStyle());
184 }
185
186 FontList FontList::DeriveFontListWithSizeDelta(int size_delta) const {
187 return DeriveFontListWithSizeDeltaAndStyle(size_delta, GetFontStyle());
188 }
189
190 FontList FontList::DeriveFontListWithSizeDeltaAndStyle(int size_delta,
191 int style) const {
192 // If there is a font vector, derive from that. 177 // If there is a font vector, derive from that.
193 if (!fonts_.empty()) { 178 if (!fonts_.empty()) {
194 std::vector<Font> fonts = fonts_; 179 std::vector<Font> fonts = fonts_;
195 for (size_t i = 0; i < fonts.size(); ++i) 180 for (size_t i = 0; i < fonts.size(); ++i)
196 fonts[i] = fonts[i].DeriveFont(size_delta, style); 181 fonts[i] = fonts[i].DeriveFont(size_delta, font_style);
197 return FontList(fonts); 182 return FontList(fonts);
198 } 183 }
199 184
200 // Otherwise, parse the font description string to derive from it. 185 // Otherwise, parse the font description string to derive from it.
201 std::vector<std::string> font_names; 186 std::vector<std::string> font_names;
202 int old_size; 187 int old_size;
203 int old_style; 188 int old_style;
204 ParseFontDescriptionString(font_description_string_, &font_names, 189 ParseFontDescriptionString(font_description_string_, &font_names,
205 &old_style, &old_size); 190 &old_style, &old_size);
206 int size = old_size + size_delta; 191 const int size = std::max(1, old_size + size_delta);
207 DCHECK_GT(size, 0); 192 return FontList(font_names, font_style, size);
208 return FontList(font_names, style, size); 193 }
194
195 FontList FontList::DeriveWithSizeDelta(int size_delta) const {
196 return Derive(size_delta, GetFontStyle());
197 }
198
199 FontList FontList::DeriveFontListWithSizeDelta(int size_delta) const {
Alexei Svitkine (slow) 2014/01/20 15:38:10 Remove this one since it's equivalent to DeriveWit
Yuki 2014/01/20 16:43:24 Will do after I rewrite all calls to this method.
200 return Derive(size_delta, GetFontStyle());
201 }
202
203 FontList FontList::DeriveFontListWithSizeDeltaAndStyle(int size_delta,
204 int font_style) const {
205 return Derive(size_delta, font_style);
209 } 206 }
210 207
211 int FontList::GetHeight() const { 208 int FontList::GetHeight() const {
212 if (common_height_ == -1) 209 if (common_height_ == -1)
213 CacheCommonFontHeightAndBaseline(); 210 CacheCommonFontHeightAndBaseline();
214 return common_height_; 211 return common_height_;
215 } 212 }
216 213
217 int FontList::GetBaseline() const { 214 int FontList::GetBaseline() const {
218 if (common_baseline_ == -1) 215 if (common_baseline_ == -1)
219 CacheCommonFontHeightAndBaseline(); 216 CacheCommonFontHeightAndBaseline();
220 return common_baseline_; 217 return common_baseline_;
221 } 218 }
222 219
223 int FontList::GetCapHeight() const { 220 int FontList::GetCapHeight() const {
224 // Assume the primary font is used to render Latin characters. 221 // Assume the primary font is used to render Latin characters.
225 return GetPrimaryFont().GetCapHeight(); 222 return GetPrimaryFont().GetCapHeight();
226 } 223 }
227 224
228 int FontList::GetStringWidth(const base::string16& text) const {
229 // Rely on the primary font metrics for the time being.
230 // TODO(yukishiino): Not only the first font, all the fonts in the list should
231 // be taken into account to compute the pixels needed to display |text|.
232 // Also this method, including one in Font class, should be deprecated and
233 // client code should call Canvas::GetStringWidth(text, font_list) directly.
234 // Our plan is as follows:
235 // 1. Introduce the FontList version of Canvas::GetStringWidth().
236 // 2. Make client code call Canvas::GetStringWidth().
237 // 3. Retire {Font,FontList}::GetStringWidth().
238 return GetPrimaryFont().GetStringWidth(text);
239 }
240
241 int FontList::GetExpectedTextWidth(int length) const { 225 int FontList::GetExpectedTextWidth(int length) const {
242 // Rely on the primary font metrics for the time being. 226 // Rely on the primary font metrics for the time being.
243 return GetPrimaryFont().GetExpectedTextWidth(length); 227 return GetPrimaryFont().GetExpectedTextWidth(length);
244 } 228 }
245 229
246 int FontList::GetFontStyle() const { 230 int FontList::GetFontStyle() const {
247 if (font_style_ == -1) 231 if (font_style_ == -1)
248 CacheFontStyleAndSize(); 232 CacheFontStyleAndSize();
249 return font_style_; 233 return font_style_;
250 } 234 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 font_style_ = fonts_[0].GetStyle(); 303 font_style_ = fonts_[0].GetStyle();
320 font_size_ = fonts_[0].GetFontSize(); 304 font_size_ = fonts_[0].GetFontSize();
321 } else { 305 } else {
322 std::vector<std::string> font_names; 306 std::vector<std::string> font_names;
323 ParseFontDescriptionString(font_description_string_, &font_names, 307 ParseFontDescriptionString(font_description_string_, &font_names,
324 &font_style_, &font_size_); 308 &font_style_, &font_size_);
325 } 309 }
326 } 310 }
327 311
328 } // namespace gfx 312 } // namespace gfx
OLDNEW
« ui/app_list/views/speech_view.cc ('K') | « ui/gfx/font_list.h ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698