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

Unified Diff: src/ports/SkFontMgr_android.cpp

Issue 2256843003: Use CSS3 style matching on Android. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontMgr_android.cpp
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 94d114d07a48bd2e78f3c251afac0d4e0aa9272b..56c14133384d02b09637d6fe184cd5f4a2f1c662 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -217,7 +217,7 @@ public:
return;
}
if (style) {
- *style = this->style(index);
+ *style = fStyles[index]->fontStyle();
}
if (name) {
name->reset();
@@ -230,39 +230,11 @@ public:
return SkRef(fStyles[index].get());
}
- /** Find the typeface in this style set that most closely matches the given pattern.
- * TODO: consider replacing with SkStyleSet_Indirect::matchStyle();
- * this simpler version using match_score() passes all our tests.
- */
SkTypeface_AndroidSystem* matchStyle(const SkFontStyle& pattern) override {
- if (0 == fStyles.count()) {
- return nullptr;
- }
- SkTypeface_AndroidSystem* closest = fStyles[0];
- int minScore = std::numeric_limits<int>::max();
- for (int i = 0; i < fStyles.count(); ++i) {
- SkFontStyle style = this->style(i);
- int score = match_score(pattern, style);
- if (score < minScore) {
- closest = fStyles[i];
- minScore = score;
- }
- }
- return SkRef(closest);
+ return static_cast<SkTypeface_AndroidSystem*>(this->matchStyleCSS3(pattern));
}
private:
- SkFontStyle style(int index) {
- return fStyles[index]->fontStyle();
- }
- static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) {
- int score = 0;
- score += SkTAbs((pattern.width() - candidate.width()) * 100);
- score += SkTAbs((pattern.slant() == candidate.slant()) ? 0 : 1000);
- score += SkTAbs(pattern.weight() - candidate.weight());
- return score;
- }
-
SkTArray<SkAutoTUnref<SkTypeface_AndroidSystem>, true> fStyles;
friend struct NameToFamily;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698