aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkFontMgr_android.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-08-18 14:36:02 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-18 14:36:02 -0700
commit0367568d4af6a8ffd75bfd07bcb0172fef415940 (patch)
tree14bee060d31641433472ca447e6c4b2e491f1845 /src/ports/SkFontMgr_android.cpp
parent7fc08585d0d4daada1c8600b6cdef970ee6c2369 (diff)
Use CSS3 style matching on Android.
Android framework doesn't really use this, the largest user is Chromium. At the moment this doesn't resolve oblique requests in a nice way, but the existing code is somewhat close to CSS3 rules already. Instead of adding oblique handling manually, just use the existing CSS3 style matching. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2256843003 Review-Url: https://codereview.chromium.org/2256843003
Diffstat (limited to 'src/ports/SkFontMgr_android.cpp')
-rw-r--r--src/ports/SkFontMgr_android.cpp32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 94d114d07a..56c1413338 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;