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

Unified Diff: ui/gfx/font_render_params_linux.cc

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a lost comment and modify a render text unittest to not test black because of test env font con… Created 4 years, 7 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
« no previous file with comments | « ui/gfx/font_render_params.cc ('k') | ui/gfx/font_render_params_linux_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/font_render_params_linux.cc
diff --git a/ui/gfx/font_render_params_linux.cc b/ui/gfx/font_render_params_linux.cc
index f2db4facf70e08719e09174b8dd9a79632a8cfb1..92f9edc5edd8cc9adf5effd889a2834c10823015 100644
--- a/ui/gfx/font_render_params_linux.cc
+++ b/ui/gfx/font_render_params_linux.cc
@@ -28,6 +28,44 @@ namespace gfx {
namespace {
+int FontWeightToFCWeight(Font::Weight weight) {
+ const int weight_number = static_cast<int>(weight);
+ if (weight_number <= (static_cast<int>(Font::Weight::THIN) +
+ static_cast<int>(Font::Weight::EXTRA_LIGHT)) /
+ 2)
+ return FC_WEIGHT_THIN;
+ else if (weight_number <= (static_cast<int>(Font::Weight::EXTRA_LIGHT) +
+ static_cast<int>(Font::Weight::LIGHT)) /
+ 2)
+ return FC_WEIGHT_ULTRALIGHT;
+ else if (weight_number <= (static_cast<int>(Font::Weight::LIGHT) +
+ static_cast<int>(Font::Weight::NORMAL)) /
+ 2)
+ return FC_WEIGHT_LIGHT;
+ else if (weight_number <= (static_cast<int>(Font::Weight::NORMAL) +
+ static_cast<int>(Font::Weight::MEDIUM)) /
+ 2)
+ return FC_WEIGHT_NORMAL;
+ else if (weight_number <= (static_cast<int>(Font::Weight::MEDIUM) +
+ static_cast<int>(Font::Weight::SEMIBOLD)) /
+ 2)
+ return FC_WEIGHT_MEDIUM;
+ else if (weight_number <= (static_cast<int>(Font::Weight::SEMIBOLD) +
+ static_cast<int>(Font::Weight::BOLD)) /
+ 2)
+ return FC_WEIGHT_DEMIBOLD;
+ else if (weight_number <= (static_cast<int>(Font::Weight::BOLD) +
+ static_cast<int>(Font::Weight::EXTRA_BOLD)) /
+ 2)
+ return FC_WEIGHT_BOLD;
+ else if (weight_number <= (static_cast<int>(Font::Weight::EXTRA_BOLD) +
+ static_cast<int>(Font::Weight::BLACK)) /
+ 2)
+ return FC_WEIGHT_ULTRABOLD;
+ else
+ return FC_WEIGHT_BLACK;
+}
+
// A device scale factor used to determine if subpixel positioning
// should be used.
float device_scale_factor_ = 1.0f;
@@ -112,8 +150,10 @@ bool QueryFontconfig(const FontRenderParamsQuery& query,
if (query.style >= 0) {
FcPatternAddInteger(query_pattern.get(), FC_SLANT,
(query.style & Font::ITALIC) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
+ }
+ if (query.weight != Font::Weight::INVALID) {
FcPatternAddInteger(query_pattern.get(), FC_WEIGHT,
- (query.style & Font::BOLD) ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL);
+ FontWeightToFCWeight(query.weight));
}
FcConfigSubstitute(NULL, query_pattern.get(), FcMatchPattern);
@@ -191,7 +231,8 @@ bool QueryFontconfig(const FontRenderParamsQuery& query,
// cache key.
uint32_t HashFontRenderParamsQuery(const FontRenderParamsQuery& query) {
return base::Hash(base::StringPrintf(
- "%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style,
+ "%d|%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style,
+ static_cast<int>(query.weight),
base::JoinString(query.families, ",").c_str(),
query.device_scale_factor));
}
« no previous file with comments | « ui/gfx/font_render_params.cc ('k') | ui/gfx/font_render_params_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698