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

Unified Diff: ui/gfx/font_list.cc

Issue 903423002: Make FontList description-parsing public. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge and apply review feedback Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/font_list.cc
diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc
index ca0c8ade58410c5604dbde0de45f5539439ded6e..aea739637cc6b3e8bc820b00ef9395f88353fd0e 100644
--- a/ui/gfx/font_list.cc
+++ b/ui/gfx/font_list.cc
@@ -5,6 +5,8 @@
#include "ui/gfx/font_list.h"
#include "base/lazy_instance.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "ui/gfx/font_list_impl.h"
@@ -23,6 +25,52 @@ bool g_default_impl_initialized = false;
namespace gfx {
+// static
+bool FontList::ParseDescription(const std::string& description,
+ std::vector<std::string>* families_out,
+ int* style_out,
+ int* size_pixels_out) {
+ DCHECK(families_out);
+ DCHECK(style_out);
+ DCHECK(size_pixels_out);
+
+ base::SplitString(description, ',', families_out);
+ if (families_out->empty())
+ return false;
+ for (auto& family : *families_out)
+ base::TrimWhitespaceASCII(family, base::TRIM_ALL, &family);
+
+ // The last item is "[STYLE1] [STYLE2] [...] SIZE".
+ std::vector<std::string> styles;
+ base::SplitStringAlongWhitespace(families_out->back(), &styles);
+ families_out->pop_back();
+ if (styles.empty())
+ return false;
+
+ // The size takes the form "<INT>px".
+ std::string size_string = styles.back();
+ styles.pop_back();
+ if (!EndsWith(size_string, "px", true /* case_sensitive */))
+ return false;
+ size_string.resize(size_string.size() - 2);
+ if (!base::StringToInt(size_string, size_pixels_out) ||
+ *size_pixels_out <= 0)
+ return false;
+
+ // Font supports BOLD and ITALIC; underline is supported via RenderText.
+ *style_out = gfx::Font::NORMAL;
+ for (const auto& style_string : styles) {
+ if (style_string == "Bold")
+ *style_out |= gfx::Font::BOLD;
+ else if (style_string == "Italic")
+ *style_out |= gfx::Font::ITALIC;
+ else
+ return false;
+ }
+
+ return true;
+}
+
FontList::FontList() : impl_(GetDefaultImpl()) {}
FontList::FontList(const FontList& other) : impl_(other.impl_) {}
@@ -111,10 +159,6 @@ int FontList::GetFontStyle() const {
return impl_->GetFontStyle();
}
-const std::string& FontList::GetFontDescriptionString() const {
- return impl_->GetFontDescriptionString();
-}
-
int FontList::GetFontSize() const {
return impl_->GetFontSize();
}
« no previous file with comments | « ui/gfx/font_list.h ('k') | ui/gfx/font_list_impl.h » ('j') | ui/gfx/pango_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698