aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkFontMgr.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-04-27 10:21:04 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-27 10:21:05 -0700
commitb4bb7d825566042ed64697be49457dbac060e6c4 (patch)
treebaad2b4f5125674cc06c06a7d2dd04f7100379c4 /src/core/SkFontMgr.cpp
parent12135f50bd8d7d8abbb2befb99a9784043cb90e5 (diff)
Add oblique as a slant.
Diffstat (limited to 'src/core/SkFontMgr.cpp')
-rw-r--r--src/core/SkFontMgr.cpp63
1 files changed, 39 insertions, 24 deletions
diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp
index eba2b28fd6..ebb9a89662 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, &current, 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;
}
}