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 29 matching lines...) Expand all Loading... | |
40 return 96.0; | 40 return 96.0; |
41 } | 41 } |
42 | 42 |
43 private: | 43 private: |
44 FontRenderParams params_; | 44 FontRenderParams params_; |
45 | 45 |
46 DISALLOW_COPY_AND_ASSIGN(TestFontDelegate); | 46 DISALLOW_COPY_AND_ASSIGN(TestFontDelegate); |
47 }; | 47 }; |
48 | 48 |
49 // Loads the first system font defined by fontconfig_util_linux.h with a base | 49 // Loads the first system font defined by fontconfig_util_linux.h with a base |
50 // filename of |basename|. Case is ignored. | 50 // filename of |basename|. Case is ignored. FcFontMatch() requires there to be |
51 // at least one font present. | |
51 bool LoadSystemFont(const std::string& basename) { | 52 bool LoadSystemFont(const std::string& basename) { |
52 for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) { | 53 for (size_t i = 0; i < kNumSystemFontsForFontconfig; ++i) { |
53 base::FilePath path(gfx::kSystemFontsForFontconfig[i]); | 54 base::FilePath path(gfx::kSystemFontsForFontconfig[i]); |
54 if (strcasecmp(path.BaseName().value().c_str(), basename.c_str()) == 0) | 55 if (strcasecmp(path.BaseName().value().c_str(), basename.c_str()) == 0) |
55 return LoadFontIntoFontconfig(path); | 56 return LoadFontIntoFontconfig(path); |
56 } | 57 } |
57 LOG(ERROR) << "Unable to find system font named " << basename; | 58 LOG(ERROR) << "Unable to find system font named " << basename; |
58 return false; | 59 return false; |
59 } | 60 } |
60 | 61 |
(...skipping 28 matching lines...) Expand all Loading... | |
89 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 90 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
90 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 91 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
91 std::string(kFontconfigFileHeader) + | 92 std::string(kFontconfigFileHeader) + |
92 kFontconfigMatchPatternHeader + | 93 kFontconfigMatchPatternHeader + |
93 CreateFontconfigEditStanza("antialias", "bool", "true") + | 94 CreateFontconfigEditStanza("antialias", "bool", "true") + |
94 CreateFontconfigEditStanza("autohint", "bool", "true") + | 95 CreateFontconfigEditStanza("autohint", "bool", "true") + |
95 CreateFontconfigEditStanza("hinting", "bool", "true") + | 96 CreateFontconfigEditStanza("hinting", "bool", "true") + |
96 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") + | 97 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") + |
97 CreateFontconfigEditStanza("rgba", "const", "rgb") + | 98 CreateFontconfigEditStanza("rgba", "const", "rgb") + |
98 kFontconfigMatchFooter + | 99 kFontconfigMatchFooter + |
99 // Add a font match for Arial; it shouldn't be used when querying for | 100 // Add a font match for Arial; it shouldn't be used on Chrome OS but when |
100 // default settings: http://crbug.com/421247 | 101 // querying for default settings: http://crbug.com/421247 |
102 // | |
103 // The match _should_ take effect on desktop Linux, though: | |
104 // http://crbug.com/442443 | |
101 kFontconfigMatchFontHeader + | 105 kFontconfigMatchFontHeader + |
102 CreateFontconfigTestStanza("family", "eq", "string", "Arial") + | 106 CreateFontconfigTestStanza("family", "eq", "string", "Arial") + |
103 CreateFontconfigEditStanza("antialias", "bool", "true") + | 107 CreateFontconfigEditStanza("antialias", "bool", "true") + |
104 CreateFontconfigEditStanza("autohint", "bool", "false") + | 108 CreateFontconfigEditStanza("autohint", "bool", "false") + |
105 CreateFontconfigEditStanza("hinting", "bool", "true") + | 109 CreateFontconfigEditStanza("hinting", "bool", "true") + |
106 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + | 110 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + |
107 kFontconfigMatchFooter + | 111 kFontconfigMatchFooter + |
108 kFontconfigFileFooter)); | 112 kFontconfigFileFooter)); |
109 | 113 |
110 FontRenderParams params = GetFontRenderParams( | 114 FontRenderParams params = GetFontRenderParams( |
111 FontRenderParamsQuery(true), NULL); | 115 FontRenderParamsQuery(true), NULL); |
112 EXPECT_TRUE(params.antialiasing); | 116 EXPECT_TRUE(params.antialiasing); |
117 EXPECT_TRUE(params.use_bitmaps); | |
118 #if defined(OS_CHROMEOS) | |
113 EXPECT_TRUE(params.autohinter); | 119 EXPECT_TRUE(params.autohinter); |
114 EXPECT_TRUE(params.use_bitmaps); | |
115 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); | 120 EXPECT_EQ(FontRenderParams::HINTING_SLIGHT, params.hinting); |
121 #else | |
122 EXPECT_FALSE(params.autohinter); | |
123 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | |
124 #endif | |
116 EXPECT_FALSE(params.subpixel_positioning); | 125 EXPECT_FALSE(params.subpixel_positioning); |
117 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, | 126 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, |
118 params.subpixel_rendering); | 127 params.subpixel_rendering); |
119 } | 128 } |
120 | 129 |
121 TEST_F(FontRenderParamsTest, Size) { | 130 TEST_F(FontRenderParamsTest, Size) { |
122 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 131 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
123 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 132 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
124 std::string(kFontconfigFileHeader) + | 133 std::string(kFontconfigFileHeader) + |
125 kFontconfigMatchPatternHeader + | 134 kFontconfigMatchPatternHeader + |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 params.subpixel_rendering); | 216 params.subpixel_rendering); |
208 | 217 |
209 query.style = Font::BOLD | Font::ITALIC; | 218 query.style = Font::BOLD | Font::ITALIC; |
210 params = GetFontRenderParams(query, NULL); | 219 params = GetFontRenderParams(query, NULL); |
211 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); | 220 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); |
212 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | 221 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, |
213 params.subpixel_rendering); | 222 params.subpixel_rendering); |
214 } | 223 } |
215 | 224 |
216 TEST_F(FontRenderParamsTest, Scalable) { | 225 TEST_F(FontRenderParamsTest, Scalable) { |
226 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | |
msw
2014/12/18 01:10:49
nit: We previously tried to avoid loading fonts fo
Daniel Erat
2014/12/18 17:17:59
sure, done. just added it here since just about al
| |
217 // Load a config that only enables antialiasing for scalable fonts. | 227 // Load a config that only enables antialiasing for scalable fonts. |
218 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 228 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
219 std::string(kFontconfigFileHeader) + | 229 std::string(kFontconfigFileHeader) + |
220 kFontconfigMatchPatternHeader + | 230 kFontconfigMatchPatternHeader + |
221 CreateFontconfigEditStanza("antialias", "bool", "false") + | 231 CreateFontconfigEditStanza("antialias", "bool", "false") + |
222 kFontconfigMatchFooter + | 232 kFontconfigMatchFooter + |
223 kFontconfigMatchPatternHeader + | 233 kFontconfigMatchPatternHeader + |
224 CreateFontconfigTestStanza("scalable", "eq", "bool", "true") + | 234 CreateFontconfigTestStanza("scalable", "eq", "bool", "true") + |
225 CreateFontconfigEditStanza("antialias", "bool", "true") + | 235 CreateFontconfigEditStanza("antialias", "bool", "true") + |
226 kFontconfigMatchFooter + | 236 kFontconfigMatchFooter + |
(...skipping 22 matching lines...) Expand all Loading... | |
249 FontRenderParamsQuery query(false); | 259 FontRenderParamsQuery query(false); |
250 FontRenderParams params = GetFontRenderParams(query, NULL); | 260 FontRenderParams params = GetFontRenderParams(query, NULL); |
251 EXPECT_FALSE(params.use_bitmaps); | 261 EXPECT_FALSE(params.use_bitmaps); |
252 | 262 |
253 query.pixel_size = 5; | 263 query.pixel_size = 5; |
254 params = GetFontRenderParams(query, NULL); | 264 params = GetFontRenderParams(query, NULL); |
255 EXPECT_TRUE(params.use_bitmaps); | 265 EXPECT_TRUE(params.use_bitmaps); |
256 } | 266 } |
257 | 267 |
258 TEST_F(FontRenderParamsTest, ForceFullHintingWhenAntialiasingIsDisabled) { | 268 TEST_F(FontRenderParamsTest, ForceFullHintingWhenAntialiasingIsDisabled) { |
269 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | |
259 // Load a config that disables antialiasing and hinting while requesting | 270 // Load a config that disables antialiasing and hinting while requesting |
260 // subpixel rendering. | 271 // subpixel rendering. |
261 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 272 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
262 std::string(kFontconfigFileHeader) + | 273 std::string(kFontconfigFileHeader) + |
263 kFontconfigMatchPatternHeader + | 274 kFontconfigMatchPatternHeader + |
264 CreateFontconfigEditStanza("antialias", "bool", "false") + | 275 CreateFontconfigEditStanza("antialias", "bool", "false") + |
265 CreateFontconfigEditStanza("hinting", "bool", "false") + | 276 CreateFontconfigEditStanza("hinting", "bool", "false") + |
266 CreateFontconfigEditStanza("hintstyle", "const", "hintnone") + | 277 CreateFontconfigEditStanza("hintstyle", "const", "hintnone") + |
267 CreateFontconfigEditStanza("rgba", "const", "rgb") + | 278 CreateFontconfigEditStanza("rgba", "const", "rgb") + |
268 kFontconfigMatchFooter + | 279 kFontconfigMatchFooter + |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 EXPECT_EQ("Verdana", suggested_family); | 390 EXPECT_EQ("Verdana", suggested_family); |
380 | 391 |
381 query.families.clear(); | 392 query.families.clear(); |
382 query.families.push_back("Arial"); | 393 query.families.push_back("Arial"); |
383 suggested_family.clear(); | 394 suggested_family.clear(); |
384 GetFontRenderParams(query, &suggested_family); | 395 GetFontRenderParams(query, &suggested_family); |
385 EXPECT_EQ("Verdana", suggested_family); | 396 EXPECT_EQ("Verdana", suggested_family); |
386 } | 397 } |
387 | 398 |
388 } // namespace gfx | 399 } // namespace gfx |
OLD | NEW |