Index: src/core/SkFontMgr.cpp |
diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp |
index eba2b28fd6375bd65fc79debf59511830c7703ad..e2d3815700a85ac6028d994dde155852391677c4 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 }; |
@@ -223,54 +226,78 @@ SkTypeface* SkFontStyleSet::matchStyleCSS3(const SkFontStyle& pattern) { |
// This has the highest priority. |
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; |
+ currentScore <<= 8; |
+ |
+ // CSS style (normal/italic/oblique) |
+ // Style takes priority over all valid weights. |
reed1
2016/04/26 20:36:09
s/Style/Slant ?
bungeman-skia
2016/04/27 15:37:20
Eck, yeah. So CSS uses the terms stretch, style, w
|
+ switch (pattern.slant()) { |
+ case SkFontStyle::kUpright_Slant: { |
reed1
2016/04/26 20:36:09
Sure seems like a table or other calc might be cle
bungeman-skia
2016/04/27 15:37:20
I originally wrote this as a small 3x3 score table
|
+ switch (current.slant()) { |
+ case SkFontStyle::kUpright_Slant: currentScore += 3; break; |
+ case SkFontStyle::kItalic_Slant : currentScore += 1; break; |
+ case SkFontStyle::kOblique_Slant: currentScore += 2; break; |
+ default: SkASSERT(false); break; |
+ }; |
+ } break; |
+ case SkFontStyle::kItalic_Slant: { |
+ switch (current.slant()) { |
+ case SkFontStyle::kUpright_Slant: currentScore += 1; break; |
+ case SkFontStyle::kItalic_Slant : currentScore += 3; break; |
+ case SkFontStyle::kOblique_Slant: currentScore += 2; break; |
+ default: SkASSERT(false); break; |
+ }; |
+ } break; |
+ case SkFontStyle::kOblique_Slant: { |
+ switch (current.slant()) { |
+ case SkFontStyle::kUpright_Slant: currentScore += 1; break; |
+ case SkFontStyle::kItalic_Slant : currentScore += 2; break; |
+ case SkFontStyle::kOblique_Slant: currentScore += 3; break; |
+ default: SkASSERT(false); break; |
+ }; |
+ } break; |
+ default: SkASSERT(false); break; |
} |
+ currentScore <<= 8; |
// Synthetics (weight/style) [no stretch synthetic?] |
// 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; |
} |
} |