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

Unified Diff: src/ports/SkFontMgr_custom.cpp

Issue 1915103002: Simplify style handling in custom font manager. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase. Created 4 years, 8 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_custom.cpp
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index 6401d5591432c25290f0f9b1b9825d94d61c6e58..ed5e58dd332b2cf814aa98e69808989225c604e0 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -133,12 +133,12 @@ public:
void getStyle(int index, SkFontStyle* style, SkString* name) override {
SkASSERT(index < fStyles.count());
- bool bold = fStyles[index]->isBold();
- bool italic = fStyles[index]->isItalic();
- *style = SkFontStyle(bold ? SkFontStyle::kBold_Weight : SkFontStyle::kNormal_Weight,
- SkFontStyle::kNormal_Width,
- italic ? SkFontStyle::kItalic_Slant : SkFontStyle::kUpright_Slant);
- name->reset();
+ if (style) {
+ *style = fStyles[index]->fontStyle();
+ }
+ if (name) {
+ name->reset();
+ }
}
SkTypeface* createTypeface(int index) override {
@@ -146,37 +146,8 @@ public:
return SkRef(fStyles[index].get());
}
- static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) {
- int score = 0;
- score += (pattern.width() - candidate.width()) * 100;
- score += (pattern.slant() == candidate.slant()) ? 0 : 1000;
- score += pattern.weight() - candidate.weight();
- return score;
- }
-
SkTypeface* matchStyle(const SkFontStyle& pattern) override {
- if (0 == fStyles.count()) {
- return nullptr;
- }
-
- SkTypeface_Custom* closest = fStyles[0];
- int minScore = std::numeric_limits<int>::max();
- for (int i = 0; i < fStyles.count(); ++i) {
- bool bold = fStyles[i]->isBold();
- bool italic = fStyles[i]->isItalic();
- SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight
- : SkFontStyle::kNormal_Weight,
- SkFontStyle::kNormal_Width,
- italic ? SkFontStyle::kItalic_Slant
- : SkFontStyle::kUpright_Slant);
-
- int score = match_score(pattern, style);
- if (score < minScore) {
- closest = fStyles[i];
- minScore = score;
- }
- }
- return SkRef(closest);
+ return this->matchStyleCSS3(pattern);
}
SkString getFamilyName() { return fFamilyName; }
« 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