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

Unified Diff: ui/gfx/font_list_impl.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_impl.cc
diff --git a/ui/gfx/font_list_impl.cc b/ui/gfx/font_list_impl.cc
index 3bab76feacefdc025d3418f227b6d89f2fcca31b..a88978792c688571ce2e246334b0f395b80ff34f 100644
--- a/ui/gfx/font_list_impl.cc
+++ b/ui/gfx/font_list_impl.cc
@@ -11,7 +11,6 @@
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#include "ui/gfx/font.h"
#include "ui/gfx/font_list.h"
namespace {
@@ -19,17 +18,49 @@ namespace {
// Returns a font description from |families|, |style|, and |size_pixels|.
std::string BuildDescription(const std::vector<std::string>& families,
int style,
- int size_pixels) {
+ int size_pixels,
+ int weight) {
sky 2016/03/21 17:13:22 Can this takes a Font::FontWeight?
std::string description = base::JoinString(families, ",");
description += ",";
- if (style & gfx::Font::BOLD)
- description += "Bold ";
if (style & gfx::Font::ITALIC)
description += "Italic ";
+ switch (static_cast<gfx::Font::FontWeight>(weight)) {
+ case gfx::Font::FontWeight::WEIGHT_THIN:
+ description += "Thin ";
+ break;
+ case gfx::Font::FontWeight::WEIGHT_EXTRA_LIGHT:
+ description += "Ultra-Light ";
+ break;
+ case gfx::Font::FontWeight::WEIGHT_LIGHT:
+ description += "Light ";
+ break;
+ case gfx::Font::FontWeight::WEIGHT_NORMAL:
+ description += "Normal ";
msw 2016/03/22 01:53:43 Can/should we omit normal here?
Mikus 2016/03/22 14:19:51 I guess there'd be nothing wrong with that.
+ break;
+ case gfx::Font::FontWeight::WEIGHT_MEDIUM:
+ description += "Medium ";
+ break;
+ case gfx::Font::FontWeight::WEIGHT_SEMIBOLD:
+ description += "Semi-Bold ";
+ break;
+ case gfx::Font::FontWeight::WEIGHT_BOLD:
+ description += "Bold ";
+ break;
+ case gfx::Font::FontWeight::WEIGHT_EXTRA_BOLD:
+ description += "Ultra-Bold ";
+ break;
+ case gfx::Font::FontWeight::WEIGHT_BLACK:
+ description += "Heavy ";
+ break;
+ default:
+ break;
+ }
description += base::IntToString(size_pixels);
- description += "px";
+ description += "px ";
+
msw 2016/03/22 01:53:43 nit: remove blank line
+ description += base::IntToString(weight);
return description;
}
@@ -43,7 +74,8 @@ FontListImpl::FontListImpl(const std::string& font_description_string)
common_height_(-1),
common_baseline_(-1),
font_style_(-1),
- font_size_(-1) {
+ font_size_(-1),
+ font_weight_(gfx::Font::WEIGHT_INVALID) {
DCHECK(!font_description_string.empty());
// DCHECK description string ends with "px" for size in pixel.
DCHECK(base::EndsWith(font_description_string, "px",
@@ -52,13 +84,15 @@ 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_(BuildDescription(font_names, font_style,
- font_size)),
+ int font_size,
+ int font_weight)
+ : font_description_string_(
+ BuildDescription(font_names, font_style, font_size, font_weight)),
common_height_(-1),
common_baseline_(-1),
font_style_(font_style),
- font_size_(font_size) {
+ font_size_(font_size),
+ font_weight_(gfx::Font::WEIGHT_INVALID) {
msw 2016/03/22 01:53:43 Shouldn't this init to |font_weight|?
Mikus 2016/03/22 14:19:51 Done.
DCHECK(!font_names.empty());
DCHECK(!font_names[0].empty());
}
@@ -68,10 +102,12 @@ FontListImpl::FontListImpl(const std::vector<Font>& fonts)
common_height_(-1),
common_baseline_(-1),
font_style_(-1),
- font_size_(-1) {
+ font_size_(-1),
+ font_weight_(gfx::Font::WEIGHT_INVALID) {
DCHECK(!fonts.empty());
font_style_ = fonts[0].GetStyle();
font_size_ = fonts[0].GetFontSize();
+ font_weight_ = fonts[0].GetWeight();
#if DCHECK_IS_ON()
for (size_t i = 1; i < fonts.size(); ++i) {
DCHECK_EQ(fonts[i].GetStyle(), font_style_);
@@ -84,16 +120,19 @@ FontListImpl::FontListImpl(const Font& font)
: common_height_(-1),
common_baseline_(-1),
font_style_(-1),
- font_size_(-1) {
+ font_size_(-1),
+ font_weight_(gfx::Font::WEIGHT_INVALID) {
fonts_.push_back(font);
}
-FontListImpl* FontListImpl::Derive(int size_delta, int font_style) const {
+FontListImpl* FontListImpl::Derive(int size_delta,
+ int font_style,
+ gfx::Font::FontWeight weight) const {
// If there is a font vector, derive from that.
if (!fonts_.empty()) {
std::vector<Font> fonts = fonts_;
for (size_t i = 0; i < fonts.size(); ++i)
- fonts[i] = fonts[i].Derive(size_delta, font_style);
+ fonts[i] = fonts[i].Derive(size_delta, font_style, weight);
return new FontListImpl(fonts);
}
@@ -101,10 +140,11 @@ FontListImpl* FontListImpl::Derive(int size_delta, int font_style) const {
std::vector<std::string> font_names;
int old_size;
int old_style;
msw 2016/03/22 01:53:43 I find it weird that this code ignores the descrip
Mikus 2016/03/22 14:19:51 It's just like with old_style, it's ignored as wel
msw 2016/03/22 18:24:10 Acknowledged; the current style and weight don't m
+ gfx::Font::FontWeight old_weight;
CHECK(FontList::ParseDescription(font_description_string_, &font_names,
- &old_style, &old_size));
+ &old_style, &old_size, &old_weight));
const int size = std::max(1, old_size + size_delta);
- return new FontListImpl(font_names, font_style, size);
+ return new FontListImpl(font_names, font_style, size, weight);
}
int FontListImpl::GetHeight() const {
@@ -141,6 +181,12 @@ int FontListImpl::GetFontSize() const {
return font_size_;
}
+gfx::Font::FontWeight FontListImpl::GetFontWeight() const {
+ if (font_weight_ == gfx::Font::WEIGHT_INVALID)
+ CacheFontStyleAndSize();
+ return font_weight_;
+}
+
const std::vector<Font>& FontListImpl::GetFonts() const {
if (fonts_.empty()) {
DCHECK(!font_description_string_.empty());
@@ -152,7 +198,7 @@ const std::vector<Font>& FontListImpl::GetFonts() const {
// valid.
int style = 0;
CHECK(FontList::ParseDescription(font_description_string_, &font_names,
- &style, &font_size_));
+ &style, &font_size_, &font_weight_));
if (font_style_ == -1)
font_style_ = style;
for (size_t i = 0; i < font_names.size(); ++i) {
@@ -162,7 +208,7 @@ const std::vector<Font>& FontListImpl::GetFonts() const {
if (font_style_ == Font::NORMAL)
fonts_.push_back(font);
else
- fonts_.push_back(font.Derive(0, font_style_));
+ fonts_.push_back(font.Derive(0, font_style_, font_weight_));
}
}
return fonts_;
@@ -191,10 +237,11 @@ void FontListImpl::CacheFontStyleAndSize() const {
if (!fonts_.empty()) {
font_style_ = fonts_[0].GetStyle();
font_size_ = fonts_[0].GetFontSize();
+ font_weight_ = fonts_[0].GetWeight();
} else {
std::vector<std::string> font_names;
CHECK(FontList::ParseDescription(font_description_string_, &font_names,
- &font_style_, &font_size_));
+ &font_style_, &font_size_, &font_weight_));
}
}

Powered by Google App Engine
This is Rietveld 408576698