| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 std::string(kFontconfigFileHeader) + | 91 std::string(kFontconfigFileHeader) + |
| 92 kFontconfigMatchHeader + | 92 kFontconfigMatchHeader + |
| 93 CreateFontconfigEditStanza("antialias", "bool", "true") + | 93 CreateFontconfigEditStanza("antialias", "bool", "true") + |
| 94 CreateFontconfigEditStanza("autohint", "bool", "false") + | 94 CreateFontconfigEditStanza("autohint", "bool", "false") + |
| 95 CreateFontconfigEditStanza("hinting", "bool", "true") + | 95 CreateFontconfigEditStanza("hinting", "bool", "true") + |
| 96 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + | 96 CreateFontconfigEditStanza("hintstyle", "const", "hintfull") + |
| 97 CreateFontconfigEditStanza("rgba", "const", "rgb") + | 97 CreateFontconfigEditStanza("rgba", "const", "rgb") + |
| 98 kFontconfigMatchFooter + | 98 kFontconfigMatchFooter + |
| 99 kFontconfigFileFooter)); | 99 kFontconfigFileFooter)); |
| 100 | 100 |
| 101 FontRenderParams params = GetDefaultFontRenderParams(); | 101 FontRenderParams params = GetFontRenderParams( |
| 102 FontRenderParamsQuery(true), NULL); |
| 102 EXPECT_TRUE(params.antialiasing); | 103 EXPECT_TRUE(params.antialiasing); |
| 103 EXPECT_FALSE(params.autohinter); | 104 EXPECT_FALSE(params.autohinter); |
| 104 EXPECT_TRUE(params.use_bitmaps); | 105 EXPECT_TRUE(params.use_bitmaps); |
| 105 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 106 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 106 EXPECT_FALSE(params.subpixel_positioning); | 107 EXPECT_FALSE(params.subpixel_positioning); |
| 107 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, | 108 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_RGB, |
| 108 params.subpixel_rendering); | 109 params.subpixel_rendering); |
| 109 } | 110 } |
| 110 | 111 |
| 111 TEST_F(FontRenderParamsTest, Size) { | 112 TEST_F(FontRenderParamsTest, Size) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 124 kFontconfigMatchFooter + | 125 kFontconfigMatchFooter + |
| 125 kFontconfigMatchHeader + | 126 kFontconfigMatchHeader + |
| 126 CreateFontconfigTestStanza("size", "more_eq", "double", "20") + | 127 CreateFontconfigTestStanza("size", "more_eq", "double", "20") + |
| 127 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") + | 128 CreateFontconfigEditStanza("hintstyle", "const", "hintslight") + |
| 128 CreateFontconfigEditStanza("rgba", "const", "rgb") + | 129 CreateFontconfigEditStanza("rgba", "const", "rgb") + |
| 129 kFontconfigMatchFooter + | 130 kFontconfigMatchFooter + |
| 130 kFontconfigFileFooter)); | 131 kFontconfigFileFooter)); |
| 131 | 132 |
| 132 // The defaults should be used when the supplied size isn't matched by the | 133 // The defaults should be used when the supplied size isn't matched by the |
| 133 // second or third blocks. | 134 // second or third blocks. |
| 134 int pixel_size = 12; | 135 FontRenderParamsQuery query(false); |
| 135 FontRenderParams params = GetCustomFontRenderParams( | 136 query.pixel_size = 12; |
| 136 false, NULL, &pixel_size, NULL, NULL, NULL); | 137 FontRenderParams params = GetFontRenderParams(query, NULL); |
| 137 EXPECT_TRUE(params.antialiasing); | 138 EXPECT_TRUE(params.antialiasing); |
| 138 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 139 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 139 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | 140 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, |
| 140 params.subpixel_rendering); | 141 params.subpixel_rendering); |
| 141 | 142 |
| 142 pixel_size = 10; | 143 query.pixel_size = 10; |
| 143 params = GetCustomFontRenderParams( | 144 params = GetFontRenderParams(query, NULL); |
| 144 false, NULL, &pixel_size, NULL, NULL, NULL); | |
| 145 EXPECT_FALSE(params.antialiasing); | 145 EXPECT_FALSE(params.antialiasing); |
| 146 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 146 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 147 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, | 147 EXPECT_EQ(FontRenderParams::SUBPIXEL_RENDERING_NONE, |
| 148 params.subpixel_rendering); | 148 params.subpixel_rendering); |
| 149 | 149 |
| 150 int point_size = 20; | 150 query.pixel_size = 0; |
| 151 params = GetCustomFontRenderParams( | 151 query.point_size = 20; |
| 152 false, NULL, NULL, &point_size, NULL, 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 antialiasing for bold text and disables |
| 162 // hinting for italic text. | 162 // hinting 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", "hintfull") + |
| 169 kFontconfigMatchFooter + | 169 kFontconfigMatchFooter + |
| 170 kFontconfigMatchHeader + | 170 kFontconfigMatchHeader + |
| 171 CreateFontconfigTestStanza("weight", "eq", "const", "bold") + | 171 CreateFontconfigTestStanza("weight", "eq", "const", "bold") + |
| 172 CreateFontconfigEditStanza("antialias", "bool", "false") + | 172 CreateFontconfigEditStanza("antialias", "bool", "false") + |
| 173 kFontconfigMatchFooter + | 173 kFontconfigMatchFooter + |
| 174 kFontconfigMatchHeader + | 174 kFontconfigMatchHeader + |
| 175 CreateFontconfigTestStanza("slant", "eq", "const", "italic") + | 175 CreateFontconfigTestStanza("slant", "eq", "const", "italic") + |
| 176 CreateFontconfigEditStanza("hinting", "bool", "false") + | 176 CreateFontconfigEditStanza("hinting", "bool", "false") + |
| 177 kFontconfigMatchFooter + | 177 kFontconfigMatchFooter + |
| 178 kFontconfigFileFooter)); | 178 kFontconfigFileFooter)); |
| 179 | 179 |
| 180 int style = Font::NORMAL; | 180 FontRenderParamsQuery query(false); |
| 181 FontRenderParams params = GetCustomFontRenderParams( | 181 query.style = Font::NORMAL; |
| 182 false, NULL, NULL, NULL, &style, NULL); | 182 FontRenderParams params = GetFontRenderParams(query, NULL); |
| 183 EXPECT_TRUE(params.antialiasing); | 183 EXPECT_TRUE(params.antialiasing); |
| 184 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 184 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 185 | 185 |
| 186 style = Font::BOLD; | 186 query.style = Font::BOLD; |
| 187 params = GetCustomFontRenderParams( | 187 params = GetFontRenderParams(query, NULL); |
| 188 false, NULL, NULL, NULL, &style, NULL); | |
| 189 EXPECT_FALSE(params.antialiasing); | 188 EXPECT_FALSE(params.antialiasing); |
| 190 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); | 189 EXPECT_EQ(FontRenderParams::HINTING_FULL, params.hinting); |
| 191 | 190 |
| 192 style = Font::ITALIC; | 191 query.style = Font::ITALIC; |
| 193 params = GetCustomFontRenderParams( | 192 params = GetFontRenderParams(query, NULL); |
| 194 false, NULL, NULL, NULL, &style, NULL); | |
| 195 EXPECT_TRUE(params.antialiasing); | 193 EXPECT_TRUE(params.antialiasing); |
| 196 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); | 194 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); |
| 197 | 195 |
| 198 style = Font::BOLD | Font::ITALIC; | 196 query.style = Font::BOLD | Font::ITALIC; |
| 199 params = GetCustomFontRenderParams( | 197 params = GetFontRenderParams(query, NULL); |
| 200 false, NULL, NULL, NULL, &style, NULL); | |
| 201 EXPECT_FALSE(params.antialiasing); | 198 EXPECT_FALSE(params.antialiasing); |
| 202 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); | 199 EXPECT_EQ(FontRenderParams::HINTING_NONE, params.hinting); |
| 203 } | 200 } |
| 204 | 201 |
| 205 TEST_F(FontRenderParamsTest, Scalable) { | 202 TEST_F(FontRenderParamsTest, Scalable) { |
| 206 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 203 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
| 207 // Load a config that only enables antialiasing for scalable fonts. | 204 // Load a config that only enables antialiasing for scalable fonts. |
| 208 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 205 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
| 209 std::string(kFontconfigFileHeader) + | 206 std::string(kFontconfigFileHeader) + |
| 210 kFontconfigMatchHeader + | 207 kFontconfigMatchHeader + |
| 211 CreateFontconfigEditStanza("antialias", "bool", "false") + | 208 CreateFontconfigEditStanza("antialias", "bool", "false") + |
| 212 kFontconfigMatchFooter + | 209 kFontconfigMatchFooter + |
| 213 kFontconfigMatchHeader + | 210 kFontconfigMatchHeader + |
| 214 CreateFontconfigTestStanza("scalable", "eq", "bool", "true") + | 211 CreateFontconfigTestStanza("scalable", "eq", "bool", "true") + |
| 215 CreateFontconfigEditStanza("antialias", "bool", "true") + | 212 CreateFontconfigEditStanza("antialias", "bool", "true") + |
| 216 kFontconfigMatchFooter + | 213 kFontconfigMatchFooter + |
| 217 kFontconfigFileFooter)); | 214 kFontconfigFileFooter)); |
| 218 | 215 |
| 219 // Check that we specifically ask how scalable fonts should be rendered. | 216 // Check that we specifically ask how scalable fonts should be rendered. |
| 220 FontRenderParams params = GetCustomFontRenderParams( | 217 FontRenderParams params = GetFontRenderParams( |
| 221 false, NULL, NULL, NULL, NULL, NULL); | 218 FontRenderParamsQuery(false), NULL); |
| 222 EXPECT_TRUE(params.antialiasing); | 219 EXPECT_TRUE(params.antialiasing); |
| 223 } | 220 } |
| 224 | 221 |
| 225 TEST_F(FontRenderParamsTest, UseBitmaps) { | 222 TEST_F(FontRenderParamsTest, UseBitmaps) { |
| 226 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 223 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
| 227 // Load a config that enables embedded bitmaps for fonts <= 10 pixels. | 224 // Load a config that enables embedded bitmaps for fonts <= 10 pixels. |
| 228 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 225 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
| 229 std::string(kFontconfigFileHeader) + | 226 std::string(kFontconfigFileHeader) + |
| 230 kFontconfigMatchHeader + | 227 kFontconfigMatchHeader + |
| 231 CreateFontconfigEditStanza("embeddedbitmap", "bool", "false") + | 228 CreateFontconfigEditStanza("embeddedbitmap", "bool", "false") + |
| 232 kFontconfigMatchFooter + | 229 kFontconfigMatchFooter + |
| 233 kFontconfigMatchHeader + | 230 kFontconfigMatchHeader + |
| 234 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") + | 231 CreateFontconfigTestStanza("pixelsize", "less_eq", "double", "10") + |
| 235 CreateFontconfigEditStanza("embeddedbitmap", "bool", "true") + | 232 CreateFontconfigEditStanza("embeddedbitmap", "bool", "true") + |
| 236 kFontconfigMatchFooter + | 233 kFontconfigMatchFooter + |
| 237 kFontconfigFileFooter)); | 234 kFontconfigFileFooter)); |
| 238 | 235 |
| 239 FontRenderParams params = GetCustomFontRenderParams( | 236 FontRenderParamsQuery query(false); |
| 240 false, NULL, NULL, NULL, NULL, NULL); | 237 FontRenderParams params = GetFontRenderParams(query, NULL); |
| 241 EXPECT_FALSE(params.use_bitmaps); | 238 EXPECT_FALSE(params.use_bitmaps); |
| 242 | 239 |
| 243 const int pixel_size = 5; | 240 query.pixel_size = 5; |
| 244 params = GetCustomFontRenderParams( | 241 params = GetFontRenderParams(query, NULL); |
| 245 false, NULL, &pixel_size, NULL, NULL, NULL); | |
| 246 EXPECT_TRUE(params.use_bitmaps); | 242 EXPECT_TRUE(params.use_bitmaps); |
| 247 } | 243 } |
| 248 | 244 |
| 249 TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) { | 245 TEST_F(FontRenderParamsTest, OnlySetConfiguredValues) { |
| 250 // Configure the LinuxFontDelegate (which queries GtkSettings on desktop | 246 // Configure the LinuxFontDelegate (which queries GtkSettings on desktop |
| 251 // Linux) to request subpixel rendering. | 247 // Linux) to request subpixel rendering. |
| 252 FontRenderParams system_params; | 248 FontRenderParams system_params; |
| 253 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; | 249 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; |
| 254 test_font_delegate_.set_params(system_params); | 250 test_font_delegate_.set_params(system_params); |
| 255 | 251 |
| 256 // Load a Fontconfig config that enables antialiasing but doesn't say anything | 252 // Load a Fontconfig config that enables antialiasing but doesn't say anything |
| 257 // about subpixel rendering. | 253 // about subpixel rendering. |
| 258 ASSERT_TRUE(LoadSystemFont("arial.ttf")); | 254 ASSERT_TRUE(LoadSystemFont("arial.ttf")); |
| 259 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), | 255 ASSERT_TRUE(LoadConfigDataIntoFontconfig(temp_dir_.path(), |
| 260 std::string(kFontconfigFileHeader) + | 256 std::string(kFontconfigFileHeader) + |
| 261 kFontconfigMatchHeader + | 257 kFontconfigMatchHeader + |
| 262 CreateFontconfigEditStanza("antialias", "bool", "true") + | 258 CreateFontconfigEditStanza("antialias", "bool", "true") + |
| 263 kFontconfigMatchFooter + | 259 kFontconfigMatchFooter + |
| 264 kFontconfigFileFooter)); | 260 kFontconfigFileFooter)); |
| 265 | 261 |
| 266 // The subpixel rendering setting from the delegate should make it through. | 262 // The subpixel rendering setting from the delegate should make it through. |
| 267 FontRenderParams params = GetCustomFontRenderParams( | 263 FontRenderParams params = GetFontRenderParams( |
| 268 false, NULL, NULL, NULL, NULL, NULL); | 264 FontRenderParamsQuery(false), NULL); |
| 269 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); | 265 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); |
| 270 } | 266 } |
| 271 | 267 |
| 272 TEST_F(FontRenderParamsTest, NoFontconfigMatch) { | 268 TEST_F(FontRenderParamsTest, NoFontconfigMatch) { |
| 273 // Don't load a Fontconfig configuration. | 269 // Don't load a Fontconfig configuration. |
| 274 FontRenderParams system_params; | 270 FontRenderParams system_params; |
| 275 system_params.antialiasing = true; | 271 system_params.antialiasing = true; |
| 276 system_params.hinting = FontRenderParams::HINTING_MEDIUM; | 272 system_params.hinting = FontRenderParams::HINTING_MEDIUM; |
| 277 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; | 273 system_params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_RGB; |
| 278 test_font_delegate_.set_params(system_params); | 274 test_font_delegate_.set_params(system_params); |
| 279 | 275 |
| 280 std::vector<std::string> families; | 276 FontRenderParamsQuery query(false); |
| 281 families.push_back("Arial"); | 277 query.families.push_back("Arial"); |
| 282 families.push_back("Times New Roman"); | 278 query.families.push_back("Times New Roman"); |
| 283 const int pixel_size = 10; | 279 query.pixel_size = 10; |
| 284 std::string suggested_family; | 280 std::string suggested_family; |
| 285 FontRenderParams params = GetCustomFontRenderParams( | 281 FontRenderParams params = GetFontRenderParams(query, &suggested_family); |
| 286 false, &families, &pixel_size, NULL, NULL, &suggested_family); | |
| 287 | 282 |
| 288 // The system params and the first requested family should be returned. | 283 // The system params and the first requested family should be returned. |
| 289 EXPECT_EQ(system_params.antialiasing, params.antialiasing); | 284 EXPECT_EQ(system_params.antialiasing, params.antialiasing); |
| 290 EXPECT_EQ(system_params.hinting, params.hinting); | 285 EXPECT_EQ(system_params.hinting, params.hinting); |
| 291 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); | 286 EXPECT_EQ(system_params.subpixel_rendering, params.subpixel_rendering); |
| 292 EXPECT_EQ("Arial", suggested_family); | 287 EXPECT_EQ(query.families[0], suggested_family); |
| 293 } | 288 } |
| 294 | 289 |
| 295 } // namespace gfx | 290 } // namespace gfx |
| OLD | NEW |