Revert "Revert "migrate to sk_sp for SkFontMgr API""
This reverts commit f40ae1a4b5
.
Bug: skia:
Change-Id: I752606de92ea405d6e50219c98030409b00a2841
Reviewed-on: https://skia-review.googlesource.com/51160
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
f6f7cf6098
commit
592273965a
@ -46,8 +46,7 @@ static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
|
||||
// it expects to get the same glyph when following this pattern.
|
||||
SkString familyName;
|
||||
typeface->getFamilyName(&familyName);
|
||||
paint.setTypeface(sk_sp<SkTypeface>(fm->legacyCreateTypeface(familyName.c_str(),
|
||||
typeface->fontStyle())));
|
||||
paint.setTypeface(fm->legacyMakeTypeface(familyName.c_str(), typeface->fontStyle()));
|
||||
return drawString(canvas, ch, x, y, paint) + 20;
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,8 @@ protected:
|
||||
SkFontArguments::VariationPosition::Coordinate coordinates[] = {{tag, styleValue}};
|
||||
SkFontArguments::VariationPosition position =
|
||||
{ coordinates, SK_ARRAY_COUNT(coordinates) };
|
||||
paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream(
|
||||
distortable->duplicate().release(),
|
||||
paint.setTypeface(sk_sp<SkTypeface>(fontMgr->makeFromStream(
|
||||
distortable->duplicate(),
|
||||
SkFontArguments().setVariationDesignPosition(position))));
|
||||
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
|
@ -2,4 +2,7 @@
|
||||
#
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
flutter_defines = [ "SK_SUPPORT_LEGACY_IMAGE_ENCODE_API" ]
|
||||
flutter_defines = [
|
||||
"SK_SUPPORT_LEGACY_IMAGE_ENCODE_API",
|
||||
"SK_SUPPORT_LEGACY_FONTMGR_API",
|
||||
]
|
||||
|
@ -95,26 +95,28 @@ public:
|
||||
* or NULL if the data is not recognized. The caller must call unref() on
|
||||
* the returned object if it is not null.
|
||||
*/
|
||||
SkTypeface* createFromData(SkData*, int ttcIndex = 0) const;
|
||||
sk_sp<SkTypeface> makeFromData(sk_sp<SkData>, int ttcIndex = 0) const;
|
||||
|
||||
/**
|
||||
* Create a typeface for the specified stream and TTC index
|
||||
* (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.
|
||||
*/
|
||||
SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const;
|
||||
sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, int ttcIndex = 0) const;
|
||||
|
||||
// deprecated, use SkFontArguments instead.
|
||||
#ifdef SK_SUPPORT_LEGACY_FONTMGR_API
|
||||
using FontParameters = SkFontArguments;
|
||||
#endif
|
||||
|
||||
/* Experimental, API subject to change. */
|
||||
SkTypeface* createFromStream(SkStreamAsset*, const SkFontArguments&) const;
|
||||
sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&) const;
|
||||
|
||||
/**
|
||||
* Create a typeface from the specified font data.
|
||||
* Will return NULL if the typeface could not be created.
|
||||
* The caller must call unref() on the returned object if it is not null.
|
||||
*/
|
||||
SkTypeface* createFromFontData(std::unique_ptr<SkFontData>) const;
|
||||
sk_sp<SkTypeface> makeFromFontData(std::unique_ptr<SkFontData>) const;
|
||||
|
||||
/**
|
||||
* Create a typeface for the specified fileName and TTC index
|
||||
@ -122,9 +124,18 @@ public:
|
||||
* not recognized. The caller must call unref() on the returned object
|
||||
* if it is not null.
|
||||
*/
|
||||
SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const;
|
||||
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* legacyCreateTypeface(const char familyName[], SkFontStyle style) const;
|
||||
#endif
|
||||
|
||||
/** Return the default fontmgr. */
|
||||
static sk_sp<SkFontMgr> RefDefault();
|
||||
@ -145,14 +156,38 @@ protected:
|
||||
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
||||
const SkFontStyle&) const = 0;
|
||||
|
||||
virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0;
|
||||
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0;
|
||||
// TODO: make pure virtual.
|
||||
#ifdef SK_SUPPORT_LEGACY_FONTMGR_API
|
||||
// legacy virtuals
|
||||
virtual SkTypeface* onCreateFromData(SkData*, int) const { return nullptr; }
|
||||
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int) const { return nullptr; }
|
||||
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const SkFontArguments&) const;
|
||||
virtual SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData>) const;
|
||||
virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0;
|
||||
virtual SkTypeface* onCreateFromFile(const char[], int) const { return nullptr; }
|
||||
virtual SkTypeface* onLegacyCreateTypeface(const char[], SkFontStyle) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0;
|
||||
// new virtuals express as calling legacy versions
|
||||
|
||||
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:
|
||||
|
||||
|
@ -50,11 +50,10 @@ protected:
|
||||
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
||||
const SkFontStyle& fontStyle) const override;
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override;
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
|
||||
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
|
||||
|
||||
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const override;
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override;
|
||||
|
||||
private:
|
||||
SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;
|
||||
|
@ -49,32 +49,37 @@ protected:
|
||||
return SkFontStyleSet::CreateEmpty();
|
||||
}
|
||||
|
||||
virtual SkTypeface* onMatchFamilyStyle(const char[],
|
||||
const SkFontStyle&) const override {
|
||||
SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override {
|
||||
return nullptr;
|
||||
}
|
||||
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
||||
const SkFontStyle& style,
|
||||
const char* bcp47[],
|
||||
int bcp47Count,
|
||||
SkUnichar character) const override {
|
||||
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
||||
const SkFontStyle& style,
|
||||
const char* bcp47[],
|
||||
int bcp47Count,
|
||||
SkUnichar character) const override {
|
||||
return nullptr;
|
||||
}
|
||||
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
||||
const SkFontStyle&) const override {
|
||||
SkTypeface* onMatchFaceStyle(const SkTypeface*, const SkFontStyle&) const override {
|
||||
return nullptr;
|
||||
}
|
||||
SkTypeface* onCreateFromData(SkData*, int) const override {
|
||||
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int) const override {
|
||||
return nullptr;
|
||||
}
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* stream, int) const override {
|
||||
delete stream;
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int) const override {
|
||||
return nullptr;
|
||||
}
|
||||
SkTypeface* onCreateFromFile(const char[], int) const override {
|
||||
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
|
||||
const SkFontArguments&) const override {
|
||||
return nullptr;
|
||||
}
|
||||
SkTypeface* onLegacyCreateTypeface(const char [], SkFontStyle) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) 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;
|
||||
}
|
||||
};
|
||||
@ -118,55 +123,106 @@ SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
|
||||
return this->onMatchFaceStyle(face, fs);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const {
|
||||
sk_sp<SkTypeface> SkFontMgr::makeFromData(sk_sp<SkData> data, int ttcIndex) const {
|
||||
if (nullptr == data) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->onCreateFromData(data, ttcIndex);
|
||||
return this->onMakeFromData(std::move(data), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, int ttcIndex) const {
|
||||
sk_sp<SkTypeface> SkFontMgr::makeFromStream(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const {
|
||||
if (nullptr == stream) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->onCreateFromStream(stream, ttcIndex);
|
||||
return this->onMakeFromStreamIndex(std::move(stream), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, const SkFontArguments& args) const {
|
||||
sk_sp<SkTypeface> SkFontMgr::makeFromStream(std::unique_ptr<SkStreamAsset> stream,
|
||||
const SkFontArguments& args) const {
|
||||
if (nullptr == stream) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->onCreateFromStream(stream, args);
|
||||
return this->onMakeFromStreamArgs(std::move(stream), args);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr::createFromFontData(std::unique_ptr<SkFontData> data) const {
|
||||
sk_sp<SkTypeface> SkFontMgr::makeFromFontData(std::unique_ptr<SkFontData> data) const {
|
||||
if (nullptr == data) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->onCreateFromFontData(std::move(data));
|
||||
return this->onMakeFromFontData(std::move(data));
|
||||
}
|
||||
|
||||
// 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 {
|
||||
sk_sp<SkTypeface> SkFontMgr::makeFromFile(const char path[], int ttcIndex) const {
|
||||
if (nullptr == path) {
|
||||
return nullptr;
|
||||
}
|
||||
return this->onCreateFromFile(path, ttcIndex);
|
||||
return this->onMakeFromFile(path, ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], SkFontStyle style) const {
|
||||
return this->onLegacyCreateTypeface(familyName, style);
|
||||
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 {
|
||||
return this->legacyMakeTypeface(familyName, style).release();
|
||||
}
|
||||
|
||||
// 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() {
|
||||
static SkOnce once;
|
||||
static sk_sp<SkFontMgr> singleton;
|
||||
|
@ -40,7 +40,7 @@ namespace {
|
||||
|
||||
class SkEmptyTypeface : public SkTypeface {
|
||||
public:
|
||||
static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
|
||||
static sk_sp<SkTypeface> Make() { return sk_sp<SkTypeface>(new SkEmptyTypeface); }
|
||||
protected:
|
||||
SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
|
||||
|
||||
@ -88,15 +88,15 @@ protected:
|
||||
|
||||
SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
|
||||
static SkOnce once[4];
|
||||
static SkTypeface* defaults[4];
|
||||
static sk_sp<SkTypeface> defaults[4];
|
||||
|
||||
SkASSERT((int)style < 4);
|
||||
once[style]([style] {
|
||||
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
|
||||
SkTypeface* t = fm->legacyCreateTypeface(nullptr, SkFontStyle::FromOldStyle(style));
|
||||
defaults[style] = t ? t : SkEmptyTypeface::Create();
|
||||
auto t = fm->legacyMakeTypeface(nullptr, SkFontStyle::FromOldStyle(style));
|
||||
defaults[style] = t ? t : SkEmptyTypeface::Make();
|
||||
});
|
||||
return defaults[style];
|
||||
return defaults[style].get();
|
||||
}
|
||||
|
||||
sk_sp<SkTypeface> SkTypeface::MakeDefault(Style style) {
|
||||
@ -135,7 +135,7 @@ sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[],
|
||||
SkTypeface::kNormal)));
|
||||
}
|
||||
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
|
||||
return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, fontStyle));
|
||||
return fm->legacyMakeTypeface(name, fontStyle);
|
||||
}
|
||||
|
||||
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<SkFontMgr> fm(SkFontMgr::RefDefault());
|
||||
return sk_sp<SkTypeface>(fm->createFromStream(stream, index));
|
||||
return fm->makeFromStream(std::unique_ptr<SkStreamAsset>(stream), index);
|
||||
}
|
||||
|
||||
sk_sp<SkTypeface> SkTypeface::MakeFromFontData(std::unique_ptr<SkFontData> data) {
|
||||
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
|
||||
return sk_sp<SkTypeface>(fm->createFromFontData(std::move(data)));
|
||||
return fm->makeFromFontData(std::move(data));
|
||||
}
|
||||
|
||||
sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) {
|
||||
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
|
||||
return sk_sp<SkTypeface>(fm->createFromFile(path, index));
|
||||
return fm->makeFromFile(path, index);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -111,7 +111,7 @@ SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& i
|
||||
if (dataTypeface.get() != nullptr) {
|
||||
std::unique_ptr<SkStreamAsset> stream(dataTypeface->openStream(nullptr));
|
||||
if (stream.get() != nullptr) {
|
||||
return fImpl->createFromStream(stream.release(), dataTypefaceIndex);
|
||||
return fImpl->makeFromStream(std::move(stream), dataTypefaceIndex).release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& i
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkTypeface> typeface(fImpl->createFromStream(stream.release(), id.fTtcIndex));
|
||||
sk_sp<SkTypeface> typeface(fImpl->makeFromStream(std::move(stream), id.fTtcIndex));
|
||||
if (typeface.get() == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -158,20 +158,21 @@ SkTypeface* SkFontMgr_Indirect::onMatchFaceStyle(const SkTypeface* familyMember,
|
||||
return this->matchFamilyStyle(familyName.c_str(), fontStyle);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Indirect::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const {
|
||||
return fImpl->createFromStream(stream, ttcIndex);
|
||||
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const {
|
||||
return fImpl->makeFromStream(std::move(stream), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Indirect::onCreateFromFile(const char path[], int ttcIndex) const {
|
||||
return fImpl->createFromFile(path, ttcIndex);
|
||||
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromFile(const char path[], int ttcIndex) const {
|
||||
return fImpl->makeFromFile(path, ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Indirect::onCreateFromData(SkData* data, int ttcIndex) const {
|
||||
return fImpl->createFromData(data, ttcIndex);
|
||||
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const {
|
||||
return fImpl->makeFromData(std::move(data), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Indirect::onLegacyCreateTypeface(const char familyName[],
|
||||
SkFontStyle style) const {
|
||||
sk_sp<SkTypeface> SkFontMgr_Indirect::onLegacyMakeTypeface(const char familyName[],
|
||||
SkFontStyle style) const {
|
||||
sk_sp<SkTypeface> face(this->matchFamilyStyle(familyName, style));
|
||||
|
||||
if (nullptr == face.get()) {
|
||||
@ -183,5 +184,5 @@ SkTypeface* SkFontMgr_Indirect::onLegacyCreateTypeface(const char familyName[],
|
||||
face.reset(this->createTypefaceFromFontId(fontId));
|
||||
}
|
||||
|
||||
return face.release();
|
||||
return face;
|
||||
}
|
||||
|
@ -545,15 +545,15 @@ static bool find_by_CTFontRef(SkTypeface* cached, void* context) {
|
||||
}
|
||||
|
||||
/** Creates a typeface, searching the cache if isLocalStream is false. */
|
||||
static SkTypeface* create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
|
||||
UniqueCFRef<CFTypeRef> resource,
|
||||
bool isLocalStream) {
|
||||
static sk_sp<SkTypeface> create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
|
||||
UniqueCFRef<CFTypeRef> resource,
|
||||
bool isLocalStream) {
|
||||
SkASSERT(font);
|
||||
|
||||
if (!isLocalStream) {
|
||||
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (void*)font.get());
|
||||
if (face) {
|
||||
return face;
|
||||
return sk_sp<SkTypeface>(face);
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,11 +567,11 @@ static SkTypeface* create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
|
||||
if (!isLocalStream) {
|
||||
SkTypefaceCache::Add(face);
|
||||
}
|
||||
return face;
|
||||
return sk_sp<SkTypeface>(face);
|
||||
}
|
||||
|
||||
/** Creates a typeface from a descriptor, searching the cache. */
|
||||
static SkTypeface* create_from_desc(CTFontDescriptorRef desc) {
|
||||
static sk_sp<SkTypeface> create_from_desc(CTFontDescriptorRef desc) {
|
||||
UniqueCFRef<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, nullptr));
|
||||
if (!ctFont) {
|
||||
return nullptr;
|
||||
@ -646,7 +646,7 @@ static UniqueCFRef<CTFontDescriptorRef> create_descriptor(const char familyName[
|
||||
}
|
||||
|
||||
/** Creates a typeface from a name, searching the cache. */
|
||||
static SkTypeface* create_from_name(const char familyName[], const SkFontStyle& style) {
|
||||
static sk_sp<SkTypeface> create_from_name(const char familyName[], const SkFontStyle& style) {
|
||||
UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style);
|
||||
if (!desc) {
|
||||
return nullptr;
|
||||
@ -666,7 +666,7 @@ SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef font, CFTypeRef resource) {
|
||||
}
|
||||
return create_from_CTFontRef(UniqueCFRef<CTFontRef>(font),
|
||||
UniqueCFRef<CFTypeRef>(resource),
|
||||
false);
|
||||
false).release();
|
||||
}
|
||||
|
||||
static const char* map_css_names(const char* name) {
|
||||
@ -1394,7 +1394,8 @@ void SkScalerContext_Mac::CTPathElement(void *info, const CGPathElement *element
|
||||
|
||||
// Returns nullptr on failure
|
||||
// Call must still manage its ownership of provider
|
||||
static SkTypeface* create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider, int ttcIndex) {
|
||||
static sk_sp<SkTypeface> create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider,
|
||||
int ttcIndex) {
|
||||
if (ttcIndex != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -2262,14 +2263,14 @@ public:
|
||||
SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray.get()));
|
||||
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray.get(), index);
|
||||
|
||||
return create_from_desc(desc);
|
||||
return create_from_desc(desc).release();
|
||||
}
|
||||
|
||||
SkTypeface* matchStyle(const SkFontStyle& pattern) override {
|
||||
if (0 == fCount) {
|
||||
return nullptr;
|
||||
}
|
||||
return create_from_desc(findMatchingDesc(pattern));
|
||||
return create_from_desc(findMatchingDesc(pattern)).release();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2365,7 +2366,7 @@ protected:
|
||||
SkTypeface* onMatchFamilyStyle(const char familyName[],
|
||||
const SkFontStyle& style) const override {
|
||||
UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style);
|
||||
return create_from_desc(desc.get());
|
||||
return create_from_desc(desc.get()).release();
|
||||
}
|
||||
|
||||
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
||||
@ -2388,7 +2389,7 @@ protected:
|
||||
CFRange range = CFRangeMake(0, CFStringGetLength(string.get())); // in UniChar units.
|
||||
UniqueCFRef<CTFontRef> fallbackFont(
|
||||
CTFontCreateForString(currentFont.get(), string.get(), range));
|
||||
return create_from_CTFontRef(std::move(fallbackFont), nullptr, false);
|
||||
return create_from_CTFontRef(std::move(fallbackFont), nullptr, false).release();
|
||||
}
|
||||
|
||||
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
||||
@ -2396,16 +2397,16 @@ protected:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
|
||||
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(sk_ref_sp(data)));
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
|
||||
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(std::move(data)));
|
||||
if (!pr) {
|
||||
return nullptr;
|
||||
}
|
||||
return create_from_dataProvider(std::move(pr), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
|
||||
std::unique_ptr<SkStreamAsset> stream(bareStream);
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const override {
|
||||
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::move(stream)));
|
||||
if (!pr) {
|
||||
return nullptr;
|
||||
@ -2501,8 +2502,8 @@ protected:
|
||||
}
|
||||
return std::move(dict);
|
||||
}
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* bs, const SkFontArguments& args) const override {
|
||||
std::unique_ptr<SkStreamAsset> s(bs);
|
||||
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> s,
|
||||
const SkFontArguments& args) const override {
|
||||
if (args.getCollectionIndex() != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -2588,7 +2589,7 @@ protected:
|
||||
}
|
||||
return std::move(dict);
|
||||
}
|
||||
SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fontData) const override {
|
||||
if (fontData->getIndex() != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -2621,7 +2622,7 @@ protected:
|
||||
return create_from_CTFontRef(std::move(ct), std::move(cg), true);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
|
||||
UniqueCFRef<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(path));
|
||||
if (!pr) {
|
||||
return nullptr;
|
||||
@ -2629,12 +2630,12 @@ protected:
|
||||
return create_from_dataProvider(std::move(pr), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
if (familyName) {
|
||||
familyName = map_css_names(familyName);
|
||||
}
|
||||
|
||||
SkTypeface* face = create_from_name(familyName, style);
|
||||
sk_sp<SkTypeface> face = create_from_name(familyName, style);
|
||||
if (face) {
|
||||
return face;
|
||||
}
|
||||
@ -2643,9 +2644,9 @@ protected:
|
||||
static SkOnce lookupDefault;
|
||||
static const char FONT_DEFAULT_NAME[] = "Lucida Sans";
|
||||
lookupDefault([]{
|
||||
gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle());
|
||||
gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle()).release();
|
||||
});
|
||||
return SkSafeRef(gDefaultFace);
|
||||
return sk_ref_sp(gDefaultFace);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1894,7 +1894,7 @@ static HANDLE activate_font(SkData* fontData) {
|
||||
}
|
||||
|
||||
// Does not affect ownership of stream.
|
||||
static SkTypeface* create_from_stream(SkStreamAsset* stream) {
|
||||
static sk_sp<SkTypeface> create_from_stream(std::unique_ptr<SkStreamAsset> stream) {
|
||||
// Create a unique and unpredictable font name.
|
||||
// Avoids collisions and access from CSS.
|
||||
char familyName[BASE64_GUID_ID_LEN];
|
||||
@ -1904,7 +1904,7 @@ static SkTypeface* create_from_stream(SkStreamAsset* stream) {
|
||||
}
|
||||
|
||||
// Change the name of the font.
|
||||
sk_sp<SkData> rewrittenFontData(SkOTUtils::RenameFont(stream, familyName, familyNameSize-1));
|
||||
sk_sp<SkData> rewrittenFontData(SkOTUtils::RenameFont(stream.get(), familyName, familyNameSize-1));
|
||||
if (nullptr == rewrittenFontData.get()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -1919,7 +1919,7 @@ static SkTypeface* create_from_stream(SkStreamAsset* stream) {
|
||||
LOGFONT lf;
|
||||
logfont_for_name(familyName, &lf);
|
||||
|
||||
return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference);
|
||||
return sk_sp<SkTypeface>(SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference));
|
||||
}
|
||||
|
||||
SkStreamAsset* LogFontTypeface::onOpenStream(int* ttcIndex) const {
|
||||
@ -2449,25 +2449,27 @@ protected:
|
||||
return this->matchFamilyStyle(familyName.c_str(), fontstyle);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
|
||||
std::unique_ptr<SkStreamAsset> stream(bareStream);
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const override {
|
||||
if (ttcIndex != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return create_from_stream(stream.get());
|
||||
return create_from_stream(std::move(stream));
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
|
||||
// could be in base impl
|
||||
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
|
||||
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data))),
|
||||
ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
|
||||
// could be in base impl
|
||||
return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
|
||||
auto stream = SkStream::MakeFromFile(path);
|
||||
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
LOGFONT lf;
|
||||
if (nullptr == familyName) {
|
||||
lf = get_default_font();
|
||||
@ -2477,7 +2479,7 @@ protected:
|
||||
|
||||
lf.lfWeight = style.weight();
|
||||
lf.lfItalic = style.slant() == SkFontStyle::kUpright_Slant ? FALSE : TRUE;
|
||||
return SkCreateTypefaceFromLOGFONT(lf);
|
||||
return sk_sp<SkTypeface>(SkCreateTypefaceFromLOGFONT(lf));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -198,10 +198,10 @@ protected:
|
||||
SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
||||
const SkFontStyle&) const override { return nullptr; }
|
||||
|
||||
SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; }
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override { return nullptr; }
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
|
||||
std::unique_ptr<SkStreamAsset> stream(bareStream);
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const override {
|
||||
const size_t length = stream->getLength();
|
||||
if (!length) {
|
||||
return nullptr;
|
||||
@ -219,12 +219,13 @@ protected:
|
||||
}
|
||||
|
||||
auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
|
||||
return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
|
||||
return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name),
|
||||
style, isFixedPitch));
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
|
||||
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
|
||||
const SkFontArguments& args) const override {
|
||||
using Scanner = SkTypeface_FreeType::Scanner;
|
||||
std::unique_ptr<SkStreamAsset> stream(s);
|
||||
const size_t length = stream->getLength();
|
||||
if (!length) {
|
||||
return nullptr;
|
||||
@ -251,16 +252,17 @@ protected:
|
||||
args.getCollectionIndex(),
|
||||
axisValues.get(),
|
||||
axisDefinitions.count());
|
||||
return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
|
||||
return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name),
|
||||
style, isFixedPitch));
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
|
||||
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
|
||||
return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
|
||||
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[],
|
||||
SkFontStyle requestedStyle) const override
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char requestedFamilyName[],
|
||||
SkFontStyle requestedStyle) const override
|
||||
{
|
||||
SkAutoMutexAcquire ama(fMutex);
|
||||
|
||||
@ -269,7 +271,7 @@ protected:
|
||||
std::unique_ptr<Request> request(Request::Create(requestedFamilyName, requestedStyle));
|
||||
SkTypeface* face = fCache.findAndRef(request.get());
|
||||
if (face) {
|
||||
return face;
|
||||
return sk_sp<SkTypeface>(face);
|
||||
}
|
||||
|
||||
SkFontConfigInterface::FontIdentity identity;
|
||||
@ -291,7 +293,7 @@ protected:
|
||||
// Add this request to the request cache.
|
||||
fCache.add(face, request.release());
|
||||
|
||||
return face;
|
||||
return sk_sp<SkTypeface>(face);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -414,17 +414,18 @@ protected:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
|
||||
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
|
||||
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data))),
|
||||
ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
|
||||
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
|
||||
return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
|
||||
return stream.get() ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
|
||||
std::unique_ptr<SkStreamAsset> stream(bareStream);
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const override {
|
||||
bool isFixedPitch;
|
||||
SkFontStyle style;
|
||||
SkString name;
|
||||
@ -432,12 +433,13 @@ protected:
|
||||
return nullptr;
|
||||
}
|
||||
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
|
||||
return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
|
||||
style, isFixedPitch, name));
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
|
||||
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
|
||||
const SkFontArguments& args) const override {
|
||||
using Scanner = SkTypeface_FreeType::Scanner;
|
||||
std::unique_ptr<SkStreamAsset> stream(s);
|
||||
bool isFixedPitch;
|
||||
SkFontStyle style;
|
||||
SkString name;
|
||||
@ -454,10 +456,11 @@ protected:
|
||||
|
||||
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
|
||||
axisValues.get(), axisDefinitions.count());
|
||||
return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
|
||||
style, isFixedPitch, name));
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> data) const override {
|
||||
SkStreamAsset* stream(data->getStream());
|
||||
bool isFixedPitch;
|
||||
SkFontStyle style;
|
||||
@ -465,18 +468,19 @@ protected:
|
||||
if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, nullptr)) {
|
||||
return nullptr;
|
||||
}
|
||||
return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
|
||||
style, isFixedPitch, name));
|
||||
}
|
||||
|
||||
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
if (familyName) {
|
||||
// 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
|
||||
// mechanism. On other platforms we'd provide a typeface from the
|
||||
// default family instead.
|
||||
return this->onMatchFamilyStyle(familyName, style);
|
||||
return sk_sp<SkTypeface>(this->onMatchFamilyStyle(familyName, style));
|
||||
}
|
||||
return fDefaultStyleSet->matchStyle(style);
|
||||
return sk_sp<SkTypeface>(fDefaultStyleSet->matchStyle(style));
|
||||
}
|
||||
|
||||
|
||||
|
@ -192,19 +192,18 @@ SkTypeface* SkFontMgr_Custom::onMatchFaceStyle(const SkTypeface* familyMember,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Custom::onCreateFromData(SkData* data, int ttcIndex) const {
|
||||
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
|
||||
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const {
|
||||
return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const {
|
||||
return this->createFromStream(bareStream, FontParameters().setCollectionIndex(ttcIndex));
|
||||
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const {
|
||||
return this->makeFromStream(std::move(stream), SkFontArguments().setCollectionIndex(ttcIndex));
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* s,
|
||||
const SkFontArguments& args) const
|
||||
{
|
||||
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
|
||||
const SkFontArguments& args) const {
|
||||
using Scanner = SkTypeface_FreeType::Scanner;
|
||||
std::unique_ptr<SkStreamAsset> stream(s);
|
||||
bool isFixedPitch;
|
||||
SkFontStyle style;
|
||||
SkString name;
|
||||
@ -221,37 +220,35 @@ SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* s,
|
||||
|
||||
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
|
||||
axisValues.get(), axisDefinitions.count());
|
||||
return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name));
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Custom::onCreateFromFontData(std::unique_ptr<SkFontData> data) const {
|
||||
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFontData(std::unique_ptr<SkFontData> data) const {
|
||||
bool isFixedPitch;
|
||||
SkFontStyle style;
|
||||
SkString name;
|
||||
if (!fScanner.scanFont(data->getStream(), data->getIndex(),
|
||||
&name, &style, &isFixedPitch, nullptr))
|
||||
{
|
||||
&name, &style, &isFixedPitch, nullptr)) {
|
||||
return nullptr;
|
||||
}
|
||||
return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name));
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Custom::onCreateFromFile(const char path[], int ttcIndex) const {
|
||||
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFile(const char path[], int ttcIndex) const {
|
||||
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
|
||||
return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
|
||||
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_Custom::onLegacyCreateTypeface(const char familyName[],
|
||||
SkFontStyle style) const
|
||||
{
|
||||
SkTypeface* tf = nullptr;
|
||||
sk_sp<SkTypeface> SkFontMgr_Custom::onLegacyMakeTypeface(const char familyName[],
|
||||
SkFontStyle style) const {
|
||||
sk_sp<SkTypeface> tf;
|
||||
|
||||
if (familyName) {
|
||||
tf = this->onMatchFamilyStyle(familyName, style);
|
||||
tf.reset(this->onMatchFamilyStyle(familyName, style));
|
||||
}
|
||||
|
||||
if (nullptr == tf) {
|
||||
tf = fDefaultFamily->matchStyle(style);
|
||||
tf.reset(fDefaultFamily->matchStyle(style));
|
||||
}
|
||||
|
||||
return tf;
|
||||
|
@ -142,12 +142,12 @@ protected:
|
||||
SkUnichar character) const override;
|
||||
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
||||
const SkFontStyle& fontStyle) const override;
|
||||
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override;
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override;
|
||||
SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override;
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
|
||||
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override;
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, const SkFontArguments&) const override;
|
||||
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> data) const override;
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override;
|
||||
|
||||
private:
|
||||
Families fFamilies;
|
||||
|
@ -895,8 +895,8 @@ protected:
|
||||
return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY), style);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
|
||||
std::unique_ptr<SkStreamAsset> stream(bareStream);
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const override {
|
||||
const size_t length = stream->getLength();
|
||||
if (length <= 0 || (1u << 30) < length) {
|
||||
return nullptr;
|
||||
@ -910,12 +910,13 @@ protected:
|
||||
}
|
||||
|
||||
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
|
||||
return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedWidth);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(data), std::move(name),
|
||||
style, isFixedWidth));
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
|
||||
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
|
||||
const SkFontArguments& args) const override {
|
||||
using Scanner = SkTypeface_FreeType::Scanner;
|
||||
std::unique_ptr<SkStreamAsset> stream(s);
|
||||
bool isFixedPitch;
|
||||
SkFontStyle style;
|
||||
SkString name;
|
||||
@ -932,18 +933,19 @@ protected:
|
||||
|
||||
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
|
||||
axisValues.get(), axisDefinitions.count());
|
||||
return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedPitch);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(data), std::move(name),
|
||||
style, isFixedPitch));
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
|
||||
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
|
||||
return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
|
||||
return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
|
||||
return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
|
||||
sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fontData) const override {
|
||||
SkStreamAsset* stream(fontData->getStream());
|
||||
const size_t length = stream->getLength();
|
||||
if (length <= 0 || (1u << 30) < length) {
|
||||
@ -958,16 +960,17 @@ protected:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new SkTypeface_stream(std::move(fontData), std::move(name), style, isFixedWidth);
|
||||
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(fontData), std::move(name),
|
||||
style, isFixedWidth));
|
||||
}
|
||||
|
||||
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
|
||||
sk_sp<SkTypeface> typeface(this->matchFamilyStyle(familyName, style));
|
||||
if (typeface.get()) {
|
||||
return typeface.release();
|
||||
if (typeface) {
|
||||
return typeface;
|
||||
}
|
||||
|
||||
return this->matchFamilyStyle(nullptr, style);
|
||||
return sk_sp<SkTypeface>(this->matchFamilyStyle(nullptr, style));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "SkDWriteFontFileStream.h"
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkHRESULT.h"
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkMutex.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkTScopedComPtr.h"
|
||||
@ -40,8 +41,9 @@ public:
|
||||
IDWriteFontFileStream** fontFileStream);
|
||||
|
||||
// Takes ownership of stream.
|
||||
static HRESULT Create(SkStreamAsset* stream, StreamFontFileLoader** streamFontFileLoader) {
|
||||
*streamFontFileLoader = new StreamFontFileLoader(stream);
|
||||
static HRESULT Create(std::unique_ptr<SkStreamAsset> stream,
|
||||
StreamFontFileLoader** streamFontFileLoader) {
|
||||
*streamFontFileLoader = new StreamFontFileLoader(std::move(stream));
|
||||
if (nullptr == *streamFontFileLoader) {
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
@ -51,7 +53,9 @@ public:
|
||||
std::unique_ptr<SkStreamAsset> fStream;
|
||||
|
||||
private:
|
||||
StreamFontFileLoader(SkStreamAsset* stream) : fStream(stream), fRefCount(1) { }
|
||||
StreamFontFileLoader(std::unique_ptr<SkStreamAsset> stream)
|
||||
: fStream(std::move(stream)), fRefCount(1)
|
||||
{}
|
||||
virtual ~StreamFontFileLoader() { }
|
||||
|
||||
ULONG fRefCount;
|
||||
@ -291,19 +295,19 @@ protected:
|
||||
SkUnichar character) const override;
|
||||
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
||||
const SkFontStyle& fontstyle) const override;
|
||||
SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override;
|
||||
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
|
||||
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
|
||||
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const override;
|
||||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override;
|
||||
|
||||
private:
|
||||
HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFamily) const;
|
||||
HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const;
|
||||
|
||||
/** Creates a typeface using a typeface cache. */
|
||||
SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
|
||||
IDWriteFont* font,
|
||||
IDWriteFontFamily* fontFamily) const;
|
||||
sk_sp<SkTypeface> makeTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
|
||||
IDWriteFont* font,
|
||||
IDWriteFontFamily* fontFamily) const;
|
||||
|
||||
SkTScopedComPtr<IDWriteFactory> fFactory;
|
||||
SkTScopedComPtr<IDWriteFactory2> fFactory2;
|
||||
@ -446,7 +450,7 @@ static bool FindByDWriteFont(SkTypeface* cached, void* ctx) {
|
||||
wcscmp(cshFaceName.get(), ctxFaceName.get()) == 0;
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
|
||||
sk_sp<SkTypeface> SkFontMgr_DirectWrite::makeTypefaceFromDWriteFont(
|
||||
IDWriteFontFace* fontFace,
|
||||
IDWriteFont* font,
|
||||
IDWriteFontFamily* fontFamily) const {
|
||||
@ -459,7 +463,7 @@ SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
|
||||
fTFCache.add(face);
|
||||
}
|
||||
}
|
||||
return face;
|
||||
return sk_sp<SkTypeface>(face);
|
||||
}
|
||||
|
||||
int SkFontMgr_DirectWrite::onCountFamilies() const {
|
||||
@ -539,9 +543,9 @@ public:
|
||||
if (exists) {
|
||||
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
|
||||
HRM(font->GetFontFamily(&fontFamily), "Could not get family.");
|
||||
fResolvedTypeface = fOuter->createTypefaceFromDWriteFont(glyphRun->fontFace,
|
||||
font.get(),
|
||||
fontFamily.get());
|
||||
fResolvedTypeface = fOuter->makeTypefaceFromDWriteFont(glyphRun->fontFace,
|
||||
font.get(),
|
||||
fontFamily.get()).release();
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
@ -803,7 +807,7 @@ SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family
|
||||
|
||||
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
|
||||
HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font.");
|
||||
return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
|
||||
return this->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get()).release();
|
||||
}
|
||||
|
||||
SkTScopedComPtr<IDWriteTextFormat> fallbackFormat;
|
||||
@ -872,10 +876,11 @@ private:
|
||||
T* fUnregister;
|
||||
};
|
||||
|
||||
SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const {
|
||||
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
|
||||
int ttcIndex) const {
|
||||
SkTScopedComPtr<StreamFontFileLoader> fontFileLoader;
|
||||
// This transfers ownership of stream to the new object.
|
||||
HRN(StreamFontFileLoader::Create(stream, &fontFileLoader));
|
||||
HRN(StreamFontFileLoader::Create(std::move(stream), &fontFileLoader));
|
||||
HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get()));
|
||||
SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader(
|
||||
fFactory.get(), fontFileLoader.get());
|
||||
@ -908,10 +913,10 @@ SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int
|
||||
|
||||
UINT32 faceIndex = fontFace->GetIndex();
|
||||
if (faceIndex == ttcIndex) {
|
||||
return DWriteFontTypeface::Create(fFactory.get(),
|
||||
return sk_sp<SkTypeface>(DWriteFontTypeface::Create(fFactory.get(),
|
||||
fontFace.get(), font.get(), fontFamily.get(),
|
||||
autoUnregisterFontFileLoader.detatch(),
|
||||
autoUnregisterFontCollectionLoader.detatch());
|
||||
autoUnregisterFontCollectionLoader.detatch()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -919,12 +924,12 @@ SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) const {
|
||||
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
|
||||
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const {
|
||||
return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex);
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIndex) const {
|
||||
return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
|
||||
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromFile(const char path[], int ttcIndex) const {
|
||||
return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex);
|
||||
}
|
||||
|
||||
HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[],
|
||||
@ -950,8 +955,8 @@ HRESULT SkFontMgr_DirectWrite::getDefaultFontFamily(IDWriteFontFamily** fontFami
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[],
|
||||
SkFontStyle style) const {
|
||||
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onLegacyMakeTypeface(const char familyName[],
|
||||
SkFontStyle style) const {
|
||||
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
|
||||
if (familyName) {
|
||||
SkSMallocWCHAR wideFamilyName;
|
||||
@ -979,7 +984,7 @@ SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
|
||||
SkTScopedComPtr<IDWriteFontFace> fontFace;
|
||||
HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
|
||||
|
||||
return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
|
||||
return this->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -995,7 +1000,7 @@ SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) {
|
||||
SkTScopedComPtr<IDWriteFontFace> fontFace;
|
||||
HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
|
||||
|
||||
return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontFamily.get());
|
||||
return fFontMgr->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontFamily.get()).release();
|
||||
}
|
||||
|
||||
void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString* styleName) {
|
||||
@ -1024,8 +1029,8 @@ SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) {
|
||||
SkTScopedComPtr<IDWriteFontFace> fontFace;
|
||||
HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
|
||||
|
||||
return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(),
|
||||
fFontFamily.get());
|
||||
return fFontMgr->makeTypefaceFromDWriteFont(fontFace.get(), font.get(),
|
||||
fFontFamily.get()).release();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -109,7 +109,7 @@ DEF_TEST(TypefaceAxes, reporter) {
|
||||
SkFontArguments params;
|
||||
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?
|
||||
sk_sp<SkTypeface> typeface(fm->createFromStream(distortable.release(), params));
|
||||
sk_sp<SkTypeface> typeface = fm->makeFromStream(std::move(distortable), params);
|
||||
|
||||
int count = typeface->getVariationDesignPosition(nullptr, 0);
|
||||
if (count == -1) {
|
||||
@ -140,7 +140,7 @@ DEF_TEST(TypefaceVariationIndex, reporter) {
|
||||
SkFontArguments params;
|
||||
// The first named variation position in Distortable is 'Thin'.
|
||||
params.setCollectionIndex(0x00010000);
|
||||
sk_sp<SkTypeface> typeface(fm->createFromStream(distortable.release(), params));
|
||||
sk_sp<SkTypeface> typeface = fm->makeFromStream(std::move(distortable), params);
|
||||
if (!typeface) {
|
||||
// FreeType is the only weird thing that supports this, Skia just needs to make sure if it
|
||||
// gets one of these things make sense.
|
||||
|
@ -48,7 +48,7 @@ sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
|
||||
// If we called SkTypeface::CreateFromName() here we'd recurse infinitely,
|
||||
// so we reimplement its core logic here inline without the recursive aspect.
|
||||
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
|
||||
return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, style));
|
||||
return fm->legacyMakeTypeface(name, style);
|
||||
}
|
||||
} else {
|
||||
sub = &gSubFonts[gDefaultFontIndex];
|
||||
|
Loading…
Reference in New Issue
Block a user