Index: src/core/SkFontMgr.cpp |
diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp |
index eba2b28fd6375bd65fc79debf59511830c7703ad..ebb9a8966207814024d2d6b5b66095c64882bf2e 100644 |
--- a/src/core/SkFontMgr.cpp |
+++ b/src/core/SkFontMgr.cpp |
@@ -211,6 +211,9 @@ SkTypeface* SkFontStyleSet::matchStyleCSS3(const SkFontStyle& pattern) { |
struct Score { |
int score; |
int index; |
+ Score& operator +=(int rhs) { this->score += rhs; return *this; } |
+ Score& operator <<=(int rhs) { this->score <<= rhs; return *this; } |
+ bool operator <(const Score& that) { return this->score < that.score; } |
}; |
Score maxScore = { 0, 0 }; |
@@ -219,58 +222,70 @@ SkTypeface* SkFontStyleSet::matchStyleCSS3(const SkFontStyle& pattern) { |
this->getStyle(i, ¤t, nullptr); |
Score currentScore = { 0, i }; |
- // CSS stretch. (This is the width.) |
- // This has the highest priority. |
+ // CSS stretch / SkFontStyle::Width |
+ // Takes priority over everything else. |
if (pattern.width() <= SkFontStyle::kNormal_Width) { |
if (current.width() <= pattern.width()) { |
- currentScore.score += 10 - pattern.width() + current.width(); |
+ currentScore += 10 - pattern.width() + current.width(); |
} else { |
- currentScore.score += 10 - current.width(); |
+ currentScore += 10 - current.width(); |
} |
} else { |
if (current.width() > pattern.width()) { |
- currentScore.score += 10 + pattern.width() - current.width(); |
+ currentScore += 10 + pattern.width() - current.width(); |
} else { |
- currentScore.score += current.width(); |
+ currentScore += current.width(); |
} |
} |
- currentScore.score *= 1002; |
- |
- // CSS style (italic/oblique) |
- // Being italic trumps all valid weights which are not italic. |
- // Note that newer specs differentiate between italic and oblique. |
- if (pattern.isItalic() == current.isItalic()) { |
- currentScore.score += 1001; |
- } |
- |
- // Synthetics (weight/style) [no stretch synthetic?] |
- |
+ currentScore <<= 8; |
+ |
+ // CSS style (normal, italic, oblique) / SkFontStyle::Slant (upright, italic, oblique) |
+ // Takes priority over all valid weights. |
+ static_assert(SkFontStyle::kUpright_Slant == 0 && |
+ SkFontStyle::kItalic_Slant == 1 && |
+ SkFontStyle::kOblique_Slant == 2, |
+ "SkFontStyle::Slant values not as required."); |
+ SkASSERT(0 <= pattern.slant() && pattern.slant() <= 2 && |
+ 0 <= current.slant() && current.slant() <= 2); |
+ static const int score[3][3] = { |
+ /* Upright Italic Oblique [current]*/ |
+ /* Upright */ { 3 , 1 , 2 }, |
+ /* Italic */ { 1 , 3 , 2 }, |
+ /* Oblique */ { 1 , 2 , 3 }, |
+ /* [pattern] */ |
+ }; |
+ currentScore += score[pattern.slant()][current.slant()]; |
+ currentScore <<= 8; |
+ |
+ // Synthetics (weight, style) [no stretch synthetic?] |
+ |
+ // CSS weight / SkFontStyle::Weight |
// The 'closer' to the target weight, the higher the score. |
// 1000 is the 'heaviest' recognized weight |
if (pattern.weight() == current.weight()) { |
- currentScore.score += 1000; |
+ currentScore += 1000; |
} else if (pattern.weight() <= 500) { |
if (400 <= pattern.weight() && pattern.weight() < 450) { |
if (450 <= current.weight() && current.weight() <= 500) { |
// Artificially boost the 500 weight. |
// TODO: determine correct number to use. |
- currentScore.score += 500; |
+ currentScore += 500; |
} |
} |
if (current.weight() <= pattern.weight()) { |
- currentScore.score += 1000 - pattern.weight() + current.weight(); |
+ currentScore += 1000 - pattern.weight() + current.weight(); |
} else { |
- currentScore.score += 1000 - current.weight(); |
+ currentScore += 1000 - current.weight(); |
} |
} else if (pattern.weight() > 500) { |
if (current.weight() > pattern.weight()) { |
- currentScore.score += 1000 + pattern.weight() - current.weight(); |
+ currentScore += 1000 + pattern.weight() - current.weight(); |
} else { |
- currentScore.score += current.weight(); |
+ currentScore += current.weight(); |
} |
} |
- if (currentScore.score > maxScore.score) { |
+ if (maxScore < currentScore) { |
maxScore = currentScore; |
} |
} |