diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 9fe0686e29..d2c5a3b9a9 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -108,14 +108,25 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, if (ch >= mMaxChar) { return NULL; } - const Range& range = mRanges[ch >> kLogCharsPerPage]; + + // Even if the font supports variation sequence, mRanges isn't aware of the base character of + // the sequence. Search all FontFamilies if variation sequence is specified. + // TODO: Always use mRanges for font search. + const std::vector& familyVec = (vs == 0) ? mFamilyVec : mFamilies; + Range range; + if (vs == 0) { + range = mRanges[ch >> kLogCharsPerPage]; + } else { + range = { 0, mFamilies.size() }; + } + #ifdef VERBOSE_DEBUG ALOGD("querying range %zd:%zd\n", range.start, range.end); #endif FontFamily* bestFamily = nullptr; int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { - FontFamily* family = mFamilyVec[i]; + FontFamily* family = familyVec[i]; if (vs == 0 ? family->getCoverage()->get(ch) : family->hasVariationSelector(ch, vs)) { // First font family in collection always matches if (mFamilies[0] == family) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index ae1cbf47db..47f5259c73 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -21,6 +21,7 @@ #include "UnicodeUtils.h" using android::FontCollection; +using android::FontFamily; using android::FontLanguage; using android::FontStyle; @@ -614,3 +615,31 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); } +TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { + // kVSTestFont supports U+717D U+FE02 but doesn't support U+717D. + // kVSTestFont should be selected for U+717D U+FE02 even if it does not support the base code + // point. + const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; + + std::vector families; + FontFamily* family1 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + family1->addFont(new MinikinFontForTest(kLatinFont)); + families.push_back(family1); + + FontFamily* family2 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + family2->addFont(new MinikinFontForTest(kVSTestFont)); + families.push_back(family2); + + FontCollection collection(families); + + std::vector runs; + + itemize(&collection, "U+717D U+FE02", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kVSTestFont, getFontPath(runs[0])); + + family1->Unref(); + family2->Unref(); +}