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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/font_render_params.h" 5 #include "ui/gfx/font_render_params.h"
6 6
7 #include <fontconfig/fontconfig.h> 7 #include <fontconfig/fontconfig.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "ui/gfx/font.h" 23 #include "ui/gfx/font.h"
24 #include "ui/gfx/linux_font_delegate.h" 24 #include "ui/gfx/linux_font_delegate.h"
25 #include "ui/gfx/switches.h" 25 #include "ui/gfx/switches.h"
26 26
27 namespace gfx { 27 namespace gfx {
28 28
29 namespace { 29 namespace {
30 30
31 int FontWeightToFCWeight(Font::Weight weight) {
32 const int weight_number = static_cast<int>(weight);
33 if (weight_number <= (static_cast<int>(Font::Weight::THIN) +
34 static_cast<int>(Font::Weight::EXTRA_LIGHT)) /
35 2)
36 return FC_WEIGHT_THIN;
37 else if (weight_number <= (static_cast<int>(Font::Weight::EXTRA_LIGHT) +
38 static_cast<int>(Font::Weight::LIGHT)) /
39 2)
40 return FC_WEIGHT_ULTRALIGHT;
41 else if (weight_number <= (static_cast<int>(Font::Weight::LIGHT) +
42 static_cast<int>(Font::Weight::NORMAL)) /
43 2)
44 return FC_WEIGHT_LIGHT;
45 else if (weight_number <= (static_cast<int>(Font::Weight::NORMAL) +
46 static_cast<int>(Font::Weight::MEDIUM)) /
47 2)
48 return FC_WEIGHT_NORMAL;
49 else if (weight_number <= (static_cast<int>(Font::Weight::MEDIUM) +
50 static_cast<int>(Font::Weight::SEMIBOLD)) /
51 2)
52 return FC_WEIGHT_MEDIUM;
53 else if (weight_number <= (static_cast<int>(Font::Weight::SEMIBOLD) +
54 static_cast<int>(Font::Weight::BOLD)) /
55 2)
56 return FC_WEIGHT_DEMIBOLD;
57 else if (weight_number <= (static_cast<int>(Font::Weight::BOLD) +
58 static_cast<int>(Font::Weight::EXTRA_BOLD)) /
59 2)
60 return FC_WEIGHT_BOLD;
61 else if (weight_number <= (static_cast<int>(Font::Weight::EXTRA_BOLD) +
62 static_cast<int>(Font::Weight::BLACK)) /
63 2)
64 return FC_WEIGHT_ULTRABOLD;
65 else
66 return FC_WEIGHT_BLACK;
67 }
68
31 // A device scale factor used to determine if subpixel positioning 69 // A device scale factor used to determine if subpixel positioning
32 // should be used. 70 // should be used.
33 float device_scale_factor_ = 1.0f; 71 float device_scale_factor_ = 1.0f;
34 72
35 // Number of recent GetFontRenderParams() results to cache. 73 // Number of recent GetFontRenderParams() results to cache.
36 const size_t kCacheSize = 256; 74 const size_t kCacheSize = 256;
37 75
38 // Cached result from a call to GetFontRenderParams(). 76 // Cached result from a call to GetFontRenderParams().
39 struct QueryResult { 77 struct QueryResult {
40 QueryResult(const FontRenderParams& params, const std::string& family) 78 QueryResult(const FontRenderParams& params, const std::string& family)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 FcPatternAddString(query_pattern.get(), 143 FcPatternAddString(query_pattern.get(),
106 FC_FAMILY, reinterpret_cast<const FcChar8*>(it->c_str())); 144 FC_FAMILY, reinterpret_cast<const FcChar8*>(it->c_str()));
107 } 145 }
108 if (query.pixel_size > 0) 146 if (query.pixel_size > 0)
109 FcPatternAddDouble(query_pattern.get(), FC_PIXEL_SIZE, query.pixel_size); 147 FcPatternAddDouble(query_pattern.get(), FC_PIXEL_SIZE, query.pixel_size);
110 if (query.point_size > 0) 148 if (query.point_size > 0)
111 FcPatternAddInteger(query_pattern.get(), FC_SIZE, query.point_size); 149 FcPatternAddInteger(query_pattern.get(), FC_SIZE, query.point_size);
112 if (query.style >= 0) { 150 if (query.style >= 0) {
113 FcPatternAddInteger(query_pattern.get(), FC_SLANT, 151 FcPatternAddInteger(query_pattern.get(), FC_SLANT,
114 (query.style & Font::ITALIC) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); 152 (query.style & Font::ITALIC) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
153 }
154 if (query.weight() != Font::Weight::INVALID) {
115 FcPatternAddInteger(query_pattern.get(), FC_WEIGHT, 155 FcPatternAddInteger(query_pattern.get(), FC_WEIGHT,
116 (query.style & Font::BOLD) ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL); 156 FontWeightToFCWeight(query.weight));
117 } 157 }
118 158
119 FcConfigSubstitute(NULL, query_pattern.get(), FcMatchPattern); 159 FcConfigSubstitute(NULL, query_pattern.get(), FcMatchPattern);
120 FcDefaultSubstitute(query_pattern.get()); 160 FcDefaultSubstitute(query_pattern.get());
121 161
122 ScopedFcPattern result_pattern; 162 ScopedFcPattern result_pattern;
123 if (query.is_empty()) { 163 if (query.is_empty()) {
124 // If the query was empty, call FcConfigSubstituteWithPat() to get a 164 // If the query was empty, call FcConfigSubstituteWithPat() to get a
125 // non-family- or size-specific configuration so it can be used as the 165 // non-family- or size-specific configuration so it can be used as the
126 // default. 166 // default.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 308
269 float GetFontRenderParamsDeviceScaleFactor() { 309 float GetFontRenderParamsDeviceScaleFactor() {
270 return device_scale_factor_; 310 return device_scale_factor_;
271 } 311 }
272 312
273 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { 313 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) {
274 device_scale_factor_ = device_scale_factor; 314 device_scale_factor_ = device_scale_factor;
275 } 315 }
276 316
277 } // namespace gfx 317 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698