• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
8 #include "include/core/SkFont.h"
9 #include "include/core/SkFontMgr.h"
10 #include "include/core/SkPaint.h"
11 #include "include/core/SkStream.h"
12 #include "include/core/SkTypeface.h"
13 #include "src/core/SkAdvancedTypefaceMetrics.h"
14 #include "tests/Test.h"
15 #include "tools/flags/CommandLineFlags.h"
16 
17 #include <initializer_list>
18 #include <limits>
19 #include <vector>
20 
test_font(skiatest::Reporter * reporter)21 static void test_font(skiatest::Reporter* reporter) {
22     SkFont font(nullptr, 24);
23 
24     //REPORTER_ASSERT(reporter, SkTypeface::GetDefaultTypeface() == font.getTypeface());
25     REPORTER_ASSERT(reporter, 24 == font.getSize());
26     REPORTER_ASSERT(reporter, 1 == font.getScaleX());
27     REPORTER_ASSERT(reporter, 0 == font.getSkewX());
28 
29     uint16_t glyphs[5];
30     sk_bzero(glyphs, sizeof(glyphs));
31 
32     // Check that no glyphs are copied with insufficient storage.
33     int count = font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, 2);
34     REPORTER_ASSERT(reporter, 5 == count);
35     for (const auto glyph : glyphs) { REPORTER_ASSERT(reporter, glyph == 0); }
36 
37     SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs,
38                                      SK_ARRAY_COUNT(glyphs)) == count);
39 
40     for (int i = 0; i < count; ++i) {
41         REPORTER_ASSERT(reporter, 0 != glyphs[i]);
42     }
43     REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
44     REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
45 
46     const SkFont newFont(font.makeWithSize(36));
47     REPORTER_ASSERT(reporter, font.getTypefaceOrDefault() == newFont.getTypefaceOrDefault());
48     REPORTER_ASSERT(reporter, 36 == newFont.getSize());   // double check we haven't changed
49     REPORTER_ASSERT(reporter, 24 == font.getSize());   // double check we haven't changed
50 }
51 
52 /*
53  *  If the font backend is going to "alias" some font names to other fonts
54  *  (e.g. sans -> Arial) then we want to at least get the same typeface back
55  *  if we request the alias name multiple times.
56  */
test_alias_names(skiatest::Reporter * reporter)57 static void test_alias_names(skiatest::Reporter* reporter) {
58     const char* inNames[] = {
59         "sans", "sans-serif", "serif", "monospace", "times", "helvetica"
60     };
61 
62     for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) {
63         sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
64         if (nullptr == first.get()) {
65             continue;
66         }
67         for (int j = 0; j < 10; ++j) {
68             sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
69     #if 0
70             SkString name;
71             face->getFamilyName(&name);
72             printf("request %s, received %s, first id %x received %x\n",
73                    inNames[i], name.c_str(), first->uniqueID(), face->uniqueID());
74     #endif
75             REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID());
76         }
77     }
78 }
79 
test_fontiter(skiatest::Reporter * reporter,bool verbose)80 static void test_fontiter(skiatest::Reporter* reporter, bool verbose) {
81     sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
82     int count = fm->countFamilies();
83 
84     for (int i = 0; i < count; ++i) {
85         SkString fname;
86         fm->getFamilyName(i, &fname);
87 
88         sk_sp<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
89         sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
90         REPORTER_ASSERT(reporter, fnset->count() == set->count());
91 
92         if (verbose) {
93             SkDebugf("[%2d] %s\n", i, fname.c_str());
94         }
95 
96         for (int j = 0; j < set->count(); ++j) {
97             SkString sname;
98             SkFontStyle fs;
99             set->getStyle(j, &fs, &sname);
100 //            REPORTER_ASSERT(reporter, sname.size() > 0);
101 
102             sk_sp<SkTypeface> face(set->createTypeface(j));
103 //            REPORTER_ASSERT(reporter, face.get());
104 
105             if (verbose) {
106                 SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(),
107                          fs.weight(), fs.width(), fs.slant());
108             }
109         }
110     }
111 }
112 
test_match(skiatest::Reporter * reporter)113 static void test_match(skiatest::Reporter* reporter) {
114     sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
115     sk_sp<SkFontStyleSet> styleSet(fm->matchFamily(nullptr));
116     REPORTER_ASSERT(reporter, styleSet);
117 }
118 
test_matchStyleCSS3(skiatest::Reporter * reporter)119 static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
120     static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
121 
122     class TestTypeface : public SkTypeface {
123     public:
124         TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){}
125     protected:
126         std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
127         sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
128             return sk_ref_sp(this);
129         }
130         SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
131                                                const SkDescriptor*) const override {
132             return nullptr;
133         }
134         void onFilterRec(SkScalerContextRec*) const override { }
135         std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
136             return nullptr;
137         }
138         void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
139         void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override {
140             sk_bzero(glyphs, count * sizeof(glyphs[0]));
141         }
142         int onCountGlyphs() const override { return 0; }
143         void getPostScriptGlyphNames(SkString*) const override {}
144         void getGlyphToUnicodeMap(SkUnichar*) const override {}
145         int onGetUPEM() const override { return 0; }
146         class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
147         public:
148             bool next(SkTypeface::LocalizedString*) override { return false; }
149         };
150         void onGetFamilyName(SkString* familyName) const override {
151             familyName->reset();
152         }
153         SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
154             return new EmptyLocalizedStrings;
155         }
156         int onGetVariationDesignPosition(
157                 SkFontArguments::VariationPosition::Coordinate coordinates[],
158                 int coordinateCount) const override
159         {
160             return 0;
161         }
162         int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
163                                            int parameterCount) const override
164         {
165             return -1;
166         }
167         int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
168         size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
169             return 0;
170         }
171     };
172 
173     class TestFontStyleSet : public SkFontStyleSet {
174     public:
175         TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
176         int count() override { return static_cast<int>(fStyles.size()); }
177         void getStyle(int index, SkFontStyle* style, SkString*) override {
178             if (style) {
179                 *style = fStyles[index];
180             }
181         }
182         SkTypeface* createTypeface(int index) override {
183             if (index < 0 || this->count() <= index) {
184                 return new TestTypeface(invalidFontStyle);
185             }
186             return new TestTypeface(fStyles[index]);
187         }
188         SkTypeface* matchStyle(const SkFontStyle& pattern) override {
189             return this->matchStyleCSS3(pattern);
190         }
191     private:
192         std::vector<SkFontStyle> fStyles;
193     };
194 
195     SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight,  SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
196     SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
197     SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight,  SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
198     SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
199     SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight,  SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
200     SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
201     SkFontStyle  expanded_normal_100(SkFontStyle::kThin_Weight,  SkFontStyle::kExpanded_Width,  SkFontStyle::kUpright_Slant);
202     SkFontStyle  expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width,  SkFontStyle::kUpright_Slant);
203     SkFontStyle  expanded_italic_100(SkFontStyle::kThin_Weight,  SkFontStyle::kExpanded_Width,  SkFontStyle::kItalic_Slant);
204     SkFontStyle  expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width,  SkFontStyle::kItalic_Slant);
205     SkFontStyle  expanded_obliqu_100(SkFontStyle::kThin_Weight,  SkFontStyle::kExpanded_Width,  SkFontStyle::kOblique_Slant);
206     SkFontStyle  expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width,  SkFontStyle::kOblique_Slant);
207 
208     SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight,       SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
209     SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight,      SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
210     SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight,     SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
211     SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight,     SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
212     SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight,   SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
213     SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight,      SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
214 
215     struct StyleSetTest {
216         TestFontStyleSet styleSet;
217         struct Case {
218             SkFontStyle pattern;
219             SkFontStyle expectedResult;
220         };
221         std::vector<Case> cases;
222     } tests[] = {
223         {
224             { normal_normal_500, normal_normal_400 },
225             {
226                 { normal_normal_400, normal_normal_400 },
227                 { normal_normal_500, normal_normal_500 },
228             },
229         },
230 
231         {
232             { normal_normal_500, normal_normal_300 },
233             {
234                 { normal_normal_300, normal_normal_300 },
235                 { normal_normal_400, normal_normal_500 },
236                 { normal_normal_500, normal_normal_500 },
237             },
238         },
239 
240         {
241             { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
242                expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
243             {
244                 { condensed_normal_100, condensed_normal_100 },
245                 { condensed_normal_900, condensed_normal_900 },
246                 { condensed_italic_100, condensed_italic_100 },
247                 { condensed_italic_900, condensed_italic_900 },
248                 { expanded_normal_100, expanded_normal_100 },
249                 { expanded_normal_900, expanded_normal_900 },
250                 { expanded_italic_100, expanded_italic_100 },
251                 { expanded_italic_900, expanded_italic_900 },
252             },
253         },
254 
255         {
256             { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
257             {
258                 { condensed_normal_100, condensed_normal_100 },
259                 { condensed_normal_900, condensed_normal_100 },
260                 { condensed_italic_100, condensed_italic_100 },
261                 { condensed_italic_900, condensed_italic_100 },
262                 { expanded_normal_100, expanded_normal_100 },
263                 { expanded_normal_900, expanded_normal_100 },
264                 { expanded_italic_100, expanded_italic_100 },
265                 { expanded_italic_900, expanded_italic_100 },
266             },
267         },
268 
269         {
270             { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
271             {
272                 { condensed_normal_100, condensed_normal_900 },
273                 { condensed_normal_900, condensed_normal_900 },
274                 { condensed_italic_100, condensed_italic_900 },
275                 { condensed_italic_900, condensed_italic_900 },
276                 { expanded_normal_100, expanded_normal_900 },
277                 { expanded_normal_900, expanded_normal_900 },
278                 { expanded_italic_100, expanded_italic_900 },
279                 { expanded_italic_900, expanded_italic_900 },
280             },
281         },
282 
283         {
284             { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
285             {
286                 { condensed_normal_100, condensed_normal_100 },
287                 { condensed_normal_900, condensed_normal_900 },
288                 { condensed_italic_100, condensed_normal_100 },
289                 { condensed_italic_900, condensed_normal_900 },
290                 { expanded_normal_100, expanded_normal_100 },
291                 { expanded_normal_900, expanded_normal_900 },
292                 { expanded_italic_100, expanded_normal_100 },
293                 { expanded_italic_900, expanded_normal_900 },
294             },
295         },
296 
297         {
298             { condensed_normal_100,expanded_normal_100 },
299             {
300                 { condensed_normal_100, condensed_normal_100 },
301                 { condensed_normal_900, condensed_normal_100 },
302                 { condensed_italic_100, condensed_normal_100 },
303                 { condensed_italic_900, condensed_normal_100 },
304                 { expanded_normal_100, expanded_normal_100 },
305                 { expanded_normal_900, expanded_normal_100 },
306                 { expanded_italic_100, expanded_normal_100 },
307                 { expanded_italic_900, expanded_normal_100 },
308             },
309         },
310 
311         {
312             { condensed_normal_900,expanded_normal_900 },
313             {
314                 { condensed_normal_100, condensed_normal_900 },
315                 { condensed_normal_900, condensed_normal_900 },
316                 { condensed_italic_100, condensed_normal_900 },
317                 { condensed_italic_900, condensed_normal_900 },
318                 { expanded_normal_100, expanded_normal_900 },
319                 { expanded_normal_900, expanded_normal_900 },
320                 { expanded_italic_100, expanded_normal_900 },
321                 { expanded_italic_900, expanded_normal_900 },
322             },
323         },
324 
325         {
326             { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
327             {
328                 { condensed_normal_100, condensed_italic_100 },
329                 { condensed_normal_900, condensed_italic_900 },
330                 { condensed_italic_100, condensed_italic_100 },
331                 { condensed_italic_900, condensed_italic_900 },
332                 { expanded_normal_100, expanded_italic_100 },
333                 { expanded_normal_900, expanded_italic_900 },
334                 { expanded_italic_100, expanded_italic_100 },
335                 { expanded_italic_900, expanded_italic_900 },
336             },
337         },
338 
339         {
340             { condensed_italic_100,expanded_italic_100 },
341             {
342                 { condensed_normal_100, condensed_italic_100 },
343                 { condensed_normal_900, condensed_italic_100 },
344                 { condensed_italic_100, condensed_italic_100 },
345                 { condensed_italic_900, condensed_italic_100 },
346                 { expanded_normal_100, expanded_italic_100 },
347                 { expanded_normal_900, expanded_italic_100 },
348                 { expanded_italic_100, expanded_italic_100 },
349                 { expanded_italic_900, expanded_italic_100 },
350             },
351         },
352 
353         {
354             { condensed_italic_900,expanded_italic_900 },
355             {
356                 { condensed_normal_100, condensed_italic_900 },
357                 { condensed_normal_900, condensed_italic_900 },
358                 { condensed_italic_100, condensed_italic_900 },
359                 { condensed_italic_900, condensed_italic_900 },
360                 { expanded_normal_100, expanded_italic_900 },
361                 { expanded_normal_900, expanded_italic_900 },
362                 { expanded_italic_100, expanded_italic_900 },
363                 { expanded_italic_900, expanded_italic_900 },
364             },
365         },
366 
367         {
368             { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
369             {
370                 { condensed_normal_100, condensed_normal_100 },
371                 { condensed_normal_900, condensed_normal_900 },
372                 { condensed_italic_100, condensed_italic_100 },
373                 { condensed_italic_900, condensed_italic_900 },
374                 { expanded_normal_100, condensed_normal_100 },
375                 { expanded_normal_900, condensed_normal_900 },
376                 { expanded_italic_100, condensed_italic_100 },
377                 { expanded_italic_900, condensed_italic_900 },
378             },
379         },
380 
381         {
382             { condensed_normal_100,condensed_italic_100 },
383             {
384                 { condensed_normal_100, condensed_normal_100 },
385                 { condensed_normal_900, condensed_normal_100 },
386                 { condensed_italic_100, condensed_italic_100 },
387                 { condensed_italic_900, condensed_italic_100 },
388                 { expanded_normal_100, condensed_normal_100 },
389                 { expanded_normal_900, condensed_normal_100 },
390                 { expanded_italic_100, condensed_italic_100 },
391                 { expanded_italic_900, condensed_italic_100 },
392             },
393         },
394 
395         {
396             { condensed_normal_900,condensed_italic_900 },
397             {
398                 { condensed_normal_100, condensed_normal_900 },
399                 { condensed_normal_900, condensed_normal_900 },
400                 { condensed_italic_100, condensed_italic_900 },
401                 { condensed_italic_900, condensed_italic_900 },
402                 { expanded_normal_100, condensed_normal_900 },
403                 { expanded_normal_900, condensed_normal_900 },
404                 { expanded_italic_100, condensed_italic_900 },
405                 { expanded_italic_900, condensed_italic_900 },
406             },
407         },
408 
409         {
410             { condensed_normal_100,condensed_normal_900 },
411             {
412                 { condensed_normal_100, condensed_normal_100 },
413                 { condensed_normal_900, condensed_normal_900 },
414                 { condensed_italic_100, condensed_normal_100 },
415                 { condensed_italic_900, condensed_normal_900 },
416                 { expanded_normal_100, condensed_normal_100 },
417                 { expanded_normal_900, condensed_normal_900 },
418                 { expanded_italic_100, condensed_normal_100 },
419                 { expanded_italic_900, condensed_normal_900 },
420             },
421         },
422 
423         {
424             { condensed_normal_100 },
425             {
426                 { condensed_normal_100, condensed_normal_100 },
427                 { condensed_normal_900, condensed_normal_100 },
428                 { condensed_italic_100, condensed_normal_100 },
429                 { condensed_italic_900, condensed_normal_100 },
430                 { expanded_normal_100, condensed_normal_100 },
431                 { expanded_normal_900, condensed_normal_100 },
432                 { expanded_italic_100, condensed_normal_100 },
433                 { expanded_italic_900, condensed_normal_100 },
434             },
435         },
436 
437         {
438             { condensed_normal_900 },
439             {
440                 { condensed_normal_100, condensed_normal_900 },
441                 { condensed_normal_900, condensed_normal_900 },
442                 { condensed_italic_100, condensed_normal_900 },
443                 { condensed_italic_900, condensed_normal_900 },
444                 { expanded_normal_100, condensed_normal_900 },
445                 { expanded_normal_900, condensed_normal_900 },
446                 { expanded_italic_100, condensed_normal_900 },
447                 { expanded_italic_900, condensed_normal_900 },
448             },
449         },
450 
451         {
452             { condensed_italic_100,condensed_italic_900 },
453             {
454                 { condensed_normal_100, condensed_italic_100 },
455                 { condensed_normal_900, condensed_italic_900 },
456                 { condensed_italic_100, condensed_italic_100 },
457                 { condensed_italic_900, condensed_italic_900 },
458                 { expanded_normal_100, condensed_italic_100 },
459                 { expanded_normal_900, condensed_italic_900 },
460                 { expanded_italic_100, condensed_italic_100 },
461                 { expanded_italic_900, condensed_italic_900 },
462             },
463         },
464 
465         {
466             { condensed_italic_100 },
467             {
468                 { condensed_normal_100, condensed_italic_100 },
469                 { condensed_normal_900, condensed_italic_100 },
470                 { condensed_italic_100, condensed_italic_100 },
471                 { condensed_italic_900, condensed_italic_100 },
472                 { expanded_normal_100, condensed_italic_100 },
473                 { expanded_normal_900, condensed_italic_100 },
474                 { expanded_italic_100, condensed_italic_100 },
475                 { expanded_italic_900, condensed_italic_100 },
476             },
477         },
478 
479         {
480             { condensed_italic_900 },
481             {
482                 { condensed_normal_100, condensed_italic_900 },
483                 { condensed_normal_900, condensed_italic_900 },
484                 { condensed_italic_100, condensed_italic_900 },
485                 { condensed_italic_900, condensed_italic_900 },
486                 { expanded_normal_100, condensed_italic_900 },
487                 { expanded_normal_900, condensed_italic_900 },
488                 { expanded_italic_100, condensed_italic_900 },
489                 { expanded_italic_900, condensed_italic_900 },
490             },
491         },
492 
493         {
494             { expanded_normal_100,expanded_normal_900,
495               expanded_italic_100,expanded_italic_900 },
496             {
497                 { condensed_normal_100, expanded_normal_100 },
498                 { condensed_normal_900, expanded_normal_900 },
499                 { condensed_italic_100, expanded_italic_100 },
500                 { condensed_italic_900, expanded_italic_900 },
501                 { condensed_obliqu_100, expanded_italic_100 },
502                 { condensed_obliqu_900, expanded_italic_900 },
503                 { expanded_normal_100, expanded_normal_100 },
504                 { expanded_normal_900, expanded_normal_900 },
505                 { expanded_italic_100, expanded_italic_100 },
506                 { expanded_italic_900, expanded_italic_900 },
507                 { expanded_obliqu_100, expanded_italic_100 },
508                 { expanded_obliqu_900, expanded_italic_900 },
509             },
510         },
511 
512         {
513             { expanded_normal_100,expanded_italic_100 },
514             {
515                 { condensed_normal_100, expanded_normal_100 },
516                 { condensed_normal_900, expanded_normal_100 },
517                 { condensed_italic_100, expanded_italic_100 },
518                 { condensed_italic_900, expanded_italic_100 },
519                 { expanded_normal_100, expanded_normal_100 },
520                 { expanded_normal_900, expanded_normal_100 },
521                 { expanded_italic_100, expanded_italic_100 },
522                 { expanded_italic_900, expanded_italic_100 },
523             },
524         },
525 
526         {
527             { expanded_normal_900,expanded_italic_900 },
528             {
529                 { condensed_normal_100, expanded_normal_900 },
530                 { condensed_normal_900, expanded_normal_900 },
531                 { condensed_italic_100, expanded_italic_900 },
532                 { condensed_italic_900, expanded_italic_900 },
533                 { expanded_normal_100, expanded_normal_900 },
534                 { expanded_normal_900, expanded_normal_900 },
535                 { expanded_italic_100, expanded_italic_900 },
536                 { expanded_italic_900, expanded_italic_900 },
537             },
538         },
539 
540         {
541             { expanded_normal_100,expanded_normal_900 },
542             {
543                 { condensed_normal_100, expanded_normal_100 },
544                 { condensed_normal_900, expanded_normal_900 },
545                 { condensed_italic_100, expanded_normal_100 },
546                 { condensed_italic_900, expanded_normal_900 },
547                 { expanded_normal_100, expanded_normal_100 },
548                 { expanded_normal_900, expanded_normal_900 },
549                 { expanded_italic_100, expanded_normal_100 },
550                 { expanded_italic_900, expanded_normal_900 },
551             },
552         },
553 
554         {
555             { expanded_normal_100 },
556             {
557                 { condensed_normal_100, expanded_normal_100 },
558                 { condensed_normal_900, expanded_normal_100 },
559                 { condensed_italic_100, expanded_normal_100 },
560                 { condensed_italic_900, expanded_normal_100 },
561                 { expanded_normal_100, expanded_normal_100 },
562                 { expanded_normal_900, expanded_normal_100 },
563                 { expanded_italic_100, expanded_normal_100 },
564                 { expanded_italic_900, expanded_normal_100 },
565             },
566         },
567 
568         {
569             { expanded_normal_900 },
570             {
571                 { condensed_normal_100, expanded_normal_900 },
572                 { condensed_normal_900, expanded_normal_900 },
573                 { condensed_italic_100, expanded_normal_900 },
574                 { condensed_italic_900, expanded_normal_900 },
575                 { expanded_normal_100, expanded_normal_900 },
576                 { expanded_normal_900, expanded_normal_900 },
577                 { expanded_italic_100, expanded_normal_900 },
578                 { expanded_italic_900, expanded_normal_900 },
579             },
580         },
581 
582         {
583             { expanded_italic_100,expanded_italic_900 },
584             {
585                 { condensed_normal_100, expanded_italic_100 },
586                 { condensed_normal_900, expanded_italic_900 },
587                 { condensed_italic_100, expanded_italic_100 },
588                 { condensed_italic_900, expanded_italic_900 },
589                 { expanded_normal_100, expanded_italic_100 },
590                 { expanded_normal_900, expanded_italic_900 },
591                 { expanded_italic_100, expanded_italic_100 },
592                 { expanded_italic_900, expanded_italic_900 },
593             },
594         },
595 
596         {
597             { expanded_italic_100 },
598             {
599                 { condensed_normal_100, expanded_italic_100 },
600                 { condensed_normal_900, expanded_italic_100 },
601                 { condensed_italic_100, expanded_italic_100 },
602                 { condensed_italic_900, expanded_italic_100 },
603                 { expanded_normal_100, expanded_italic_100 },
604                 { expanded_normal_900, expanded_italic_100 },
605                 { expanded_italic_100, expanded_italic_100 },
606                 { expanded_italic_900, expanded_italic_100 },
607             },
608         },
609 
610         {
611             { expanded_italic_900 },
612             {
613                 { condensed_normal_100, expanded_italic_900 },
614                 { condensed_normal_900, expanded_italic_900 },
615                 { condensed_italic_100, expanded_italic_900 },
616                 { condensed_italic_900, expanded_italic_900 },
617                 { expanded_normal_100, expanded_italic_900 },
618                 { expanded_normal_900, expanded_italic_900 },
619                 { expanded_italic_100, expanded_italic_900 },
620                 { expanded_italic_900, expanded_italic_900 },
621             },
622         },
623 
624         {
625             { normal_normal_100, normal_normal_900 },
626             {
627                 { normal_normal_300, normal_normal_100 },
628                 { normal_normal_400, normal_normal_100 },
629                 { normal_normal_500, normal_normal_100 },
630                 { normal_normal_600, normal_normal_900 },
631             },
632         },
633 
634         {
635             { normal_normal_100, normal_normal_400, normal_normal_900 },
636             {
637                 { normal_normal_300, normal_normal_100 },
638                 { normal_normal_400, normal_normal_400 },
639                 { normal_normal_500, normal_normal_400 },
640                 { normal_normal_600, normal_normal_900 },
641             },
642         },
643 
644         {
645             { normal_normal_100, normal_normal_500, normal_normal_900 },
646             {
647                 { normal_normal_300, normal_normal_100 },
648                 { normal_normal_400, normal_normal_500 },
649                 { normal_normal_500, normal_normal_500 },
650                 { normal_normal_600, normal_normal_900 },
651             },
652         },
653 
654         {
655             { },
656             {
657                 { normal_normal_300, invalidFontStyle },
658                 { normal_normal_400, invalidFontStyle },
659                 { normal_normal_500, invalidFontStyle },
660                 { normal_normal_600, invalidFontStyle },
661             },
662         },
663         {
664             { expanded_normal_100,expanded_normal_900,
665               expanded_italic_100,expanded_italic_900,
666               expanded_obliqu_100,expanded_obliqu_900, },
667             {
668                 { condensed_normal_100, expanded_normal_100 },
669                 { condensed_normal_900, expanded_normal_900 },
670                 { condensed_italic_100, expanded_italic_100 },
671                 { condensed_italic_900, expanded_italic_900 },
672                 { condensed_obliqu_100, expanded_obliqu_100 },
673                 { condensed_obliqu_900, expanded_obliqu_900 },
674                 { expanded_normal_100, expanded_normal_100 },
675                 { expanded_normal_900, expanded_normal_900 },
676                 { expanded_italic_100, expanded_italic_100 },
677                 { expanded_italic_900, expanded_italic_900 },
678                 { expanded_obliqu_100, expanded_obliqu_100 },
679                 { expanded_obliqu_900, expanded_obliqu_900 },
680             },
681         },
682         {
683             { expanded_normal_100,expanded_normal_900,
684               expanded_obliqu_100,expanded_obliqu_900, },
685             {
686                 { condensed_normal_100, expanded_normal_100 },
687                 { condensed_normal_900, expanded_normal_900 },
688                 { condensed_italic_100, expanded_obliqu_100 },
689                 { condensed_italic_900, expanded_obliqu_900 },
690                 { condensed_obliqu_100, expanded_obliqu_100 },
691                 { condensed_obliqu_900, expanded_obliqu_900 },
692                 { expanded_normal_100, expanded_normal_100 },
693                 { expanded_normal_900, expanded_normal_900 },
694                 { expanded_italic_100, expanded_obliqu_100 },
695                 { expanded_italic_900, expanded_obliqu_900 },
696                 { expanded_obliqu_100, expanded_obliqu_100 },
697                 { expanded_obliqu_900, expanded_obliqu_900 },
698             },
699         },
700         {
701             { expanded_italic_100,expanded_italic_900,
702               expanded_obliqu_100,expanded_obliqu_900, },
703             {
704                 { condensed_normal_100, expanded_obliqu_100 },
705                 { condensed_normal_900, expanded_obliqu_900 },
706                 { condensed_italic_100, expanded_italic_100 },
707                 { condensed_italic_900, expanded_italic_900 },
708                 { condensed_obliqu_100, expanded_obliqu_100 },
709                 { condensed_obliqu_900, expanded_obliqu_900 },
710                 { expanded_normal_100, expanded_obliqu_100 },
711                 { expanded_normal_900, expanded_obliqu_900 },
712                 { expanded_italic_100, expanded_italic_100 },
713                 { expanded_italic_900, expanded_italic_900 },
714                 { expanded_obliqu_100, expanded_obliqu_100 },
715                 { expanded_obliqu_900, expanded_obliqu_900 },
716             },
717         },
718     };
719 
720     for (StyleSetTest& test : tests) {
721         for (const StyleSetTest::Case& testCase : test.cases) {
722             sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
723             if (typeface) {
724                 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
725             } else {
726                 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
727             }
728         }
729     }
730 }
731 
732 DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
733 
DEF_TEST(FontMgr,reporter)734 DEF_TEST(FontMgr, reporter) {
735     test_match(reporter);
736     test_matchStyleCSS3(reporter);
737     test_fontiter(reporter, FLAGS_verboseFontMgr);
738     test_alias_names(reporter);
739     test_font(reporter);
740 }
741