Revert "migrate to sk_sp for SkFontMgr API"

This reverts commit 4bf296be28.

Reason for revert: need guard for flutter

Original change's description:
> migrate to sk_sp for SkFontMgr API
> 
> Bug: skia:
> Change-Id: I1bf2a13537f67938cdc9956080065d10ea0bd1d8
> Reviewed-on: https://skia-review.googlesource.com/48740
> Commit-Queue: Ben Wagner <bungeman@google.com>
> Reviewed-by: Ben Wagner <bungeman@google.com>

TBR=bungeman@google.com,reed@google.com

Change-Id: Ib0b2d00fcbcdb6131444f94d1046df6dae24f551
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/50940
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2017-09-25 20:00:31 +00:00 committed by Skia Commit-Bot
parent a3ab53b93a
commit f40ae1a4b5
17 changed files with 216 additions and 320 deletions

View File

@ -46,7 +46,8 @@ static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
// it expects to get the same glyph when following this pattern. // it expects to get the same glyph when following this pattern.
SkString familyName; SkString familyName;
typeface->getFamilyName(&familyName); typeface->getFamilyName(&familyName);
paint.setTypeface(fm->legacyMakeTypeface(familyName.c_str(), typeface->fontStyle())); paint.setTypeface(sk_sp<SkTypeface>(fm->legacyCreateTypeface(familyName.c_str(),
typeface->fontStyle())));
return drawString(canvas, ch, x, y, paint) + 20; return drawString(canvas, ch, x, y, paint) + 20;
} }

View File

@ -52,8 +52,8 @@ protected:
SkFontArguments::VariationPosition::Coordinate coordinates[] = {{tag, styleValue}}; SkFontArguments::VariationPosition::Coordinate coordinates[] = {{tag, styleValue}};
SkFontArguments::VariationPosition position = SkFontArguments::VariationPosition position =
{ coordinates, SK_ARRAY_COUNT(coordinates) }; { coordinates, SK_ARRAY_COUNT(coordinates) };
paint.setTypeface(sk_sp<SkTypeface>(fontMgr->makeFromStream( paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream(
distortable->duplicate(), distortable->duplicate().release(),
SkFontArguments().setVariationDesignPosition(position)))); SkFontArguments().setVariationDesignPosition(position))));
SkAutoCanvasRestore acr(canvas, true); SkAutoCanvasRestore acr(canvas, true);

View File

@ -95,28 +95,26 @@ public:
* or NULL if the data is not recognized. The caller must call unref() on * or NULL if the data is not recognized. The caller must call unref() on
* the returned object if it is not null. * the returned object if it is not null.
*/ */
sk_sp<SkTypeface> makeFromData(sk_sp<SkData>, int ttcIndex = 0) const; SkTypeface* createFromData(SkData*, int ttcIndex = 0) const;
/** /**
* Create a typeface for the specified stream and TTC index * Create a typeface for the specified stream and TTC index
* (pass 0 for none) or NULL if the stream is not recognized. The caller * (pass 0 for none) or NULL if the stream is not recognized. The caller
* must call unref() on the returned object if it is not null. * must call unref() on the returned object if it is not null.
*/ */
sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, int ttcIndex = 0) const; SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const;
#ifdef SK_SUPPORT_LEGACY_FONTMGR_API // deprecated, use SkFontArguments instead.
using FontParameters = SkFontArguments; using FontParameters = SkFontArguments;
#endif
/* Experimental, API subject to change. */ /* Experimental, API subject to change. */
sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&) const; SkTypeface* createFromStream(SkStreamAsset*, const SkFontArguments&) const;
/** /**
* Create a typeface from the specified font data. * Create a typeface from the specified font data.
* Will return NULL if the typeface could not be created. * Will return NULL if the typeface could not be created.
* The caller must call unref() on the returned object if it is not null. * The caller must call unref() on the returned object if it is not null.
*/ */
sk_sp<SkTypeface> makeFromFontData(std::unique_ptr<SkFontData>) const; SkTypeface* createFromFontData(std::unique_ptr<SkFontData>) const;
/** /**
* Create a typeface for the specified fileName and TTC index * Create a typeface for the specified fileName and TTC index
@ -124,18 +122,9 @@ public:
* not recognized. The caller must call unref() on the returned object * not recognized. The caller must call unref() on the returned object
* if it is not null. * if it is not null.
*/ */
sk_sp<SkTypeface> makeFromFile(const char path[], int ttcIndex = 0) const;
sk_sp<SkTypeface> legacyMakeTypeface(const char familyName[], SkFontStyle style) const;
#ifdef SK_SUPPORT_LEGACY_FONTMGR_API
SkTypeface* createFromData(SkData* data, int ttcIndex = 0) const;
SkTypeface* createFromStream(SkStreamAsset* strm, int ttcIndex = 0) const;
SkTypeface* createFromStream(SkStreamAsset* strm, const SkFontArguments& args) const;
SkTypeface* createFromFontData(std::unique_ptr<SkFontData> fd) const;
SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const; SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const;
SkTypeface* legacyCreateTypeface(const char familyName[], SkFontStyle style) const; SkTypeface* legacyCreateTypeface(const char familyName[], SkFontStyle style) const;
#endif
/** Return the default fontmgr. */ /** Return the default fontmgr. */
static sk_sp<SkFontMgr> RefDefault(); static sk_sp<SkFontMgr> RefDefault();
@ -156,38 +145,14 @@ protected:
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
const SkFontStyle&) const = 0; const SkFontStyle&) const = 0;
#ifdef SK_SUPPORT_LEGACY_FONTMGR_API virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0;
// legacy virtuals virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0;
virtual SkTypeface* onCreateFromData(SkData*, int) const { return nullptr; } // TODO: make pure virtual.
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int) const { return nullptr; }
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const SkFontArguments&) const; virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const SkFontArguments&) const;
virtual SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData>) const; virtual SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData>) const;
virtual SkTypeface* onCreateFromFile(const char[], int) const { return nullptr; } virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0;
virtual SkTypeface* onLegacyCreateTypeface(const char[], SkFontStyle) const {
return nullptr;
}
// new virtuals express as calling legacy versions virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0;
virtual sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const;
virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> strm,
int ttcIndex) const;
virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> strm,
const SkFontArguments& args) const;
virtual sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fd) const;
virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const;
virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const;
#else
virtual sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const = 0;
virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
int ttcIndex) const = 0;
virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
const SkFontArguments&) const;
virtual sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const;
virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const = 0;
virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0;
#endif
private: private:

View File

@ -50,10 +50,11 @@ protected:
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontStyle) const override; const SkFontStyle& fontStyle) const override;
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override; SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override;
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override; SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override; SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override;
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const override;
private: private:
SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const; SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;

View File

@ -49,37 +49,32 @@ protected:
return SkFontStyleSet::CreateEmpty(); return SkFontStyleSet::CreateEmpty();
} }
SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override { virtual SkTypeface* onMatchFamilyStyle(const char[],
const SkFontStyle&) const override {
return nullptr; return nullptr;
} }
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style, const SkFontStyle& style,
const char* bcp47[], const char* bcp47[],
int bcp47Count, int bcp47Count,
SkUnichar character) const override { SkUnichar character) const override {
return nullptr; return nullptr;
} }
SkTypeface* onMatchFaceStyle(const SkTypeface*, const SkFontStyle&) const override { virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
const SkFontStyle&) const override {
return nullptr; return nullptr;
} }
SkTypeface* onCreateFromData(SkData*, int) const override {
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int) const override {
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int) const override { SkTypeface* onCreateFromStream(SkStreamAsset* stream, int) const override {
delete stream;
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, SkTypeface* onCreateFromFile(const char[], int) const override {
const SkFontArguments&) const override {
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const override { SkTypeface* onLegacyCreateTypeface(const char [], SkFontStyle) const override {
return nullptr;
}
sk_sp<SkTypeface> onMakeFromFile(const char[], int) const override {
return nullptr;
}
sk_sp<SkTypeface> onLegacyMakeTypeface(const char [], SkFontStyle) const override {
return nullptr; return nullptr;
} }
}; };
@ -123,106 +118,55 @@ SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
return this->onMatchFaceStyle(face, fs); return this->onMatchFaceStyle(face, fs);
} }
sk_sp<SkTypeface> SkFontMgr::makeFromData(sk_sp<SkData> data, int ttcIndex) const { SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const {
if (nullptr == data) { if (nullptr == data) {
return nullptr; return nullptr;
} }
return this->onMakeFromData(std::move(data), ttcIndex); return this->onCreateFromData(data, ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr::makeFromStream(std::unique_ptr<SkStreamAsset> stream, SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, int ttcIndex) const {
int ttcIndex) const {
if (nullptr == stream) { if (nullptr == stream) {
return nullptr; return nullptr;
} }
return this->onMakeFromStreamIndex(std::move(stream), ttcIndex); return this->onCreateFromStream(stream, ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr::makeFromStream(std::unique_ptr<SkStreamAsset> stream, SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, const SkFontArguments& args) const {
const SkFontArguments& args) const {
if (nullptr == stream) { if (nullptr == stream) {
return nullptr; return nullptr;
} }
return this->onMakeFromStreamArgs(std::move(stream), args); return this->onCreateFromStream(stream, args);
} }
sk_sp<SkTypeface> SkFontMgr::makeFromFontData(std::unique_ptr<SkFontData> data) const { SkTypeface* SkFontMgr::createFromFontData(std::unique_ptr<SkFontData> data) const {
if (nullptr == data) { if (nullptr == data) {
return nullptr; return nullptr;
} }
return this->onMakeFromFontData(std::move(data)); return this->onCreateFromFontData(std::move(data));
} }
sk_sp<SkTypeface> SkFontMgr::makeFromFile(const char path[], int ttcIndex) const { // This implementation is temporary until it can be made pure virtual.
SkTypeface* SkFontMgr::onCreateFromStream(SkStreamAsset* stream, const SkFontArguments& args) const{
return this->createFromStream(stream, args.getCollectionIndex());
}
// This implementation is temporary until it can be made pure virtual.
SkTypeface* SkFontMgr::onCreateFromFontData(std::unique_ptr<SkFontData> data) const {
return this->createFromStream(data->detachStream().release(), data->getIndex());
}
SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const {
if (nullptr == path) { if (nullptr == path) {
return nullptr; return nullptr;
} }
return this->onMakeFromFile(path, ttcIndex); return this->onCreateFromFile(path, ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr::legacyMakeTypeface(const char familyName[], SkFontStyle style) const {
return this->onLegacyMakeTypeface(familyName, style);
}
#ifdef SK_SUPPORT_LEGACY_FONTMGR_API
SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const {
return this->makeFromData(sk_ref_sp(data), ttcIndex).release();
}
SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* strm, int ttcIndex) const {
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(strm), ttcIndex).release();
}
SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* strm, const SkFontArguments& args) const {
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(strm), args).release();
}
SkTypeface* SkFontMgr::createFromFontData(std::unique_ptr<SkFontData> fd) const {
return this->makeFromFontData(std::move(fd)).release();
}
SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const {
return this->makeFromFile(path, ttcIndex).release();
}
SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], SkFontStyle style) const { SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], SkFontStyle style) const {
return this->legacyMakeTypeface(familyName, style).release(); return this->onLegacyCreateTypeface(familyName, style);
} }
// These implementations are temporary until they can be made pure virtual.
SkTypeface* SkFontMgr::onCreateFromStream(SkStreamAsset* stream, const SkFontArguments& args) const {
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(stream),
args.getCollectionIndex()).release();
}
SkTypeface* SkFontMgr::onCreateFromFontData(std::unique_ptr<SkFontData> data) const {
return this->makeFromStream(data->detachStream(), data->getIndex()).release();
}
sk_sp<SkTypeface> SkFontMgr::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const {
return sk_sp<SkTypeface>(this->onCreateFromData(data.get(), ttcIndex));
}
sk_sp<SkTypeface> SkFontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> strm,
int ttcIndex) const {
return sk_sp<SkTypeface>(this->onCreateFromStream(strm.release(), ttcIndex));
}
sk_sp<SkTypeface> SkFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> strm,
const SkFontArguments& args) const {
return sk_sp<SkTypeface>(onCreateFromStream(strm.release(), args));
}
sk_sp<SkTypeface> SkFontMgr::onMakeFromFontData(std::unique_ptr<SkFontData> fd) const {
return sk_sp<SkTypeface>(this->onCreateFromFontData(std::move(fd)));
}
sk_sp<SkTypeface> SkFontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
return sk_sp<SkTypeface>(this->onCreateFromFile(path, ttcIndex));
}
sk_sp<SkTypeface> SkFontMgr::onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const {
return sk_sp<SkTypeface>(this->onLegacyCreateTypeface(familyName, style));
}
#else
sk_sp<SkTypeface> SkFontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
const SkFontArguments& args) const {
return this->makeFromStream(std::move(stream), args.getCollectionIndex());
}
sk_sp<SkTypeface> SkFontMgr::onMakeFromFontData(std::unique_ptr<SkFontData> data) const {
return this->makeFromStream(data->detachStream(), data->getIndex());
}
#endif
sk_sp<SkFontMgr> SkFontMgr::RefDefault() { sk_sp<SkFontMgr> SkFontMgr::RefDefault() {
static SkOnce once; static SkOnce once;
static sk_sp<SkFontMgr> singleton; static sk_sp<SkFontMgr> singleton;

View File

@ -40,7 +40,7 @@ namespace {
class SkEmptyTypeface : public SkTypeface { class SkEmptyTypeface : public SkTypeface {
public: public:
static sk_sp<SkTypeface> Make() { return sk_sp<SkTypeface>(new SkEmptyTypeface); } static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
protected: protected:
SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { } SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
@ -88,15 +88,15 @@ protected:
SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
static SkOnce once[4]; static SkOnce once[4];
static sk_sp<SkTypeface> defaults[4]; static SkTypeface* defaults[4];
SkASSERT((int)style < 4); SkASSERT((int)style < 4);
once[style]([style] { once[style]([style] {
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
auto t = fm->legacyMakeTypeface(nullptr, SkFontStyle::FromOldStyle(style)); SkTypeface* t = fm->legacyCreateTypeface(nullptr, SkFontStyle::FromOldStyle(style));
defaults[style] = t ? t : SkEmptyTypeface::Make(); defaults[style] = t ? t : SkEmptyTypeface::Create();
}); });
return defaults[style].get(); return defaults[style];
} }
sk_sp<SkTypeface> SkTypeface::MakeDefault(Style style) { sk_sp<SkTypeface> SkTypeface::MakeDefault(Style style) {
@ -135,7 +135,7 @@ sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[],
SkTypeface::kNormal))); SkTypeface::kNormal)));
} }
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->legacyMakeTypeface(name, fontStyle); return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, fontStyle));
} }
sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) { sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) {
@ -153,17 +153,17 @@ sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) {
sk_sp<SkTypeface> SkTypeface::MakeFromStream(SkStreamAsset* stream, int index) { sk_sp<SkTypeface> SkTypeface::MakeFromStream(SkStreamAsset* stream, int index) {
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->makeFromStream(std::unique_ptr<SkStreamAsset>(stream), index); return sk_sp<SkTypeface>(fm->createFromStream(stream, index));
} }
sk_sp<SkTypeface> SkTypeface::MakeFromFontData(std::unique_ptr<SkFontData> data) { sk_sp<SkTypeface> SkTypeface::MakeFromFontData(std::unique_ptr<SkFontData> data) {
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->makeFromFontData(std::move(data)); return sk_sp<SkTypeface>(fm->createFromFontData(std::move(data)));
} }
sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) { sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) {
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->makeFromFile(path, index); return sk_sp<SkTypeface>(fm->createFromFile(path, index));
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -111,7 +111,7 @@ SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& i
if (dataTypeface.get() != nullptr) { if (dataTypeface.get() != nullptr) {
std::unique_ptr<SkStreamAsset> stream(dataTypeface->openStream(nullptr)); std::unique_ptr<SkStreamAsset> stream(dataTypeface->openStream(nullptr));
if (stream.get() != nullptr) { if (stream.get() != nullptr) {
return fImpl->makeFromStream(std::move(stream), dataTypefaceIndex).release(); return fImpl->createFromStream(stream.release(), dataTypefaceIndex);
} }
} }
@ -121,7 +121,7 @@ SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& i
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> typeface(fImpl->makeFromStream(std::move(stream), id.fTtcIndex)); sk_sp<SkTypeface> typeface(fImpl->createFromStream(stream.release(), id.fTtcIndex));
if (typeface.get() == nullptr) { if (typeface.get() == nullptr) {
return nullptr; return nullptr;
} }
@ -158,20 +158,19 @@ SkTypeface* SkFontMgr_Indirect::onMatchFaceStyle(const SkTypeface* familyMember,
return this->matchFamilyStyle(familyName.c_str(), fontStyle); return this->matchFamilyStyle(familyName.c_str(), fontStyle);
} }
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* SkFontMgr_Indirect::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const {
int ttcIndex) const { return fImpl->createFromStream(stream, ttcIndex);
return fImpl->makeFromStream(std::move(stream), ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromFile(const char path[], int ttcIndex) const { SkTypeface* SkFontMgr_Indirect::onCreateFromFile(const char path[], int ttcIndex) const {
return fImpl->makeFromFile(path, ttcIndex); return fImpl->createFromFile(path, ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const { SkTypeface* SkFontMgr_Indirect::onCreateFromData(SkData* data, int ttcIndex) const {
return fImpl->makeFromData(std::move(data), ttcIndex); return fImpl->createFromData(data, ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr_Indirect::onLegacyMakeTypeface(const char familyName[], SkTypeface* SkFontMgr_Indirect::onLegacyCreateTypeface(const char familyName[],
SkFontStyle style) const { SkFontStyle style) const {
sk_sp<SkTypeface> face(this->matchFamilyStyle(familyName, style)); sk_sp<SkTypeface> face(this->matchFamilyStyle(familyName, style));
@ -184,5 +183,5 @@ sk_sp<SkTypeface> SkFontMgr_Indirect::onLegacyMakeTypeface(const char familyName
face.reset(this->createTypefaceFromFontId(fontId)); face.reset(this->createTypefaceFromFontId(fontId));
} }
return face; return face.release();
} }

View File

@ -545,7 +545,7 @@ static bool find_by_CTFontRef(SkTypeface* cached, void* context) {
} }
/** Creates a typeface, searching the cache if isLocalStream is false. */ /** Creates a typeface, searching the cache if isLocalStream is false. */
static sk_sp<SkTypeface> create_from_CTFontRef(UniqueCFRef<CTFontRef> font, static SkTypeface* create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
UniqueCFRef<CFTypeRef> resource, UniqueCFRef<CFTypeRef> resource,
bool isLocalStream) { bool isLocalStream) {
SkASSERT(font); SkASSERT(font);
@ -553,7 +553,7 @@ static sk_sp<SkTypeface> create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
if (!isLocalStream) { if (!isLocalStream) {
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (void*)font.get()); SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (void*)font.get());
if (face) { if (face) {
return sk_sp<SkTypeface>(face); return face;
} }
} }
@ -567,11 +567,11 @@ static sk_sp<SkTypeface> create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
if (!isLocalStream) { if (!isLocalStream) {
SkTypefaceCache::Add(face); SkTypefaceCache::Add(face);
} }
return sk_sp<SkTypeface>(face); return face;
} }
/** Creates a typeface from a descriptor, searching the cache. */ /** Creates a typeface from a descriptor, searching the cache. */
static sk_sp<SkTypeface> create_from_desc(CTFontDescriptorRef desc) { static SkTypeface* create_from_desc(CTFontDescriptorRef desc) {
UniqueCFRef<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, nullptr)); UniqueCFRef<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, nullptr));
if (!ctFont) { if (!ctFont) {
return nullptr; return nullptr;
@ -646,7 +646,7 @@ static UniqueCFRef<CTFontDescriptorRef> create_descriptor(const char familyName[
} }
/** Creates a typeface from a name, searching the cache. */ /** Creates a typeface from a name, searching the cache. */
static sk_sp<SkTypeface> create_from_name(const char familyName[], const SkFontStyle& style) { static SkTypeface* create_from_name(const char familyName[], const SkFontStyle& style) {
UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style); UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style);
if (!desc) { if (!desc) {
return nullptr; return nullptr;
@ -666,7 +666,7 @@ SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef font, CFTypeRef resource) {
} }
return create_from_CTFontRef(UniqueCFRef<CTFontRef>(font), return create_from_CTFontRef(UniqueCFRef<CTFontRef>(font),
UniqueCFRef<CFTypeRef>(resource), UniqueCFRef<CFTypeRef>(resource),
false).release(); false);
} }
static const char* map_css_names(const char* name) { static const char* map_css_names(const char* name) {
@ -1394,8 +1394,7 @@ void SkScalerContext_Mac::CTPathElement(void *info, const CGPathElement *element
// Returns nullptr on failure // Returns nullptr on failure
// Call must still manage its ownership of provider // Call must still manage its ownership of provider
static sk_sp<SkTypeface> create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider, static SkTypeface* create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider, int ttcIndex) {
int ttcIndex) {
if (ttcIndex != 0) { if (ttcIndex != 0) {
return nullptr; return nullptr;
} }
@ -2263,14 +2262,14 @@ public:
SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray.get())); SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray.get()));
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray.get(), index); CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray.get(), index);
return create_from_desc(desc).release(); return create_from_desc(desc);
} }
SkTypeface* matchStyle(const SkFontStyle& pattern) override { SkTypeface* matchStyle(const SkFontStyle& pattern) override {
if (0 == fCount) { if (0 == fCount) {
return nullptr; return nullptr;
} }
return create_from_desc(findMatchingDesc(pattern)).release(); return create_from_desc(findMatchingDesc(pattern));
} }
private: private:
@ -2366,7 +2365,7 @@ protected:
SkTypeface* onMatchFamilyStyle(const char familyName[], SkTypeface* onMatchFamilyStyle(const char familyName[],
const SkFontStyle& style) const override { const SkFontStyle& style) const override {
UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style); UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style);
return create_from_desc(desc.get()).release(); return create_from_desc(desc.get());
} }
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
@ -2389,7 +2388,7 @@ protected:
CFRange range = CFRangeMake(0, CFStringGetLength(string.get())); // in UniChar units. CFRange range = CFRangeMake(0, CFStringGetLength(string.get())); // in UniChar units.
UniqueCFRef<CTFontRef> fallbackFont( UniqueCFRef<CTFontRef> fallbackFont(
CTFontCreateForString(currentFont.get(), string.get(), range)); CTFontCreateForString(currentFont.get(), string.get(), range));
return create_from_CTFontRef(std::move(fallbackFont), nullptr, false).release(); return create_from_CTFontRef(std::move(fallbackFont), nullptr, false);
} }
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
@ -2397,16 +2396,16 @@ protected:
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override { SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(std::move(data))); UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(sk_ref_sp(data)));
if (!pr) { if (!pr) {
return nullptr; return nullptr;
} }
return create_from_dataProvider(std::move(pr), ttcIndex); return create_from_dataProvider(std::move(pr), ttcIndex);
} }
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
int ttcIndex) const override { std::unique_ptr<SkStreamAsset> stream(bareStream);
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::move(stream))); UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::move(stream)));
if (!pr) { if (!pr) {
return nullptr; return nullptr;
@ -2502,8 +2501,8 @@ protected:
} }
return std::move(dict); return std::move(dict);
} }
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> s, SkTypeface* onCreateFromStream(SkStreamAsset* bs, const SkFontArguments& args) const override {
const SkFontArguments& args) const override { std::unique_ptr<SkStreamAsset> s(bs);
if (args.getCollectionIndex() != 0) { if (args.getCollectionIndex() != 0) {
return nullptr; return nullptr;
} }
@ -2589,7 +2588,7 @@ protected:
} }
return std::move(dict); return std::move(dict);
} }
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fontData) const override { SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
if (fontData->getIndex() != 0) { if (fontData->getIndex() != 0) {
return nullptr; return nullptr;
} }
@ -2622,7 +2621,7 @@ protected:
return create_from_CTFontRef(std::move(ct), std::move(cg), true); return create_from_CTFontRef(std::move(ct), std::move(cg), true);
} }
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override { SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
UniqueCFRef<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(path)); UniqueCFRef<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(path));
if (!pr) { if (!pr) {
return nullptr; return nullptr;
@ -2630,12 +2629,12 @@ protected:
return create_from_dataProvider(std::move(pr), ttcIndex); return create_from_dataProvider(std::move(pr), ttcIndex);
} }
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override { SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
if (familyName) { if (familyName) {
familyName = map_css_names(familyName); familyName = map_css_names(familyName);
} }
sk_sp<SkTypeface> face = create_from_name(familyName, style); SkTypeface* face = create_from_name(familyName, style);
if (face) { if (face) {
return face; return face;
} }
@ -2644,9 +2643,9 @@ protected:
static SkOnce lookupDefault; static SkOnce lookupDefault;
static const char FONT_DEFAULT_NAME[] = "Lucida Sans"; static const char FONT_DEFAULT_NAME[] = "Lucida Sans";
lookupDefault([]{ lookupDefault([]{
gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle()).release(); gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle());
}); });
return sk_ref_sp(gDefaultFace); return SkSafeRef(gDefaultFace);
} }
}; };

View File

@ -1894,7 +1894,7 @@ static HANDLE activate_font(SkData* fontData) {
} }
// Does not affect ownership of stream. // Does not affect ownership of stream.
static sk_sp<SkTypeface> create_from_stream(std::unique_ptr<SkStreamAsset> stream) { static SkTypeface* create_from_stream(SkStreamAsset* stream) {
// Create a unique and unpredictable font name. // Create a unique and unpredictable font name.
// Avoids collisions and access from CSS. // Avoids collisions and access from CSS.
char familyName[BASE64_GUID_ID_LEN]; char familyName[BASE64_GUID_ID_LEN];
@ -1904,7 +1904,7 @@ static sk_sp<SkTypeface> create_from_stream(std::unique_ptr<SkStreamAsset> strea
} }
// Change the name of the font. // Change the name of the font.
sk_sp<SkData> rewrittenFontData(SkOTUtils::RenameFont(stream.get(), familyName, familyNameSize-1)); sk_sp<SkData> rewrittenFontData(SkOTUtils::RenameFont(stream, familyName, familyNameSize-1));
if (nullptr == rewrittenFontData.get()) { if (nullptr == rewrittenFontData.get()) {
return nullptr; return nullptr;
} }
@ -1919,7 +1919,7 @@ static sk_sp<SkTypeface> create_from_stream(std::unique_ptr<SkStreamAsset> strea
LOGFONT lf; LOGFONT lf;
logfont_for_name(familyName, &lf); logfont_for_name(familyName, &lf);
return sk_sp<SkTypeface>(SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference)); return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference);
} }
SkStreamAsset* LogFontTypeface::onOpenStream(int* ttcIndex) const { SkStreamAsset* LogFontTypeface::onOpenStream(int* ttcIndex) const {
@ -2449,27 +2449,25 @@ protected:
return this->matchFamilyStyle(familyName.c_str(), fontstyle); return this->matchFamilyStyle(familyName.c_str(), fontstyle);
} }
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
int ttcIndex) const override { std::unique_ptr<SkStreamAsset> stream(bareStream);
if (ttcIndex != 0) { if (ttcIndex != 0) {
return nullptr; return nullptr;
} }
return create_from_stream(std::move(stream)); return create_from_stream(stream.get());
} }
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override { SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
// could be in base impl // could be in base impl
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data))), return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
ttcIndex);
} }
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override { SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
// could be in base impl // could be in base impl
auto stream = SkStream::MakeFromFile(path); return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
} }
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override { SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
LOGFONT lf; LOGFONT lf;
if (nullptr == familyName) { if (nullptr == familyName) {
lf = get_default_font(); lf = get_default_font();
@ -2479,7 +2477,7 @@ protected:
lf.lfWeight = style.weight(); lf.lfWeight = style.weight();
lf.lfItalic = style.slant() == SkFontStyle::kUpright_Slant ? FALSE : TRUE; lf.lfItalic = style.slant() == SkFontStyle::kUpright_Slant ? FALSE : TRUE;
return sk_sp<SkTypeface>(SkCreateTypefaceFromLOGFONT(lf)); return SkCreateTypefaceFromLOGFONT(lf);
} }
private: private:

View File

@ -198,10 +198,10 @@ protected:
SkTypeface* onMatchFaceStyle(const SkTypeface*, SkTypeface* onMatchFaceStyle(const SkTypeface*,
const SkFontStyle&) const override { return nullptr; } const SkFontStyle&) const override { return nullptr; }
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override { return nullptr; } SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; }
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
int ttcIndex) const override { std::unique_ptr<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength(); const size_t length = stream->getLength();
if (!length) { if (!length) {
return nullptr; return nullptr;
@ -219,13 +219,12 @@ protected:
} }
auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0); auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name), return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
style, isFixedPitch));
} }
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner; using Scanner = SkTypeface_FreeType::Scanner;
std::unique_ptr<SkStreamAsset> stream(s);
const size_t length = stream->getLength(); const size_t length = stream->getLength();
if (!length) { if (!length) {
return nullptr; return nullptr;
@ -252,16 +251,15 @@ protected:
args.getCollectionIndex(), args.getCollectionIndex(),
axisValues.get(), axisValues.get(),
axisDefinitions.count()); axisDefinitions.count());
return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name), return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
style, isFixedPitch));
} }
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override { SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path); std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr; return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
} }
sk_sp<SkTypeface> onLegacyMakeTypeface(const char requestedFamilyName[], SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[],
SkFontStyle requestedStyle) const override SkFontStyle requestedStyle) const override
{ {
SkAutoMutexAcquire ama(fMutex); SkAutoMutexAcquire ama(fMutex);
@ -271,7 +269,7 @@ protected:
std::unique_ptr<Request> request(Request::Create(requestedFamilyName, requestedStyle)); std::unique_ptr<Request> request(Request::Create(requestedFamilyName, requestedStyle));
SkTypeface* face = fCache.findAndRef(request.get()); SkTypeface* face = fCache.findAndRef(request.get());
if (face) { if (face) {
return sk_sp<SkTypeface>(face); return face;
} }
SkFontConfigInterface::FontIdentity identity; SkFontConfigInterface::FontIdentity identity;
@ -293,7 +291,7 @@ protected:
// Add this request to the request cache. // Add this request to the request cache.
fCache.add(face, request.release()); fCache.add(face, request.release());
return sk_sp<SkTypeface>(face); return face;
} }
}; };

View File

@ -414,18 +414,17 @@ protected:
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override { SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data))), return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
ttcIndex);
} }
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override { SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path); std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
return stream.get() ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr; return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
} }
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
int ttcIndex) const override { std::unique_ptr<SkStreamAsset> stream(bareStream);
bool isFixedPitch; bool isFixedPitch;
SkFontStyle style; SkFontStyle style;
SkString name; SkString name;
@ -433,13 +432,12 @@ protected:
return nullptr; return nullptr;
} }
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0); auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data), return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
style, isFixedPitch, name));
} }
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner; using Scanner = SkTypeface_FreeType::Scanner;
std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch; bool isFixedPitch;
SkFontStyle style; SkFontStyle style;
SkString name; SkString name;
@ -456,11 +454,10 @@ protected:
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(), auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count()); axisValues.get(), axisDefinitions.count());
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data), return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
style, isFixedPitch, name));
} }
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> data) const override { SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override {
SkStreamAsset* stream(data->getStream()); SkStreamAsset* stream(data->getStream());
bool isFixedPitch; bool isFixedPitch;
SkFontStyle style; SkFontStyle style;
@ -468,19 +465,18 @@ protected:
if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, nullptr)) { if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, nullptr)) {
return nullptr; return nullptr;
} }
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data), return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
style, isFixedPitch, name));
} }
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override { SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
if (familyName) { if (familyName) {
// On Android, we must return nullptr when we can't find the requested // On Android, we must return nullptr when we can't find the requested
// named typeface so that the system/app can provide their own recovery // named typeface so that the system/app can provide their own recovery
// mechanism. On other platforms we'd provide a typeface from the // mechanism. On other platforms we'd provide a typeface from the
// default family instead. // default family instead.
return sk_sp<SkTypeface>(this->onMatchFamilyStyle(familyName, style)); return this->onMatchFamilyStyle(familyName, style);
} }
return sk_sp<SkTypeface>(fDefaultStyleSet->matchStyle(style)); return fDefaultStyleSet->matchStyle(style);
} }

View File

@ -192,18 +192,19 @@ SkTypeface* SkFontMgr_Custom::onMatchFaceStyle(const SkTypeface* familyMember,
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const { SkTypeface* SkFontMgr_Custom::onCreateFromData(SkData* data, int ttcIndex) const {
return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex); return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const {
int ttcIndex) const { return this->createFromStream(bareStream, FontParameters().setCollectionIndex(ttcIndex));
return this->makeFromStream(std::move(stream), SkFontArguments().setCollectionIndex(ttcIndex));
} }
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream, SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* s,
const SkFontArguments& args) const { const SkFontArguments& args) const
{
using Scanner = SkTypeface_FreeType::Scanner; using Scanner = SkTypeface_FreeType::Scanner;
std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch; bool isFixedPitch;
SkFontStyle style; SkFontStyle style;
SkString name; SkString name;
@ -220,35 +221,37 @@ sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamArgs(std::unique_ptr<SkStrea
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(), auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count()); axisValues.get(), axisDefinitions.count());
return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name)); return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
} }
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFontData(std::unique_ptr<SkFontData> data) const { SkTypeface* SkFontMgr_Custom::onCreateFromFontData(std::unique_ptr<SkFontData> data) const {
bool isFixedPitch; bool isFixedPitch;
SkFontStyle style; SkFontStyle style;
SkString name; SkString name;
if (!fScanner.scanFont(data->getStream(), data->getIndex(), if (!fScanner.scanFont(data->getStream(), data->getIndex(),
&name, &style, &isFixedPitch, nullptr)) { &name, &style, &isFixedPitch, nullptr))
{
return nullptr; return nullptr;
} }
return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name)); return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
} }
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFile(const char path[], int ttcIndex) const { SkTypeface* SkFontMgr_Custom::onCreateFromFile(const char path[], int ttcIndex) const {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path); std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr; return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
} }
sk_sp<SkTypeface> SkFontMgr_Custom::onLegacyMakeTypeface(const char familyName[], SkTypeface* SkFontMgr_Custom::onLegacyCreateTypeface(const char familyName[],
SkFontStyle style) const { SkFontStyle style) const
sk_sp<SkTypeface> tf; {
SkTypeface* tf = nullptr;
if (familyName) { if (familyName) {
tf.reset(this->onMatchFamilyStyle(familyName, style)); tf = this->onMatchFamilyStyle(familyName, style);
} }
if (nullptr == tf) { if (nullptr == tf) {
tf.reset(fDefaultFamily->matchStyle(style)); tf = fDefaultFamily->matchStyle(style);
} }
return tf; return tf;

View File

@ -142,12 +142,12 @@ protected:
SkUnichar character) const override; SkUnichar character) const override;
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontStyle) const override; const SkFontStyle& fontStyle) const override;
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override; SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override; SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override;
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, const SkFontArguments&) const override; SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override;
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> data) const override; SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override;
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override; SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override; SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override;
private: private:
Families fFamilies; Families fFamilies;

View File

@ -895,8 +895,8 @@ protected:
return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY), style); return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY), style);
} }
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
int ttcIndex) const override { std::unique_ptr<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength(); const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) { if (length <= 0 || (1u << 30) < length) {
return nullptr; return nullptr;
@ -910,13 +910,12 @@ protected:
} }
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0); auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(data), std::move(name), return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedWidth);
style, isFixedWidth));
} }
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream, SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner; using Scanner = SkTypeface_FreeType::Scanner;
std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch; bool isFixedPitch;
SkFontStyle style; SkFontStyle style;
SkString name; SkString name;
@ -933,19 +932,18 @@ protected:
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(), auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count()); axisValues.get(), axisDefinitions.count());
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(data), std::move(name), return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedPitch);
style, isFixedPitch));
} }
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override { SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex); return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
} }
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override { SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex); return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
} }
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fontData) const override { SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
SkStreamAsset* stream(fontData->getStream()); SkStreamAsset* stream(fontData->getStream());
const size_t length = stream->getLength(); const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) { if (length <= 0 || (1u << 30) < length) {
@ -960,17 +958,16 @@ protected:
return nullptr; return nullptr;
} }
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(fontData), std::move(name), return new SkTypeface_stream(std::move(fontData), std::move(name), style, isFixedWidth);
style, isFixedWidth));
} }
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override { SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
sk_sp<SkTypeface> typeface(this->matchFamilyStyle(familyName, style)); sk_sp<SkTypeface> typeface(this->matchFamilyStyle(familyName, style));
if (typeface) { if (typeface.get()) {
return typeface; return typeface.release();
} }
return sk_sp<SkTypeface>(this->matchFamilyStyle(nullptr, style)); return this->matchFamilyStyle(nullptr, style);
} }
}; };

View File

@ -12,7 +12,6 @@
#include "SkDWriteFontFileStream.h" #include "SkDWriteFontFileStream.h"
#include "SkFontMgr.h" #include "SkFontMgr.h"
#include "SkHRESULT.h" #include "SkHRESULT.h"
#include "SkMakeUnique.h"
#include "SkMutex.h" #include "SkMutex.h"
#include "SkStream.h" #include "SkStream.h"
#include "SkTScopedComPtr.h" #include "SkTScopedComPtr.h"
@ -41,9 +40,8 @@ public:
IDWriteFontFileStream** fontFileStream); IDWriteFontFileStream** fontFileStream);
// Takes ownership of stream. // Takes ownership of stream.
static HRESULT Create(std::unique_ptr<SkStreamAsset> stream, static HRESULT Create(SkStreamAsset* stream, StreamFontFileLoader** streamFontFileLoader) {
StreamFontFileLoader** streamFontFileLoader) { *streamFontFileLoader = new StreamFontFileLoader(stream);
*streamFontFileLoader = new StreamFontFileLoader(std::move(stream));
if (nullptr == *streamFontFileLoader) { if (nullptr == *streamFontFileLoader) {
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -53,9 +51,7 @@ public:
std::unique_ptr<SkStreamAsset> fStream; std::unique_ptr<SkStreamAsset> fStream;
private: private:
StreamFontFileLoader(std::unique_ptr<SkStreamAsset> stream) StreamFontFileLoader(SkStreamAsset* stream) : fStream(stream), fRefCount(1) { }
: fStream(std::move(stream)), fRefCount(1)
{}
virtual ~StreamFontFileLoader() { } virtual ~StreamFontFileLoader() { }
ULONG fRefCount; ULONG fRefCount;
@ -295,17 +291,17 @@ protected:
SkUnichar character) const override; SkUnichar character) const override;
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontstyle) const override; const SkFontStyle& fontstyle) const override;
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override; SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override;
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override; SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override; SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override; SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const override;
private: private:
HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFamily) const; HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFamily) const;
HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const;
/** Creates a typeface using a typeface cache. */ /** Creates a typeface using a typeface cache. */
sk_sp<SkTypeface> makeTypefaceFromDWriteFont(IDWriteFontFace* fontFace, SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
IDWriteFont* font, IDWriteFont* font,
IDWriteFontFamily* fontFamily) const; IDWriteFontFamily* fontFamily) const;
@ -450,7 +446,7 @@ static bool FindByDWriteFont(SkTypeface* cached, void* ctx) {
wcscmp(cshFaceName.get(), ctxFaceName.get()) == 0; wcscmp(cshFaceName.get(), ctxFaceName.get()) == 0;
} }
sk_sp<SkTypeface> SkFontMgr_DirectWrite::makeTypefaceFromDWriteFont( SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
IDWriteFontFace* fontFace, IDWriteFontFace* fontFace,
IDWriteFont* font, IDWriteFont* font,
IDWriteFontFamily* fontFamily) const { IDWriteFontFamily* fontFamily) const {
@ -463,7 +459,7 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::makeTypefaceFromDWriteFont(
fTFCache.add(face); fTFCache.add(face);
} }
} }
return sk_sp<SkTypeface>(face); return face;
} }
int SkFontMgr_DirectWrite::onCountFamilies() const { int SkFontMgr_DirectWrite::onCountFamilies() const {
@ -543,9 +539,9 @@ public:
if (exists) { if (exists) {
SkTScopedComPtr<IDWriteFontFamily> fontFamily; SkTScopedComPtr<IDWriteFontFamily> fontFamily;
HRM(font->GetFontFamily(&fontFamily), "Could not get family."); HRM(font->GetFontFamily(&fontFamily), "Could not get family.");
fResolvedTypeface = fOuter->makeTypefaceFromDWriteFont(glyphRun->fontFace, fResolvedTypeface = fOuter->createTypefaceFromDWriteFont(glyphRun->fontFace,
font.get(), font.get(),
fontFamily.get()).release(); fontFamily.get());
} }
return S_OK; return S_OK;
@ -807,7 +803,7 @@ SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family
SkTScopedComPtr<IDWriteFontFamily> fontFamily; SkTScopedComPtr<IDWriteFontFamily> fontFamily;
HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font."); HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font.");
return this->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get()).release(); return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
} }
SkTScopedComPtr<IDWriteTextFormat> fallbackFormat; SkTScopedComPtr<IDWriteTextFormat> fallbackFormat;
@ -876,11 +872,10 @@ private:
T* fUnregister; T* fUnregister;
}; };
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const {
int ttcIndex) const {
SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; SkTScopedComPtr<StreamFontFileLoader> fontFileLoader;
// This transfers ownership of stream to the new object. // This transfers ownership of stream to the new object.
HRN(StreamFontFileLoader::Create(std::move(stream), &fontFileLoader)); HRN(StreamFontFileLoader::Create(stream, &fontFileLoader));
HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get())); HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get()));
SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader(
fFactory.get(), fontFileLoader.get()); fFactory.get(), fontFileLoader.get());
@ -913,10 +908,10 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<S
UINT32 faceIndex = fontFace->GetIndex(); UINT32 faceIndex = fontFace->GetIndex();
if (faceIndex == ttcIndex) { if (faceIndex == ttcIndex) {
return sk_sp<SkTypeface>(DWriteFontTypeface::Create(fFactory.get(), return DWriteFontTypeface::Create(fFactory.get(),
fontFace.get(), font.get(), fontFamily.get(), fontFace.get(), font.get(), fontFamily.get(),
autoUnregisterFontFileLoader.detatch(), autoUnregisterFontFileLoader.detatch(),
autoUnregisterFontCollectionLoader.detatch())); autoUnregisterFontCollectionLoader.detatch());
} }
} }
} }
@ -924,12 +919,12 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<S
return nullptr; return nullptr;
} }
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const { SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) const {
return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex); return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
} }
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromFile(const char path[], int ttcIndex) const { SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIndex) const {
return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex); return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
} }
HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[], HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[],
@ -955,7 +950,7 @@ HRESULT SkFontMgr_DirectWrite::getDefaultFontFamily(IDWriteFontFamily** fontFami
return S_OK; return S_OK;
} }
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onLegacyMakeTypeface(const char familyName[], SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[],
SkFontStyle style) const { SkFontStyle style) const {
SkTScopedComPtr<IDWriteFontFamily> fontFamily; SkTScopedComPtr<IDWriteFontFamily> fontFamily;
if (familyName) { if (familyName) {
@ -984,7 +979,7 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::onLegacyMakeTypeface(const char familyN
SkTScopedComPtr<IDWriteFontFace> fontFace; SkTScopedComPtr<IDWriteFontFace> fontFace;
HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
return this->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get()); return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -1000,7 +995,7 @@ SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) {
SkTScopedComPtr<IDWriteFontFace> fontFace; SkTScopedComPtr<IDWriteFontFace> fontFace;
HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
return fFontMgr->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontFamily.get()).release(); return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontFamily.get());
} }
void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString* styleName) { void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString* styleName) {
@ -1029,8 +1024,8 @@ SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) {
SkTScopedComPtr<IDWriteFontFace> fontFace; SkTScopedComPtr<IDWriteFontFace> fontFace;
HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
return fFontMgr->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(),
fFontFamily.get()).release(); fFontFamily.get());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -109,7 +109,7 @@ DEF_TEST(TypefaceAxes, reporter) {
SkFontArguments params; SkFontArguments params;
params.setVariationDesignPosition({position, SK_ARRAY_COUNT(position)}); params.setVariationDesignPosition({position, SK_ARRAY_COUNT(position)});
// TODO: if axes are set and the back-end doesn't support them, should we create the typeface? // TODO: if axes are set and the back-end doesn't support them, should we create the typeface?
sk_sp<SkTypeface> typeface = fm->makeFromStream(std::move(distortable), params); sk_sp<SkTypeface> typeface(fm->createFromStream(distortable.release(), params));
int count = typeface->getVariationDesignPosition(nullptr, 0); int count = typeface->getVariationDesignPosition(nullptr, 0);
if (count == -1) { if (count == -1) {
@ -140,7 +140,7 @@ DEF_TEST(TypefaceVariationIndex, reporter) {
SkFontArguments params; SkFontArguments params;
// The first named variation position in Distortable is 'Thin'. // The first named variation position in Distortable is 'Thin'.
params.setCollectionIndex(0x00010000); params.setCollectionIndex(0x00010000);
sk_sp<SkTypeface> typeface = fm->makeFromStream(std::move(distortable), params); sk_sp<SkTypeface> typeface(fm->createFromStream(distortable.release(), params));
if (!typeface) { if (!typeface) {
// FreeType is the only weird thing that supports this, Skia just needs to make sure if it // FreeType is the only weird thing that supports this, Skia just needs to make sure if it
// gets one of these things make sense. // gets one of these things make sense.

View File

@ -48,7 +48,7 @@ sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
// If we called SkTypeface::CreateFromName() here we'd recurse infinitely, // If we called SkTypeface::CreateFromName() here we'd recurse infinitely,
// so we reimplement its core logic here inline without the recursive aspect. // so we reimplement its core logic here inline without the recursive aspect.
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->legacyMakeTypeface(name, style); return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, style));
} }
} else { } else {
sub = &gSubFonts[gDefaultFontIndex]; sub = &gSubFonts[gDefaultFontIndex];