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 |
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") + |
msw
2014/07/24 22:25:43
nit: remove the antialias setting and checks below
Daniel Erat
2014/07/24 22:52:01
i'll remove the checks, but i believe that setting
msw
2014/07/24 22:58:25
Acknowledged.
| |
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("hinting", "bool", "false") + |
msw
2014/07/24 22:25:43
optional nit: continue disabling hinting for itali
Daniel Erat
2014/07/24 22:52:01
Done.
| |
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("rgba", "const", "none") + |
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_TRUE(params.antialiasing); |
184 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 185 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
186 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, | |
187 params.subpixel_rendering); | |
185 | 188 |
186 query.style = Font::BOLD; | 189 query.style = Font::BOLD; |
187 params = GetFontRenderParams(query, NULL); | 190 params = GetFontRenderParams(query, NULL); |
188 EXPECT_FALSE(params.antialiasing); | 191 EXPECT_TRUE(params.antialiasing); |
189 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 192 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); |
193 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, | |
194 params.subpixel_rendering); | |
190 | 195 |
191 query.style = Font::ITALIC; | 196 query.style = Font::ITALIC; |
192 params = GetFontRenderParams(query, NULL); | 197 params = GetFontRenderParams(query, NULL); |
193 EXPECT_TRUE(params.antialiasing); | 198 EXPECT_TRUE(params.antialiasing); |
194 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); | 199 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
200 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | |
201 params.subpixel_rendering); | |
195 | 202 |
196 query.style = Font::BOLD | Font::ITALIC; | 203 query.style = Font::BOLD | Font::ITALIC; |
197 params = GetFontRenderParams(query, NULL); | 204 params = GetFontRenderParams(query, NULL); |
198 EXPECT_FALSE(params.antialiasing); | 205 EXPECT_TRUE(params.antialiasing); |
199 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); | 206 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); |
207 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | |
208 params.subpixel_rendering); | |
200 } | 209 } |
201 | 210 |
202 TEST_F(FontRenderParamsTest, Scalable) { | 211 TEST_F(FontRenderParamsTest, Scalable) { |
203 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 212 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
204 // Load a config that only enables antialiasing for scalable fonts. | 213 // Load a config that only enables antialiasing for scalable fonts. |
205 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 214 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
206 std::string(kFontconfigFileHeader) + | 215 std::string(kFontconfigFileHeader) + |
207 kFontconfigMatchHeader + | 216 kFontconfigMatchHeader + |
208 CreateFontconfigEditStanza("antialias", "bool", "false") + | 217 CreateFontconfigEditStanza("antialias", "bool", "false") + |
209 kFontconfigMatchFooter + | 218 kFontconfigMatchFooter + |
(...skipping 25 matching lines...) Expand all Loading... | |
235 | 244 |
236 FontRenderParamsQuery query(false); | 245 FontRenderParamsQuery query(false); |
237 FontRenderParams params = GetFontRenderParams(query, NULL); | 246 FontRenderParams params = GetFontRenderParams(query, NULL); |
238 EXPECT_FALSE(params.use_bitmaps); | 247 EXPECT_FALSE(params.use_bitmaps); |
239 | 248 |
240 query.pixel_size = 5; | 249 query.pixel_size = 5; |
241 params = GetFontRenderParams(query, NULL); | 250 params = GetFontRenderParams(query, NULL); |
242 EXPECT_TRUE(params.use_bitmaps); | 251 EXPECT_TRUE(params.use_bitmaps); |
243 } | 252 } |
244 | 253 |
254 TEST_F(FontRenderParamsTest, ForceFullHintingWhenAntialiasingIsDisabled) { | |
255 // Load a config that disables antialiasing and hinting while requesting | |
256 // subpixel rendering. | |
257 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | |
258 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | |
259 std::string(kFontconfigFileHeader) + | |
260 kFontconfigMatchHeader + | |
261 CreateFontconfigEditStanza("antialias", "bool", "false") + | |
262 CreateFontconfigEditStanza("hinting", "bool", "false") + | |
263 CreateFontconfigEditStanza("hintstyle", "const", "hintnone") + | |
264 CreateFontconfigEditStanza("rgba", "const", "rgb") + | |
265 kFontconfigMatchFooter + | |
266 kFontconfigFileFooter)); | |
267 | |
268 // Full hinting should be forced. | |
msw
2014/07/24 22:25:44
optional nit: add "See the comment in GetFontRende
Daniel Erat
2014/07/24 22:52:00
Done.
| |
269 FontRenderParams params = GetFontRenderParams( | |
270 FontRenderParamsQuery(false), NULL); | |
271 EXPECT_FALSE(params.antialiasing); | |
272 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | |
273 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | |
274 params.subpixel_rendering); | |
275 EXPECT_FALSE(params.subpixel_positioning); | |
276 } | |
277 | |
245 TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) { | 278 TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) { |
246 // Configure the LinuxFontDelegate (which queries GtkSettings on desktop | 279 // Configure the LinuxFontDelegate (which queries GtkSettings on desktop |
247 // Linux) to request subpixel rendering. | 280 // Linux) to request subpixel rendering. |
248 FontRenderParams system_params; | 281 FontRenderParams system_params; |
249 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; | 282 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; |
250 test_font_delegate_.set_params(system_params); | 283 test_font_delegate_.set_params(system_params); |
251 | 284 |
252 // Load a Fontconfig config that enables antialiasing but doesn't say anything | 285 // Load a Fontconfig config that enables antialiasing but doesn't say anything |
253 // about subpixel rendering. | 286 // about subpixel rendering. |
254 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 287 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
(...skipping 26 matching lines...) Expand all Loading... | |
281 FontRenderParams params = GetFontRenderParams(query, &suggested_family); | 314 FontRenderParams params = GetFontRenderParams(query, &suggested_family); |
282 | 315 |
283 // The system params and the first requested family should be returned. | 316 // The system params and the first requested family should be returned. |
284 EXPECT_EQ(system_params.antialiasing, params.antialiasing); | 317 EXPECT_EQ(system_params.antialiasing, params.antialiasing); |
285 EXPECT_EQ(system_params.hinting, params.hinting); | 318 EXPECT_EQ(system_params.hinting, params.hinting); |
286 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); | 319 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); |
287 EXPECT_EQ(query.families[0], suggested_family); | 320 EXPECT_EQ(query.families[0], suggested_family); |
288 } | 321 } |
289 | 322 |
290 } // namespace gfx | 323 } // namespace gfx |
OLD | NEW |