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