| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 fonts.push_back(gfx::Font("Arial", 8)); | 200 fonts.push_back(gfx::Font("Arial", 8)); |
| 201 fonts.push_back(gfx::Font("Sans serif", 8)); | 201 fonts.push_back(gfx::Font("Sans serif", 8)); |
| 202 FontList font_list = FontList(fonts); | 202 FontList font_list = FontList(fonts); |
| 203 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); | 203 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); |
| 204 fonts[0] = fonts[0].DeriveFont(0, Font::ITALIC | Font::BOLD); | 204 fonts[0] = fonts[0].DeriveFont(0, Font::ITALIC | Font::BOLD); |
| 205 fonts[1] = fonts[1].DeriveFont(0, Font::ITALIC | Font::BOLD); | 205 fonts[1] = fonts[1].DeriveFont(0, Font::ITALIC | Font::BOLD); |
| 206 font_list = FontList(fonts); | 206 font_list = FontList(fonts); |
| 207 EXPECT_EQ(Font::ITALIC | Font::BOLD, font_list.GetFontStyle()); | 207 EXPECT_EQ(Font::ITALIC | Font::BOLD, font_list.GetFontStyle()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST(FontListTest, FontDescString_DeriveFontList) { | 210 TEST(FontListTest, FontDescString_Derive) { |
| 211 FontList font_list = FontList("Arial,Sans serif, 8px"); | 211 FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px"); |
| 212 | 212 |
| 213 FontList derived = font_list.DeriveFontList(Font::BOLD | Font::ITALIC); | 213 FontList derived = font_list.Derive(10, Font::ITALIC | Font::UNDERLINE); |
| 214 EXPECT_EQ("Arial,Sans serif,Bold Italic 8px", | 214 EXPECT_EQ("Arial,Sans serif,Italic 18px", derived.GetFontDescriptionString()); |
| 215 derived.GetFontDescriptionString()); | 215 EXPECT_EQ(Font::ITALIC | Font::UNDERLINE, derived.GetFontStyle()); |
| 216 |
| 217 // FontList has a special case for Font::UNDERLINE. See if the handling of |
| 218 // Font::UNDERLINE in GetFonts() is okay or not. |
| 219 derived.GetFonts(); |
| 220 EXPECT_EQ(Font::ITALIC | Font::UNDERLINE, derived.GetFontStyle()); |
| 216 } | 221 } |
| 217 | 222 |
| 218 TEST(FontListTest, Fonts_DeriveFontList) { | 223 TEST(FontListTest, Fonts_Derive) { |
| 219 std::vector<Font> fonts; | 224 std::vector<Font> fonts; |
| 220 fonts.push_back(gfx::Font("Arial", 8)); | 225 fonts.push_back(gfx::Font("Arial", 8)); |
| 221 fonts.push_back(gfx::Font("Sans serif", 8)); | 226 fonts.push_back(gfx::Font("Sans serif", 8)); |
| 222 FontList font_list = FontList(fonts); | 227 FontList font_list = FontList(fonts); |
| 223 | 228 |
| 224 FontList derived = font_list.DeriveFontList(Font::BOLD | Font::ITALIC); | 229 FontList derived = font_list.Derive(5, Font::BOLD | Font::UNDERLINE); |
| 225 const std::vector<Font>& derived_fonts = derived.GetFonts(); | 230 const std::vector<Font>& derived_fonts = derived.GetFonts(); |
| 226 | 231 |
| 227 EXPECT_EQ(2U, derived_fonts.size()); | 232 EXPECT_EQ(2U, derived_fonts.size()); |
| 228 EXPECT_EQ("Arial|8|bold|italic", FontToString(derived_fonts[0])); | 233 EXPECT_EQ("Arial|13|bold|underline", FontToString(derived_fonts[0])); |
| 229 EXPECT_EQ("Sans serif|8|bold|italic", FontToString(derived_fonts[1])); | 234 EXPECT_EQ("Sans serif|13|bold|underline", FontToString(derived_fonts[1])); |
| 230 } | 235 } |
| 231 | 236 |
| 232 TEST(FontListTest, FontDescString_DeriveFontListWithSize) { | 237 TEST(FontListTest, FontDescString_DeriveWithSizeDelta) { |
| 233 FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px"); | |
| 234 | |
| 235 FontList derived = font_list.DeriveFontListWithSize(10); | |
| 236 EXPECT_EQ("Arial,Sans serif,Bold Italic 10px", | |
| 237 derived.GetFontDescriptionString()); | |
| 238 } | |
| 239 | |
| 240 TEST(FontListTest, Fonts_DeriveFontListWithSize) { | |
| 241 std::vector<Font> fonts; | |
| 242 fonts.push_back(gfx::Font("Arial", 8)); | |
| 243 fonts.push_back(gfx::Font("Sans serif", 8)); | |
| 244 FontList font_list = FontList(fonts); | |
| 245 | |
| 246 FontList derived = font_list.DeriveFontListWithSize(5); | |
| 247 const std::vector<Font>& derived_fonts = derived.GetFonts(); | |
| 248 | |
| 249 EXPECT_EQ(2U, derived_fonts.size()); | |
| 250 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0])); | |
| 251 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1])); | |
| 252 } | |
| 253 | |
| 254 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDelta) { | |
| 255 FontList font_list = FontList("Arial,Sans serif,Bold 18px"); | 238 FontList font_list = FontList("Arial,Sans serif,Bold 18px"); |
| 256 | 239 |
| 257 FontList derived = font_list.DeriveFontListWithSizeDelta(-8); | 240 FontList derived = font_list.DeriveWithSizeDelta(-8); |
| 258 EXPECT_EQ("Arial,Sans serif,Bold 10px", | 241 EXPECT_EQ("Arial,Sans serif,Bold 10px", |
| 259 derived.GetFontDescriptionString()); | 242 derived.GetFontDescriptionString()); |
| 260 } | 243 } |
| 261 | 244 |
| 262 TEST(FontListTest, Fonts_DeriveFontListWithSizeDelta) { | 245 TEST(FontListTest, Fonts_DeriveWithSizeDelta) { |
| 263 std::vector<Font> fonts; | 246 std::vector<Font> fonts; |
| 264 fonts.push_back(gfx::Font("Arial", 18).DeriveFont(0, Font::ITALIC)); | 247 fonts.push_back(gfx::Font("Arial", 18).DeriveFont(0, Font::ITALIC)); |
| 265 fonts.push_back(gfx::Font("Sans serif", 18).DeriveFont(0, Font::ITALIC)); | 248 fonts.push_back(gfx::Font("Sans serif", 18).DeriveFont(0, Font::ITALIC)); |
| 266 FontList font_list = FontList(fonts); | 249 FontList font_list = FontList(fonts); |
| 267 | 250 |
| 268 FontList derived = font_list.DeriveFontListWithSizeDelta(-5); | 251 FontList derived = font_list.DeriveWithSizeDelta(-5); |
| 269 const std::vector<Font>& derived_fonts = derived.GetFonts(); | 252 const std::vector<Font>& derived_fonts = derived.GetFonts(); |
| 270 | 253 |
| 271 EXPECT_EQ(2U, derived_fonts.size()); | 254 EXPECT_EQ(2U, derived_fonts.size()); |
| 272 EXPECT_EQ("Arial|13|italic", FontToString(derived_fonts[0])); | 255 EXPECT_EQ("Arial|13|italic", FontToString(derived_fonts[0])); |
| 273 EXPECT_EQ("Sans serif|13|italic", FontToString(derived_fonts[1])); | 256 EXPECT_EQ("Sans serif|13|italic", FontToString(derived_fonts[1])); |
| 274 } | 257 } |
| 275 | 258 |
| 276 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDeltaAndStyle) { | |
| 277 FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px"); | |
| 278 | |
| 279 FontList derived = font_list.DeriveFontListWithSizeDeltaAndStyle( | |
| 280 10, Font::ITALIC | Font::UNDERLINE); | |
| 281 EXPECT_EQ("Arial,Sans serif,Italic 18px", | |
| 282 derived.GetFontDescriptionString()); | |
| 283 EXPECT_EQ(Font::ITALIC | Font::UNDERLINE, | |
| 284 derived.GetFontStyle()); | |
| 285 | |
| 286 // FontList has a special care for Font::UNDERLINE. See if the handling of | |
| 287 // Font::UNDERLINE in GetFonts() is okay or not. | |
| 288 derived.GetFonts(); | |
| 289 EXPECT_EQ(Font::ITALIC | Font::UNDERLINE, | |
| 290 derived.GetFontStyle()); | |
| 291 } | |
| 292 | |
| 293 TEST(FontListTest, Fonts_DeriveFontListWithSizeDeltaAndStyle) { | |
| 294 std::vector<Font> fonts; | |
| 295 fonts.push_back(gfx::Font("Arial", 8)); | |
| 296 fonts.push_back(gfx::Font("Sans serif", 8)); | |
| 297 FontList font_list = FontList(fonts); | |
| 298 | |
| 299 FontList derived = font_list.DeriveFontListWithSizeDeltaAndStyle( | |
| 300 5, Font::BOLD | Font::UNDERLINE); | |
| 301 const std::vector<Font>& derived_fonts = derived.GetFonts(); | |
| 302 | |
| 303 EXPECT_EQ(2U, derived_fonts.size()); | |
| 304 EXPECT_EQ("Arial|13|bold|underline", FontToString(derived_fonts[0])); | |
| 305 EXPECT_EQ("Sans serif|13|bold|underline", FontToString(derived_fonts[1])); | |
| 306 } | |
| 307 | |
| 308 TEST(FontListTest, Fonts_GetHeight_GetBaseline) { | 259 TEST(FontListTest, Fonts_GetHeight_GetBaseline) { |
| 309 // If a font list has only one font, the height and baseline must be the same. | 260 // If a font list has only one font, the height and baseline must be the same. |
| 310 Font font1("Arial", 16); | 261 Font font1("Arial", 16); |
| 311 ASSERT_EQ("arial", StringToLowerASCII(font1.GetActualFontNameForTesting())); | 262 ASSERT_EQ("arial", StringToLowerASCII(font1.GetActualFontNameForTesting())); |
| 312 FontList font_list1("Arial, 16px"); | 263 FontList font_list1("Arial, 16px"); |
| 313 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight()); | 264 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight()); |
| 314 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline()); | 265 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline()); |
| 315 | 266 |
| 316 // If there are two different fonts, the font list returns the max value | 267 // If there are two different fonts, the font list returns the max value |
| 317 // for ascent and descent. | 268 // for ascent and descent. |
| 318 Font font2("Symbol", 16); | 269 Font font2("Symbol", 16); |
| 319 ASSERT_EQ("symbol", StringToLowerASCII(font2.GetActualFontNameForTesting())); | 270 ASSERT_EQ("symbol", StringToLowerASCII(font2.GetActualFontNameForTesting())); |
| 320 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline()); | 271 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline()); |
| 321 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(), | 272 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(), |
| 322 font2.GetHeight() - font2.GetBaseline()); | 273 font2.GetHeight() - font2.GetBaseline()); |
| 323 std::vector<Font> fonts; | 274 std::vector<Font> fonts; |
| 324 fonts.push_back(font1); | 275 fonts.push_back(font1); |
| 325 fonts.push_back(font2); | 276 fonts.push_back(font2); |
| 326 FontList font_list_mix(fonts); | 277 FontList font_list_mix(fonts); |
| 327 // ascent of FontList == max(ascent of Fonts) | 278 // ascent of FontList == max(ascent of Fonts) |
| 328 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(), | 279 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(), |
| 329 font2.GetHeight() - font2.GetBaseline()), | 280 font2.GetHeight() - font2.GetBaseline()), |
| 330 font_list_mix.GetHeight() - font_list_mix.GetBaseline()); | 281 font_list_mix.GetHeight() - font_list_mix.GetBaseline()); |
| 331 // descent of FontList == max(descent of Fonts) | 282 // descent of FontList == max(descent of Fonts) |
| 332 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()), | 283 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()), |
| 333 font_list_mix.GetBaseline()); | 284 font_list_mix.GetBaseline()); |
| 334 } | 285 } |
| 335 | 286 |
| 336 } // namespace gfx | 287 } // namespace gfx |
| OLD | NEW |