From 0928c1af2f45361a9473565d7946978dbc42493e Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 5 Nov 2019 12:27:34 -0800 Subject: [PATCH] Add 'Cough' test font and support multiple test fonts. (#13649) --- lib/ui/text/font_collection.cc | 19 +- runtime/test_font_data.cc | 178 ++++++++++++++++++- runtime/test_font_data.h | 4 +- third_party/txt/src/txt/test_font_manager.cc | 15 +- third_party/txt/src/txt/test_font_manager.h | 5 +- 5 files changed, 205 insertions(+), 16 deletions(-) diff --git a/lib/ui/text/font_collection.cc b/lib/ui/text/font_collection.cc index 4ef95709cad59..170f30c864f11 100644 --- a/lib/ui/text/font_collection.cc +++ b/lib/ui/text/font_collection.cc @@ -129,17 +129,24 @@ void FontCollection::RegisterFonts( } void FontCollection::RegisterTestFonts() { - sk_sp test_typeface = - SkTypeface::MakeFromStream(GetTestFontData()); + std::vector> test_typefaces; + std::vector> font_data = GetTestFontData(); + for (auto& font : font_data) { + test_typefaces.push_back(SkTypeface::MakeFromStream(std::move(font))); + } std::unique_ptr font_provider = std::make_unique(); - font_provider->RegisterTypeface(std::move(test_typeface), - GetTestFontFamilyName()); + size_t index = 0; + std::vector names = GetTestFontFamilyNames(); + for (sk_sp typeface : test_typefaces) { + font_provider->RegisterTypeface(std::move(typeface), names[index]); + index++; + } - collection_->SetTestFontManager(sk_make_sp( - std::move(font_provider), GetTestFontFamilyName())); + collection_->SetTestFontManager( + sk_make_sp(std::move(font_provider), names)); collection_->DisableFontFallback(); } diff --git a/runtime/test_font_data.cc b/runtime/test_font_data.cc index dd6e070159e65..302c8d05c2455 100644 --- a/runtime/test_font_data.cc +++ b/runtime/test_font_data.cc @@ -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 GetTestFontData() { +std::vector> GetTestFontData() { + std::vector> data; if (kAhemFontLength == 0) { - return nullptr; + data.push_back(nullptr); + } else { + data.push_back(std::make_unique(kAhemFont, kAhemFontLength, + false /* copy data */)); + } + + if (kCoughFontLength == 0) { + data.push_back(nullptr); + } else { + data.push_back(std::make_unique( + kCoughFont, kCoughFontLength, false /* copy data */)); } - return std::make_unique(kAhemFont, kAhemFontLength, - false /* copy data */); + return data; } std::string GetTestFontFamilyName() { return "Ahem"; } +std::vector GetTestFontFamilyNames() { + std::vector names = {"Ahem", "Cough"}; + return names; +} + } // namespace flutter diff --git a/runtime/test_font_data.h b/runtime/test_font_data.h index 957422e0bd470..83ef523aa1dba 100644 --- a/runtime/test_font_data.h +++ b/runtime/test_font_data.h @@ -7,13 +7,15 @@ #include #include +#include #include "third_party/skia/include/core/SkStream.h" namespace flutter { -std::unique_ptr GetTestFontData(); +std::vector> GetTestFontData(); std::string GetTestFontFamilyName(); +std::vector GetTestFontFamilyNames(); } // namespace flutter diff --git a/third_party/txt/src/txt/test_font_manager.cc b/third_party/txt/src/txt/test_font_manager.cc index d5b1146fd4474..a23a8aa58807b 100644 --- a/third_party/txt/src/txt/test_font_manager.cc +++ b/third_party/txt/src/txt/test_font_manager.cc @@ -21,14 +21,23 @@ namespace txt { TestFontManager::TestFontManager( std::unique_ptr font_provider, - std::string test_font_family_name) + std::vector 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 diff --git a/third_party/txt/src/txt/test_font_manager.h b/third_party/txt/src/txt/test_font_manager.h index 1c2fc8966edc0..b1a7d58b999cf 100644 --- a/third_party/txt/src/txt/test_font_manager.h +++ b/third_party/txt/src/txt/test_font_manager.h @@ -19,6 +19,7 @@ #include #include +#include #include "flutter/fml/macros.h" #include "third_party/skia/include/core/SkFontMgr.h" @@ -32,12 +33,12 @@ namespace txt { class TestFontManager : public AssetFontManager { public: TestFontManager(std::unique_ptr font_provider, - std::string test_font_family_name); + std::vector test_font_family_names); ~TestFontManager() override; private: - std::string test_font_family_name_; + std::vector test_font_family_names_; SkFontStyleSet* onMatchFamily(const char family_name[]) const override;