aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
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
parent12135f50bd8d7d8abbb2befb99a9784043cb90e5 (diff)
Add oblique as a slant.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkFontMgr.cpp63
-rw-r--r--src/core/SkFontStyle.cpp2
-rw-r--r--src/core/SkTypeface.cpp9
3 files changed, 41 insertions, 33 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;
}
}
diff --git a/src/core/SkFontStyle.cpp b/src/core/SkFontStyle.cpp
index c28e721337..01628ae9d9 100644
--- a/src/core/SkFontStyle.cpp
+++ b/src/core/SkFontStyle.cpp
@@ -20,7 +20,7 @@ SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
fUnion.fU32 = 0;
fUnion.fR.fWeight = SkTPin<int>(weight, kThin_Weight, kBlack_Weight);
fUnion.fR.fWidth = SkTPin<int>(width, kUltraCondensed_Width, kUltaExpanded_Width);
- fUnion.fR.fSlant = SkTPin<int>(slant, kUpright_Slant, kItalic_Slant);
+ fUnion.fR.fSlant = SkTPin<int>(slant, kUpright_Slant, kOblique_Slant);
}
/*static*/SkFontStyle SkFontStyle::FromOldStyle(unsigned oldStyle) {
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 855ef909e8..d768efc603 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -138,14 +138,7 @@ SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
}
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- bool bold = s & SkTypeface::kBold;
- bool italic = s & SkTypeface::kItalic;
- SkFontStyle newStyle = SkFontStyle(bold ? SkFontStyle::kBold_Weight
- : SkFontStyle::kNormal_Weight,
- SkFontStyle::kNormal_Width,
- italic ? SkFontStyle::kItalic_Slant
- : SkFontStyle::kUpright_Slant);
- return fm->matchFaceStyle(family, newStyle);
+ return fm->matchFaceStyle(family, SkFontStyle::FromOldStyle(s));
}
SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) {