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

Unified Diff: sky/engine/platform/fonts/skia/FontCacheSkia.cpp

Issue 1017563002: Sky shouldn't round font weights (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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: sky/engine/platform/fonts/skia/FontCacheSkia.cpp
diff --git a/sky/engine/platform/fonts/skia/FontCacheSkia.cpp b/sky/engine/platform/fonts/skia/FontCacheSkia.cpp
index 2654ba85b9ff35453b4a51b0fe81302c096f53aa..b5cec4f182bb93c47233f19476b213bad31ed253 100644
--- a/sky/engine/platform/fonts/skia/FontCacheSkia.cpp
+++ b/sky/engine/platform/fonts/skia/FontCacheSkia.cpp
@@ -69,6 +69,56 @@ static tmp::StreamType streamForFontconfigInterfaceId(int fontconfigInterfaceId)
namespace blink {
+static int toSkiaWeight(FontWeight weight)
+{
+ switch (weight) {
+ case FontWeight100:
+ return 100;
+ case FontWeight200:
+ return 200;
+ case FontWeight300:
+ return 300;
+ case FontWeight400:
+ return 400;
+ case FontWeight500:
+ return 500;
+ case FontWeight600:
+ return 600;
+ case FontWeight700:
+ return 700;
+ case FontWeight800:
+ return 800;
+ case FontWeight900:
+ return 900;
+ }
+ ASSERT_NOT_REACHED();
+ return 400;
+}
+
+static SkFontStyle::Slant toSkiaSlant(FontStyle style)
+{
+ switch (style) {
+ case FontStyleNormal:
+ return SkFontStyle::kUpright_Slant;
+ case FontStyleItalic:
+ return SkFontStyle::kItalic_Slant;
+ }
+ ASSERT_NOT_REACHED();
+ return SkFontStyle::kUpright_Slant;
+}
+
+static int toSkiaWidth(FontStretch stretch)
+{
+ return static_cast<int>(stretch);
eseidel 2015/03/16 23:57:54 I still might add a one-line comment.
+}
+
+static SkFontStyle toSkiaFontStyle(const FontDescription& fontDescription)
+{
+ return SkFontStyle(toSkiaWeight(fontDescription.weight()),
+ toSkiaWidth(fontDescription.stretch()),
+ toSkiaSlant(fontDescription.style()));
+}
+
void FontCache::platformInit()
{
}
@@ -190,15 +240,8 @@ PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc
name = family.utf8();
}
- int style = SkTypeface::kNormal;
- if (fontDescription.weight() >= FontWeight600)
- style |= SkTypeface::kBold;
- if (fontDescription.style())
- style |= SkTypeface::kItalic;
-
- // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of
- // CreateFromName on all platforms.
- return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypeface::Style>(style)));
+ RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
+ return adoptRef(fm->matchFamilyStyle(name.data(), toSkiaFontStyle(fontDescription)));
}
#if !OS(WIN)
« 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