OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 query.point_size = 20; | 151 query.point_size = 20; |
152 params = GetFontRenderParams(query, NULL); | 152 params = GetFontRenderParams(query, NULL); |
153 EXPECT_TRUE(params.antialiasing); | 153 EXPECT_TRUE(params.antialiasing); |
154 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); | 154 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
155 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, | 155 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, |
156 params.subpixel_rendering); | 156 params.subpixel_rendering); |
157 } | 157 } |
158 | 158 |
159 TEST_F(FontRenderParamsTest, Style) { | 159 TEST_F(FontRenderParamsTest, Style) { |
160 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 160 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
161 // Load a config that disables antialiasing for bold text and disables | 161 // Load a config that disables hinting for bold text and disables subpixel |
msw
2014/07/24 22:58:26
nit: "subpixel rendering for bold" and "hinting fo
Daniel Erat
2014/07/24 23:00:07
sorry. :-( done
| |
162 // hinting for italic text. | 162 // rendering for italic text. |
163 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 163 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
164 std::string(kFontconfigFileHeader) + | 164 std::string(kFontconfigFileHeader) + |
165 kFontconfigMatchHeader + | 165 kFontconfigMatchHeader + |
166 CreateFontconfigEditStanza("antialias", "bool", "true") + | 166 CreateFontconfigEditStanza("antialias", "bool", "true") + |
167 CreateFontconfigEditStanza("hinting", "bool", "true") + | 167 CreateFontconfigEditStanza("hinting", "bool", "true") + |
168 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + | 168 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") + |
169 CreateFontconfigEditStanza("rgba", "const", "rgb") + | |
169 kFontconfigMatchFooter + | 170 kFontconfigMatchFooter + |
170 kFontconfigMatchHeader + | 171 kFontconfigMatchHeader + |
171 CreateFontconfigTestStanza("weight", "eq", "const", "bold") + | 172 CreateFontconfigTestStanza("weight", "eq", "const", "bold") + |
172 CreateFontconfigEditStanza("antialias", "bool", "false") + | 173 CreateFontconfigEditStanza("rgba", "const", "none") + |
173 kFontconfigMatchFooter + | 174 kFontconfigMatchFooter + |
174 kFontconfigMatchHeader + | 175 kFontconfigMatchHeader + |
175 CreateFontconfigTestStanza("slant", "eq", "const", "italic") + | 176 CreateFontconfigTestStanza("slant", "eq", "const", "italic") + |
176 CreateFontconfigEditStanza("hinting", "bool", "false") + | 177 CreateFontconfigEditStanza("hinting", "bool", "false") + |
177 kFontconfigMatchFooter + | 178 kFontconfigMatchFooter + |
178 kFontconfigFileFooter)); | 179 kFontconfigFileFooter)); |
179 | 180 |
180 FontRenderParamsQuery query(false); | 181 FontRenderParamsQuery query(false); |
181 query.style = Font::NORMAL; | 182 query.style = Font::NORMAL; |
182 FontRenderParams params = GetFontRenderParams(query, NULL); | 183 FontRenderParams params = GetFontRenderParams(query, NULL); |
183 EXPECT_TRUE(params.antialiasing); | 184 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
184 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 185 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, |
186 params.subpixel_rendering); | |
185 | 187 |
186 query.style = Font::BOLD; | 188 query.style = Font::BOLD; |
187 params = GetFontRenderParams(query, NULL); | 189 params = GetFontRenderParams(query, NULL); |
188 EXPECT_FALSE(params.antialiasing); | 190 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
189 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 191 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, |
192 params.subpixel_rendering); | |
190 | 193 |
191 query.style = Font::ITALIC; | 194 query.style = Font::ITALIC; |
192 params = GetFontRenderParams(query, NULL); | 195 params = GetFontRenderParams(query, NULL); |
193 EXPECT_TRUE(params.antialiasing); | |
194 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); | 196 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); |
197 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, | |
198 params.subpixel_rendering); | |
195 | 199 |
196 query.style = Font::BOLD | Font::ITALIC; | 200 query.style = Font::BOLD | Font::ITALIC; |
197 params = GetFontRenderParams(query, NULL); | 201 params = GetFontRenderParams(query, NULL); |
198 EXPECT_FALSE(params.antialiasing); | |
199 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); | 202 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); |
203 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | |
204 params.subpixel_rendering); | |
200 } | 205 } |
201 | 206 |
202 TEST_F(FontRenderParamsTest, Scalable) { | 207 TEST_F(FontRenderParamsTest, Scalable) { |
203 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 208 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
204 // Load a config that only enables antialiasing for scalable fonts. | 209 // Load a config that only enables antialiasing for scalable fonts. |
205 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 210 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
206 std::string(kFontconfigFileHeader) + | 211 std::string(kFontconfigFileHeader) + |
207 kFontconfigMatchHeader + | 212 kFontconfigMatchHeader + |
208 CreateFontconfigEditStanza("antialias", "bool", "false") + | 213 CreateFontconfigEditStanza("antialias", "bool", "false") + |
209 kFontconfigMatchFooter + | 214 kFontconfigMatchFooter + |
(...skipping 25 matching lines...) Expand all Loading... | |
235 | 240 |
236 FontRenderParamsQuery query(false); | 241 FontRenderParamsQuery query(false); |
237 FontRenderParams params = GetFontRenderParams(query, NULL); | 242 FontRenderParams params = GetFontRenderParams(query, NULL); |
238 EXPECT_FALSE(params.use_bitmaps); | 243 EXPECT_FALSE(params.use_bitmaps); |
239 | 244 |
240 query.pixel_size = 5; | 245 query.pixel_size = 5; |
241 params = GetFontRenderParams(query, NULL); | 246 params = GetFontRenderParams(query, NULL); |
242 EXPECT_TRUE(params.use_bitmaps); | 247 EXPECT_TRUE(params.use_bitmaps); |
243 } | 248 } |
244 | 249 |
250 TEST_F(FontRenderParamsTest, ForceFullHintingWhenAntialiasingIsDisabled) { | |
251 // Load a config that disables antialiasing and hinting while requesting | |
252 // subpixel rendering. | |
253 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | |
254 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | |
255 std::string(kFontconfigFileHeader) + | |
256 kFontconfigMatchHeader + | |
257 CreateFontconfigEditStanza("antialias", "bool", "false") + | |
258 CreateFontconfigEditStanza("hinting", "bool", "false") + | |
259 CreateFontconfigEditStanza("hintstyle", "const", "hintnone") + | |
260 CreateFontconfigEditStanza("rgba", "const", "rgb") + | |
261 kFontconfigMatchFooter + | |
262 kFontconfigFileFooter)); | |
263 | |
264 // Full hinting should be forced. See the comment in GetFontRenderParams() for | |
265 // more information. | |
266 FontRenderParams params = GetFontRenderParams( | |
267 FontRenderParamsQuery(false), NULL); | |
268 EXPECT_FALSE(params.antialiasing); | |
269 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | |
270 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | |
271 params.subpixel_rendering); | |
272 EXPECT_FALSE(params.subpixel_positioning); | |
273 } | |
274 | |
245 TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) { | 275 TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) { |
246 // Configure the LinuxFontDelegate (which queries GtkSettings on desktop | 276 // Configure the LinuxFontDelegate (which queries GtkSettings on desktop |
247 // Linux) to request subpixel rendering. | 277 // Linux) to request subpixel rendering. |
248 FontRenderParams system_params; | 278 FontRenderParams system_params; |
249 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; | 279 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; |
250 test_font_delegate_.set_params(system_params); | 280 test_font_delegate_.set_params(system_params); |
251 | 281 |
252 // Load a Fontconfig config that enables antialiasing but doesn't say anything | 282 // Load a Fontconfig config that enables antialiasing but doesn't say anything |
253 // about subpixel rendering. | 283 // about subpixel rendering. |
254 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 284 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
(...skipping 26 matching lines...) Expand all Loading... | |
281 FontRenderParams params = GetFontRenderParams(query, &suggested_family); | 311 FontRenderParams params = GetFontRenderParams(query, &suggested_family); |
282 | 312 |
283 // The system params and the first requested family should be returned. | 313 // The system params and the first requested family should be returned. |
284 EXPECT_EQ(system_params.antialiasing, params.antialiasing); | 314 EXPECT_EQ(system_params.antialiasing, params.antialiasing); |
285 EXPECT_EQ(system_params.hinting, params.hinting); | 315 EXPECT_EQ(system_params.hinting, params.hinting); |
286 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); | 316 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); |
287 EXPECT_EQ(query.families[0], suggested_family); | 317 EXPECT_EQ(query.families[0], suggested_family); |
288 } | 318 } |
289 | 319 |
290 } // namespace gfx | 320 } // namespace gfx |
OLD | NEW |