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

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: apply review feedback 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
« no previous file with comments | « ui/gfx/font_render_params_android.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 "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 21 matching lines...) Expand all
92 100
93 int fc_rgba = FC_RGBA_NONE; 101 int fc_rgba = FC_RGBA_NONE;
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 // Returns the system's default settings.
103 void LoadDefaults(FontRenderParams* params, bool for_web_contents) { 111 FontRenderParams LoadDefaults(bool for_web_contents) {
104 *params = GetCustomFontRenderParams(for_web_contents, NULL, NULL, NULL, NULL); 112 return 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 FontRenderParams default_params = LoadDefaults(false);
111 static FontRenderParams default_params;
112 if (!loaded_defaults)
113 LoadDefaults(&default_params, /* for_web_contents */ false);
114 loaded_defaults = true;
115 return default_params; 120 return default_params;
116 } 121 }
117 122
118 const FontRenderParams& GetDefaultWebKitFontRenderParams() { 123 const FontRenderParams& GetDefaultWebKitFontRenderParams() {
119 static bool loaded_defaults = false; 124 static FontRenderParams default_params = LoadDefaults(true);
120 static FontRenderParams default_params;
121 if (!loaded_defaults)
122 LoadDefaults(&default_params, /* for_web_contents */ true);
123 loaded_defaults = true;
124 return default_params; 125 return default_params;
125 } 126 }
126 127
127 FontRenderParams GetCustomFontRenderParams( 128 FontRenderParams GetCustomFontRenderParams(
128 bool for_web_contents, 129 bool for_web_contents,
129 const std::vector<std::string>* family_list, 130 const std::vector<std::string>* family_list,
130 const int* pixel_size, 131 const int* pixel_size,
131 const int* point_size, 132 const int* point_size,
133 const int* style,
132 std::string* family_out) { 134 std::string* family_out) {
133 if (family_out) 135 if (family_out)
134 family_out->clear(); 136 family_out->clear();
135 137
136 // Start with the delegate's settings, but let Fontconfig have the final say. 138 // Start with the delegate's settings, but let Fontconfig have the final say.
137 FontRenderParams params; 139 FontRenderParams params;
138 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); 140 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance();
139 if (delegate) 141 if (delegate)
140 params = delegate->GetDefaultFontRenderParams(); 142 params = delegate->GetDefaultFontRenderParams();
141 QueryFontconfig(family_list, pixel_size, point_size, &params, family_out); 143 QueryFontconfig(
144 family_list, pixel_size, point_size, style, &params, family_out);
142 145
143 // Fontconfig doesn't support configuring subpixel positioning; check a flag. 146 // Fontconfig doesn't support configuring subpixel positioning; check a flag.
144 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch( 147 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch(
145 for_web_contents ? 148 for_web_contents ?
146 switches::kEnableWebkitTextSubpixelPositioning : 149 switches::kEnableWebkitTextSubpixelPositioning :
147 switches::kEnableBrowserTextSubpixelPositioning); 150 switches::kEnableBrowserTextSubpixelPositioning);
148 151
149 // To enable subpixel positioning, we need to disable hinting. 152 // To enable subpixel positioning, we need to disable hinting.
150 if (params.subpixel_positioning) 153 if (params.subpixel_positioning)
151 params.hinting = FontRenderParams::HINTING_NONE; 154 params.hinting = FontRenderParams::HINTING_NONE;
152 155
153 // Use the first family from the list if Fontconfig didn't suggest a family. 156 // Use the first family from the list if Fontconfig didn't suggest a family.
154 if (family_out && family_out->empty() && 157 if (family_out && family_out->empty() &&
155 family_list && !family_list->empty()) 158 family_list && !family_list->empty())
156 *family_out = (*family_list)[0]; 159 *family_out = (*family_list)[0];
157 160
158 return params; 161 return params;
159 } 162 }
160 163
161 } // namespace gfx 164 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_render_params_android.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