OLD | NEW |
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/linux_font_delegate.h" |
9 #include "ui/gfx/switches.h" | 10 #include "ui/gfx/switches.h" |
10 | 11 |
11 #include <fontconfig/fontconfig.h> | 12 #include <fontconfig/fontconfig.h> |
12 | 13 |
13 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
14 #include "ui/gfx/linux_font_delegate.h" | |
15 #endif | |
16 | |
17 namespace gfx { | 14 namespace gfx { |
18 | 15 |
19 namespace { | 16 namespace { |
20 | 17 |
21 bool SubpixelPositioningRequested(bool for_web_contents) { | |
22 return CommandLine::ForCurrentProcess()->HasSwitch( | |
23 for_web_contents ? switches::kEnableWebkitTextSubpixelPositioning | |
24 : switches::kEnableBrowserTextSubpixelPositioning); | |
25 } | |
26 | |
27 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. | 18 // Converts Fontconfig FC_HINT_STYLE to FontRenderParams::Hinting. |
28 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) { | 19 FontRenderParams::Hinting ConvertFontconfigHintStyle(int hint_style) { |
29 switch (hint_style) { | 20 switch (hint_style) { |
30 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; | 21 case FC_HINT_SLIGHT: return FontRenderParams::HINTING_SLIGHT; |
31 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; | 22 case FC_HINT_MEDIUM: return FontRenderParams::HINTING_MEDIUM; |
32 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; | 23 case FC_HINT_FULL: return FontRenderParams::HINTING_FULL; |
33 default: return FontRenderParams::HINTING_NONE; | 24 default: return FontRenderParams::HINTING_NONE; |
34 } | 25 } |
35 } | 26 } |
36 | 27 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 loaded_defaults = true; | 123 loaded_defaults = true; |
133 return default_params; | 124 return default_params; |
134 } | 125 } |
135 | 126 |
136 FontRenderParams GetCustomFontRenderParams( | 127 FontRenderParams GetCustomFontRenderParams( |
137 bool for_web_contents, | 128 bool for_web_contents, |
138 const std::vector<std::string>* family_list, | 129 const std::vector<std::string>* family_list, |
139 const int* pixel_size, | 130 const int* pixel_size, |
140 const int* point_size, | 131 const int* point_size, |
141 std::string* family_out) { | 132 std::string* family_out) { |
142 FontRenderParams params; | |
143 if (family_out) | 133 if (family_out) |
144 family_out->clear(); | 134 family_out->clear(); |
145 | 135 |
146 #if defined(OS_CHROMEOS) | 136 // Start with the delegate's settings, but let Fontconfig have the final say. |
147 // Use reasonable defaults. | 137 FontRenderParams params; |
148 params.antialiasing = true; | 138 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); |
149 params.autohinter = true; | 139 if (delegate) |
150 params.use_bitmaps = true; | 140 params = delegate->GetDefaultFontRenderParams(); |
151 params.hinting = FontRenderParams::HINTING_SLIGHT; | 141 QueryFontconfig(family_list, pixel_size, point_size, ¶ms, family_out); |
152 | 142 |
153 // Query Fontconfig to get the family name and subpixel rendering setting. | 143 // Fontconfig doesn't support configuring subpixel positioning; check a flag. |
154 // In general, we try to limit Chrome OS's dependency on Fontconfig, but it's | 144 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch( |
155 // used to configure fonts for different scripts and to disable subpixel | 145 for_web_contents ? |
156 // rendering on systems that use external displays. | 146 switches::kEnableWebkitTextSubpixelPositioning : |
157 // TODO(derat): Decide if we should just use Fontconfig wholeheartedly on | 147 switches::kEnableBrowserTextSubpixelPositioning); |
158 // Chrome OS; Blink is using it, after all. | |
159 FontRenderParams fc_params; | |
160 QueryFontconfig(family_list, pixel_size, point_size, &fc_params, family_out); | |
161 params.subpixel_rendering = fc_params.subpixel_rendering; | |
162 #else | |
163 // Start with the delegate's settings, but let Fontconfig have the final say. | |
164 // TODO(derat): Figure out if we need to query the delegate at all. Does | |
165 // GtkSettings always get overridden by Fontconfig in GTK apps? | |
166 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); | |
167 if (delegate) { | |
168 params.antialiasing = delegate->UseAntialiasing(); | |
169 params.hinting = delegate->GetHintingStyle(); | |
170 params.subpixel_rendering = delegate->GetSubpixelRenderingStyle(); | |
171 } | |
172 QueryFontconfig(family_list, pixel_size, point_size, ¶ms, family_out); | |
173 #endif | |
174 | |
175 params.subpixel_positioning = SubpixelPositioningRequested(for_web_contents); | |
176 | 148 |
177 // To enable subpixel positioning, we need to disable hinting. | 149 // To enable subpixel positioning, we need to disable hinting. |
178 if (params.subpixel_positioning) | 150 if (params.subpixel_positioning) |
179 params.hinting = FontRenderParams::HINTING_NONE; | 151 params.hinting = FontRenderParams::HINTING_NONE; |
180 | 152 |
181 // Use the first family from the list if Fontconfig didn't suggest a family. | 153 // Use the first family from the list if Fontconfig didn't suggest a family. |
182 if (family_out && family_out->empty() && | 154 if (family_out && family_out->empty() && |
183 family_list && !family_list->empty()) | 155 family_list && !family_list->empty()) |
184 *family_out = (*family_list)[0]; | 156 *family_out = (*family_list)[0]; |
185 | 157 |
186 return params; | 158 return params; |
187 } | 159 } |
188 | 160 |
189 } // namespace gfx | 161 } // namespace gfx |
OLD | NEW |