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

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

Issue 413003002: Add FontRenderParamsQuery. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update PlatformFontWin::GetFontRenderParams() to use a static 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/font.h"
10 #include "ui/gfx/linux_font_delegate.h" 10 #include "ui/gfx/linux_font_delegate.h"
(...skipping 20 matching lines...) Expand all
31 switch (rgba) { 31 switch (rgba) {
32 case FC_RGBA_RGB: return FontRenderParams::SUBPIXEL_RENDERING_RGB; 32 case FC_RGBA_RGB: return FontRenderParams::SUBPIXEL_RENDERING_RGB;
33 case FC_RGBA_BGR: return FontRenderParams::SUBPIXEL_RENDERING_BGR; 33 case FC_RGBA_BGR: return FontRenderParams::SUBPIXEL_RENDERING_BGR;
34 case FC_RGBA_VRGB: return FontRenderParams::SUBPIXEL_RENDERING_VRGB; 34 case FC_RGBA_VRGB: return FontRenderParams::SUBPIXEL_RENDERING_VRGB;
35 case FC_RGBA_VBGR: return FontRenderParams::SUBPIXEL_RENDERING_VBGR; 35 case FC_RGBA_VBGR: return FontRenderParams::SUBPIXEL_RENDERING_VBGR;
36 default: return FontRenderParams::SUBPIXEL_RENDERING_NONE; 36 default: return FontRenderParams::SUBPIXEL_RENDERING_NONE;
37 } 37 }
38 } 38 }
39 39
40 // Queries Fontconfig for rendering settings and updates |params_out| and 40 // Queries Fontconfig for rendering settings and updates |params_out| and
41 // |family_out| (if non-NULL). Returns false on failure. See 41 // |family_out| (if non-NULL). Returns false on failure.
42 // GetCustomFontRenderParams() for descriptions of arguments. 42 bool QueryFontconfig(const FontRenderParamsQuery& query,
43 bool QueryFontconfig(const std::vector<std::string>* family_list,
44 const int* pixel_size,
45 const int* point_size,
46 const int* style,
47 FontRenderParams* params_out, 43 FontRenderParams* params_out,
48 std::string* family_out) { 44 std::string* family_out) {
49 FcPattern* pattern = FcPatternCreate(); 45 FcPattern* pattern = FcPatternCreate();
50 CHECK(pattern); 46 CHECK(pattern);
51 47
52 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); 48 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
53 49
54 if (family_list) { 50 for (std::vector<std::string>::const_iterator it = query.families.begin();
55 for (std::vector<std::string>::const_iterator it = family_list->begin(); 51 it != query.families.end(); ++it) {
56 it != family_list->end(); ++it) { 52 FcPatternAddString(
57 FcPatternAddString( 53 pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(it->c_str()));
58 pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(it->c_str()));
59 }
60 } 54 }
61 if (pixel_size) 55 if (query.pixel_size > 0)
62 FcPatternAddDouble(pattern, FC_PIXEL_SIZE, *pixel_size); 56 FcPatternAddDouble(pattern, FC_PIXEL_SIZE, query.pixel_size);
63 if (point_size) 57 if (query.point_size > 0)
64 FcPatternAddInteger(pattern, FC_SIZE, *point_size); 58 FcPatternAddInteger(pattern, FC_SIZE, query.point_size);
65 if (style) { 59 if (query.style >= 0) {
66 FcPatternAddInteger(pattern, FC_SLANT, 60 FcPatternAddInteger(pattern, FC_SLANT,
67 (*style & Font::ITALIC) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); 61 (query.style & Font::ITALIC) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
68 FcPatternAddInteger(pattern, FC_WEIGHT, 62 FcPatternAddInteger(pattern, FC_WEIGHT,
69 (*style & Font::BOLD) ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL); 63 (query.style & Font::BOLD) ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL);
70 } 64 }
71 65
72 FcConfigSubstitute(NULL, pattern, FcMatchPattern); 66 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
73 FcDefaultSubstitute(pattern); 67 FcDefaultSubstitute(pattern);
74 FcResult result; 68 FcResult result;
75 FcPattern* match = FcFontMatch(NULL, pattern, &result); 69 FcPattern* match = FcFontMatch(NULL, pattern, &result);
76 FcPatternDestroy(pattern); 70 FcPatternDestroy(pattern);
77 if (!match) 71 if (!match)
78 return false; 72 return false;
79 73
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 107
114 int fc_rgba = FC_RGBA_NONE; 108 int fc_rgba = FC_RGBA_NONE;
115 if (FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba) == FcResultMatch) 109 if (FcPatternGetInteger(match, FC_RGBA, 0, &fc_rgba) == FcResultMatch)
116 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba); 110 params_out->subpixel_rendering = ConvertFontconfigRgba(fc_rgba);
117 } 111 }
118 112
119 FcPatternDestroy(match); 113 FcPatternDestroy(match);
120 return true; 114 return true;
121 } 115 }
122 116
123 // Returns the system's default settings.
124 FontRenderParams LoadDefaults(bool for_web_contents) {
125 return GetCustomFontRenderParams(
126 for_web_contents, NULL, NULL, NULL, NULL, NULL);
127 }
128
129 } // namespace 117 } // namespace
130 118
131 const FontRenderParams& GetDefaultFontRenderParams() { 119 FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
132 static FontRenderParams default_params = LoadDefaults(false); 120 std::string* family_out) {
133 return default_params;
134 }
135
136 const FontRenderParams& GetDefaultWebKitFontRenderParams() {
137 static FontRenderParams default_params = LoadDefaults(true);
138 return default_params;
139 }
140
141 FontRenderParams GetCustomFontRenderParams(
142 bool for_web_contents,
143 const std::vector<std::string>* family_list,
144 const int* pixel_size,
145 const int* point_size,
146 const int* style,
147 std::string* family_out) {
148 if (family_out) 121 if (family_out)
149 family_out->clear(); 122 family_out->clear();
150 123
151 // Start with the delegate's settings, but let Fontconfig have the final say. 124 // Start with the delegate's settings, but let Fontconfig have the final say.
152 FontRenderParams params; 125 FontRenderParams params;
153 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance(); 126 const LinuxFontDelegate* delegate = LinuxFontDelegate::instance();
154 if (delegate) 127 if (delegate)
155 params = delegate->GetDefaultFontRenderParams(); 128 params = delegate->GetDefaultFontRenderParams();
156 QueryFontconfig( 129 QueryFontconfig(query, &params, family_out);
157 family_list, pixel_size, point_size, style, &params, family_out);
158 130
159 // Fontconfig doesn't support configuring subpixel positioning; check a flag. 131 // Fontconfig doesn't support configuring subpixel positioning; check a flag.
160 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch( 132 params.subpixel_positioning = CommandLine::ForCurrentProcess()->HasSwitch(
161 for_web_contents ? 133 query.for_web_contents ?
162 switches::kEnableWebkitTextSubpixelPositioning : 134 switches::kEnableWebkitTextSubpixelPositioning :
163 switches::kEnableBrowserTextSubpixelPositioning); 135 switches::kEnableBrowserTextSubpixelPositioning);
164 136
165 // To enable subpixel positioning, we need to disable hinting. 137 // To enable subpixel positioning, we need to disable hinting.
166 if (params.subpixel_positioning) 138 if (params.subpixel_positioning)
167 params.hinting = FontRenderParams::HINTING_NONE; 139 params.hinting = FontRenderParams::HINTING_NONE;
168 140
169 // Use the first family from the list if Fontconfig didn't suggest a family. 141 // Use the first family from the list if Fontconfig didn't suggest a family.
170 if (family_out && family_out->empty() && 142 if (family_out && family_out->empty() && !query.families.empty())
171 family_list && !family_list->empty()) 143 *family_out = query.families[0];
172 *family_out = (*family_list)[0];
173 144
174 return params; 145 return params;
175 } 146 }
176 147
177 } // namespace gfx 148 } // 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