Remove script matching score from the font selection fallback.
Removing the extra score of 2 for the script matching from the font fallback score calculation. If the two langauges have different scripts, we should treat them as different languages. Change-Id: Ie0d6f27bd1086248895935a7bd01b5d404044ad0
This commit is contained in:
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
std::string getString() const;
|
||||
|
||||
// 0 = no match, 1 = language matches, 2 = language and script match
|
||||
// 0 = no match, 1 = language matches
|
||||
int match(const FontLanguage other) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -104,18 +104,17 @@ FontCollection::~FontCollection() {
|
||||
|
||||
// Implement heuristic for choosing best-match font. Here are the rules:
|
||||
// 1. If first font in the collection has the character, it wins.
|
||||
// 2. If a font matches both language and script, it gets a score of 4.
|
||||
// 3. If a font matches just language, it gets a score of 2.
|
||||
// 4. Matching the "compact" or "elegant" variant adds one to the score.
|
||||
// 5. If there is a variation selector and a font supports the complete variation sequence, we add
|
||||
// 12 to the score.
|
||||
// 6. If there is a color variation selector (U+FE0F), we add 6 to the score if the font is an emoji
|
||||
// font. This additional score of 6 is only given if the base character is supported in the font,
|
||||
// 2. If a font matches language, it gets a score of 2.
|
||||
// 3. Matching the "compact" or "elegant" variant adds one to the score.
|
||||
// 4. If there is a variation selector and a font supports the complete variation sequence, we add
|
||||
// 8 to the score.
|
||||
// 5. If there is a color variation selector (U+FE0F), we add 4 to the score if the font is an emoji
|
||||
// font. This additional score of 4 is only given if the base character is supported in the font,
|
||||
// but not the whole variation sequence.
|
||||
// 7. If there is a text variation selector (U+FE0E), we add 6 to the score if the font is not an
|
||||
// emoji font. This additional score of 6 is only given if the base character is supported in the
|
||||
// 6. If there is a text variation selector (U+FE0E), we add 4 to the score if the font is not an
|
||||
// emoji font. This additional score of 4 is only given if the base character is supported in the
|
||||
// font, but not the whole variation sequence.
|
||||
// 8. Highest score wins, with ties resolved to the first font.
|
||||
// 7. Highest score wins, with ties resolved to the first font.
|
||||
FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
|
||||
uint32_t langListId, int variant) const {
|
||||
if (ch >= mMaxChar) {
|
||||
@@ -156,10 +155,10 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
|
||||
score++;
|
||||
}
|
||||
if (hasVSGlyph) {
|
||||
score += 12;
|
||||
score += 8;
|
||||
} else if (((vs == 0xFE0F) && family->lang().hasEmojiFlag()) ||
|
||||
((vs == 0xFE0E) && !family->lang().hasEmojiFlag())) {
|
||||
score += 6;
|
||||
score += 4;
|
||||
}
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
|
||||
@@ -119,17 +119,7 @@ std::string FontLanguage::getString() const {
|
||||
}
|
||||
|
||||
int FontLanguage::match(const FontLanguage other) const {
|
||||
if (mBits == kUnsupportedLanguage || other.mBits == kUnsupportedLanguage)
|
||||
return 0;
|
||||
|
||||
int result = 0;
|
||||
if ((mBits & kBaseLangMask) == (other.mBits & kBaseLangMask)) {
|
||||
result++;
|
||||
if ((mBits & kScriptMask) != 0 && (mBits & kScriptMask) == (other.mBits & kScriptMask)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return *this == other;
|
||||
}
|
||||
|
||||
FontLanguages::FontLanguages(const char* buf, size_t size) {
|
||||
|
||||
@@ -164,7 +164,7 @@ TEST(FontCollectionItemizeTest, itemize_emoji) {
|
||||
ASSERT_EQ(2U, runs.size());
|
||||
EXPECT_EQ(0, runs[0].start);
|
||||
EXPECT_EQ(2, runs[0].end);
|
||||
EXPECT_EQ(kZH_HantFont, getFontPath(runs[0]));
|
||||
EXPECT_EQ(kJAFont, getFontPath(runs[0]));
|
||||
EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold());
|
||||
EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic());
|
||||
|
||||
@@ -267,6 +267,17 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) {
|
||||
EXPECT_EQ(kZH_HansFont, getFontPath(runs[0]));
|
||||
EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold());
|
||||
EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic());
|
||||
|
||||
// Both zh-Hant and ja fonts support U+242EE, but zh-Hans doesn't.
|
||||
// Here, ja and zh-Hant font should have the same score but ja should be selected since it is
|
||||
// listed before zh-Hant.
|
||||
itemize(collection.get(), "U+242EE", kZH_HansStyle, &runs);
|
||||
ASSERT_EQ(1U, runs.size());
|
||||
EXPECT_EQ(0, runs[0].start);
|
||||
EXPECT_EQ(2, runs[0].end);
|
||||
EXPECT_EQ(kJAFont, getFontPath(runs[0]));
|
||||
EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold());
|
||||
EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic());
|
||||
}
|
||||
|
||||
TEST(FontCollectionItemizeTest, itemize_mixed) {
|
||||
|
||||
Reference in New Issue
Block a user