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

Side by Side Diff: ui/gfx/font_render_params_linux.cc

Issue 403923002: Make GetCustomFontRenderParams() pass font style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove an extra assignment Created 6 years, 5 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 | Annotate | Revision Log
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "ui/gfx/font.h"
9 #include "ui/gfx/linux_font_delegate.h" 10 #include "ui/gfx/linux_font_delegate.h"
10 #include "ui/gfx/switches.h" 11 #include "ui/gfx/switches.h"
11 12
12 #include <fontconfig/fontconfig.h> 13 #include <fontconfig/fontconfig.h>
13 14
14 namespace gfx { 15 namespace gfx {
15 16
16 namespace { 17 namespace {
17 18
18 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. 19 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting.
(...skipping 16 matching lines...) Expand all
35 default: return FontRenderParams::SUBPIXEL_RENDERING_NONE; 36 default: return FontRenderParams::SUBPIXEL_RENDERING_NONE;
36 } 37 }
37 } 38 }
38 39
39 // Queries Fontconfig for rendering settings and updates |params_out| and 40 // Queries Fontconfig for rendering settings and updates |params_out| and
40 // |family_out| (if non-NULL). Returns false on failure. See 41 // |family_out| (if non-NULL). Returns false on failure. See
41 // GetCustomFontRenderParams() for descriptions of arguments. 42 // GetCustomFontRenderParams() for descriptions of arguments.
42 bool QueryFontconfig(const std::vector<std::string>* family_list, 43 bool QueryFontconfig(const std::vector<std::string>* family_list,
43 const int* pixel_size, 44 const int* pixel_size,
44 const int* point_size, 45 const int* point_size,
46 const int* style,
45 FontRenderParams* params_out, 47 FontRenderParams* params_out,
46 std::string* family_out) { 48 std::string* family_out) {
47 FcPattern* pattern = FcPatternCreate(); 49 FcPattern* pattern = FcPatternCreate();
48 CHECK(pattern); 50 CHECK(pattern);
49 51
50 if (family_list) { 52 if (family_list) {
51 for (std::vector<std::string>::const_iterator it = family_list->begin(); 53 for (std::vector<std::string>::const_iterator it = family_list->begin();
52 it != family_list->end(); ++it) { 54 it != family_list->end(); ++it) {
53 FcPatternAddString( 55 FcPatternAddString(
54 pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(it->c_str())); 56 pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(it->c_str()));
55 } 57 }
56 } 58 }
57 if (pixel_size) 59 if (pixel_size)
58 FcPatternAddDouble(pattern, FC_PIXEL_SIZE, *pixel_size); 60 FcPatternAddDouble(pattern, FC_PIXEL_SIZE, *pixel_size);
59 if (point_size) 61 if (point_size)
60 FcPatternAddInteger(pattern, FC_SIZE, *point_size); 62 FcPatternAddInteger(pattern, FC_SIZE, *point_size);
63 if (style) {
64 FcPatternAddInteger(pattern, FC_SLANT,
65 (*style & Font::ITALIC) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
66 FcPatternAddInteger(pattern, FC_WEIGHT,
67 (*style & Font::BOLD) ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL);
68 }
61 69
62 FcConfigSubstitute(NULL, pattern, FcMatchPattern); 70 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
63 FcDefaultSubstitute(pattern); 71 FcDefaultSubstitute(pattern);
64 FcResult result; 72 FcResult result;
65 FcPattern* match = FcFontMatch(NULL, pattern, &result); 73 FcPattern* match = FcFontMatch(NULL, pattern, &result);
66 FcPatternDestroy(pattern); 74 FcPatternDestroy(pattern);
67 if (!match) 75 if (!match)
68 return false; 76 return false;
69 77
70 if (family_out) { 78 if (family_out) {
(...skipping 23 matching lines...) Expand all
94 FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba); 102 FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba);
95 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba); 103 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba);
96 } 104 }
97 105
98 FcPatternDestroy(match); 106 FcPatternDestroy(match);
99 return true; 107 return true;
100 } 108 }
101 109
102 // Initializes |params| with the system's default settings. 110 // Initializes |params| with the system's default settings.
103 void LoadDefaults(FontRenderParams* params, bool for_web_contents) { 111 void LoadDefaults(FontRenderParams* params, bool for_web_contents) {
104 *params = GetCustomFontRenderParams(for_web_contents, NULL, NULL, NULL, NULL); 112 *params = GetCustomFontRenderParams(
113 for_web_contents, NULL, NULL, NULL, NULL, NULL);
105 } 114 }
106 115
107 } // namespace 116 } // namespace
108 117
109 const FontRenderParams& GetDefaultFontRenderParams() { 118 const FontRenderParams& GetDefaultFontRenderParams() {
110 static bool loaded_defaults = false; 119 static bool loaded_defaults = false;
111 static FontRenderParams default_params; 120 static FontRenderParams default_params;
msw 2014/07/19 03:11:52 nit: initialize these with their decalarations by
Daniel Erat 2014/07/19 14:29:05 Done.
112 if (!loaded_defaults) 121 if (!loaded_defaults)
113 LoadDefaults(&default_params, /* for_web_contents */ false); 122 LoadDefaults(&default_params, /* for_web_contents */ false);
114 loaded_defaults = true; 123 loaded_defaults = true;
115 return default_params; 124 return default_params;
116 } 125 }
117 126
118 const FontRenderParams& GetDefaultWebKitFontRenderParams() { 127 const FontRenderParams& GetDefaultWebKitFontRenderParams() {
119 static bool loaded_defaults = false; 128 static bool loaded_defaults = false;
120 static FontRenderParams default_params; 129 static FontRenderParams default_params;
121 if (!loaded_defaults) 130 if (!loaded_defaults)
122 LoadDefaults(&default_params, /* for_web_contents */ true); 131 LoadDefaults(&default_params, /* for_web_contents */ true);
123 loaded_defaults = true; 132 loaded_defaults = true;
124 return default_params; 133 return default_params;
125 } 134 }
126 135
127 FontRenderParams GetCustomFontRenderParams( 136 FontRenderParams GetCustomFontRenderParams(
128 bool for_web_contents, 137 bool for_web_contents,
129 const std::vector<std::string>* family_list, 138 const std::vector<std::string>* family_list,
130 const int* pixel_size, 139 const int* pixel_size,
131 const int* point_size, 140 const int* point_size,
141 const int* style,
132 std::string* family_out) { 142 std::string* family_out) {
133 if (family_out) 143 if (family_out)
134 family_out->clear(); 144 family_out->clear();
135 145
136 // Start with the delegate's settings, but let Fontconfig have the final say. 146 // Start with the delegate's settings, but let Fontconfig have the final say.
137 FontRenderParams params; 147 FontRenderParams params;
138 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); 148 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance();
139 if (delegate) 149 if (delegate)
140 params = delegate->GetDefaultFontRenderParams(); 150 params = delegate->GetDefaultFontRenderParams();
141 QueryFontconfig(family_list, pixel_size, point_size, &params, family_out); 151 QueryFontconfig(
152 family_list, pixel_size, point_size, style, &params, family_out);
142 153
143 // Fontconfig doesn't support configuring subpixel positioning; check a flag. 154 // Fontconfig doesn't support configuring subpixel positioning; check a flag.
144 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch( 155 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch(
145 for_web_contents ? 156 for_web_contents ?
146 switches::kEnableWebkitTextSubpixelPositioning : 157 switches::kEnableWebkitTextSubpixelPositioning :
147 switches::kEnableBrowserTextSubpixelPositioning); 158 switches::kEnableBrowserTextSubpixelPositioning);
148 159
149 // To enable subpixel positioning, we need to disable hinting. 160 // To enable subpixel positioning, we need to disable hinting.
150 if (params.subpixel_positioning) 161 if (params.subpixel_positioning)
151 params.hinting = FontRenderParams::HINTING_NONE; 162 params.hinting = FontRenderParams::HINTING_NONE;
152 163
153 // Use the first family from the list if Fontconfig didn't suggest a family. 164 // Use the first family from the list if Fontconfig didn't suggest a family.
154 if (family_out && family_out->empty() && 165 if (family_out && family_out->empty() &&
155 family_list && !family_list->empty()) 166 family_list && !family_list->empty())
156 *family_out = (*family_list)[0]; 167 *family_out = (*family_list)[0];
157 168
158 return params; 169 return params;
159 } 170 }
160 171
161 } // namespace gfx 172 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698