Merge "Fix lookup order for VS in itemization."
This commit is contained in:
@@ -281,22 +281,11 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
|
||||
return mFamilies[0];
|
||||
}
|
||||
|
||||
const std::vector<FontFamily*>* familyVec = &mFamilyVec;
|
||||
const std::vector<FontFamily*>& familyVec = (vs == 0) ? mFamilyVec : mFamilies;
|
||||
Range range = mRanges[ch >> kLogCharsPerPage];
|
||||
|
||||
std::vector<FontFamily*> familyVecForVS;
|
||||
if (vs != 0) {
|
||||
// If variation selector is specified, need to search for both the variation sequence and
|
||||
// its base codepoint. Compute the union vector of them.
|
||||
familyVecForVS = mVSFamilyVec;
|
||||
familyVecForVS.insert(familyVecForVS.end(),
|
||||
mFamilyVec.begin() + range.start, mFamilyVec.begin() + range.end);
|
||||
std::sort(familyVecForVS.begin(), familyVecForVS.end());
|
||||
auto last = std::unique(familyVecForVS.begin(), familyVecForVS.end());
|
||||
familyVecForVS.erase(last, familyVecForVS.end());
|
||||
|
||||
familyVec = &familyVecForVS;
|
||||
range = { 0, familyVecForVS.size() };
|
||||
range = { 0, mFamilies.size() };
|
||||
}
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
@@ -305,7 +294,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
|
||||
FontFamily* bestFamily = nullptr;
|
||||
uint32_t bestScore = kUnsupportedFontScore;
|
||||
for (size_t i = range.start; i < range.end; i++) {
|
||||
FontFamily* family = (*familyVec)[i];
|
||||
FontFamily* family = familyVec[i];
|
||||
const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family);
|
||||
if (score == kFirstFontScore) {
|
||||
// If the first font family supports the given character or variation sequence, always
|
||||
|
||||
@@ -32,6 +32,7 @@ font_src_files := \
|
||||
data/Italic.ttf \
|
||||
data/Ja.ttf \
|
||||
data/Ko.ttf \
|
||||
data/NoCmapFormat14.ttf \
|
||||
data/NoGlyphFont.ttf \
|
||||
data/Regular.ttf \
|
||||
data/TextEmojiFont.ttf \
|
||||
|
||||
@@ -44,6 +44,9 @@ const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf";
|
||||
const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf";
|
||||
const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf";
|
||||
|
||||
const char kHasCmapFormat14Font[] = kTestFontDir "NoCmapFormat14.ttf";
|
||||
const char kNoCmapFormat14Font[] = kTestFontDir "VarioationSelectorTest-Regular.ttf";
|
||||
|
||||
typedef ICUTestBase FontCollectionItemizeTest;
|
||||
|
||||
// Utility function for calling itemize function.
|
||||
@@ -1392,4 +1395,74 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) {
|
||||
EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0]));
|
||||
}
|
||||
|
||||
// For b/29585939
|
||||
TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) {
|
||||
const FontStyle kDefaultFontStyle;
|
||||
|
||||
MinikinAutoUnref<MinikinFont> dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont));
|
||||
MinikinAutoUnref<MinikinFont> fontA(MinikinFontForTest::createFromFile(kZH_HansFont));
|
||||
MinikinAutoUnref<MinikinFont> fontB(MinikinFontForTest::createFromFile(kZH_HansFont));
|
||||
|
||||
MinikinAutoUnref<FontFamily> dummyFamily(new FontFamily());
|
||||
MinikinAutoUnref<FontFamily> familyA(new FontFamily());
|
||||
MinikinAutoUnref<FontFamily> familyB(new FontFamily());
|
||||
|
||||
dummyFamily->addFont(dummyFont.get());
|
||||
familyA->addFont(fontA.get());
|
||||
familyB->addFont(fontB.get());
|
||||
|
||||
std::vector<FontFamily*> families =
|
||||
{ dummyFamily.get(), familyA.get(), familyB.get() };
|
||||
std::vector<FontFamily*> reversedFamilies =
|
||||
{ dummyFamily.get(), familyB.get(), familyA.get() };
|
||||
|
||||
MinikinAutoUnref<FontCollection> collection(new FontCollection(families));
|
||||
MinikinAutoUnref<FontCollection> reversedCollection(new FontCollection(reversedFamilies));
|
||||
|
||||
// Both fontA/fontB support U+35A8 but don't support U+35A8 U+E0100. The first font should be
|
||||
// selected.
|
||||
std::vector<FontCollection::Run> runs;
|
||||
itemize(collection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs);
|
||||
EXPECT_EQ(fontA.get(), runs[0].fakedFont.font);
|
||||
|
||||
itemize(reversedCollection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs);
|
||||
EXPECT_EQ(fontB.get(), runs[0].fakedFont.font);
|
||||
}
|
||||
|
||||
// For b/29585939
|
||||
TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) {
|
||||
const FontStyle kDefaultFontStyle;
|
||||
|
||||
MinikinAutoUnref<MinikinFont> dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont));
|
||||
MinikinAutoUnref<MinikinFont> hasCmapFormat14Font(
|
||||
MinikinFontForTest::createFromFile(kHasCmapFormat14Font));
|
||||
MinikinAutoUnref<MinikinFont> noCmapFormat14Font(
|
||||
MinikinFontForTest::createFromFile(kNoCmapFormat14Font));
|
||||
|
||||
MinikinAutoUnref<FontFamily> dummyFamily(new FontFamily());
|
||||
MinikinAutoUnref<FontFamily> hasCmapFormat14Family(new FontFamily());
|
||||
MinikinAutoUnref<FontFamily> noCmapFormat14Family(new FontFamily());
|
||||
|
||||
dummyFamily->addFont(dummyFont.get());
|
||||
hasCmapFormat14Family->addFont(hasCmapFormat14Font.get());
|
||||
noCmapFormat14Family->addFont(noCmapFormat14Font.get());
|
||||
|
||||
std::vector<FontFamily*> families =
|
||||
{ dummyFamily.get(), hasCmapFormat14Family.get(), noCmapFormat14Family.get() };
|
||||
std::vector<FontFamily*> reversedFamilies =
|
||||
{ dummyFamily.get(), noCmapFormat14Family.get(), hasCmapFormat14Family.get() };
|
||||
|
||||
MinikinAutoUnref<FontCollection> collection(new FontCollection(families));
|
||||
MinikinAutoUnref<FontCollection> reversedCollection(new FontCollection(reversedFamilies));
|
||||
|
||||
// Both hasCmapFormat14Font/noCmapFormat14Font support U+5380 but don't support U+5380 U+E0100.
|
||||
// The first font should be selected.
|
||||
std::vector<FontCollection::Run> runs;
|
||||
itemize(collection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs);
|
||||
EXPECT_EQ(hasCmapFormat14Font.get(), runs[0].fakedFont.font);
|
||||
|
||||
itemize(reversedCollection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs);
|
||||
EXPECT_EQ(noCmapFormat14Font.get(), runs[0].fakedFont.font);
|
||||
}
|
||||
|
||||
} // namespace minikin
|
||||
|
||||
Reference in New Issue
Block a user