Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: ui/gfx/font_list_unittest.cc

Issue 21868004: Supports FontList::DeriveFontListWithSizeDeltaAndStyle, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes based on review comments. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« ui/gfx/font_list.cc ('K') | « ui/gfx/font_list.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 return font_string; 26 return font_string;
27 } 27 }
28 28
29 } // namespace 29 } // namespace
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 EXPECT_EQ("Droid Sans serif, Sans serif, 10px",
37 EXPECT_EQ("Droid Sans serif, Sans serif, 10px", font_str); 37 font_list.GetFontDescriptionString());
38 }
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 EXPECT_EQ("Arial,Droid Sans serif,Bold Italic 11px",
49 font_list.GetFontDescriptionString());
38 } 50 }
39 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 EXPECT_EQ("Arial,8px", font_list.GetFontDescriptionString());
45 EXPECT_EQ("Arial,8px", font_str);
46 } 57 }
47 58
48 TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) { 59 TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) {
49 // Test init from Font with non-normal style. 60 // Test init from Font with non-normal style.
50 Font font("Arial", 8); 61 Font font("Arial", 8);
51 FontList font_list = FontList(font.DeriveFont(2, Font::BOLD)); 62 FontList font_list = FontList(font.DeriveFont(2, Font::BOLD));
52 EXPECT_EQ("Arial,Bold 10px", font_list.GetFontDescriptionString()); 63 EXPECT_EQ("Arial,Bold 10px", font_list.GetFontDescriptionString());
53 64
54 font_list = FontList(font.DeriveFont(-2, Font::ITALIC)); 65 font_list = FontList(font.DeriveFont(-2, Font::ITALIC));
55 EXPECT_EQ("Arial,Italic 6px", font_list.GetFontDescriptionString()); 66 EXPECT_EQ("Arial,Italic 6px", font_list.GetFontDescriptionString());
56 } 67 }
57 68
58 TEST(FontListTest, FontDescString_FromFontVector) { 69 TEST(FontListTest, FontDescString_FromFontVector) {
59 // Test init from Font vector. 70 // Test init from Font vector.
60 Font font("Arial", 8); 71 Font font("Arial", 8);
61 Font font_1("Sans serif", 10); 72 Font font_1("Sans serif", 10);
62 std::vector<Font> fonts; 73 std::vector<Font> fonts;
63 fonts.push_back(font.DeriveFont(0, Font::BOLD)); 74 fonts.push_back(font.DeriveFont(0, Font::BOLD));
64 fonts.push_back(font_1.DeriveFont(-2, Font::BOLD)); 75 fonts.push_back(font_1.DeriveFont(-2, Font::BOLD));
65 FontList font_list = FontList(fonts); 76 FontList font_list = FontList(fonts);
66 const std::string& font_str = font_list.GetFontDescriptionString(); 77 EXPECT_EQ("Arial,Sans serif,Bold 8px", font_list.GetFontDescriptionString());
67 EXPECT_EQ("Arial,Sans serif,Bold 8px", font_str);
68 } 78 }
69 79
70 TEST(FontListTest, Fonts_FromDescString) { 80 TEST(FontListTest, Fonts_FromDescString) {
71 // Test init from font name size string. 81 // Test init from font name size string.
72 FontList font_list = FontList("serif,Sans serif, 13px"); 82 FontList font_list = FontList("serif,Sans serif, 13px");
73 const std::vector<Font>& fonts = font_list.GetFonts(); 83 const std::vector<Font>& fonts = font_list.GetFonts();
74 EXPECT_EQ(2U, fonts.size()); 84 EXPECT_EQ(2U, fonts.size());
75 EXPECT_EQ("serif|13", FontToString(fonts[0])); 85 EXPECT_EQ("serif|13", FontToString(fonts[0]));
76 EXPECT_EQ("Sans serif|13", FontToString(fonts[1])); 86 EXPECT_EQ("Sans serif|13", FontToString(fonts[1]));
77 } 87 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 FontList font_list = FontList(fonts); 236 FontList font_list = FontList(fonts);
227 237
228 FontList derived = font_list.DeriveFontListWithSize(5); 238 FontList derived = font_list.DeriveFontListWithSize(5);
229 const std::vector<Font>& derived_fonts = derived.GetFonts(); 239 const std::vector<Font>& derived_fonts = derived.GetFonts();
230 240
231 EXPECT_EQ(2U, derived_fonts.size()); 241 EXPECT_EQ(2U, derived_fonts.size());
232 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0])); 242 EXPECT_EQ("Arial|5", FontToString(derived_fonts[0]));
233 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1])); 243 EXPECT_EQ("Sans serif|5", FontToString(derived_fonts[1]));
234 } 244 }
235 245
246 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDelta) {
247 FontList font_list = FontList("Arial,Sans serif,Bold 18px");
248
249 FontList derived = font_list.DeriveFontListWithSizeDelta(-8);
250 EXPECT_EQ("Arial,Sans serif,Bold 10px",
251 derived.GetFontDescriptionString());
252 }
253
254 TEST(FontListTest, Fonts_DeriveFontListWithSizeDelta) {
255 std::vector<Font> fonts;
256 fonts.push_back(gfx::Font("Arial", 18).DeriveFont(0, Font::ITALIC));
257 fonts.push_back(gfx::Font("Sans serif", 18).DeriveFont(0, Font::ITALIC));
258 FontList font_list = FontList(fonts);
259
260 FontList derived = font_list.DeriveFontListWithSizeDelta(-5);
261 const std::vector<Font>& derived_fonts = derived.GetFonts();
262
263 EXPECT_EQ(2U, derived_fonts.size());
264 EXPECT_EQ("Arial|13|italic", FontToString(derived_fonts[0]));
265 EXPECT_EQ("Sans serif|13|italic", FontToString(derived_fonts[1]));
266 }
267
268 TEST(FontListTest, FontDescString_DeriveFontListWithSizeDeltaAndStyle) {
269 FontList font_list = FontList("Arial,Sans serif,Bold Italic 8px");
270
271 FontList derived =
272 font_list.DeriveFontListWithSizeDeltaAndStyle(10, Font::ITALIC);
273 EXPECT_EQ("Arial,Sans serif,Italic 18px",
274 derived.GetFontDescriptionString());
275 }
276
277 TEST(FontListTest, Fonts_DeriveFontListWithSizeDeltaAndStyle) {
278 std::vector<Font> fonts;
279 fonts.push_back(gfx::Font("Arial", 8));
280 fonts.push_back(gfx::Font("Sans serif", 8));
281 FontList font_list = FontList(fonts);
282
283 FontList derived =
284 font_list.DeriveFontListWithSizeDeltaAndStyle(5, Font::BOLD);
285 const std::vector<Font>& derived_fonts = derived.GetFonts();
286
287 EXPECT_EQ(2U, derived_fonts.size());
288 EXPECT_EQ("Arial|13|bold", FontToString(derived_fonts[0]));
289 EXPECT_EQ("Sans serif|13|bold", FontToString(derived_fonts[1]));
290 }
291
236 TEST(FontListTest, Fonts_GetHeight_GetBaseline) { 292 TEST(FontListTest, Fonts_GetHeight_GetBaseline) {
237 // If a font list has only one font, the height and baseline must be the same. 293 // If a font list has only one font, the height and baseline must be the same.
238 Font font1("Arial", 16); 294 Font font1("Arial", 16);
239 FontList font_list1("Arial, 16px"); 295 FontList font_list1("Arial, 16px");
240 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight()); 296 EXPECT_EQ(font1.GetHeight(), font_list1.GetHeight());
241 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline()); 297 EXPECT_EQ(font1.GetBaseline(), font_list1.GetBaseline());
242 298
243 // If there are two different fonts, the font list returns the max value 299 // If there are two different fonts, the font list returns the max value
244 // for ascent and descent. 300 // for ascent and descent.
245 Font font2("Symbol", 16); 301 Font font2("Symbol", 16);
246 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline()); 302 EXPECT_NE(font1.GetBaseline(), font2.GetBaseline());
247 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(), 303 EXPECT_NE(font1.GetHeight() - font1.GetBaseline(),
248 font2.GetHeight() - font2.GetBaseline()); 304 font2.GetHeight() - font2.GetBaseline());
249 std::vector<Font> fonts; 305 std::vector<Font> fonts;
250 fonts.push_back(font1); 306 fonts.push_back(font1);
251 fonts.push_back(font2); 307 fonts.push_back(font2);
252 FontList font_list_mix(fonts); 308 FontList font_list_mix(fonts);
253 // ascent of FontList == max(ascent of Fonts) 309 // ascent of FontList == max(ascent of Fonts)
254 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(), 310 EXPECT_EQ(std::max(font1.GetHeight() - font1.GetBaseline(),
255 font2.GetHeight() - font2.GetBaseline()), 311 font2.GetHeight() - font2.GetBaseline()),
256 font_list_mix.GetHeight() - font_list_mix.GetBaseline()); 312 font_list_mix.GetHeight() - font_list_mix.GetBaseline());
257 // descent of FontList == max(descent of Fonts) 313 // descent of FontList == max(descent of Fonts)
258 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()), 314 EXPECT_EQ(std::max(font1.GetBaseline(), font2.GetBaseline()),
259 font_list_mix.GetBaseline()); 315 font_list_mix.GetBaseline());
260 } 316 }
261 317
262 } // namespace gfx 318 } // namespace gfx
OLDNEW
« ui/gfx/font_list.cc ('K') | « ui/gfx/font_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698