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

Unified Diff: ui/gfx/font_list.cc

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 f9b34a674e1f7a72d524b854c16d7a4260512f7e..573c661da72f942131ff6b0d7a6aaa10d3d3859e 100644
--- a/ui/gfx/font_list.cc
+++ b/ui/gfx/font_list.cc
@@ -29,10 +29,12 @@ namespace gfx {
bool FontList::ParseDescription(const std::string& description,
std::vector<std::string>* families_out,
int* style_out,
- int* size_pixels_out) {
+ int* size_pixels_out,
+ gfx::Font::FontWeight* weight_out) {
DCHECK(families_out);
DCHECK(style_out);
DCHECK(size_pixels_out);
+ DCHECK(weight_out);
*families_out = base::SplitString(
description, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
@@ -59,13 +61,30 @@ bool FontList::ParseDescription(const std::string& description,
*size_pixels_out <= 0)
return false;
- // Font supports BOLD and ITALIC; underline is supported via RenderText.
+ // Font supports ITALIC; underline is supported via RenderText.
msw 2016/03/22 01:53:43 nit: "ITALIC and weights"
Mikus 2016/03/22 14:19:51 Done.
*style_out = gfx::Font::NORMAL;
+ *weight_out = gfx::Font::WEIGHT_NORMAL;
for (const auto& style_string : styles) {
- if (style_string == "Bold")
- *style_out |= gfx::Font::BOLD;
- else if (style_string == "Italic")
+ if (style_string == "Italic")
*style_out |= gfx::Font::ITALIC;
+ else if (style_string == "Thin")
+ *weight_out = gfx::Font::WEIGHT_THIN;
+ else if (style_string == "Ultra-Light")
+ *weight_out = gfx::Font::WEIGHT_EXTRA_LIGHT;
+ else if (style_string == "Light")
+ *weight_out = gfx::Font::WEIGHT_LIGHT;
+ else if (style_string == "Normal")
+ *weight_out = gfx::Font::WEIGHT_NORMAL;
+ else if (style_string == "Medium")
+ *weight_out = gfx::Font::WEIGHT_MEDIUM;
+ else if (style_string == "Semi-Bold")
+ *weight_out = gfx::Font::WEIGHT_SEMIBOLD;
+ else if (style_string == "Bold")
+ *weight_out = gfx::Font::WEIGHT_BOLD;
+ else if (style_string == "Ultra-Bold")
+ *weight_out = gfx::Font::WEIGHT_EXTRA_BOLD;
+ else if (style_string == "Heavy")
+ *weight_out = gfx::Font::WEIGHT_BLACK;
else
return false;
}
@@ -82,8 +101,9 @@ FontList::FontList(const std::string& font_description_string)
FontList::FontList(const std::vector<std::string>& font_names,
int font_style,
- int font_size)
- : impl_(new FontListImpl(font_names, font_style, font_size)) {}
+ int font_size,
+ int font_weight)
+ : impl_(new FontListImpl(font_names, font_style, font_size, font_weight)) {}
FontList::FontList(const std::vector<Font>& fonts)
: impl_(new FontListImpl(fonts)) {}
@@ -108,16 +128,22 @@ void FontList::SetDefaultFontDescription(const std::string& font_description) {
g_default_impl_initialized = false;
}
-FontList FontList::Derive(int size_delta, int font_style) const {
- return FontList(impl_->Derive(size_delta, font_style));
+FontList FontList::Derive(int size_delta,
+ int font_style,
+ gfx::Font::FontWeight weight) const {
+ return FontList(impl_->Derive(size_delta, font_style, weight));
}
FontList FontList::DeriveWithSizeDelta(int size_delta) const {
- return Derive(size_delta, GetFontStyle());
+ return Derive(size_delta, GetFontStyle(), GetFontWeight());
}
FontList FontList::DeriveWithStyle(int font_style) const {
- return Derive(0, font_style);
+ return Derive(0, font_style, GetFontWeight());
+}
+
+FontList FontList::DeriveWithWeight(gfx::Font::FontWeight weight) const {
+ return Derive(0, GetFontStyle(), weight);
}
gfx::FontList FontList::DeriveWithHeightUpperBound(int height) const {
@@ -165,6 +191,10 @@ int FontList::GetFontSize() const {
return impl_->GetFontSize();
}
+gfx::Font::FontWeight FontList::GetFontWeight() const {
+ return impl_->GetFontWeight();
+}
+
const std::vector<Font>& FontList::GetFonts() const {
return impl_->GetFonts();
}

Powered by Google App Engine
This is Rietveld 408576698