aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2018-06-06 11:02:07 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-07 19:32:11 +0000
commitc174cc675cbc190c43372d53fb89711663ac945f (patch)
tree262fbd45c6b60bd465e86da2e0952111065da59e
parent61201641383dada029f79be4df98d925efc1a827 (diff)
Add SkTypeface::makeClone.
This adds an method to typeface to allow users to create a copy of the typeface with different arguments for its parameters. This is far more efficient when animating a variation font. BUG=skia:7121 Change-Id: I34e7557a08c7005f8149ea44f0c28de9c59d15a7 Reviewed-on: https://skia-review.googlesource.com/132480 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Reed <reed@google.com>
-rw-r--r--include/core/SkTypeface.h10
-rw-r--r--src/core/SkTypeface.cpp8
2 files changed, 18 insertions, 0 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 665491c3db..4118152dea 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -117,6 +117,14 @@ public:
*/
static sk_sp<SkTypeface> MakeFromFontData(std::unique_ptr<SkFontData>);
+ /** Return a new typeface based on this typeface but parameterized as specified in the
+ SkFontArguments. If the SkFontArguments does not supply an argument for a parameter
+ in the font then the value from this typeface will be used as the value for that
+ argument. If the cloned typeface would be exaclty the same as this typeface then
+ this typeface may be ref'ed and returned. May return nullptr on failure.
+ */
+ sk_sp<SkTypeface> makeClone(const SkFontArguments&) const;
+
/** Write a unique signature to a stream, sufficient to reconstruct a
typeface referencing the same font when Deserialize is called.
*/
@@ -301,6 +309,8 @@ protected:
SkTypeface(const SkFontStyle& style, bool isFixedPitch = false);
virtual ~SkTypeface();
+ virtual sk_sp<SkTypeface> onMakeClone(const SkFontArguments&) const;
+
/** Sets the fixedPitch bit. If used, must be called in the constructor. */
void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; }
/** Sets the font style. If used, must be called in the constructor. */
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 92c8c09e33..a59075b908 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -161,6 +161,10 @@ sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) {
return fm->makeFromFile(path, index);
}
+sk_sp<SkTypeface> SkTypeface::makeClone(const SkFontArguments& args) const {
+ return this->onMakeClone(args);
+}
+
///////////////////////////////////////////////////////////////////////////////
void SkTypeface::serialize(SkWStream* wstream) const {
@@ -321,6 +325,10 @@ bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
return false;
}
+sk_sp<SkTypeface> SkTypeface::onMakeClone(const SkFontArguments& args) const {
+ return sk_ref_sp(this);
+}
+
///////////////////////////////////////////////////////////////////////////////
#include "SkDescriptor.h"