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

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: Add a lost comment and modify a render text unittest to not test black because of test env font con… 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba); 224 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba);
185 } 225 }
186 226
187 return true; 227 return true;
188 } 228 }
189 229
190 // Serialize |query| into a string and hash it to a value suitable for use as a 230 // Serialize |query| into a string and hash it to a value suitable for use as a
191 // cache key. 231 // cache key.
192 uint32_t HashFontRenderParamsQuery(const FontRenderParamsQuery& query) { 232 uint32_t HashFontRenderParamsQuery(const FontRenderParamsQuery& query) {
193 return base::Hash(base::StringPrintf( 233 return base::Hash(base::StringPrintf(
194 "%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style, 234 "%d|%d|%d|%d|%s|%f", query.pixel_size, query.point_size, query.style,
235 static_cast<int>(query.weight),
195 base::JoinString(query.families, ",").c_str(), 236 base::JoinString(query.families, ",").c_str(),
196 query.device_scale_factor)); 237 query.device_scale_factor));
197 } 238 }
198 239
199 } // namespace 240 } // namespace
200 241
201 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query, 242 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
202 std::string* family_out) { 243 std::string* family_out) {
203 FontRenderParamsQuery actual_query(query); 244 FontRenderParamsQuery actual_query(query);
204 if (actual_query.device_scale_factor == 0) 245 if (actual_query.device_scale_factor == 0)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 309
269 float GetFontRenderParamsDeviceScaleFactor() { 310 float GetFontRenderParamsDeviceScaleFactor() {
270 return device_scale_factor_; 311 return device_scale_factor_;
271 } 312 }
272 313
273 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) { 314 void SetFontRenderParamsDeviceScaleFactor(float device_scale_factor) {
274 device_scale_factor_ = device_scale_factor; 315 device_scale_factor_ = device_scale_factor;
275 } 316 }
276 317
277 } // namespace gfx 318 } // namespace gfx
OLDNEW
« 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