Flutter Engine
The Flutter Engine
FontMgrTest.cpp
Go to the documentation of this file.
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
21#include "src/core/SkAdvancedTypefaceMetrics.h" // IWYU pragma: keep
22#include "src/core/SkFontPriv.h"
24#include "tests/Test.h"
27
28#include <cstddef>
29#include <cstdint>
30#include <initializer_list>
31#include <memory>
32#include <vector>
33
34class SkDescriptor;
36
37DECLARE_bool(verboseFontMgr)
38
39DEF_TEST(FontMgr_Font, reporter) {
41
42 REPORTER_ASSERT(reporter, 24 == font.getSize());
43 REPORTER_ASSERT(reporter, 1 == font.getScaleX());
44 REPORTER_ASSERT(reporter, 0 == font.getSkewX());
45
46 uint16_t glyphs[5];
48
49 // Check that no glyphs are copied with insufficient storage.
50 int count = font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, 2);
52 for (const auto glyph : glyphs) { REPORTER_ASSERT(reporter, glyph == 0); }
53
56
57 for (int i = 0; i < count; ++i) {
59 }
60 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
61 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
62
63 const SkFont newFont(font.makeWithSize(36));
65 REPORTER_ASSERT(reporter, 36 == newFont.getSize()); // double check we haven't changed
66 REPORTER_ASSERT(reporter, 24 == font.getSize()); // double check we haven't changed
67}
68
69/*
70 * If the font backend is going to "alias" some font names to other fonts
71 * (e.g. sans -> Arial) then we want to at least get the same typeface back
72 * if we request the alias name multiple times.
73 */
74DEF_TEST(FontMgr_AliasNames, reporter) {
75 const char* inNames[] = {
76 "sans", "sans-serif", "serif", "monospace", "times", "helvetica"
77 };
78
79 for (size_t i = 0; i < std::size(inNames); ++i) {
81 if (nullptr == first.get()) {
82 continue;
83 }
84 SkString firstName;
85 first->getFamilyName(&firstName);
86 for (int j = 0; j < 10; ++j) {
88
90 face->getFamilyName(&name);
91 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID(),
92 "Request \"%s\" First Name: \"%s\" Id: %x Received Name \"%s\" Id %x",
93 inNames[i], firstName.c_str(), first->uniqueID(), name.c_str(), face->uniqueID());
94 }
95 }
96}
97
98DEF_TEST(FontMgr_Iter, reporter) {
100 int count = fm->countFamilies();
101
102 for (int i = 0; i < count; ++i) {
103 SkString fname;
104 fm->getFamilyName(i, &fname);
105
106 sk_sp<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
108 REPORTER_ASSERT(reporter, fnset->count() == set->count());
109
110 if (FLAGS_verboseFontMgr) {
111 SkDebugf("[%2d] %s\n", i, fname.c_str());
112 }
113
114 for (int j = 0; j < set->count(); ++j) {
115 SkString sname;
116 SkFontStyle fs;
117 set->getStyle(j, &fs, &sname);
118
119 if (FLAGS_verboseFontMgr) {
120 SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(),
121 fs.weight(), fs.width(), fs.slant());
122 }
123
124 sk_sp<SkTypeface> face1(set->createTypeface(j));
125 if (!face1) {
126 REPORTER_ASSERT(reporter, face1.get());
127 continue;
128 }
129 SkString name1;
130 face1->getFamilyName(&name1);
131 SkFontStyle s1 = face1->fontStyle();
132
133 // Note that fs != s1 is fine, though probably rare.
134
135 sk_sp<SkTypeface> face2(fm->matchFamilyStyle(name1.c_str(), s1));
136 if (!face2) {
137 REPORTER_ASSERT(reporter, face2.get());
138 continue;
139 }
140 SkString name2;
141 face2->getFamilyName(&name2);
142
143 REPORTER_ASSERT(reporter, name1 == name2, "%s == %s", name1.c_str(), name2.c_str());
144
145 // TODO: This should work, but Mac matches the wrong font sometimes.
146 if ((false)) {
147 SkFontStyle s2 = face2->fontStyle();
148 REPORTER_ASSERT(reporter, s1 == s2, "%s [%3d %d %d] != %s [%3d %d %d]",
149 name1.c_str(), s1.weight(), s1.width(), s1.slant(),
150 name2.c_str(), s2.weight(), s2.width(), s2.slant());
151 }
152 }
153 }
154}
155
156DEF_TEST(FontMgr_Match, reporter) {
158 sk_sp<SkFontStyleSet> styleSet(fm->matchFamily(nullptr));
159 REPORTER_ASSERT(reporter, styleSet);
160}
161
162DEF_TEST(FontMgr_MatchFamilyStyle, reporter) {
164
165 sk_sp<SkFontStyleSet> styleSet(fm->matchFamily("Non Existing Family Name"));
166 REPORTER_ASSERT(reporter, styleSet);
167 REPORTER_ASSERT(reporter, styleSet->count() == 0);
168
169 using FS = SkFontStyle;
170 sk_sp<SkTypeface> typeface(fm->matchFamilyStyle("Non Existing Family Name", FS::Normal()));
171 REPORTER_ASSERT(reporter, !typeface);
172
173 // TODO: enable after determining if a default font should be required.
174 if ((false)) {
175 sk_sp<SkTypeface> def(fm->matchFamilyStyle(nullptr, FS::Normal()));
177 }
178}
179
180DEF_TEST(FontMgr_MatchStyleCSS3, reporter) {
181 static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
182
183 class TestTypeface : public SkTypeface {
184 public:
186 protected:
187 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
188 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
189 return sk_ref_sp(this);
190 }
191 std::unique_ptr<SkScalerContext> onCreateScalerContext(
192 const SkScalerContextEffects& effects, const SkDescriptor* desc) const override
193 {
195 sk_ref_sp(const_cast<TestTypeface*>(this)), effects, desc);
196 }
197 void onFilterRec(SkScalerContextRec*) const override { }
198 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
199 return nullptr;
200 }
201 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
202 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override {
203 sk_bzero(glyphs, count * sizeof(glyphs[0]));
204 }
205 int onCountGlyphs() const override { return 0; }
206 void getPostScriptGlyphNames(SkString*) const override {}
207 void getGlyphToUnicodeMap(SkUnichar*) const override {}
208 int onGetUPEM() const override { return 0; }
209 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
210 public:
211 bool next(SkTypeface::LocalizedString*) override { return false; }
212 };
213 void onGetFamilyName(SkString* familyName) const override {
214 familyName->reset();
215 }
216 bool onGetPostScriptName(SkString*) const override { return false; }
218 return new EmptyLocalizedStrings;
219 }
220 bool onGlyphMaskNeedsCurrentColor() const override { return false; }
223 int coordinateCount) const override
224 {
225 return 0;
226 }
228 int parameterCount) const override
229 {
230 return -1;
231 }
232 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
233 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
234 return 0;
235 }
236 };
237
238 class TestFontStyleSet : public SkFontStyleSet {
239 public:
240 TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
241 int count() override { return static_cast<int>(fStyles.size()); }
242 void getStyle(int index, SkFontStyle* style, SkString*) override {
243 if (style) {
244 *style = fStyles[index];
245 }
246 }
247 sk_sp<SkTypeface> createTypeface(int index) override {
248 if (index < 0 || this->count() <= index) {
249 return sk_sp<SkTypeface>(new TestTypeface(invalidFontStyle));
250 }
251 return sk_sp<SkTypeface>(new TestTypeface(fStyles[index]));
252 }
253 sk_sp<SkTypeface> matchStyle(const SkFontStyle& pattern) override {
254 return this->matchStyleCSS3(pattern);
255 }
256 private:
257 std::vector<SkFontStyle> fStyles;
258 };
259
272
279
280 struct StyleSetTest {
281 TestFontStyleSet styleSet;
282 struct Case {
283 SkFontStyle pattern;
284 SkFontStyle expectedResult;
285 };
286 std::vector<Case> cases;
287 } tests[] = {
288 {
289 { normal_normal_500, normal_normal_400 },
290 {
291 { normal_normal_400, normal_normal_400 },
292 { normal_normal_500, normal_normal_500 },
293 },
294 },
295
296 {
297 { normal_normal_500, normal_normal_300 },
298 {
299 { normal_normal_300, normal_normal_300 },
300 { normal_normal_400, normal_normal_500 },
301 { normal_normal_500, normal_normal_500 },
302 },
303 },
304
305 {
306 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
307 expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
308 {
309 { condensed_normal_100, condensed_normal_100 },
310 { condensed_normal_900, condensed_normal_900 },
311 { condensed_italic_100, condensed_italic_100 },
312 { condensed_italic_900, condensed_italic_900 },
313 { expanded_normal_100, expanded_normal_100 },
314 { expanded_normal_900, expanded_normal_900 },
315 { expanded_italic_100, expanded_italic_100 },
316 { expanded_italic_900, expanded_italic_900 },
317 },
318 },
319
320 {
321 { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
322 {
323 { condensed_normal_100, condensed_normal_100 },
324 { condensed_normal_900, condensed_normal_100 },
325 { condensed_italic_100, condensed_italic_100 },
326 { condensed_italic_900, condensed_italic_100 },
327 { expanded_normal_100, expanded_normal_100 },
328 { expanded_normal_900, expanded_normal_100 },
329 { expanded_italic_100, expanded_italic_100 },
330 { expanded_italic_900, expanded_italic_100 },
331 },
332 },
333
334 {
335 { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
336 {
337 { condensed_normal_100, condensed_normal_900 },
338 { condensed_normal_900, condensed_normal_900 },
339 { condensed_italic_100, condensed_italic_900 },
340 { condensed_italic_900, condensed_italic_900 },
341 { expanded_normal_100, expanded_normal_900 },
342 { expanded_normal_900, expanded_normal_900 },
343 { expanded_italic_100, expanded_italic_900 },
344 { expanded_italic_900, expanded_italic_900 },
345 },
346 },
347
348 {
349 { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
350 {
351 { condensed_normal_100, condensed_normal_100 },
352 { condensed_normal_900, condensed_normal_900 },
353 { condensed_italic_100, condensed_normal_100 },
354 { condensed_italic_900, condensed_normal_900 },
355 { expanded_normal_100, expanded_normal_100 },
356 { expanded_normal_900, expanded_normal_900 },
357 { expanded_italic_100, expanded_normal_100 },
358 { expanded_italic_900, expanded_normal_900 },
359 },
360 },
361
362 {
363 { condensed_normal_100,expanded_normal_100 },
364 {
365 { condensed_normal_100, condensed_normal_100 },
366 { condensed_normal_900, condensed_normal_100 },
367 { condensed_italic_100, condensed_normal_100 },
368 { condensed_italic_900, condensed_normal_100 },
369 { expanded_normal_100, expanded_normal_100 },
370 { expanded_normal_900, expanded_normal_100 },
371 { expanded_italic_100, expanded_normal_100 },
372 { expanded_italic_900, expanded_normal_100 },
373 },
374 },
375
376 {
377 { condensed_normal_900,expanded_normal_900 },
378 {
379 { condensed_normal_100, condensed_normal_900 },
380 { condensed_normal_900, condensed_normal_900 },
381 { condensed_italic_100, condensed_normal_900 },
382 { condensed_italic_900, condensed_normal_900 },
383 { expanded_normal_100, expanded_normal_900 },
384 { expanded_normal_900, expanded_normal_900 },
385 { expanded_italic_100, expanded_normal_900 },
386 { expanded_italic_900, expanded_normal_900 },
387 },
388 },
389
390 {
391 { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
392 {
393 { condensed_normal_100, condensed_italic_100 },
394 { condensed_normal_900, condensed_italic_900 },
395 { condensed_italic_100, condensed_italic_100 },
396 { condensed_italic_900, condensed_italic_900 },
397 { expanded_normal_100, expanded_italic_100 },
398 { expanded_normal_900, expanded_italic_900 },
399 { expanded_italic_100, expanded_italic_100 },
400 { expanded_italic_900, expanded_italic_900 },
401 },
402 },
403
404 {
405 { condensed_italic_100,expanded_italic_100 },
406 {
407 { condensed_normal_100, condensed_italic_100 },
408 { condensed_normal_900, condensed_italic_100 },
409 { condensed_italic_100, condensed_italic_100 },
410 { condensed_italic_900, condensed_italic_100 },
411 { expanded_normal_100, expanded_italic_100 },
412 { expanded_normal_900, expanded_italic_100 },
413 { expanded_italic_100, expanded_italic_100 },
414 { expanded_italic_900, expanded_italic_100 },
415 },
416 },
417
418 {
419 { condensed_italic_900,expanded_italic_900 },
420 {
421 { condensed_normal_100, condensed_italic_900 },
422 { condensed_normal_900, condensed_italic_900 },
423 { condensed_italic_100, condensed_italic_900 },
424 { condensed_italic_900, condensed_italic_900 },
425 { expanded_normal_100, expanded_italic_900 },
426 { expanded_normal_900, expanded_italic_900 },
427 { expanded_italic_100, expanded_italic_900 },
428 { expanded_italic_900, expanded_italic_900 },
429 },
430 },
431
432 {
433 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
434 {
435 { condensed_normal_100, condensed_normal_100 },
436 { condensed_normal_900, condensed_normal_900 },
437 { condensed_italic_100, condensed_italic_100 },
438 { condensed_italic_900, condensed_italic_900 },
439 { expanded_normal_100, condensed_normal_100 },
440 { expanded_normal_900, condensed_normal_900 },
441 { expanded_italic_100, condensed_italic_100 },
442 { expanded_italic_900, condensed_italic_900 },
443 },
444 },
445
446 {
447 { condensed_normal_100,condensed_italic_100 },
448 {
449 { condensed_normal_100, condensed_normal_100 },
450 { condensed_normal_900, condensed_normal_100 },
451 { condensed_italic_100, condensed_italic_100 },
452 { condensed_italic_900, condensed_italic_100 },
453 { expanded_normal_100, condensed_normal_100 },
454 { expanded_normal_900, condensed_normal_100 },
455 { expanded_italic_100, condensed_italic_100 },
456 { expanded_italic_900, condensed_italic_100 },
457 },
458 },
459
460 {
461 { condensed_normal_900,condensed_italic_900 },
462 {
463 { condensed_normal_100, condensed_normal_900 },
464 { condensed_normal_900, condensed_normal_900 },
465 { condensed_italic_100, condensed_italic_900 },
466 { condensed_italic_900, condensed_italic_900 },
467 { expanded_normal_100, condensed_normal_900 },
468 { expanded_normal_900, condensed_normal_900 },
469 { expanded_italic_100, condensed_italic_900 },
470 { expanded_italic_900, condensed_italic_900 },
471 },
472 },
473
474 {
475 { condensed_normal_100,condensed_normal_900 },
476 {
477 { condensed_normal_100, condensed_normal_100 },
478 { condensed_normal_900, condensed_normal_900 },
479 { condensed_italic_100, condensed_normal_100 },
480 { condensed_italic_900, condensed_normal_900 },
481 { expanded_normal_100, condensed_normal_100 },
482 { expanded_normal_900, condensed_normal_900 },
483 { expanded_italic_100, condensed_normal_100 },
484 { expanded_italic_900, condensed_normal_900 },
485 },
486 },
487
488 {
489 { condensed_normal_100 },
490 {
491 { condensed_normal_100, condensed_normal_100 },
492 { condensed_normal_900, condensed_normal_100 },
493 { condensed_italic_100, condensed_normal_100 },
494 { condensed_italic_900, condensed_normal_100 },
495 { expanded_normal_100, condensed_normal_100 },
496 { expanded_normal_900, condensed_normal_100 },
497 { expanded_italic_100, condensed_normal_100 },
498 { expanded_italic_900, condensed_normal_100 },
499 },
500 },
501
502 {
503 { condensed_normal_900 },
504 {
505 { condensed_normal_100, condensed_normal_900 },
506 { condensed_normal_900, condensed_normal_900 },
507 { condensed_italic_100, condensed_normal_900 },
508 { condensed_italic_900, condensed_normal_900 },
509 { expanded_normal_100, condensed_normal_900 },
510 { expanded_normal_900, condensed_normal_900 },
511 { expanded_italic_100, condensed_normal_900 },
512 { expanded_italic_900, condensed_normal_900 },
513 },
514 },
515
516 {
517 { condensed_italic_100,condensed_italic_900 },
518 {
519 { condensed_normal_100, condensed_italic_100 },
520 { condensed_normal_900, condensed_italic_900 },
521 { condensed_italic_100, condensed_italic_100 },
522 { condensed_italic_900, condensed_italic_900 },
523 { expanded_normal_100, condensed_italic_100 },
524 { expanded_normal_900, condensed_italic_900 },
525 { expanded_italic_100, condensed_italic_100 },
526 { expanded_italic_900, condensed_italic_900 },
527 },
528 },
529
530 {
531 { condensed_italic_100 },
532 {
533 { condensed_normal_100, condensed_italic_100 },
534 { condensed_normal_900, condensed_italic_100 },
535 { condensed_italic_100, condensed_italic_100 },
536 { condensed_italic_900, condensed_italic_100 },
537 { expanded_normal_100, condensed_italic_100 },
538 { expanded_normal_900, condensed_italic_100 },
539 { expanded_italic_100, condensed_italic_100 },
540 { expanded_italic_900, condensed_italic_100 },
541 },
542 },
543
544 {
545 { condensed_italic_900 },
546 {
547 { condensed_normal_100, condensed_italic_900 },
548 { condensed_normal_900, condensed_italic_900 },
549 { condensed_italic_100, condensed_italic_900 },
550 { condensed_italic_900, condensed_italic_900 },
551 { expanded_normal_100, condensed_italic_900 },
552 { expanded_normal_900, condensed_italic_900 },
553 { expanded_italic_100, condensed_italic_900 },
554 { expanded_italic_900, condensed_italic_900 },
555 },
556 },
557
558 {
559 { expanded_normal_100,expanded_normal_900,
560 expanded_italic_100,expanded_italic_900 },
561 {
562 { condensed_normal_100, expanded_normal_100 },
563 { condensed_normal_900, expanded_normal_900 },
564 { condensed_italic_100, expanded_italic_100 },
565 { condensed_italic_900, expanded_italic_900 },
566 { condensed_obliqu_100, expanded_italic_100 },
567 { condensed_obliqu_900, expanded_italic_900 },
568 { expanded_normal_100, expanded_normal_100 },
569 { expanded_normal_900, expanded_normal_900 },
570 { expanded_italic_100, expanded_italic_100 },
571 { expanded_italic_900, expanded_italic_900 },
572 { expanded_obliqu_100, expanded_italic_100 },
573 { expanded_obliqu_900, expanded_italic_900 },
574 },
575 },
576
577 {
578 { expanded_normal_100,expanded_italic_100 },
579 {
580 { condensed_normal_100, expanded_normal_100 },
581 { condensed_normal_900, expanded_normal_100 },
582 { condensed_italic_100, expanded_italic_100 },
583 { condensed_italic_900, expanded_italic_100 },
584 { expanded_normal_100, expanded_normal_100 },
585 { expanded_normal_900, expanded_normal_100 },
586 { expanded_italic_100, expanded_italic_100 },
587 { expanded_italic_900, expanded_italic_100 },
588 },
589 },
590
591 {
592 { expanded_normal_900,expanded_italic_900 },
593 {
594 { condensed_normal_100, expanded_normal_900 },
595 { condensed_normal_900, expanded_normal_900 },
596 { condensed_italic_100, expanded_italic_900 },
597 { condensed_italic_900, expanded_italic_900 },
598 { expanded_normal_100, expanded_normal_900 },
599 { expanded_normal_900, expanded_normal_900 },
600 { expanded_italic_100, expanded_italic_900 },
601 { expanded_italic_900, expanded_italic_900 },
602 },
603 },
604
605 {
606 { expanded_normal_100,expanded_normal_900 },
607 {
608 { condensed_normal_100, expanded_normal_100 },
609 { condensed_normal_900, expanded_normal_900 },
610 { condensed_italic_100, expanded_normal_100 },
611 { condensed_italic_900, expanded_normal_900 },
612 { expanded_normal_100, expanded_normal_100 },
613 { expanded_normal_900, expanded_normal_900 },
614 { expanded_italic_100, expanded_normal_100 },
615 { expanded_italic_900, expanded_normal_900 },
616 },
617 },
618
619 {
620 { expanded_normal_100 },
621 {
622 { condensed_normal_100, expanded_normal_100 },
623 { condensed_normal_900, expanded_normal_100 },
624 { condensed_italic_100, expanded_normal_100 },
625 { condensed_italic_900, expanded_normal_100 },
626 { expanded_normal_100, expanded_normal_100 },
627 { expanded_normal_900, expanded_normal_100 },
628 { expanded_italic_100, expanded_normal_100 },
629 { expanded_italic_900, expanded_normal_100 },
630 },
631 },
632
633 {
634 { expanded_normal_900 },
635 {
636 { condensed_normal_100, expanded_normal_900 },
637 { condensed_normal_900, expanded_normal_900 },
638 { condensed_italic_100, expanded_normal_900 },
639 { condensed_italic_900, expanded_normal_900 },
640 { expanded_normal_100, expanded_normal_900 },
641 { expanded_normal_900, expanded_normal_900 },
642 { expanded_italic_100, expanded_normal_900 },
643 { expanded_italic_900, expanded_normal_900 },
644 },
645 },
646
647 {
648 { expanded_italic_100,expanded_italic_900 },
649 {
650 { condensed_normal_100, expanded_italic_100 },
651 { condensed_normal_900, expanded_italic_900 },
652 { condensed_italic_100, expanded_italic_100 },
653 { condensed_italic_900, expanded_italic_900 },
654 { expanded_normal_100, expanded_italic_100 },
655 { expanded_normal_900, expanded_italic_900 },
656 { expanded_italic_100, expanded_italic_100 },
657 { expanded_italic_900, expanded_italic_900 },
658 },
659 },
660
661 {
662 { expanded_italic_100 },
663 {
664 { condensed_normal_100, expanded_italic_100 },
665 { condensed_normal_900, expanded_italic_100 },
666 { condensed_italic_100, expanded_italic_100 },
667 { condensed_italic_900, expanded_italic_100 },
668 { expanded_normal_100, expanded_italic_100 },
669 { expanded_normal_900, expanded_italic_100 },
670 { expanded_italic_100, expanded_italic_100 },
671 { expanded_italic_900, expanded_italic_100 },
672 },
673 },
674
675 {
676 { expanded_italic_900 },
677 {
678 { condensed_normal_100, expanded_italic_900 },
679 { condensed_normal_900, expanded_italic_900 },
680 { condensed_italic_100, expanded_italic_900 },
681 { condensed_italic_900, expanded_italic_900 },
682 { expanded_normal_100, expanded_italic_900 },
683 { expanded_normal_900, expanded_italic_900 },
684 { expanded_italic_100, expanded_italic_900 },
685 { expanded_italic_900, expanded_italic_900 },
686 },
687 },
688
689 {
690 { normal_normal_100, normal_normal_900 },
691 {
692 { normal_normal_300, normal_normal_100 },
693 { normal_normal_400, normal_normal_100 },
694 { normal_normal_500, normal_normal_100 },
695 { normal_normal_600, normal_normal_900 },
696 },
697 },
698
699 {
700 { normal_normal_100, normal_normal_400, normal_normal_900 },
701 {
702 { normal_normal_300, normal_normal_100 },
703 { normal_normal_400, normal_normal_400 },
704 { normal_normal_500, normal_normal_400 },
705 { normal_normal_600, normal_normal_900 },
706 },
707 },
708
709 {
710 { normal_normal_100, normal_normal_500, normal_normal_900 },
711 {
712 { normal_normal_300, normal_normal_100 },
713 { normal_normal_400, normal_normal_500 },
714 { normal_normal_500, normal_normal_500 },
715 { normal_normal_600, normal_normal_900 },
716 },
717 },
718
719 {
720 { },
721 {
722 { normal_normal_300, invalidFontStyle },
723 { normal_normal_400, invalidFontStyle },
724 { normal_normal_500, invalidFontStyle },
725 { normal_normal_600, invalidFontStyle },
726 },
727 },
728 {
729 { expanded_normal_100,expanded_normal_900,
730 expanded_italic_100,expanded_italic_900,
731 expanded_obliqu_100,expanded_obliqu_900, },
732 {
733 { condensed_normal_100, expanded_normal_100 },
734 { condensed_normal_900, expanded_normal_900 },
735 { condensed_italic_100, expanded_italic_100 },
736 { condensed_italic_900, expanded_italic_900 },
737 { condensed_obliqu_100, expanded_obliqu_100 },
738 { condensed_obliqu_900, expanded_obliqu_900 },
739 { expanded_normal_100, expanded_normal_100 },
740 { expanded_normal_900, expanded_normal_900 },
741 { expanded_italic_100, expanded_italic_100 },
742 { expanded_italic_900, expanded_italic_900 },
743 { expanded_obliqu_100, expanded_obliqu_100 },
744 { expanded_obliqu_900, expanded_obliqu_900 },
745 },
746 },
747 {
748 { expanded_normal_100,expanded_normal_900,
749 expanded_obliqu_100,expanded_obliqu_900, },
750 {
751 { condensed_normal_100, expanded_normal_100 },
752 { condensed_normal_900, expanded_normal_900 },
753 { condensed_italic_100, expanded_obliqu_100 },
754 { condensed_italic_900, expanded_obliqu_900 },
755 { condensed_obliqu_100, expanded_obliqu_100 },
756 { condensed_obliqu_900, expanded_obliqu_900 },
757 { expanded_normal_100, expanded_normal_100 },
758 { expanded_normal_900, expanded_normal_900 },
759 { expanded_italic_100, expanded_obliqu_100 },
760 { expanded_italic_900, expanded_obliqu_900 },
761 { expanded_obliqu_100, expanded_obliqu_100 },
762 { expanded_obliqu_900, expanded_obliqu_900 },
763 },
764 },
765 {
766 { expanded_italic_100,expanded_italic_900,
767 expanded_obliqu_100,expanded_obliqu_900, },
768 {
769 { condensed_normal_100, expanded_obliqu_100 },
770 { condensed_normal_900, expanded_obliqu_900 },
771 { condensed_italic_100, expanded_italic_100 },
772 { condensed_italic_900, expanded_italic_900 },
773 { condensed_obliqu_100, expanded_obliqu_100 },
774 { condensed_obliqu_900, expanded_obliqu_900 },
775 { expanded_normal_100, expanded_obliqu_100 },
776 { expanded_normal_900, expanded_obliqu_900 },
777 { expanded_italic_100, expanded_italic_100 },
778 { expanded_italic_900, expanded_italic_900 },
779 { expanded_obliqu_100, expanded_obliqu_100 },
780 { expanded_obliqu_900, expanded_obliqu_900 },
781 },
782 },
783 };
784
785 for (StyleSetTest& test : tests) {
786 for (const StyleSetTest::Case& testCase : test.cases) {
787 sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
788 if (typeface) {
789 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
790 } else {
791 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
792 }
793 }
794 }
795}
796
797DEF_TEST(FontMgr_MatchCharacter, reporter) {
799 // 0xD800 <= codepoint <= 0xDFFF || 0x10FFFF < codepoint are invalid
800 fm->matchFamilyStyleCharacter("Blah", SkFontStyle::Normal(), nullptr, 0, 0x0);
801 fm->matchFamilyStyleCharacter("Blah", SkFontStyle::Normal(), nullptr, 0, 0xD800);
802 fm->matchFamilyStyleCharacter("Blah", SkFontStyle::Normal(), nullptr, 0, 0xDFFF);
803 fm->matchFamilyStyleCharacter("Blah", SkFontStyle::Normal(), nullptr, 0, 0x110000);
804 fm->matchFamilyStyleCharacter("Blah", SkFontStyle::Normal(), nullptr, 0, 0x1FFFFF);
805 fm->matchFamilyStyleCharacter("Blah", SkFontStyle::Normal(), nullptr, 0, -1);
806}
static BlurTest tests[]
Definition: BlurTest.cpp:84
sk_bzero(glyphs, sizeof(glyphs))
const SkFont newFont(font.makeWithSize(36))
reporter
Definition: FontMgrTest.cpp:39
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
DECLARE_bool(verboseFontMgr) DEF_TEST(FontMgr_Font
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
REPORTER_ASSERT(reporter, 24==font.getSize())
int count
Definition: FontMgrTest.cpp:50
DEF_TEST(FontMgr_AliasNames, reporter)
Definition: FontMgrTest.cpp:74
static float next(float f)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
@ kUTF8
uses bytes to represent UTF-8 or ASCII
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
uint32_t SkFontTableTag
Definition: SkTypeface.h:41
int32_t SkUnichar
Definition: SkTypes.h:175
uint16_t SkGlyphID
Definition: SkTypes.h:179
sk_sp< SkFontStyleSet > createStyleSet(int index) const
Definition: SkFontMgr.cpp:101
sk_sp< SkTypeface > matchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const
Definition: SkFontMgr.cpp:114
void getFamilyName(int index, SkString *familyName) const
Definition: SkFontMgr.cpp:97
sk_sp< SkFontStyleSet > matchFamily(const char familyName[]) const
Definition: SkFontMgr.cpp:105
int countFamilies() const
Definition: SkFontMgr.cpp:93
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
sk_sp< SkTypeface > matchStyleCSS3(const SkFontStyle &pattern)
Definition: SkFontMgr.cpp:184
virtual sk_sp< SkTypeface > createTypeface(int index)=0
virtual sk_sp< SkTypeface > matchStyle(const SkFontStyle &pattern)=0
virtual int count()=0
virtual void getStyle(int index, SkFontStyle *, SkString *style)=0
@ kSemiBold_Weight
Definition: SkFontStyle.h:25
Slant slant() const
Definition: SkFontStyle.h:64
int width() const
Definition: SkFontStyle.h:63
int weight() const
Definition: SkFontStyle.h:62
@ kCondensed_Width
Definition: SkFontStyle.h:35
static constexpr SkFontStyle Normal()
Definition: SkFontStyle.h:66
Definition: SkFont.h:35
SkTypeface * getTypeface() const
Definition: SkFont.h:208
SkScalar getSize() const
Definition: SkFont.h:217
static std::unique_ptr< SkScalerContext > MakeEmpty(sk_sp< SkTypeface > typeface, const SkScalerContextEffects &effects, const SkDescriptor *desc)
void reset()
Definition: SkString.cpp:358
const char * c_str() const
Definition: SkString.h:133
SkTypefaceID uniqueID() const
Definition: SkTypeface.h:101
void getFamilyName(SkString *name) const
Definition: SkTypeface.cpp:459
SkFontStyle fontStyle() const
Definition: SkTypeface.h:55
SkTypeface(const SkFontStyle &style, bool isFixedPitch=false)
Definition: SkTypeface.cpp:56
void getGlyphToUnicodeMap(SkUnichar *glyphToUnicode) const override
bool onGlyphMaskNeedsCurrentColor() const override
Definition: TestTypeface.h:113
void onCharsToGlyphs(const SkUnichar *chars, int count, SkGlyphID glyphs[]) const override
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const override
Definition: TestTypeface.h:115
SkTypeface::LocalizedStrings * onCreateFamilyNameIterator() const override
int onGetUPEM() const override
Definition: TestTypeface.h:107
void getPostScriptGlyphNames(SkString *) const override
Definition: TestTypeface.h:105
bool onGetPostScriptName(SkString *) const override
std::unique_ptr< SkAdvancedTypefaceMetrics > onGetAdvancedMetrics() const override
void onGetFamilyName(SkString *familyName) const override
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], int parameterCount) const override
Definition: TestTypeface.h:120
int onGetTableTags(SkFontTableTag tags[]) const override
Definition: TestTypeface.h:125
std::unique_ptr< SkStreamAsset > onOpenStream(int *ttcIndex) const override
size_t onGetTableData(SkFontTableTag tag, size_t offset, size_t length, void *data) const override
Definition: TestTypeface.h:127
std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *desc) const override
void onFilterRec(SkScalerContextRec *rec) const override
sk_sp< SkTypeface > onMakeClone(const SkFontArguments &args) const override
Definition: TestTypeface.h:95
int onCountGlyphs() const override
Definition: TestTypeface.h:103
void onGetFontDescriptor(SkFontDescriptor *desc, bool *serialize) const override
T * get() const
Definition: SkRefCnt.h:303
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
sk_sp< SkTypeface > DefaultTypeface()
sk_sp< SkTypeface > CreateTestTypeface(const char *name, SkFontStyle style)
sk_sp< SkFontMgr > TestFontMgr()
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
font
Font Metadata and Metrics.