Skip to content

Commit

Permalink
Add 'Cough' test font and support multiple test fonts. (flutter#13649)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryQian authored Nov 5, 2019
1 parent 4229993 commit 0928c1a
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 16 deletions.
19 changes: 13 additions & 6 deletions lib/ui/text/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,24 @@ void FontCollection::RegisterFonts(
}

void FontCollection::RegisterTestFonts() {
sk_sp<SkTypeface> test_typeface =
SkTypeface::MakeFromStream(GetTestFontData());
std::vector<sk_sp<SkTypeface>> test_typefaces;
std::vector<std::unique_ptr<SkStreamAsset>> font_data = GetTestFontData();
for (auto& font : font_data) {
test_typefaces.push_back(SkTypeface::MakeFromStream(std::move(font)));
}

std::unique_ptr<txt::TypefaceFontAssetProvider> font_provider =
std::make_unique<txt::TypefaceFontAssetProvider>();

font_provider->RegisterTypeface(std::move(test_typeface),
GetTestFontFamilyName());
size_t index = 0;
std::vector<std::string> names = GetTestFontFamilyNames();
for (sk_sp<SkTypeface> typeface : test_typefaces) {
font_provider->RegisterTypeface(std::move(typeface), names[index]);
index++;
}

collection_->SetTestFontManager(sk_make_sp<txt::TestFontManager>(
std::move(font_provider), GetTestFontFamilyName()));
collection_->SetTestFontManager(
sk_make_sp<txt::TestFontManager>(std::move(font_provider), names));

collection_->DisableFontFallback();
}
Expand Down
178 changes: 174 additions & 4 deletions runtime/test_font_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1205,28 +1205,198 @@ static const unsigned char kAhemFont[] = {
0x69, 0x69, 0x33, 0x30, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0x00, 0x08, 0x00, 0x02, 0x00, 0x10, 0x00, 0x01, 0xff, 0xff, 0x00, 0x03};

// "Cough" font is Flutter's custom test font and may expand to cover
// font-dependent testing specific features that "Ahem" cannot cover.
//
// Features and description of Cough:
//
// * EM square size of 1000. This is atypical of a power of 2 EM size, but
// is included to make it easier to tell the final value a metric is meant
// to be. For example, with fontSize 100, 10 units = 1 pixel.
// * The EM square has an ascent of 800 and a descent of 200.
// * The HHead, typo and win metrics are identical, making this font platform
// agnostic.
// * The ASCII glyphs of "A", "a", and "g" are included. This will likely expand
// in the future to include representative CJK glyphs as well as hanging
// glyphs. These glyphs are meant for testing purposes only, and only vaguely
// look like the character in order to minimize the size of the font.
// * Cap height is 800.
// * X height is 500.
// * Underline height is -100.
static const unsigned char kCoughFont[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x80, 0x00, 0x03, 0x00, 0x50,
0x46, 0x46, 0x54, 0x4d, 0x89, 0xba, 0x1a, 0x0b, 0x00, 0x00, 0x06, 0x10,
0x00, 0x00, 0x00, 0x1c, 0x47, 0x44, 0x45, 0x46, 0x00, 0x27, 0x00, 0x2d,
0x00, 0x00, 0x05, 0xe8, 0x00, 0x00, 0x00, 0x26, 0x4f, 0x53, 0x2f, 0x32,
0x7d, 0x51, 0x4a, 0x11, 0x00, 0x00, 0x01, 0x58, 0x00, 0x00, 0x00, 0x60,
0x63, 0x6d, 0x61, 0x70, 0x01, 0x14, 0x07, 0x66, 0x00, 0x00, 0x01, 0xd0,
0x00, 0x00, 0x01, 0x6a, 0x67, 0x61, 0x73, 0x70, 0xff, 0xff, 0x00, 0x03,
0x00, 0x00, 0x05, 0xe0, 0x00, 0x00, 0x00, 0x08, 0x67, 0x6c, 0x79, 0x66,
0x53, 0x7d, 0x78, 0xff, 0x00, 0x00, 0x03, 0x4c, 0x00, 0x00, 0x01, 0x08,
0x68, 0x65, 0x61, 0x64, 0x15, 0x1b, 0x17, 0x3d, 0x00, 0x00, 0x00, 0xdc,
0x00, 0x00, 0x00, 0x36, 0x68, 0x68, 0x65, 0x61, 0x05, 0x84, 0x01, 0x3b,
0x00, 0x00, 0x01, 0x14, 0x00, 0x00, 0x00, 0x24, 0x68, 0x6d, 0x74, 0x78,
0x05, 0x51, 0xff, 0xfd, 0x00, 0x00, 0x01, 0xb8, 0x00, 0x00, 0x00, 0x18,
0x6c, 0x6f, 0x63, 0x61, 0x00, 0x8c, 0x00, 0xea, 0x00, 0x00, 0x03, 0x3c,
0x00, 0x00, 0x00, 0x10, 0x6d, 0x61, 0x78, 0x70, 0x00, 0x0b, 0x00, 0x1d,
0x00, 0x00, 0x01, 0x38, 0x00, 0x00, 0x00, 0x20, 0x6e, 0x61, 0x6d, 0x65,
0x3f, 0x88, 0x53, 0x13, 0x00, 0x00, 0x04, 0x54, 0x00, 0x00, 0x01, 0x59,
0x70, 0x6f, 0x73, 0x74, 0xff, 0xed, 0x00, 0x71, 0x00, 0x00, 0x05, 0xb0,
0x00, 0x00, 0x00, 0x30, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x39, 0x28, 0xcc, 0xe3, 0x5f, 0x0f, 0x3c, 0xf5, 0x00, 0x0b, 0x03, 0xe8,
0x00, 0x00, 0x00, 0x00, 0xd9, 0xe6, 0x56, 0x09, 0x00, 0x00, 0x00, 0x00,
0xd9, 0xe6, 0x7e, 0x49, 0xff, 0xfe, 0xff, 0x37, 0x02, 0x31, 0x02, 0xcf,
0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x03, 0x52, 0xff, 0x06, 0x00, 0x00, 0x02, 0x30,
0xff, 0xfe, 0xff, 0xff, 0x02, 0x31, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1c, 0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0xe7,
0x01, 0x90, 0x00, 0x05, 0x00, 0x00, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28,
0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28,
0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x69, 0x72, 0x64, 0x00, 0x40,
0x00, 0x00, 0x00, 0x67, 0x03, 0x52, 0xff, 0x06, 0x00, 0x64, 0x03, 0x52,
0x00, 0xfa, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf4,
0x03, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x01, 0x02, 0x12, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x00, 0x00,
0x02, 0x30, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c,
0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x08, 0x00, 0x02,
0x00, 0x06, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x20, 0x00, 0x41, 0x00, 0x61,
0x00, 0x67, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x20,
0x00, 0x41, 0x00, 0x61, 0x00, 0x67, 0xff, 0xff, 0x00, 0x01, 0xff, 0xf5,
0xff, 0xe3, 0xff, 0xc3, 0xff, 0xa4, 0xff, 0x9f, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x2e,
0x00, 0x54, 0x00, 0x84, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32, 0x01, 0x90,
0x02, 0x9e, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x00, 0x37, 0x32, 0x33, 0x34,
0x11, 0x22, 0x23, 0x14, 0x27, 0x32, 0x21, 0x14, 0x11, 0x22, 0x21, 0x34,
0x32, 0x64, 0xc8, 0x64, 0xc8, 0x32, 0x85, 0x01, 0x0b, 0x85, 0xfe, 0xf5,
0x64, 0xad, 0x01, 0x5b, 0xad, 0xdf, 0xcf, 0xfe, 0x63, 0xcf, 0x00, 0x00,
0x00, 0x01, 0xff, 0xfe, 0xff, 0xff, 0x02, 0x30, 0x02, 0xcf, 0x00, 0x05,
0x00, 0x00, 0x05, 0x22, 0x25, 0x36, 0x13, 0x16, 0x02, 0x30, 0x8d, 0xfe,
0x5b, 0x48, 0xd9, 0x44, 0x01, 0x01, 0xb4, 0x02, 0x1b, 0xb4, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x31, 0x02, 0x30, 0x00, 0x0b,
0x00, 0x15, 0x00, 0x00, 0x31, 0x30, 0x31, 0x32, 0x37, 0x36, 0x37, 0x16,
0x13, 0x06, 0x27, 0x26, 0x01, 0x06, 0x07, 0x36, 0x37, 0x36, 0x23, 0x22,
0x27, 0x26, 0x02, 0x6b, 0x6e, 0x48, 0x44, 0xca, 0x8c, 0xd2, 0xd3, 0x01,
0x17, 0x18, 0x49, 0x34, 0x4e, 0x4e, 0x01, 0x02, 0x28, 0x29, 0xd0, 0xd4,
0x8c, 0x8c, 0xfe, 0x5e, 0x01, 0x01, 0x01, 0x01, 0x1b, 0x2e, 0x88, 0x01,
0x02, 0x02, 0x42, 0x43, 0x00, 0x03, 0xff, 0xff, 0xff, 0x37, 0x02, 0x30,
0x02, 0x30, 0x00, 0x07, 0x00, 0x11, 0x00, 0x1b, 0x00, 0x00, 0x03, 0x32,
0x21, 0x06, 0x11, 0x22, 0x05, 0x34, 0x13, 0x06, 0x03, 0x36, 0x25, 0x34,
0x27, 0x34, 0x31, 0x06, 0x01, 0x14, 0x15, 0x16, 0x17, 0x30, 0x17, 0x34,
0x35, 0x26, 0x01, 0x8c, 0x01, 0xa5, 0x01, 0x8c, 0xfe, 0x5d, 0x55, 0x01,
0x03, 0x67, 0x01, 0x33, 0x01, 0x65, 0xfe, 0xcb, 0x85, 0x85, 0xa0, 0xe6,
0x02, 0x30, 0xbe, 0xfd, 0xc6, 0x01, 0xbe, 0x01, 0xe4, 0x65, 0xfe, 0xd2,
0x01, 0x01, 0x65, 0x98, 0x97, 0x01, 0xfd, 0xfb, 0x31, 0x31, 0x02, 0x01,
0x01, 0x19, 0x4a, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xae, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x15, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00, 0x2e, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x48, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x63, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x84, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0xa2, 0x00, 0x03,
0x00, 0x01, 0x04, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0x00, 0x01, 0x04, 0x09, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, 0x03,
0x00, 0x01, 0x04, 0x09, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x03,
0x00, 0x01, 0x04, 0x09, 0x00, 0x03, 0x00, 0x10, 0x00, 0x36, 0x00, 0x03,
0x00, 0x01, 0x04, 0x09, 0x00, 0x04, 0x00, 0x10, 0x00, 0x51, 0x00, 0x03,
0x00, 0x01, 0x04, 0x09, 0x00, 0x05, 0x00, 0x16, 0x00, 0x6c, 0x00, 0x03,
0x00, 0x01, 0x04, 0x09, 0x00, 0x06, 0x00, 0x10, 0x00, 0x90, 0x00, 0x00,
0x00, 0x00, 0x54, 0x00, 0x79, 0x00, 0x70, 0x00, 0x65, 0x00, 0x66, 0x00,
0x61, 0x00, 0x63, 0x00, 0x65, 0x00, 0x00, 0x54, 0x79, 0x70, 0x65, 0x66,
0x61, 0x63, 0x65, 0x00, 0x00, 0x52, 0x00, 0x65, 0x00, 0x67, 0x00, 0x75,
0x00, 0x6c, 0x00, 0x61, 0x00, 0x72, 0x00, 0x00, 0x52, 0x65, 0x67, 0x75,
0x6c, 0x61, 0x72, 0x00, 0x00, 0x54, 0x00, 0x79, 0x00, 0x70, 0x00, 0x65,
0x00, 0x66, 0x00, 0x61, 0x00, 0x63, 0x00, 0x65, 0x00, 0x00, 0x54, 0x79,
0x70, 0x65, 0x66, 0x61, 0x63, 0x65, 0x00, 0x00, 0x54, 0x00, 0x79, 0x00,
0x70, 0x00, 0x65, 0x00, 0x66, 0x00, 0x61, 0x00, 0x63, 0x00, 0x65, 0x00,
0x00, 0x54, 0x79, 0x70, 0x65, 0x66, 0x61, 0x63, 0x65, 0x00, 0x00, 0x56,
0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e,
0x00, 0x20, 0x00, 0x31, 0x00, 0x2e, 0x00, 0x30, 0x00, 0x00, 0x56, 0x65,
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x2e, 0x30, 0x00, 0x00, 0x54,
0x00, 0x79, 0x00, 0x70, 0x00, 0x65, 0x00, 0x66, 0x00, 0x61, 0x00, 0x63,
0x00, 0x65, 0x00, 0x00, 0x54, 0x79, 0x70, 0x65, 0x66, 0x61, 0x63, 0x65,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x9c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x24,
0x00, 0x44, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x02,
0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x16, 0x00, 0x1e,
0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x06, 0x00, 0x01, 0x00, 0x04,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0xd5, 0xed, 0x45, 0xb8, 0x00, 0x00, 0x00, 0x00, 0xd9, 0xe6, 0x56, 0x09,
0x00, 0x00, 0x00, 0x00, 0xd9, 0xe6, 0x7e, 0x49};

static const unsigned int kAhemFontLength = 13884;
static const unsigned int kCoughFontLength = 1576;

#else // EMBED_TEST_FONT_DATA

static const unsigned char kAhemFont[] = {};
static const unsigned char kCoughFont[] = {};

static const unsigned int kAhemFontLength = 0;
static const unsigned int kCoughFontLength = 0;

#endif // EMBED_TEST_FONT_DATA

namespace flutter {

std::unique_ptr<SkStreamAsset> GetTestFontData() {
std::vector<std::unique_ptr<SkStreamAsset>> GetTestFontData() {
std::vector<std::unique_ptr<SkStreamAsset>> data;
if (kAhemFontLength == 0) {
return nullptr;
data.push_back(nullptr);
} else {
data.push_back(std::make_unique<SkMemoryStream>(kAhemFont, kAhemFontLength,
false /* copy data */));
}

if (kCoughFontLength == 0) {
data.push_back(nullptr);
} else {
data.push_back(std::make_unique<SkMemoryStream>(
kCoughFont, kCoughFontLength, false /* copy data */));
}
return std::make_unique<SkMemoryStream>(kAhemFont, kAhemFontLength,
false /* copy data */);
return data;
}

std::string GetTestFontFamilyName() {
return "Ahem";
}

std::vector<std::string> GetTestFontFamilyNames() {
std::vector<std::string> names = {"Ahem", "Cough"};
return names;
}

} // namespace flutter
4 changes: 3 additions & 1 deletion runtime/test_font_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

#include <memory>
#include <string>
#include <vector>

#include "third_party/skia/include/core/SkStream.h"

namespace flutter {

std::unique_ptr<SkStreamAsset> GetTestFontData();
std::vector<std::unique_ptr<SkStreamAsset>> GetTestFontData();
std::string GetTestFontFamilyName();
std::vector<std::string> GetTestFontFamilyNames();

} // namespace flutter

Expand Down
15 changes: 12 additions & 3 deletions third_party/txt/src/txt/test_font_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@ namespace txt {

TestFontManager::TestFontManager(
std::unique_ptr<FontAssetProvider> font_provider,
std::string test_font_family_name)
std::vector<std::string> test_font_family_names)
: AssetFontManager(std::move(font_provider)),
test_font_family_name_(test_font_family_name) {}
test_font_family_names_(test_font_family_names) {}

TestFontManager::~TestFontManager() = default;

SkFontStyleSet* TestFontManager::onMatchFamily(const char family_name[]) const {
return AssetFontManager::onMatchFamily(test_font_family_name_.c_str());
// Find the requested name in the list, if not found, default to the first
// font family in the test font family list.
std::string requested_name(family_name);
std::string sanitized_name = test_font_family_names_[0];
for (const std::string& test_family : test_font_family_names_) {
if (requested_name == test_family) {
sanitized_name = test_family;
}
}
return AssetFontManager::onMatchFamily(sanitized_name.c_str());
}

} // namespace txt
5 changes: 3 additions & 2 deletions third_party/txt/src/txt/test_font_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <memory>
#include <string>
#include <vector>

#include "flutter/fml/macros.h"
#include "third_party/skia/include/core/SkFontMgr.h"
Expand All @@ -32,12 +33,12 @@ namespace txt {
class TestFontManager : public AssetFontManager {
public:
TestFontManager(std::unique_ptr<FontAssetProvider> font_provider,
std::string test_font_family_name);
std::vector<std::string> test_font_family_names);

~TestFontManager() override;

private:
std::string test_font_family_name_;
std::vector<std::string> test_font_family_names_;

SkFontStyleSet* onMatchFamily(const char family_name[]) const override;

Expand Down

0 comments on commit 0928c1a

Please sign in to comment.