Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_list.h" | 5 #include "ui/gfx/font_list.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 namespace gfx { | 31 namespace gfx { |
| 32 | 32 |
| 33 TEST(FontListTest, FontDescString_FromDescString) { | 33 TEST(FontListTest, FontDescString_FromDescString) { |
| 34 // Test init from font name style size string. | 34 // Test init from font name style size string. |
| 35 FontList font_list = FontList("Droid Sans serif, Sans serif, 10px"); | 35 FontList font_list = FontList("Droid Sans serif, Sans serif, 10px"); |
| 36 const std::string& font_str = font_list.GetFontDescriptionString(); | 36 const std::string& font_str = font_list.GetFontDescriptionString(); |
| 37 EXPECT_EQ("Droid Sans serif, Sans serif, 10px", font_str); | 37 EXPECT_EQ("Droid Sans serif, Sans serif, 10px", font_str); |
| 38 } | 38 } |
| 39 | 39 |
| 40 TEST(FontListTest, FontDescString_FromFontNamesStyleAndSize) { | |
| 41 // Test init from font names, style and size. | |
| 42 std::vector<std::string> font_names; | |
| 43 font_names.push_back("Arial"); | |
| 44 font_names.push_back("Droid Sans serif"); | |
| 45 int font_style = Font::BOLD | Font::ITALIC; | |
| 46 int font_size = 11; | |
| 47 FontList font_list = FontList(font_names, font_style, font_size); | |
| 48 const std::string& font_str = font_list.GetFontDescriptionString(); | |
|
msw
2013/08/06 05:10:14
nit: Inline font_list.GetFontDescriptionString() w
Yuki
2013/08/07 14:34:03
Done.
| |
| 49 EXPECT_EQ("Arial,Droid Sans serif,Bold Italic 11px", font_str); | |
| 50 } | |
| 51 | |
| 40 TEST(FontListTest, FontDescString_FromFont) { | 52 TEST(FontListTest, FontDescString_FromFont) { |
| 41 // Test init from Font. | 53 // Test init from Font. |
| 42 Font font("Arial", 8); | 54 Font font("Arial", 8); |
| 43 FontList font_list = FontList(font); | 55 FontList font_list = FontList(font); |
| 44 const std::string& font_str = font_list.GetFontDescriptionString(); | 56 const std::string& font_str = font_list.GetFontDescriptionString(); |
| 45 EXPECT_EQ("Arial,8px", font_str); | 57 EXPECT_EQ("Arial,8px", font_str); |
| 46 } | 58 } |
| 47 | 59 |
| 48 TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) { | 60 TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) { |
| 49 // Test init from Font with non-normal style. | 61 // Test init from Font with non-normal style. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 FontList font_list = FontList(fonts); | 238 FontList font_list = FontList(fonts); |
| 227 | 239 |
| 228 FontList derived = font_list.DeriveFontListWithSize(5); | 240 FontList derived = font_list.DeriveFontListWithSize(5); |
| 229 const std::vector<Font>& derived_fonts = derived.GetFonts(); | 241 const std::vector<Font>& derived_fonts = derived.GetFonts(); |
| 230 | 242 |
| 231 EXPECT_EQ(2U, derived_fonts.size()); | 243 EXPECT_EQ(2U, derived_fonts.size()); |
| 232 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0])); | 244 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0])); |
| 233 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1])); | 245 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1])); |
| 234 } | 246 } |
| 235 | 247 |
| 248 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDelta) { | |
| 249 FontList font_list = FontList("Arial,Sans serif,Bold 18px"); | |
| 250 | |
| 251 FontList derived = font_list.DeriveFontListWithSizeDelta(-8); | |
| 252 EXPECT_EQ("Arial,Sans serif,Bold 10px", | |
| 253 derived.GetFontDescriptionString()); | |
| 254 } | |
| 255 | |
| 256 TEST(FontListTest, Fonts_DeriveFontListWithSizeDelta) { | |
| 257 std::vector<Font> fonts; | |
| 258 fonts.push_back(gfx::Font("Arial", 18).DeriveFont(0, Font::ITALIC)); | |
| 259 fonts.push_back(gfx::Font("Sans serif", 18).DeriveFont(0, Font::ITALIC)); | |
| 260 FontList font_list = FontList(fonts); | |
| 261 | |
| 262 FontList derived = font_list.DeriveFontListWithSizeDelta(-5); | |
| 263 const std::vector<Font>& derived_fonts = derived.GetFonts(); | |
| 264 | |
| 265 EXPECT_EQ(2U, derived_fonts.size()); | |
| 266 EXPECT_EQ("Arial|13|italic", FontToString(derived_fonts[0])); | |
|
msw
2013/08/06 05:10:14
nit: Check GetFontDescriptionString() instead, whe
Yuki
2013/08/07 14:34:03
I guess that the original author intended to test
msw
2013/08/07 17:13:41
Okay, that's fair; thanks for the explanation.
| |
| 267 EXPECT_EQ("Sans serif|13|italic", FontToString(derived_fonts[1])); | |
| 268 } | |
| 269 | |
| 270 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDeltaAndStyle) { | |
| 271 FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px"); | |
| 272 | |
| 273 FontList derived = | |
| 274 font_list.DeriveFontListWithSizeDeltaAndStyle(10, Font::ITALIC); | |
| 275 EXPECT_EQ("Arial,Sans serif,Italic 18px", | |
| 276 derived.GetFontDescriptionString()); | |
| 277 } | |
| 278 | |
| 279 TEST(FontListTest, Fonts_DeriveFontListWithSizeDeltaAndStyle) { | |
| 280 std::vector<Font> fonts; | |
| 281 fonts.push_back(gfx::Font("Arial", 8)); | |
| 282 fonts.push_back(gfx::Font("Sans serif", 8)); | |
| 283 FontList font_list = FontList(fonts); | |
| 284 | |
| 285 FontList derived = | |
| 286 font_list.DeriveFontListWithSizeDeltaAndStyle(5, Font::BOLD); | |
| 287 const std::vector<Font>& derived_fonts = derived.GetFonts(); | |
| 288 | |
| 289 EXPECT_EQ(2U, derived_fonts.size()); | |
| 290 EXPECT_EQ("Arial|13|bold", FontToString(derived_fonts[0])); | |
| 291 EXPECT_EQ("Sans serif|13|bold", FontToString(derived_fonts[1])); | |
| 292 } | |
| 293 | |
| 236 TEST(FontListTest, Fonts_GetHeight_GetBaseline) { | 294 TEST(FontListTest, Fonts_GetHeight_GetBaseline) { |
| 237 // If a font list has only one font, the height and baseline must be the same. | 295 // If a font list has only one font, the height and baseline must be the same. |
| 238 Font font1("Arial", 16); | 296 Font font1("Arial", 16); |
| 239 FontList font_list1("Arial, 16px"); | 297 FontList font_list1("Arial, 16px"); |
| 240 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight()); | 298 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight()); |
| 241 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline()); | 299 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline()); |
| 242 | 300 |
| 243 // If there are two different fonts, the font list returns the max value | 301 // If there are two different fonts, the font list returns the max value |
| 244 // for ascent and descent. | 302 // for ascent and descent. |
| 245 Font font2("Symbol", 16); | 303 Font font2("Symbol", 16); |
| 246 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline()); | 304 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline()); |
| 247 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(), | 305 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(), |
| 248 font2.GetHeight() - font2.GetBaseline()); | 306 font2.GetHeight() - font2.GetBaseline()); |
| 249 std::vector<Font> fonts; | 307 std::vector<Font> fonts; |
| 250 fonts.push_back(font1); | 308 fonts.push_back(font1); |
| 251 fonts.push_back(font2); | 309 fonts.push_back(font2); |
| 252 FontList font_list_mix(fonts); | 310 FontList font_list_mix(fonts); |
| 253 // ascent of FontList == max(ascent of Fonts) | 311 // ascent of FontList == max(ascent of Fonts) |
| 254 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(), | 312 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(), |
| 255 font2.GetHeight() - font2.GetBaseline()), | 313 font2.GetHeight() - font2.GetBaseline()), |
| 256 font_list_mix.GetHeight() - font_list_mix.GetBaseline()); | 314 font_list_mix.GetHeight() - font_list_mix.GetBaseline()); |
| 257 // descent of FontList == max(descent of Fonts) | 315 // descent of FontList == max(descent of Fonts) |
| 258 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()), | 316 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()), |
| 259 font_list_mix.GetBaseline()); | 317 font_list_mix.GetBaseline()); |
| 260 } | 318 } |
| 261 | 319 |
| 262 } // namespace gfx | 320 } // namespace gfx |
| OLD | NEW |