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 |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // Helper function for comparing fonts for equality. | 18 // Helper function for comparing fonts for equality. |
19 std::string FontToString(const gfx::Font& font) { | 19 std::string FontToString(const gfx::Font& font) { |
20 std::string font_string = font.GetFontName(); | 20 std::string font_string = font.GetFontName(); |
21 font_string += "|"; | 21 font_string += "|"; |
22 font_string += base::IntToString(font.GetFontSize()); | 22 font_string += base::IntToString(font.GetFontSize()); |
23 int style = font.GetStyle(); | 23 int style = font.GetStyle(); |
24 if (style & gfx::Font::BOLD) | |
25 font_string += "|bold"; | |
26 if (style & gfx::Font::ITALIC) | 24 if (style & gfx::Font::ITALIC) |
27 font_string += "|italic"; | 25 font_string += "|italic"; |
28 if (style & gfx::Font::UNDERLINE) | 26 if (style & gfx::Font::UNDERLINE) |
29 font_string += "|underline"; | 27 font_string += "|underline"; |
| 28 auto weight = font.GetWeight(); |
| 29 if (weight == gfx::Font::Weight::BLACK) |
| 30 font_string += "|black"; |
| 31 else if (weight == gfx::Font::Weight::BOLD) |
| 32 font_string += "|bold"; |
| 33 else if (weight == gfx::Font::Weight::EXTRA_BOLD) |
| 34 font_string += "|extrabold"; |
| 35 else if (weight == gfx::Font::Weight::EXTRA_LIGHT) |
| 36 font_string += "|extralight"; |
| 37 else if (weight == gfx::Font::Weight::LIGHT) |
| 38 font_string += "|light"; |
| 39 else if (weight == gfx::Font::Weight::MEDIUM) |
| 40 font_string += "|medium"; |
| 41 else if (weight == gfx::Font::Weight::NORMAL) |
| 42 font_string += "|normal"; |
| 43 else if (weight == gfx::Font::Weight::SEMIBOLD) |
| 44 font_string += "|semibold"; |
| 45 else if (weight == gfx::Font::Weight::THIN) |
| 46 font_string += "|thin"; |
30 return font_string; | 47 return font_string; |
31 } | 48 } |
32 | 49 |
33 } // namespace | 50 } // namespace |
34 | 51 |
35 namespace gfx { | 52 namespace gfx { |
36 | 53 |
37 TEST(FontListTest, ParseDescription) { | 54 TEST(FontListTest, ParseDescription) { |
38 std::vector<std::string> families; | 55 std::vector<std::string> families; |
39 int style = gfx::Font::NORMAL; | 56 int style = gfx::Font::NORMAL; |
40 int size_pixels = 0; | 57 int size_pixels = 0; |
| 58 gfx::Font::Weight weight = gfx::Font::Weight::NORMAL; |
41 | 59 |
42 // Parse a well-formed description containing styles and a size. | 60 // Parse a well-formed description containing styles and a size. |
43 EXPECT_TRUE(FontList::ParseDescription("Arial,Helvetica,Bold Italic 12px", | 61 EXPECT_TRUE(FontList::ParseDescription("Arial,Helvetica,Bold Italic 12px", |
44 &families, &style, &size_pixels)); | 62 &families, &style, &size_pixels, |
| 63 &weight)); |
45 ASSERT_EQ(2U, families.size()); | 64 ASSERT_EQ(2U, families.size()); |
46 EXPECT_EQ("Arial", families[0]); | 65 EXPECT_EQ("Arial", families[0]); |
47 EXPECT_EQ("Helvetica", families[1]); | 66 EXPECT_EQ("Helvetica", families[1]); |
48 EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, style); | 67 EXPECT_EQ(gfx::Font::ITALIC, style); |
| 68 EXPECT_EQ(gfx::Font::Weight::BOLD, weight); |
49 EXPECT_EQ(12, size_pixels); | 69 EXPECT_EQ(12, size_pixels); |
50 | 70 |
51 // Whitespace should be removed. | 71 // Whitespace should be removed. |
52 EXPECT_TRUE(FontList::ParseDescription(" Verdana , Italic Bold 10px ", | 72 EXPECT_TRUE(FontList::ParseDescription(" Verdana , Italic Bold 10px ", |
53 &families, &style, &size_pixels)); | 73 &families, &style, &size_pixels, |
| 74 &weight)); |
54 ASSERT_EQ(1U, families.size()); | 75 ASSERT_EQ(1U, families.size()); |
55 EXPECT_EQ("Verdana", families[0]); | 76 EXPECT_EQ("Verdana", families[0]); |
56 EXPECT_EQ(gfx::Font::BOLD | gfx::Font::ITALIC, style); | 77 EXPECT_EQ(gfx::Font::ITALIC, style); |
| 78 EXPECT_EQ(gfx::Font::Weight::BOLD, weight); |
57 EXPECT_EQ(10, size_pixels); | 79 EXPECT_EQ(10, size_pixels); |
58 | 80 |
59 // Invalid descriptions should be rejected. | 81 // Invalid descriptions should be rejected. |
60 EXPECT_FALSE(FontList::ParseDescription("", &families, &style, &size_pixels)); | 82 EXPECT_FALSE( |
| 83 FontList::ParseDescription("", &families, &style, &size_pixels, &weight)); |
61 EXPECT_FALSE(FontList::ParseDescription("Arial", &families, &style, | 84 EXPECT_FALSE(FontList::ParseDescription("Arial", &families, &style, |
62 &size_pixels)); | 85 &size_pixels, &weight)); |
63 EXPECT_FALSE(FontList::ParseDescription("Arial,12", &families, &style, | 86 EXPECT_FALSE(FontList::ParseDescription("Arial,12", &families, &style, |
64 &size_pixels)); | 87 &size_pixels, &weight)); |
65 EXPECT_FALSE(FontList::ParseDescription("Arial 12px", &families, &style, | 88 EXPECT_FALSE(FontList::ParseDescription("Arial 12px", &families, &style, |
66 &size_pixels)); | 89 &size_pixels, &weight)); |
67 EXPECT_FALSE(FontList::ParseDescription("Arial,12px,", &families, &style, | 90 EXPECT_FALSE(FontList::ParseDescription("Arial,12px,", &families, &style, |
68 &size_pixels)); | 91 &size_pixels, &weight)); |
69 EXPECT_FALSE(FontList::ParseDescription("Arial,0px", &families, &style, | 92 EXPECT_FALSE(FontList::ParseDescription("Arial,0px", &families, &style, |
70 &size_pixels)); | 93 &size_pixels, &weight)); |
71 EXPECT_FALSE(FontList::ParseDescription("Arial,-1px", &families, &style, | 94 EXPECT_FALSE(FontList::ParseDescription("Arial,-1px", &families, &style, |
72 &size_pixels)); | 95 &size_pixels, &weight)); |
73 EXPECT_FALSE(FontList::ParseDescription("Arial,foo 12px", &families, &style, | 96 EXPECT_FALSE(FontList::ParseDescription("Arial,foo 12px", &families, &style, |
74 &size_pixels)); | 97 &size_pixels, &weight)); |
75 } | 98 } |
76 | 99 |
77 // TODO(489354): Enable this on android. | 100 // TODO(489354): Enable this on android. |
78 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
79 #define MAYBE_Fonts_FromDescString DISABLED_Fonts_FromDescString | 102 #define MAYBE_Fonts_FromDescString DISABLED_Fonts_FromDescString |
80 #else | 103 #else |
81 #define MAYBE_Fonts_FromDescString Fonts_FromDescString | 104 #define MAYBE_Fonts_FromDescString Fonts_FromDescString |
82 #endif | 105 #endif |
83 TEST(FontListTest, MAYBE_Fonts_FromDescString) { | 106 TEST(FontListTest, MAYBE_Fonts_FromDescString) { |
84 // Test init from font name size string. | 107 // Test init from font name size string. |
85 FontList font_list = FontList("arial, Courier New, 13px"); | 108 FontList font_list = FontList("arial, Courier New, 13px"); |
86 const std::vector<Font>& fonts = font_list.GetFonts(); | 109 const std::vector<Font>& fonts = font_list.GetFonts(); |
87 ASSERT_EQ(2U, fonts.size()); | 110 ASSERT_EQ(2U, fonts.size()); |
88 EXPECT_EQ("arial|13", FontToString(fonts[0])); | 111 EXPECT_EQ("arial|13|normal", FontToString(fonts[0])); |
89 EXPECT_EQ("Courier New|13", FontToString(fonts[1])); | 112 EXPECT_EQ("Courier New|13|normal", FontToString(fonts[1])); |
90 } | 113 } |
91 | 114 |
92 // TODO(489354): Enable this on android. | 115 // TODO(489354): Enable this on android. |
93 #if defined(OS_ANDROID) | 116 #if defined(OS_ANDROID) |
94 #define MAYBE_Fonts_FromDescStringInFlexibleFormat \ | 117 #define MAYBE_Fonts_FromDescStringInFlexibleFormat \ |
95 DISABLED_Fonts_FromDescStringInFlexibleFormat | 118 DISABLED_Fonts_FromDescStringInFlexibleFormat |
96 #else | 119 #else |
97 #define MAYBE_Fonts_FromDescStringInFlexibleFormat \ | 120 #define MAYBE_Fonts_FromDescStringInFlexibleFormat \ |
98 Fonts_FromDescStringInFlexibleFormat | 121 Fonts_FromDescStringInFlexibleFormat |
99 #endif | 122 #endif |
100 TEST(FontListTest, MAYBE_Fonts_FromDescStringInFlexibleFormat) { | 123 TEST(FontListTest, MAYBE_Fonts_FromDescStringInFlexibleFormat) { |
101 // Test init from font name size string with flexible format. | 124 // Test init from font name size string with flexible format. |
102 FontList font_list = FontList(" arial , Courier New , 13px"); | 125 FontList font_list = FontList(" arial , Courier New , 13px"); |
103 const std::vector<Font>& fonts = font_list.GetFonts(); | 126 const std::vector<Font>& fonts = font_list.GetFonts(); |
104 ASSERT_EQ(2U, fonts.size()); | 127 ASSERT_EQ(2U, fonts.size()); |
105 EXPECT_EQ("arial|13", FontToString(fonts[0])); | 128 EXPECT_EQ("arial|13|normal", FontToString(fonts[0])); |
106 EXPECT_EQ("Courier New|13", FontToString(fonts[1])); | 129 EXPECT_EQ("Courier New|13|normal", FontToString(fonts[1])); |
107 } | 130 } |
108 | 131 |
109 // TODO(489354): Enable this on android. | 132 // TODO(489354): Enable this on android. |
110 #if defined(OS_ANDROID) | 133 #if defined(OS_ANDROID) |
111 #define MAYBE_Fonts_FromDescStringWithStyleInFlexibleFormat \ | 134 #define MAYBE_Fonts_FromDescStringWithStyleInFlexibleFormat \ |
112 DISABLED_Fonts_FromDescStringWithStyleInFlexibleFormat | 135 DISABLED_Fonts_FromDescStringWithStyleInFlexibleFormat |
113 #else | 136 #else |
114 #define MAYBE_Fonts_FromDescStringWithStyleInFlexibleFormat \ | 137 #define MAYBE_Fonts_FromDescStringWithStyleInFlexibleFormat \ |
115 Fonts_FromDescStringWithStyleInFlexibleFormat | 138 Fonts_FromDescStringWithStyleInFlexibleFormat |
116 #endif | 139 #endif |
117 TEST(FontListTest, MAYBE_Fonts_FromDescStringWithStyleInFlexibleFormat) { | 140 TEST(FontListTest, MAYBE_Fonts_FromDescStringWithStyleInFlexibleFormat) { |
118 // Test init from font name style size string with flexible format. | 141 // Test init from font name style size string with flexible format. |
119 FontList font_list = FontList(" arial , Courier New , Bold " | 142 FontList font_list = FontList( |
120 " Italic 13px"); | 143 " arial , Courier New , Bold " |
| 144 " Italic 13px"); |
121 const std::vector<Font>& fonts = font_list.GetFonts(); | 145 const std::vector<Font>& fonts = font_list.GetFonts(); |
122 ASSERT_EQ(2U, fonts.size()); | 146 ASSERT_EQ(2U, fonts.size()); |
123 EXPECT_EQ("arial|13|bold|italic", FontToString(fonts[0])); | 147 EXPECT_EQ("arial|13|italic|bold", FontToString(fonts[0])); |
124 EXPECT_EQ("Courier New|13|bold|italic", FontToString(fonts[1])); | 148 EXPECT_EQ("Courier New|13|italic|bold", FontToString(fonts[1])); |
125 } | 149 } |
126 | 150 |
127 // TODO(489354): Enable this on android. | 151 // TODO(489354): Enable this on android. |
128 #if defined(OS_ANDROID) | 152 #if defined(OS_ANDROID) |
129 #define MAYBE_Fonts_FromFont DISABLED_Fonts_FromFont | 153 #define MAYBE_Fonts_FromFont DISABLED_Fonts_FromFont |
130 #else | 154 #else |
131 #define MAYBE_Fonts_FromFont Fonts_FromFont | 155 #define MAYBE_Fonts_FromFont Fonts_FromFont |
132 #endif | 156 #endif |
133 TEST(FontListTest, MAYBE_Fonts_FromFont) { | 157 TEST(FontListTest, MAYBE_Fonts_FromFont) { |
134 // Test init from Font. | 158 // Test init from Font. |
135 Font font("Arial", 8); | 159 Font font("Arial", 8); |
136 FontList font_list = FontList(font); | 160 FontList font_list = FontList(font); |
137 const std::vector<Font>& fonts = font_list.GetFonts(); | 161 const std::vector<Font>& fonts = font_list.GetFonts(); |
138 ASSERT_EQ(1U, fonts.size()); | 162 ASSERT_EQ(1U, fonts.size()); |
139 EXPECT_EQ("Arial|8", FontToString(fonts[0])); | 163 EXPECT_EQ("Arial|8|normal", FontToString(fonts[0])); |
140 } | 164 } |
141 | 165 |
142 // TODO(489354): Enable this on android. | 166 // TODO(489354): Enable this on android. |
143 #if defined(OS_ANDROID) | 167 #if defined(OS_ANDROID) |
144 #define MAYBE_Fonts_FromFontWithNonNormalStyle \ | 168 #define MAYBE_Fonts_FromFontWithNonNormalStyle \ |
145 DISABLED_Fonts_FromFontWithNonNormalStyle | 169 DISABLED_Fonts_FromFontWithNonNormalStyle |
146 #else | 170 #else |
147 #define MAYBE_Fonts_FromFontWithNonNormalStyle Fonts_FromFontWithNonNormalStyle | 171 #define MAYBE_Fonts_FromFontWithNonNormalStyle Fonts_FromFontWithNonNormalStyle |
148 #endif | 172 #endif |
149 TEST(FontListTest, MAYBE_Fonts_FromFontWithNonNormalStyle) { | 173 TEST(FontListTest, MAYBE_Fonts_FromFontWithNonNormalStyle) { |
150 // Test init from Font with non-normal style. | 174 // Test init from Font with non-normal style. |
151 Font font("Arial", 8); | 175 Font font("Arial", 8); |
152 FontList font_list = FontList(font.Derive(2, Font::BOLD)); | 176 FontList font_list(font.Derive(2, Font::NORMAL, Font::Weight::BOLD)); |
153 std::vector<Font> fonts = font_list.GetFonts(); | 177 std::vector<Font> fonts = font_list.GetFonts(); |
154 ASSERT_EQ(1U, fonts.size()); | 178 ASSERT_EQ(1U, fonts.size()); |
155 EXPECT_EQ("Arial|10|bold", FontToString(fonts[0])); | 179 EXPECT_EQ("Arial|10|bold", FontToString(fonts[0])); |
156 | 180 |
157 font_list = FontList(font.Derive(-2, Font::ITALIC)); | 181 font_list = FontList(font.Derive(-2, Font::ITALIC, Font::Weight::NORMAL)); |
158 fonts = font_list.GetFonts(); | 182 fonts = font_list.GetFonts(); |
159 ASSERT_EQ(1U, fonts.size()); | 183 ASSERT_EQ(1U, fonts.size()); |
160 EXPECT_EQ("Arial|6|italic", FontToString(fonts[0])); | 184 EXPECT_EQ("Arial|6|italic|normal", FontToString(fonts[0])); |
161 } | 185 } |
162 | 186 |
163 // TODO(489354): Enable this on android. | 187 // TODO(489354): Enable this on android. |
164 #if defined(OS_ANDROID) | 188 #if defined(OS_ANDROID) |
165 #define MAYBE_Fonts_FromFontVector DISABLED_Fonts_FromFontVector | 189 #define MAYBE_Fonts_FromFontVector DISABLED_Fonts_FromFontVector |
166 #else | 190 #else |
167 #define MAYBE_Fonts_FromFontVector Fonts_FromFontVector | 191 #define MAYBE_Fonts_FromFontVector Fonts_FromFontVector |
168 #endif | 192 #endif |
169 TEST(FontListTest, MAYBE_Fonts_FromFontVector) { | 193 TEST(FontListTest, MAYBE_Fonts_FromFontVector) { |
170 // Test init from Font vector. | 194 // Test init from Font vector. |
171 Font font("Arial", 8); | 195 Font font("Arial", 8); |
172 Font font_1("Courier New", 10); | 196 Font font_1("Courier New", 10); |
173 std::vector<Font> input_fonts; | 197 std::vector<Font> input_fonts; |
174 input_fonts.push_back(font.Derive(0, Font::BOLD)); | 198 input_fonts.push_back(font.Derive(0, Font::NORMAL, Font::Weight::BOLD)); |
175 input_fonts.push_back(font_1.Derive(-2, Font::BOLD)); | 199 input_fonts.push_back(font_1.Derive(-2, Font::NORMAL, Font::Weight::BOLD)); |
176 FontList font_list = FontList(input_fonts); | 200 FontList font_list = FontList(input_fonts); |
177 const std::vector<Font>& fonts = font_list.GetFonts(); | 201 const std::vector<Font>& fonts = font_list.GetFonts(); |
178 ASSERT_EQ(2U, fonts.size()); | 202 ASSERT_EQ(2U, fonts.size()); |
179 EXPECT_EQ("Arial|8|bold", FontToString(fonts[0])); | 203 EXPECT_EQ("Arial|8|bold", FontToString(fonts[0])); |
180 EXPECT_EQ("Courier New|8|bold", FontToString(fonts[1])); | 204 EXPECT_EQ("Courier New|8|bold", FontToString(fonts[1])); |
181 } | 205 } |
182 | 206 |
183 TEST(FontListTest, FontDescString_GetStyle) { | 207 TEST(FontListTest, FontDescString_GetStyle) { |
184 FontList font_list = FontList("Arial,Sans serif, 8px"); | 208 FontList font_list = FontList("Arial,Sans serif, 8px"); |
185 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); | 209 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); |
| 210 EXPECT_EQ(Font::Weight::NORMAL, font_list.GetFontWeight()); |
186 | 211 |
187 font_list = FontList("Arial,Sans serif,Bold 8px"); | 212 font_list = FontList("Arial,Sans serif,Bold 8px"); |
188 EXPECT_EQ(Font::BOLD, font_list.GetFontStyle()); | 213 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); |
| 214 EXPECT_EQ(Font::Weight::BOLD, font_list.GetFontWeight()); |
189 | 215 |
190 font_list = FontList("Arial,Sans serif,Italic 8px"); | 216 font_list = FontList("Arial,Sans serif,Italic 8px"); |
191 EXPECT_EQ(Font::ITALIC, font_list.GetFontStyle()); | 217 EXPECT_EQ(Font::ITALIC, font_list.GetFontStyle()); |
| 218 EXPECT_EQ(Font::Weight::NORMAL, font_list.GetFontWeight()); |
192 | 219 |
193 font_list = FontList("Arial,Italic Bold 8px"); | 220 font_list = FontList("Arial,Italic Bold 8px"); |
194 EXPECT_EQ(Font::BOLD | Font::ITALIC, font_list.GetFontStyle()); | 221 EXPECT_EQ(Font::ITALIC, font_list.GetFontStyle()); |
| 222 EXPECT_EQ(Font::Weight::BOLD, font_list.GetFontWeight()); |
195 } | 223 } |
196 | 224 |
197 // TODO(489354): Enable this on android. | 225 // TODO(489354): Enable this on android. |
198 #if defined(OS_ANDROID) | 226 #if defined(OS_ANDROID) |
199 #define MAYBE_Fonts_GetStyle DISABLED_Fonts_GetStyle | 227 #define MAYBE_Fonts_GetStyle DISABLED_Fonts_GetStyle |
200 #else | 228 #else |
201 #define MAYBE_Fonts_GetStyle Fonts_GetStyle | 229 #define MAYBE_Fonts_GetStyle Fonts_GetStyle |
202 #endif | 230 #endif |
203 TEST(FontListTest, MAYBE_Fonts_GetStyle) { | 231 TEST(FontListTest, MAYBE_Fonts_GetStyle) { |
204 std::vector<Font> fonts; | 232 std::vector<Font> fonts; |
205 fonts.push_back(gfx::Font("Arial", 8)); | 233 fonts.push_back(gfx::Font("Arial", 8)); |
206 fonts.push_back(gfx::Font("Sans serif", 8)); | 234 fonts.push_back(gfx::Font("Sans serif", 8)); |
207 FontList font_list = FontList(fonts); | 235 FontList font_list = FontList(fonts); |
208 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); | 236 EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); |
209 fonts[0] = fonts[0].Derive(0, Font::ITALIC | Font::BOLD); | 237 fonts[0] = fonts[0].Derive(0, Font::ITALIC, Font::Weight::BOLD); |
210 fonts[1] = fonts[1].Derive(0, Font::ITALIC | Font::BOLD); | 238 fonts[1] = fonts[1].Derive(0, Font::ITALIC, Font::Weight::BOLD); |
211 font_list = FontList(fonts); | 239 font_list = FontList(fonts); |
212 EXPECT_EQ(Font::ITALIC | Font::BOLD, font_list.GetFontStyle()); | 240 EXPECT_EQ(Font::ITALIC, font_list.GetFontStyle()); |
| 241 EXPECT_EQ(Font::Weight::BOLD, font_list.GetFontWeight()); |
213 } | 242 } |
214 | 243 |
215 // TODO(489354): Enable this on android. | 244 // TODO(489354): Enable this on android. |
216 #if defined(OS_ANDROID) | 245 #if defined(OS_ANDROID) |
217 #define MAYBE_Fonts_Derive DISABLED_Fonts_Derive | 246 #define MAYBE_Fonts_Derive DISABLED_Fonts_Derive |
218 #else | 247 #else |
219 #define MAYBE_Fonts_Derive Fonts_Derive | 248 #define MAYBE_Fonts_Derive Fonts_Derive |
220 #endif | 249 #endif |
221 TEST(FontListTest, MAYBE_Fonts_Derive) { | 250 TEST(FontListTest, MAYBE_Fonts_Derive) { |
222 std::vector<Font> fonts; | 251 std::vector<Font> fonts; |
223 fonts.push_back(gfx::Font("Arial", 8)); | 252 fonts.push_back(gfx::Font("Arial", 8)); |
224 fonts.push_back(gfx::Font("Courier New", 8)); | 253 fonts.push_back(gfx::Font("Courier New", 8)); |
225 FontList font_list = FontList(fonts); | 254 FontList font_list = FontList(fonts); |
226 | 255 |
227 FontList derived = font_list.Derive(5, Font::BOLD | Font::UNDERLINE); | 256 FontList derived = font_list.Derive(5, Font::UNDERLINE, Font::Weight::BOLD); |
228 const std::vector<Font>& derived_fonts = derived.GetFonts(); | 257 const std::vector<Font>& derived_fonts = derived.GetFonts(); |
229 | 258 |
230 EXPECT_EQ(2U, derived_fonts.size()); | 259 EXPECT_EQ(2U, derived_fonts.size()); |
231 EXPECT_EQ("Arial|13|bold|underline", FontToString(derived_fonts[0])); | 260 EXPECT_EQ("Arial|13|underline|bold", FontToString(derived_fonts[0])); |
232 EXPECT_EQ("Courier New|13|bold|underline", FontToString(derived_fonts[1])); | 261 EXPECT_EQ("Courier New|13|underline|bold", FontToString(derived_fonts[1])); |
233 } | 262 } |
234 | 263 |
235 // TODO(489354): Enable this on android. | 264 // TODO(489354): Enable this on android. |
236 #if defined(OS_ANDROID) | 265 #if defined(OS_ANDROID) |
237 #define MAYBE_Fonts_DeriveWithSizeDelta DISABLED_Fonts_DeriveWithSizeDelta | 266 #define MAYBE_Fonts_DeriveWithSizeDelta DISABLED_Fonts_DeriveWithSizeDelta |
238 #else | 267 #else |
239 #define MAYBE_Fonts_DeriveWithSizeDelta Fonts_DeriveWithSizeDelta | 268 #define MAYBE_Fonts_DeriveWithSizeDelta Fonts_DeriveWithSizeDelta |
240 #endif | 269 #endif |
241 TEST(FontListTest, MAYBE_Fonts_DeriveWithSizeDelta) { | 270 TEST(FontListTest, MAYBE_Fonts_DeriveWithSizeDelta) { |
242 std::vector<Font> fonts; | 271 std::vector<Font> fonts; |
243 fonts.push_back(gfx::Font("Arial", 18).Derive(0, Font::ITALIC)); | 272 fonts.push_back( |
244 fonts.push_back(gfx::Font("Courier New", 18).Derive(0, Font::ITALIC)); | 273 gfx::Font("Arial", 18).Derive(0, Font::ITALIC, Font::Weight::NORMAL)); |
| 274 fonts.push_back(gfx::Font("Courier New", 18) |
| 275 .Derive(0, Font::ITALIC, Font::Weight::NORMAL)); |
245 FontList font_list = FontList(fonts); | 276 FontList font_list = FontList(fonts); |
246 | 277 |
247 FontList derived = font_list.DeriveWithSizeDelta(-5); | 278 FontList derived = font_list.DeriveWithSizeDelta(-5); |
248 const std::vector<Font>& derived_fonts = derived.GetFonts(); | 279 const std::vector<Font>& derived_fonts = derived.GetFonts(); |
249 | 280 |
250 EXPECT_EQ(2U, derived_fonts.size()); | 281 EXPECT_EQ(2U, derived_fonts.size()); |
251 EXPECT_EQ("Arial|13|italic", FontToString(derived_fonts[0])); | 282 EXPECT_EQ("Arial|13|italic|normal", FontToString(derived_fonts[0])); |
252 EXPECT_EQ("Courier New|13|italic", FontToString(derived_fonts[1])); | 283 EXPECT_EQ("Courier New|13|italic|normal", FontToString(derived_fonts[1])); |
253 } | 284 } |
254 | 285 |
255 // TODO(489354): Enable this on android. | 286 // TODO(489354): Enable this on android. |
256 #if defined(OS_ANDROID) | 287 #if defined(OS_ANDROID) |
257 #define MAYBE_Fonts_GetHeight_GetBaseline DISABLED_Fonts_GetHeight_GetBaseline | 288 #define MAYBE_Fonts_GetHeight_GetBaseline DISABLED_Fonts_GetHeight_GetBaseline |
258 #else | 289 #else |
259 #define MAYBE_Fonts_GetHeight_GetBaseline Fonts_GetHeight_GetBaseline | 290 #define MAYBE_Fonts_GetHeight_GetBaseline Fonts_GetHeight_GetBaseline |
260 #endif | 291 #endif |
261 TEST(FontListTest, MAYBE_Fonts_GetHeight_GetBaseline) { | 292 TEST(FontListTest, MAYBE_Fonts_GetHeight_GetBaseline) { |
262 // 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. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 341 |
311 // A larger upper bound should not change the height of the font list. | 342 // A larger upper bound should not change the height of the font list. |
312 const int height_2 = font_list.GetHeight() + 5; | 343 const int height_2 = font_list.GetHeight() + 5; |
313 FontList derived_2 = font_list.DeriveWithHeightUpperBound(height_2); | 344 FontList derived_2 = font_list.DeriveWithHeightUpperBound(height_2); |
314 EXPECT_LE(derived_2.GetHeight(), height_2); | 345 EXPECT_LE(derived_2.GetHeight(), height_2); |
315 EXPECT_EQ(font_list.GetHeight(), derived_2.GetHeight()); | 346 EXPECT_EQ(font_list.GetHeight(), derived_2.GetHeight()); |
316 EXPECT_EQ(font_list.GetFontSize(), derived_2.GetFontSize()); | 347 EXPECT_EQ(font_list.GetFontSize(), derived_2.GetFontSize()); |
317 } | 348 } |
318 | 349 |
319 } // namespace gfx | 350 } // namespace gfx |
OLD | NEW |