diff --git a/modules/skottie/gm/ExternalProperties.cpp b/modules/skottie/gm/ExternalProperties.cpp index 786a95d0d7..0b82ba5654 100644 --- a/modules/skottie/gm/ExternalProperties.cpp +++ b/modules/skottie/gm/ExternalProperties.cpp @@ -25,14 +25,15 @@ static constexpr char kSkottieResource[] = "skottie/skottie_sample_webfont.json" // Dummy web font loader which serves a single local font (checked in under resources/). class FakeWebFontProvider final : public skresources::ResourceProvider { public: - FakeWebFontProvider() : fFontData(GetResourceAsData(kWebFontResource)) {} + FakeWebFontProvider() + : fTypeface(SkTypeface::MakeFromData(GetResourceAsData(kWebFontResource))) {} - sk_sp loadFont(const char[], const char[]) const override { - return fFontData; + sk_sp loadTypeface(const char[], const char[]) const override { + return fTypeface; } private: - sk_sp fFontData; + sk_sp fTypeface; using INHERITED = skresources::ResourceProvider; }; diff --git a/modules/skottie/gm/SkottieGM.cpp b/modules/skottie/gm/SkottieGM.cpp index 03b0b75784..6365d179b3 100644 --- a/modules/skottie/gm/SkottieGM.cpp +++ b/modules/skottie/gm/SkottieGM.cpp @@ -25,14 +25,15 @@ static constexpr char kSkottieResource[] = "skottie/skottie_sample_webfont.json" // Dummy web font loader which serves a single local font (checked in under resources/). class FakeWebFontProvider final : public skresources::ResourceProvider { public: - FakeWebFontProvider() : fFontData(GetResourceAsData(kWebFontResource)) {} + FakeWebFontProvider() + : fTypeface(SkTypeface::MakeFromData(GetResourceAsData(kWebFontResource))) {} - sk_sp loadFont(const char[], const char[]) const override { - return fFontData; + sk_sp loadTypeface(const char[], const char[]) const override { + return fTypeface; } private: - sk_sp fFontData; + sk_sp fTypeface; using INHERITED = skresources::ResourceProvider; }; diff --git a/modules/skottie/src/layers/TextLayer.cpp b/modules/skottie/src/layers/TextLayer.cpp index 633b0c8254..35e9dfe9ca 100644 --- a/modules/skottie/src/layers/TextLayer.cpp +++ b/modules/skottie/src/layers/TextLayer.cpp @@ -263,8 +263,14 @@ bool AnimationBuilder::resolveNativeTypefaces() { // 2) system font (family/style) // 3) system default - finfo->fTypeface = - fmgr->makeFromData(fResourceProvider->loadFont(name.c_str(), finfo->fPath.c_str())); + finfo->fTypeface = fResourceProvider->loadTypeface(name.c_str(), finfo->fPath.c_str()); + + // legacy API fallback + // TODO: remove after client migration + if (!finfo->fTypeface) { + finfo->fTypeface = fmgr->makeFromData( + fResourceProvider->loadFont(name.c_str(), finfo->fPath.c_str())); + } if (!finfo->fTypeface) { finfo->fTypeface.reset(fmgr->matchFamilyStyle(finfo->fFamily.c_str(), diff --git a/modules/skresources/include/SkResources.h b/modules/skresources/include/SkResources.h index 3a5769d900..c5bdb81dfa 100644 --- a/modules/skresources/include/SkResources.h +++ b/modules/skresources/include/SkResources.h @@ -11,6 +11,7 @@ #include "include/core/SkData.h" #include "include/core/SkRefCnt.h" #include "include/core/SkString.h" +#include "include/core/SkTypeface.h" #include "include/core/SkTypes.h" #include "include/private/SkMutex.h" #include "include/private/SkTHash.h" @@ -96,6 +97,8 @@ public: } /** + * DEPRECATED: implement loadTypeface() instead. + * * Load an external font and return as SkData. * * @param name font name ("fName" Lottie property) @@ -112,6 +115,17 @@ public: const char[] /* url */) const { return nullptr; } + + /** + * Load an external font and return as SkTypeface. + * + * @param name font name + * @param url web font URL + */ + virtual sk_sp loadTypeface(const char[] /* name */, + const char[] /* url */) const { + return nullptr; + } }; class FileResourceProvider final : public ResourceProvider { @@ -137,7 +151,7 @@ protected: sk_sp load(const char[], const char[]) const override; sk_sp loadImageAsset(const char[], const char[], const char[]) const override; - sk_sp loadFont(const char[], const char[]) const override; + sk_sp loadTypeface(const char[], const char[]) const override; private: const sk_sp fProxy; diff --git a/modules/skresources/src/SkResources.cpp b/modules/skresources/src/SkResources.cpp index 1d3e710c3f..8934fd40e2 100644 --- a/modules/skresources/src/SkResources.cpp +++ b/modules/skresources/src/SkResources.cpp @@ -196,8 +196,9 @@ sk_sp ResourceProviderProxyBase::loadImageAsset(const char rpath[], : nullptr; } -sk_sp ResourceProviderProxyBase::loadFont(const char name[], const char url[]) const { - return fProxy ? fProxy->loadFont(name, url) +sk_sp ResourceProviderProxyBase::loadTypeface(const char name[], + const char url[]) const { + return fProxy ? fProxy->loadTypeface(name, url) : nullptr; }