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

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: Attempt to fix yet another unittest on Linux. 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
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..74d1d10af535d40b2bcc488f719b1d11f6ca51f3 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);

Powered by Google App Engine
This is Rietveld 408576698