Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 DCHECK_GT(font_names->size(), 1U); | 27 DCHECK_GT(font_names->size(), 1U); |
| 28 | 28 |
| 29 // The last item is [STYLE_OPTIONS] SIZE. | 29 // The last item is [STYLE_OPTIONS] SIZE. |
| 30 std::vector<std::string> styles_size; | 30 std::vector<std::string> styles_size; |
| 31 base::SplitString(font_names->back(), ' ', &styles_size); | 31 base::SplitString(font_names->back(), ' ', &styles_size); |
| 32 DCHECK(!styles_size.empty()); | 32 DCHECK(!styles_size.empty()); |
| 33 base::StringToInt(styles_size.back(), font_size); | 33 base::StringToInt(styles_size.back(), font_size); |
| 34 DCHECK_GT(*font_size, 0); | 34 DCHECK_GT(*font_size, 0); |
| 35 font_names->pop_back(); | 35 font_names->pop_back(); |
| 36 | 36 |
| 37 // Font supports BOLD and ITALIC; underline is supported via RenderText. | |
| 38 *font_style = 0; | 37 *font_style = 0; |
| 39 for (size_t i = 0; i < styles_size.size() - 1; ++i) { | 38 for (size_t i = 0; i < styles_size.size() - 1; ++i) { |
| 40 // Styles are separated by white spaces. base::SplitString splits styles | 39 // Styles are separated by white spaces. base::SplitString splits styles |
| 41 // by space, and it inserts empty string for continuous spaces. | 40 // by space, and it inserts empty string for continuous spaces. |
| 42 if (styles_size[i].empty()) | 41 if (styles_size[i].empty()) |
| 43 continue; | 42 continue; |
| 44 if (!styles_size[i].compare("Bold")) | 43 if (!styles_size[i].compare("Bold")) |
| 45 *font_style |= gfx::Font::BOLD; | 44 *font_style |= gfx::Font::BOLD; |
| 46 else if (!styles_size[i].compare("Italic")) | 45 else if (!styles_size[i].compare("Italic")) |
| 47 *font_style |= gfx::Font::ITALIC; | 46 *font_style |= gfx::Font::ITALIC; |
| 47 else if (!styles_size[i].compare("Underline")) | |
|
Alexei Svitkine (slow)
2013/12/20 16:28:09
So the description string comes from a format used
Yuki
2013/12/20 17:34:52
You're right. Since underline is NOT considered a
| |
| 48 *font_style |= gfx::Font::UNDERLINE; | |
| 48 else | 49 else |
| 49 NOTREACHED(); | 50 NOTREACHED(); |
| 50 } | 51 } |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Returns the font style and size as a string. | 54 // Returns the font style and size as a string. |
| 54 std::string FontStyleAndSizeToString(int font_style, int font_size) { | 55 std::string FontStyleAndSizeToString(int font_style, int font_size) { |
| 55 std::string result; | 56 std::string result; |
| 56 if (font_style & gfx::Font::BOLD) | 57 if (font_style & gfx::Font::BOLD) |
| 57 result += "Bold "; | 58 result += "Bold "; |
| 58 if (font_style & gfx::Font::ITALIC) | 59 if (font_style & gfx::Font::ITALIC) |
| 59 result += "Italic "; | 60 result += "Italic "; |
| 61 if (font_style & gfx::Font::UNDERLINE) | |
| 62 result += "Underline "; | |
| 60 result += base::IntToString(font_size); | 63 result += base::IntToString(font_size); |
| 61 result += "px"; | 64 result += "px"; |
| 62 return result; | 65 return result; |
| 63 } | 66 } |
| 64 | 67 |
| 65 // Returns font description from |font_names|, |font_style|, and |font_size|. | 68 // Returns font description from |font_names|, |font_style|, and |font_size|. |
| 66 std::string BuildFontDescription(const std::vector<std::string>& font_names, | 69 std::string BuildFontDescription(const std::vector<std::string>& font_names, |
| 67 int font_style, | 70 int font_style, |
| 68 int font_size) { | 71 int font_size) { |
| 69 std::string description = JoinString(font_names, ','); | 72 std::string description = JoinString(font_names, ','); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 font_style_ = fonts_[0].GetStyle(); | 294 font_style_ = fonts_[0].GetStyle(); |
| 292 font_size_ = fonts_[0].GetFontSize(); | 295 font_size_ = fonts_[0].GetFontSize(); |
| 293 } else { | 296 } else { |
| 294 std::vector<std::string> font_names; | 297 std::vector<std::string> font_names; |
| 295 ParseFontDescriptionString(font_description_string_, &font_names, | 298 ParseFontDescriptionString(font_description_string_, &font_names, |
| 296 &font_style_, &font_size_); | 299 &font_style_, &font_size_); |
| 297 } | 300 } |
| 298 } | 301 } |
| 299 | 302 |
| 300 } // namespace gfx | 303 } // namespace gfx |
| OLD | NEW |