| 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 <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 Loading... |
| 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::DeriveWithStyle(int font_style) const { |
| 200 return Derive(0, font_style); |
| 201 } |
| 202 |
| 203 FontList FontList::DeriveFontListWithSizeDelta(int size_delta) const { |
| 204 return Derive(size_delta, GetFontStyle()); |
| 205 } |
| 206 |
| 207 FontList FontList::DeriveFontListWithSizeDeltaAndStyle(int size_delta, |
| 208 int font_style) const { |
| 209 return Derive(size_delta, font_style); |
| 209 } | 210 } |
| 210 | 211 |
| 211 int FontList::GetHeight() const { | 212 int FontList::GetHeight() const { |
| 212 if (common_height_ == -1) | 213 if (common_height_ == -1) |
| 213 CacheCommonFontHeightAndBaseline(); | 214 CacheCommonFontHeightAndBaseline(); |
| 214 return common_height_; | 215 return common_height_; |
| 215 } | 216 } |
| 216 | 217 |
| 217 int FontList::GetBaseline() const { | 218 int FontList::GetBaseline() const { |
| 218 if (common_baseline_ == -1) | 219 if (common_baseline_ == -1) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 font_style_ = fonts_[0].GetStyle(); | 307 font_style_ = fonts_[0].GetStyle(); |
| 307 font_size_ = fonts_[0].GetFontSize(); | 308 font_size_ = fonts_[0].GetFontSize(); |
| 308 } else { | 309 } else { |
| 309 std::vector<std::string> font_names; | 310 std::vector<std::string> font_names; |
| 310 ParseFontDescriptionString(font_description_string_, &font_names, | 311 ParseFontDescriptionString(font_description_string_, &font_names, |
| 311 &font_style_, &font_size_); | 312 &font_style_, &font_size_); |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 | 315 |
| 315 } // namespace gfx | 316 } // namespace gfx |
| OLD | NEW |