Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Unified Diff: src/fonts/SkFontMgr_indirect.cpp

Issue 1438113002: Factor CSS3 matching rules. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Tests can use C++11. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkFontMgr.cpp ('k') | src/ports/SkFontHost_win.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/fonts/SkFontMgr_indirect.cpp
diff --git a/src/fonts/SkFontMgr_indirect.cpp b/src/fonts/SkFontMgr_indirect.cpp
index 132130f0d869c29a897dd578a0a72e6c95792de1..2470f8a69336adb904bfdb2b3a09afc2e9989dc2 100644
--- a/src/fonts/SkFontMgr_indirect.cpp
+++ b/src/fonts/SkFontMgr_indirect.cpp
@@ -52,102 +52,7 @@ public:
return fOwner->createTypefaceFromFontId(id);
}
- // If this SkStyleSet was created via onMatchFamily we would need a call like
- // fOwner->fProxy->matchNameStyle(fFamilyName, pattern);
- // but would not activate fonts (only consider fonts which would come back from matchName).
-
- // CSS policy sounds good.
- struct Score {
- int score;
- int index;
- };
-
- // Width has the greatest priority.
- // If the value of pattern.width is 5 (normal) or less,
- // narrower width values are checked first, then wider values.
- // If the value of pattern.width is greater than 5 (normal),
- // wider values are checked first, followed by narrower values.
-
- // Italic/Oblique has the next highest priority.
- // If italic requested and there is some italic font, use it.
- // If oblique requested and there is some oblique font, use it.
- // If italic requested and there is some oblique font, use it.
- // If oblique requested and there is some italic font, use it.
-
- // Exact match.
- // If pattern.weight < 400, weights below pattern.weight are checked
- // in descending order followed by weights above pattern.weight
- // in ascending order until a match is found.
- // If pattern.weight > 500, weights above pattern.weight are checked
- // in ascending order followed by weights below pattern.weight
- // in descending order until a match is found.
- // If pattern.weight is 400, 500 is checked first
- // and then the rule for pattern.weight < 400 is used.
- // If pattern.weight is 500, 400 is checked first
- // and then the rule for pattern.weight < 400 is used
-
- Score maxScore = { 0, 0 };
- for (int i = 0; i < fData->count(); ++i) {
- const SkFontStyle& current = fData->at(i).fFontStyle;
- Score currentScore = { 0, i };
-
- // CSS stretch. (This is the width.)
- // This has the highest priority.
- if (pattern.width() <= SkFontStyle::kNormal_Width) {
- if (current.width() <= pattern.width()) {
- currentScore.score += 10 - pattern.width() + current.width();
- } else {
- currentScore.score += 10 - current.width();
- }
- } else {
- if (current.width() > pattern.width()) {
- currentScore.score += 10 + pattern.width() - current.width();
- } else {
- currentScore.score += 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?]
-
- // The 'closer' to the target weight, the higher the score.
- // 1000 is the 'heaviest' recognized weight
- if (pattern.weight() == current.weight()) {
- currentScore.score += 1000;
- } else if (pattern.weight() <= 500) {
- if (pattern.weight() >= 400 && pattern.weight() < 450) {
- if (current.weight() >= 450 && current.weight() <= 500) {
- // Artificially boost the 500 weight.
- // TODO: determine correct number to use.
- currentScore.score += 500;
- }
- }
- if (current.weight() <= pattern.weight()) {
- currentScore.score += 1000 - pattern.weight() + current.weight();
- } else {
- currentScore.score += 1000 - current.weight();
- }
- } else if (pattern.weight() > 500) {
- if (current.weight() > pattern.weight()) {
- currentScore.score += 1000 + pattern.weight() - current.weight();
- } else {
- currentScore.score += current.weight();
- }
- }
-
- if (currentScore.score > maxScore.score) {
- maxScore = currentScore;
- }
- }
-
- return this->createTypeface(maxScore.index);
+ return this->matchStyleCSS3(pattern);
}
private:
SkAutoTUnref<const SkFontMgr_Indirect> fOwner;
« no previous file with comments | « src/core/SkFontMgr.cpp ('k') | src/ports/SkFontHost_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698