blob: 50e2d5a606f0f666c6f64d9d5f707044dcf12918 [file] [log] [blame]
reed@google.com83165a52013-04-11 18:31:25 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
reed@google.com83165a52013-04-11 18:31:25 +00008#include "SkCommandLineFlags.h"
9#include "SkFontMgr.h"
10#include "SkTypeface.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000011#include "Test.h"
reed@google.com83165a52013-04-11 18:31:25 +000012
reed@google.com43c27582014-04-08 15:04:29 +000013#include "SkFont.h"
14#include "SkPaint.h"
bungeman147ea2f2015-11-12 09:50:08 -080015
16#include <initializer_list>
17#include <limits>
18#include <vector>
19
reed@google.com43c27582014-04-08 15:04:29 +000020static void test_font(skiatest::Reporter* reporter) {
21 uint32_t flags = 0;
bungeman13b9c952016-05-12 10:09:30 -070022 sk_sp<SkFont> font(SkFont::Make(nullptr, 24, SkFont::kA8_MaskType, flags));
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000023
bsalomon49f085d2014-09-05 13:34:00 -070024 REPORTER_ASSERT(reporter, font->getTypeface());
reed@google.com43c27582014-04-08 15:04:29 +000025 REPORTER_ASSERT(reporter, 24 == font->getSize());
26 REPORTER_ASSERT(reporter, 1 == font->getScaleX());
27 REPORTER_ASSERT(reporter, 0 == font->getSkewX());
28 REPORTER_ASSERT(reporter, SkFont::kA8_MaskType == font->getMaskType());
29
30 uint16_t glyphs[5];
31 sk_bzero(glyphs, sizeof(glyphs));
32
33 int count = font->textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_ARRAY_COUNT(glyphs));
34
35 REPORTER_ASSERT(reporter, 5 == count);
36 for (int i = 0; i < count; ++i) {
37 REPORTER_ASSERT(reporter, 0 != glyphs[i]);
38 }
39 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
40 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000041
bungeman13b9c952016-05-12 10:09:30 -070042 sk_sp<SkFont> newFont(font->makeWithSize(36));
reed@google.com43c27582014-04-08 15:04:29 +000043 REPORTER_ASSERT(reporter, newFont.get());
44 REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface());
45 REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we haven't changed
46 REPORTER_ASSERT(reporter, 24 == font->getSize()); // double check we haven't changed
47
48 SkPaint paint;
49 paint.setTextSize(18);
bungeman13b9c952016-05-12 10:09:30 -070050 font = SkFont::Testing_CreateFromPaint(paint);
reed@google.com43c27582014-04-08 15:04:29 +000051 REPORTER_ASSERT(reporter, font.get());
52 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
53 REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType());
54}
55
reed@google.comd44d9882013-09-18 20:32:25 +000056/*
57 * If the font backend is going to "alias" some font names to other fonts
58 * (e.g. sans -> Arial) then we want to at least get the same typeface back
59 * if we request the alias name multiple times.
60 */
reed@google.comc1a81eb2013-09-19 18:06:03 +000061static void test_alias_names(skiatest::Reporter* reporter) {
62 const char* inNames[] = {
63 "sans", "sans-serif", "serif", "monospace", "times", "helvetica"
64 };
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000065
reed@google.comc1a81eb2013-09-19 18:06:03 +000066 for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) {
mbocee6a9912016-05-31 11:42:36 -070067 sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
halcanary96fcdcc2015-08-27 07:41:13 -070068 if (nullptr == first.get()) {
reed@google.comc1a81eb2013-09-19 18:06:03 +000069 continue;
70 }
71 for (int j = 0; j < 10; ++j) {
mbocee6a9912016-05-31 11:42:36 -070072 sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
reed@google.comc1a81eb2013-09-19 18:06:03 +000073 #if 0
74 SkString name;
75 face->getFamilyName(&name);
76 printf("request %s, received %s, first id %x received %x\n",
77 inNames[i], name.c_str(), first->uniqueID(), face->uniqueID());
78 #endif
79 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID());
80 }
reed@google.comd44d9882013-09-18 20:32:25 +000081 }
82}
83
reed@google.com83165a52013-04-11 18:31:25 +000084static void test_fontiter(skiatest::Reporter* reporter, bool verbose) {
Hal Canary342b7ac2016-11-04 11:49:42 -040085 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
reed@google.com83165a52013-04-11 18:31:25 +000086 int count = fm->countFamilies();
87
88 for (int i = 0; i < count; ++i) {
89 SkString fname;
90 fm->getFamilyName(i, &fname);
reed@google.com83165a52013-04-11 18:31:25 +000091
Hal Canary342b7ac2016-11-04 11:49:42 -040092 sk_sp<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
93 sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
bungeman@google.com71033442013-05-01 14:21:20 +000094 REPORTER_ASSERT(reporter, fnset->count() == set->count());
reed@google.com83165a52013-04-11 18:31:25 +000095
96 if (verbose) {
97 SkDebugf("[%2d] %s\n", i, fname.c_str());
98 }
99
100 for (int j = 0; j < set->count(); ++j) {
101 SkString sname;
102 SkFontStyle fs;
103 set->getStyle(j, &fs, &sname);
reed@google.comeb029572013-04-25 14:59:32 +0000104// REPORTER_ASSERT(reporter, sname.size() > 0);
reed@google.com83165a52013-04-11 18:31:25 +0000105
Hal Canary342b7ac2016-11-04 11:49:42 -0400106 sk_sp<SkTypeface> face(set->createTypeface(j));
reed@google.comc1ccda32013-04-19 14:28:54 +0000107// REPORTER_ASSERT(reporter, face.get());
reed@google.com83165a52013-04-11 18:31:25 +0000108
109 if (verbose) {
110 SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(),
bungemanb4bb7d82016-04-27 10:21:04 -0700111 fs.weight(), fs.width(), fs.slant());
reed@google.com83165a52013-04-11 18:31:25 +0000112 }
113 }
114 }
115}
116
bungeman147ea2f2015-11-12 09:50:08 -0800117static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
bungeman147ea2f2015-11-12 09:50:08 -0800118 static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
119
120 class TestTypeface : public SkTypeface {
121 public:
bungemane3aea102016-07-13 05:16:58 -0700122 TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){}
bungeman147ea2f2015-11-12 09:50:08 -0800123 protected:
124 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
reeda9322c22016-04-12 06:47:05 -0700125 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
126 const SkDescriptor*) const override {
bungeman147ea2f2015-11-12 09:50:08 -0800127 return nullptr;
128 }
129 void onFilterRec(SkScalerContextRec*) const override { }
130 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
131 PerGlyphInfo,
132 const uint32_t*, uint32_t) const override { return nullptr; }
133 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
134 virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
135 uint16_t glyphs[], int glyphCount) const override {
136 if (glyphs && glyphCount > 0) {
137 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
138 }
139 return 0;
140 }
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400141 int onCountGlyphs() const override { return 0; }
142 int onGetUPEM() const override { return 0; }
bungeman147ea2f2015-11-12 09:50:08 -0800143 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
144 public:
145 bool next(SkTypeface::LocalizedString*) override { return false; }
146 };
147 void onGetFamilyName(SkString* familyName) const override {
148 familyName->reset();
149 }
150 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
151 return new EmptyLocalizedStrings;
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400152 }
bungeman147ea2f2015-11-12 09:50:08 -0800153 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
154 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
155 return 0;
156 }
157 };
158
159 class TestFontStyleSet : public SkFontStyleSet {
160 public:
161 TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
162 int count() override { return static_cast<int>(fStyles.size()); }
163 void getStyle(int index, SkFontStyle* style, SkString*) override {
164 if (style) {
165 *style = fStyles[index];
166 }
167 }
168 SkTypeface* createTypeface(int index) override {
169 if (index < 0 || this->count() <= index) {
bungemane3aea102016-07-13 05:16:58 -0700170 return new TestTypeface(invalidFontStyle);
bungeman147ea2f2015-11-12 09:50:08 -0800171 }
bungemane3aea102016-07-13 05:16:58 -0700172 return new TestTypeface(fStyles[index]);
bungeman147ea2f2015-11-12 09:50:08 -0800173 }
174 SkTypeface* matchStyle(const SkFontStyle& pattern) override {
175 return this->matchStyleCSS3(pattern);
176 }
177 private:
178 std::vector<SkFontStyle> fStyles;
179 };
180
181 SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
182 SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
183 SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
184 SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700185 SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
186 SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800187 SkFontStyle expanded_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
188 SkFontStyle expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
189 SkFontStyle expanded_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
190 SkFontStyle expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700191 SkFontStyle expanded_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
192 SkFontStyle expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800193
194 SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
195 SkFontStyle normal_normal_200(SkFontStyle::kExtraLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
196 SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
197 SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
198 SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
199 SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
200 SkFontStyle normal_normal_700(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
201 SkFontStyle normal_normal_800(SkFontStyle::kExtraBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
202 SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
203
204 struct StyleSetTest {
205 TestFontStyleSet styleSet;
206 struct Case {
207 SkFontStyle pattern;
208 SkFontStyle expectedResult;
209 };
210 std::vector<Case> cases;
211 } tests[] = {
212 {
213 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
214 expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
215 {
216 { condensed_normal_100, condensed_normal_100 },
217 { condensed_normal_900, condensed_normal_900 },
218 { condensed_italic_100, condensed_italic_100 },
219 { condensed_italic_900, condensed_italic_900 },
220 { expanded_normal_100, expanded_normal_100 },
221 { expanded_normal_900, expanded_normal_900 },
222 { expanded_italic_100, expanded_italic_100 },
223 { expanded_italic_900, expanded_italic_900 },
224 },
225 },
226
227 {
228 { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
229 {
230 { condensed_normal_100, condensed_normal_100 },
231 { condensed_normal_900, condensed_normal_100 },
232 { condensed_italic_100, condensed_italic_100 },
233 { condensed_italic_900, condensed_italic_100 },
234 { expanded_normal_100, expanded_normal_100 },
235 { expanded_normal_900, expanded_normal_100 },
236 { expanded_italic_100, expanded_italic_100 },
237 { expanded_italic_900, expanded_italic_100 },
238 },
239 },
240
241 {
242 { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
243 {
244 { condensed_normal_100, condensed_normal_900 },
245 { condensed_normal_900, condensed_normal_900 },
246 { condensed_italic_100, condensed_italic_900 },
247 { condensed_italic_900, condensed_italic_900 },
248 { expanded_normal_100, expanded_normal_900 },
249 { expanded_normal_900, expanded_normal_900 },
250 { expanded_italic_100, expanded_italic_900 },
251 { expanded_italic_900, expanded_italic_900 },
252 },
253 },
254
255 {
256 { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
257 {
258 { condensed_normal_100, condensed_normal_100 },
259 { condensed_normal_900, condensed_normal_900 },
260 { condensed_italic_100, condensed_normal_100 },
261 { condensed_italic_900, condensed_normal_900 },
262 { expanded_normal_100, expanded_normal_100 },
263 { expanded_normal_900, expanded_normal_900 },
264 { expanded_italic_100, expanded_normal_100 },
265 { expanded_italic_900, expanded_normal_900 },
266 },
267 },
268
269 {
270 { condensed_normal_100,expanded_normal_100 },
271 {
272 { condensed_normal_100, condensed_normal_100 },
273 { condensed_normal_900, condensed_normal_100 },
274 { condensed_italic_100, condensed_normal_100 },
275 { condensed_italic_900, condensed_normal_100 },
276 { expanded_normal_100, expanded_normal_100 },
277 { expanded_normal_900, expanded_normal_100 },
278 { expanded_italic_100, expanded_normal_100 },
279 { expanded_italic_900, expanded_normal_100 },
280 },
281 },
282
283 {
284 { condensed_normal_900,expanded_normal_900 },
285 {
286 { condensed_normal_100, condensed_normal_900 },
287 { condensed_normal_900, condensed_normal_900 },
288 { condensed_italic_100, condensed_normal_900 },
289 { condensed_italic_900, condensed_normal_900 },
290 { expanded_normal_100, expanded_normal_900 },
291 { expanded_normal_900, expanded_normal_900 },
292 { expanded_italic_100, expanded_normal_900 },
293 { expanded_italic_900, expanded_normal_900 },
294 },
295 },
296
297 {
298 { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
299 {
300 { condensed_normal_100, condensed_italic_100 },
301 { condensed_normal_900, condensed_italic_900 },
302 { condensed_italic_100, condensed_italic_100 },
303 { condensed_italic_900, condensed_italic_900 },
304 { expanded_normal_100, expanded_italic_100 },
305 { expanded_normal_900, expanded_italic_900 },
306 { expanded_italic_100, expanded_italic_100 },
307 { expanded_italic_900, expanded_italic_900 },
308 },
309 },
310
311 {
312 { condensed_italic_100,expanded_italic_100 },
313 {
314 { condensed_normal_100, condensed_italic_100 },
315 { condensed_normal_900, condensed_italic_100 },
316 { condensed_italic_100, condensed_italic_100 },
317 { condensed_italic_900, condensed_italic_100 },
318 { expanded_normal_100, expanded_italic_100 },
319 { expanded_normal_900, expanded_italic_100 },
320 { expanded_italic_100, expanded_italic_100 },
321 { expanded_italic_900, expanded_italic_100 },
322 },
323 },
324
325 {
326 { condensed_italic_900,expanded_italic_900 },
327 {
328 { condensed_normal_100, condensed_italic_900 },
329 { condensed_normal_900, condensed_italic_900 },
330 { condensed_italic_100, condensed_italic_900 },
331 { condensed_italic_900, condensed_italic_900 },
332 { expanded_normal_100, expanded_italic_900 },
333 { expanded_normal_900, expanded_italic_900 },
334 { expanded_italic_100, expanded_italic_900 },
335 { expanded_italic_900, expanded_italic_900 },
336 },
337 },
338
339 {
340 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
341 {
342 { condensed_normal_100, condensed_normal_100 },
343 { condensed_normal_900, condensed_normal_900 },
344 { condensed_italic_100, condensed_italic_100 },
345 { condensed_italic_900, condensed_italic_900 },
346 { expanded_normal_100, condensed_normal_100 },
347 { expanded_normal_900, condensed_normal_900 },
348 { expanded_italic_100, condensed_italic_100 },
349 { expanded_italic_900, condensed_italic_900 },
350 },
351 },
352
353 {
354 { condensed_normal_100,condensed_italic_100 },
355 {
356 { condensed_normal_100, condensed_normal_100 },
357 { condensed_normal_900, condensed_normal_100 },
358 { condensed_italic_100, condensed_italic_100 },
359 { condensed_italic_900, condensed_italic_100 },
360 { expanded_normal_100, condensed_normal_100 },
361 { expanded_normal_900, condensed_normal_100 },
362 { expanded_italic_100, condensed_italic_100 },
363 { expanded_italic_900, condensed_italic_100 },
364 },
365 },
366
367 {
368 { condensed_normal_900,condensed_italic_900 },
369 {
370 { condensed_normal_100, condensed_normal_900 },
371 { condensed_normal_900, condensed_normal_900 },
372 { condensed_italic_100, condensed_italic_900 },
373 { condensed_italic_900, condensed_italic_900 },
374 { expanded_normal_100, condensed_normal_900 },
375 { expanded_normal_900, condensed_normal_900 },
376 { expanded_italic_100, condensed_italic_900 },
377 { expanded_italic_900, condensed_italic_900 },
378 },
379 },
380
381 {
382 { condensed_normal_100,condensed_normal_900 },
383 {
384 { condensed_normal_100, condensed_normal_100 },
385 { condensed_normal_900, condensed_normal_900 },
386 { condensed_italic_100, condensed_normal_100 },
387 { condensed_italic_900, condensed_normal_900 },
388 { expanded_normal_100, condensed_normal_100 },
389 { expanded_normal_900, condensed_normal_900 },
390 { expanded_italic_100, condensed_normal_100 },
391 { expanded_italic_900, condensed_normal_900 },
392 },
393 },
394
395 {
396 { condensed_normal_100 },
397 {
398 { condensed_normal_100, condensed_normal_100 },
399 { condensed_normal_900, condensed_normal_100 },
400 { condensed_italic_100, condensed_normal_100 },
401 { condensed_italic_900, condensed_normal_100 },
402 { expanded_normal_100, condensed_normal_100 },
403 { expanded_normal_900, condensed_normal_100 },
404 { expanded_italic_100, condensed_normal_100 },
405 { expanded_italic_900, condensed_normal_100 },
406 },
407 },
408
409 {
410 { condensed_normal_900 },
411 {
412 { condensed_normal_100, condensed_normal_900 },
413 { condensed_normal_900, condensed_normal_900 },
414 { condensed_italic_100, condensed_normal_900 },
415 { condensed_italic_900, condensed_normal_900 },
416 { expanded_normal_100, condensed_normal_900 },
417 { expanded_normal_900, condensed_normal_900 },
418 { expanded_italic_100, condensed_normal_900 },
419 { expanded_italic_900, condensed_normal_900 },
420 },
421 },
422
423 {
424 { condensed_italic_100,condensed_italic_900 },
425 {
426 { condensed_normal_100, condensed_italic_100 },
427 { condensed_normal_900, condensed_italic_900 },
428 { condensed_italic_100, condensed_italic_100 },
429 { condensed_italic_900, condensed_italic_900 },
430 { expanded_normal_100, condensed_italic_100 },
431 { expanded_normal_900, condensed_italic_900 },
432 { expanded_italic_100, condensed_italic_100 },
433 { expanded_italic_900, condensed_italic_900 },
434 },
435 },
436
437 {
438 { condensed_italic_100 },
439 {
440 { condensed_normal_100, condensed_italic_100 },
441 { condensed_normal_900, condensed_italic_100 },
442 { condensed_italic_100, condensed_italic_100 },
443 { condensed_italic_900, condensed_italic_100 },
444 { expanded_normal_100, condensed_italic_100 },
445 { expanded_normal_900, condensed_italic_100 },
446 { expanded_italic_100, condensed_italic_100 },
447 { expanded_italic_900, condensed_italic_100 },
448 },
449 },
450
451 {
452 { condensed_italic_900 },
453 {
454 { condensed_normal_100, condensed_italic_900 },
455 { condensed_normal_900, condensed_italic_900 },
456 { condensed_italic_100, condensed_italic_900 },
457 { condensed_italic_900, condensed_italic_900 },
458 { expanded_normal_100, condensed_italic_900 },
459 { expanded_normal_900, condensed_italic_900 },
460 { expanded_italic_100, condensed_italic_900 },
461 { expanded_italic_900, condensed_italic_900 },
462 },
463 },
464
465 {
bungemanb4bb7d82016-04-27 10:21:04 -0700466 { expanded_normal_100,expanded_normal_900,
467 expanded_italic_100,expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800468 {
469 { condensed_normal_100, expanded_normal_100 },
470 { condensed_normal_900, expanded_normal_900 },
471 { condensed_italic_100, expanded_italic_100 },
472 { condensed_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700473 { condensed_obliqu_100, expanded_italic_100 },
474 { condensed_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800475 { expanded_normal_100, expanded_normal_100 },
476 { expanded_normal_900, expanded_normal_900 },
477 { expanded_italic_100, expanded_italic_100 },
478 { expanded_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700479 { expanded_obliqu_100, expanded_italic_100 },
480 { expanded_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800481 },
482 },
483
484 {
485 { expanded_normal_100,expanded_italic_100 },
486 {
487 { condensed_normal_100, expanded_normal_100 },
488 { condensed_normal_900, expanded_normal_100 },
489 { condensed_italic_100, expanded_italic_100 },
490 { condensed_italic_900, expanded_italic_100 },
491 { expanded_normal_100, expanded_normal_100 },
492 { expanded_normal_900, expanded_normal_100 },
493 { expanded_italic_100, expanded_italic_100 },
494 { expanded_italic_900, expanded_italic_100 },
495 },
496 },
497
498 {
499 { expanded_normal_900,expanded_italic_900 },
500 {
501 { condensed_normal_100, expanded_normal_900 },
502 { condensed_normal_900, expanded_normal_900 },
503 { condensed_italic_100, expanded_italic_900 },
504 { condensed_italic_900, expanded_italic_900 },
505 { expanded_normal_100, expanded_normal_900 },
506 { expanded_normal_900, expanded_normal_900 },
507 { expanded_italic_100, expanded_italic_900 },
508 { expanded_italic_900, expanded_italic_900 },
509 },
510 },
511
512 {
513 { expanded_normal_100,expanded_normal_900 },
514 {
515 { condensed_normal_100, expanded_normal_100 },
516 { condensed_normal_900, expanded_normal_900 },
517 { condensed_italic_100, expanded_normal_100 },
518 { condensed_italic_900, expanded_normal_900 },
519 { expanded_normal_100, expanded_normal_100 },
520 { expanded_normal_900, expanded_normal_900 },
521 { expanded_italic_100, expanded_normal_100 },
522 { expanded_italic_900, expanded_normal_900 },
523 },
524 },
525
526 {
527 { expanded_normal_100 },
528 {
529 { condensed_normal_100, expanded_normal_100 },
530 { condensed_normal_900, expanded_normal_100 },
531 { condensed_italic_100, expanded_normal_100 },
532 { condensed_italic_900, expanded_normal_100 },
533 { expanded_normal_100, expanded_normal_100 },
534 { expanded_normal_900, expanded_normal_100 },
535 { expanded_italic_100, expanded_normal_100 },
536 { expanded_italic_900, expanded_normal_100 },
537 },
538 },
539
540 {
541 { expanded_normal_900 },
542 {
543 { condensed_normal_100, expanded_normal_900 },
544 { condensed_normal_900, expanded_normal_900 },
545 { condensed_italic_100, expanded_normal_900 },
546 { condensed_italic_900, expanded_normal_900 },
547 { expanded_normal_100, expanded_normal_900 },
548 { expanded_normal_900, expanded_normal_900 },
549 { expanded_italic_100, expanded_normal_900 },
550 { expanded_italic_900, expanded_normal_900 },
551 },
552 },
553
554 {
555 { expanded_italic_100,expanded_italic_900 },
556 {
557 { condensed_normal_100, expanded_italic_100 },
558 { condensed_normal_900, expanded_italic_900 },
559 { condensed_italic_100, expanded_italic_100 },
560 { condensed_italic_900, expanded_italic_900 },
561 { expanded_normal_100, expanded_italic_100 },
562 { expanded_normal_900, expanded_italic_900 },
563 { expanded_italic_100, expanded_italic_100 },
564 { expanded_italic_900, expanded_italic_900 },
565 },
566 },
567
568 {
569 { expanded_italic_100 },
570 {
571 { condensed_normal_100, expanded_italic_100 },
572 { condensed_normal_900, expanded_italic_100 },
573 { condensed_italic_100, expanded_italic_100 },
574 { condensed_italic_900, expanded_italic_100 },
575 { expanded_normal_100, expanded_italic_100 },
576 { expanded_normal_900, expanded_italic_100 },
577 { expanded_italic_100, expanded_italic_100 },
578 { expanded_italic_900, expanded_italic_100 },
579 },
580 },
581
582 {
583 { expanded_italic_900 },
584 {
585 { condensed_normal_100, expanded_italic_900 },
586 { condensed_normal_900, expanded_italic_900 },
587 { condensed_italic_100, expanded_italic_900 },
588 { condensed_italic_900, expanded_italic_900 },
589 { expanded_normal_100, expanded_italic_900 },
590 { expanded_normal_900, expanded_italic_900 },
591 { expanded_italic_100, expanded_italic_900 },
592 { expanded_italic_900, expanded_italic_900 },
593 },
594 },
595
596 {
597 { normal_normal_100, normal_normal_900 },
598 {
599 { normal_normal_300, normal_normal_100 },
600 { normal_normal_400, normal_normal_100 },
601 { normal_normal_500, normal_normal_100 },
602 { normal_normal_600, normal_normal_900 },
603 },
604 },
605
606 {
607 { normal_normal_100, normal_normal_400, normal_normal_900 },
608 {
609 { normal_normal_300, normal_normal_100 },
610 { normal_normal_400, normal_normal_400 },
611 { normal_normal_500, normal_normal_400 },
612 { normal_normal_600, normal_normal_900 },
613 },
614 },
615
616 {
617 { normal_normal_100, normal_normal_500, normal_normal_900 },
618 {
619 { normal_normal_300, normal_normal_100 },
620 { normal_normal_400, normal_normal_500 },
621 { normal_normal_500, normal_normal_500 },
622 { normal_normal_600, normal_normal_900 },
623 },
624 },
625
626 {
627 { },
628 {
629 { normal_normal_300, invalidFontStyle },
630 { normal_normal_400, invalidFontStyle },
631 { normal_normal_500, invalidFontStyle },
632 { normal_normal_600, invalidFontStyle },
633 },
634 },
bungemanb4bb7d82016-04-27 10:21:04 -0700635 {
636 { expanded_normal_100,expanded_normal_900,
637 expanded_italic_100,expanded_italic_900,
638 expanded_obliqu_100,expanded_obliqu_900, },
639 {
640 { condensed_normal_100, expanded_normal_100 },
641 { condensed_normal_900, expanded_normal_900 },
642 { condensed_italic_100, expanded_italic_100 },
643 { condensed_italic_900, expanded_italic_900 },
644 { condensed_obliqu_100, expanded_obliqu_100 },
645 { condensed_obliqu_900, expanded_obliqu_900 },
646 { expanded_normal_100, expanded_normal_100 },
647 { expanded_normal_900, expanded_normal_900 },
648 { expanded_italic_100, expanded_italic_100 },
649 { expanded_italic_900, expanded_italic_900 },
650 { expanded_obliqu_100, expanded_obliqu_100 },
651 { expanded_obliqu_900, expanded_obliqu_900 },
652 },
653 },
654 {
655 { expanded_normal_100,expanded_normal_900,
656 expanded_obliqu_100,expanded_obliqu_900, },
657 {
658 { condensed_normal_100, expanded_normal_100 },
659 { condensed_normal_900, expanded_normal_900 },
660 { condensed_italic_100, expanded_obliqu_100 },
661 { condensed_italic_900, expanded_obliqu_900 },
662 { condensed_obliqu_100, expanded_obliqu_100 },
663 { condensed_obliqu_900, expanded_obliqu_900 },
664 { expanded_normal_100, expanded_normal_100 },
665 { expanded_normal_900, expanded_normal_900 },
666 { expanded_italic_100, expanded_obliqu_100 },
667 { expanded_italic_900, expanded_obliqu_900 },
668 { expanded_obliqu_100, expanded_obliqu_100 },
669 { expanded_obliqu_900, expanded_obliqu_900 },
670 },
671 },
672 {
673 { expanded_italic_100,expanded_italic_900,
674 expanded_obliqu_100,expanded_obliqu_900, },
675 {
676 { condensed_normal_100, expanded_obliqu_100 },
677 { condensed_normal_900, expanded_obliqu_900 },
678 { condensed_italic_100, expanded_italic_100 },
679 { condensed_italic_900, expanded_italic_900 },
680 { condensed_obliqu_100, expanded_obliqu_100 },
681 { condensed_obliqu_900, expanded_obliqu_900 },
682 { expanded_normal_100, expanded_obliqu_100 },
683 { expanded_normal_900, expanded_obliqu_900 },
684 { expanded_italic_100, expanded_italic_100 },
685 { expanded_italic_900, expanded_italic_900 },
686 { expanded_obliqu_100, expanded_obliqu_100 },
687 { expanded_obliqu_900, expanded_obliqu_900 },
688 },
689 },
bungeman147ea2f2015-11-12 09:50:08 -0800690 };
691
692 for (StyleSetTest& test : tests) {
Mike Klein6ad99092016-10-26 10:35:22 -0400693 for (const StyleSetTest::Case& testCase : test.cases) {
Hal Canary342b7ac2016-11-04 11:49:42 -0400694 sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
bungeman147ea2f2015-11-12 09:50:08 -0800695 if (typeface) {
696 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
697 } else {
698 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
699 }
700 }
701 }
702}
703
reed@google.com66c9f992013-04-11 19:04:34 +0000704DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
reed@google.com83165a52013-04-11 18:31:25 +0000705
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +0000706DEF_TEST(FontMgr, reporter) {
bungeman147ea2f2015-11-12 09:50:08 -0800707 test_matchStyleCSS3(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000708 test_fontiter(reporter, FLAGS_verboseFontMgr);
reed@google.comc1a81eb2013-09-19 18:06:03 +0000709 test_alias_names(reporter);
reed@google.com43c27582014-04-08 15:04:29 +0000710 test_font(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000711}