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

Unified Diff: src/core/SkTypeface.cpp

Issue 1818043002: SkTypeface::MakeFromName to take SkFontStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Address the issues. Created 4 years, 7 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 | « include/core/SkTypeface.h ('k') | src/utils/SkWhitelistTypefaces.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkTypeface.cpp
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 3c15878f737bc5c10a1d38b9d0377487300e8e38..cd80e5fb2c5e218a83c30f48c1b7a3c86c402903 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -27,7 +27,8 @@ extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* );
#define SK_TYPEFACE_DELEGATE nullptr
#endif
-sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr;
+sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char[], SkTypeface::Style) = nullptr;
+
void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE_DELEGATE;
sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
@@ -35,6 +36,19 @@ sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
namespace {
+bool UsesOnlyItalicOrBoldStyling(SkFontStyle style) {
bungeman-skia 2016/05/24 15:29:11 I would prefer not to give this a name and staying
Mikus 2016/05/25 10:57:25 Done.
+ return (style.slant() == SkFontStyle::kItalic_Slant ||
+ style.slant() == SkFontStyle::kUpright_Slant) &&
+ (style.weight() == SkFontStyle::kBold_Weight ||
+ style.weight() == SkFontStyle::kNormal_Weight);
+}
+
+SkTypeface::Style ToSkTypefaceStyle(SkFontStyle style) {
+ return static_cast<SkTypeface::Style>(
+ (style.slant() == SkFontStyle::kItalic_Slant ? SkTypeface::kItalic : SkTypeface::kNormal) |
+ (style.weight() >= SkFontStyle::kBold_Weight ? SkTypeface::kBold : SkTypeface::kNormal));
+}
+
class SkEmptyTypeface : public SkTypeface {
public:
static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
@@ -115,6 +129,7 @@ bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
///////////////////////////////////////////////////////////////////////////////
+#ifndef SK_DONT_USE_LEGACY_TYPEFACE_MAKE_FROM_NAME
bungeman-skia 2016/05/24 17:45:44 Usually we would add a define to Chromium to keep
Mikus 2016/05/25 10:57:25 Done.
sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) {
if (gCreateTypefaceDelegate) {
bungeman-skia 2016/05/24 17:45:44 Since the intent is to make this go away in the en
Mikus 2016/05/25 10:57:25 Done.
sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style);
@@ -128,6 +143,22 @@ sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style)));
}
+#endif
+
+sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[],
+ SkFontStyle fontStyle) {
+ if (gCreateTypefaceDelegate && UsesOnlyItalicOrBoldStyling(fontStyle)) {
bungeman-skia 2016/05/24 15:29:11 Far from adding to this hack, we need to make it e
Mikus 2016/05/25 10:57:25 Done.
+ sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, ToSkTypefaceStyle(fontStyle));
+ if (result) {
+ return result;
+ }
+ }
+ if (nullptr == name && UsesOnlyItalicOrBoldStyling(fontStyle)) {
+ return MakeDefault(ToSkTypefaceStyle(fontStyle));
+ }
+ SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
+ return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, fontStyle));
+}
sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) {
if (!family) {
@@ -192,7 +223,9 @@ sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) {
return typeface;
}
}
- return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle());
+
+ return SkTypeface::MakeFromName(desc.getFamilyName(),
+ SkFontStyle::FromOldStyle(desc.getStyle()));
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « include/core/SkTypeface.h ('k') | src/utils/SkWhitelistTypefaces.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698