| Index: ui/gfx/font_list_impl.cc
|
| diff --git a/ui/gfx/font_list_impl.cc b/ui/gfx/font_list_impl.cc
|
| index ec6783286960b295316f9094397ce5c0fc0d175f..babadb118c15a32e00f5006dba277d090734edcd 100644
|
| --- a/ui/gfx/font_list_impl.cc
|
| +++ b/ui/gfx/font_list_impl.cc
|
| @@ -8,62 +8,27 @@
|
|
|
| #include "base/logging.h"
|
| #include "base/strings/string_number_conversions.h"
|
| -#include "base/strings/string_split.h"
|
| #include "base/strings/string_util.h"
|
| #include "ui/gfx/font.h"
|
| +#include "ui/gfx/font_list.h"
|
|
|
| namespace {
|
|
|
| -// Parses font description into |font_names|, |font_style| and |font_size|.
|
| -void ParseFontDescriptionString(const std::string& font_description_string,
|
| - std::vector<std::string>* font_names,
|
| - int* font_style,
|
| - int* font_size) {
|
| - base::SplitString(font_description_string, ',', font_names);
|
| - DCHECK_GT(font_names->size(), 1U);
|
| -
|
| - // The last item is [STYLE_OPTIONS] SIZE.
|
| - std::vector<std::string> styles_size;
|
| - base::SplitString(font_names->back(), ' ', &styles_size);
|
| - DCHECK(!styles_size.empty());
|
| - base::StringToInt(styles_size.back(), font_size);
|
| - DCHECK_GT(*font_size, 0);
|
| - font_names->pop_back();
|
| -
|
| - // Font supports BOLD and ITALIC; underline is supported via RenderText.
|
| - *font_style = 0;
|
| - for (size_t i = 0; i < styles_size.size() - 1; ++i) {
|
| - // Styles are separated by white spaces. base::SplitString splits styles
|
| - // by space, and it inserts empty string for continuous spaces.
|
| - if (styles_size[i].empty())
|
| - continue;
|
| - if (!styles_size[i].compare("Bold"))
|
| - *font_style |= gfx::Font::BOLD;
|
| - else if (!styles_size[i].compare("Italic"))
|
| - *font_style |= gfx::Font::ITALIC;
|
| - else
|
| - NOTREACHED();
|
| - }
|
| -}
|
| +// Returns a font description from |families|, |style|, and |size_pixels|.
|
| +std::string BuildDescription(const std::vector<std::string>& families,
|
| + int style,
|
| + int size_pixels) {
|
| + std::string description = JoinString(families, ',');
|
| + description += ",";
|
| +
|
| + if (style & gfx::Font::BOLD)
|
| + description += "Bold ";
|
| + if (style & gfx::Font::ITALIC)
|
| + description += "Italic ";
|
| +
|
| + description += base::IntToString(size_pixels);
|
| + description += "px";
|
|
|
| -// Returns the font style and size as a string.
|
| -std::string FontStyleAndSizeToString(int font_style, int font_size) {
|
| - std::string result;
|
| - if (font_style & gfx::Font::BOLD)
|
| - result += "Bold ";
|
| - if (font_style & gfx::Font::ITALIC)
|
| - result += "Italic ";
|
| - result += base::IntToString(font_size);
|
| - result += "px";
|
| - return result;
|
| -}
|
| -
|
| -// Returns font description from |font_names|, |font_style|, and |font_size|.
|
| -std::string BuildFontDescription(const std::vector<std::string>& font_names,
|
| - int font_style,
|
| - int font_size) {
|
| - std::string description = JoinString(font_names, ',');
|
| - description += "," + FontStyleAndSizeToString(font_style, font_size);
|
| return description;
|
| }
|
|
|
| @@ -85,8 +50,8 @@ FontListImpl::FontListImpl(const std::string& font_description_string)
|
| FontListImpl::FontListImpl(const std::vector<std::string>& font_names,
|
| int font_style,
|
| int font_size)
|
| - : font_description_string_(BuildFontDescription(font_names, font_style,
|
| - font_size)),
|
| + : font_description_string_(BuildDescription(font_names, font_style,
|
| + font_size)),
|
| common_height_(-1),
|
| common_baseline_(-1),
|
| font_style_(font_style),
|
| @@ -133,8 +98,8 @@ FontListImpl* FontListImpl::Derive(int size_delta, int font_style) const {
|
| std::vector<std::string> font_names;
|
| int old_size;
|
| int old_style;
|
| - ParseFontDescriptionString(font_description_string_, &font_names,
|
| - &old_style, &old_size);
|
| + CHECK(FontList::ParseDescription(font_description_string_, &font_names,
|
| + &old_style, &old_size));
|
| const int size = std::max(1, old_size + size_delta);
|
| return new FontListImpl(font_names, font_style, size);
|
| }
|
| @@ -167,21 +132,6 @@ int FontListImpl::GetFontStyle() const {
|
| return font_style_;
|
| }
|
|
|
| -const std::string& FontListImpl::GetFontDescriptionString() const {
|
| - if (font_description_string_.empty()) {
|
| - DCHECK(!fonts_.empty());
|
| - for (size_t i = 0; i < fonts_.size(); ++i) {
|
| - std::string name = fonts_[i].GetFontName();
|
| - font_description_string_ += name;
|
| - font_description_string_ += ',';
|
| - }
|
| - // All fonts have the same style and size.
|
| - font_description_string_ +=
|
| - FontStyleAndSizeToString(fonts_[0].GetStyle(), fonts_[0].GetFontSize());
|
| - }
|
| - return font_description_string_;
|
| -}
|
| -
|
| int FontListImpl::GetFontSize() const {
|
| if (font_size_ == -1)
|
| CacheFontStyleAndSize();
|
| @@ -198,8 +148,8 @@ const std::vector<Font>& FontListImpl::GetFonts() const {
|
| // underline info. So we should respect |font_style_| as long as it's
|
| // valid.
|
| int style = 0;
|
| - ParseFontDescriptionString(font_description_string_, &font_names,
|
| - &style, &font_size_);
|
| + CHECK(FontList::ParseDescription(font_description_string_, &font_names,
|
| + &style, &font_size_));
|
| if (font_style_ == -1)
|
| font_style_ = style;
|
| for (size_t i = 0; i < font_names.size(); ++i) {
|
| @@ -240,8 +190,8 @@ void FontListImpl::CacheFontStyleAndSize() const {
|
| font_size_ = fonts_[0].GetFontSize();
|
| } else {
|
| std::vector<std::string> font_names;
|
| - ParseFontDescriptionString(font_description_string_, &font_names,
|
| - &font_style_, &font_size_);
|
| + CHECK(FontList::ParseDescription(font_description_string_, &font_names,
|
| + &font_style_, &font_size_));
|
| }
|
| }
|
|
|
|
|