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.
SkString 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;
}

View File

@ -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->makeFromStream(
distortable->duplicate(),
paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream(
distortable->duplicate().release(),
SkFontArguments().setVariationDesignPosition(position))));
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
* 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
* (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.
*/
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;
#endif
/* 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.
* Will return NULL if the typeface could not be created.
* 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
@ -124,18 +122,9 @@ public:
* not recognized. The caller must call unref() on the returned object
* 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* legacyCreateTypeface(const char familyName[], SkFontStyle style) const;
#endif
/** Return the default fontmgr. */
static sk_sp<SkFontMgr> RefDefault();
@ -156,38 +145,14 @@ protected:
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
const SkFontStyle&) const = 0;
#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* onCreateFromData(SkData*, int ttcIndex) const = 0;
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0;
// TODO: make pure virtual.
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const SkFontArguments&) const;
virtual SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData>) const;
virtual SkTypeface* onCreateFromFile(const char[], int) const { return nullptr; }
virtual SkTypeface* onLegacyCreateTypeface(const char[], SkFontStyle) const {
return nullptr;
}
virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) 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
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0;
private:

View File

@ -50,10 +50,11 @@ protected:
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontStyle) 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;
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;
private:
SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;

View File

@ -49,37 +49,32 @@ protected:
return SkFontStyleSet::CreateEmpty();
}
SkTypeface* onMatchFamilyStyle(const char[], const SkFontStyle&) const override {
virtual SkTypeface* onMatchFamilyStyle(const char[],
const SkFontStyle&) const override {
return nullptr;
}
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style,
const char* bcp47[],
int bcp47Count,
SkUnichar character) const override {
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style,
const char* bcp47[],
int bcp47Count,
SkUnichar character) const override {
return nullptr;
}
SkTypeface* onMatchFaceStyle(const SkTypeface*, const SkFontStyle&) const override {
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
const SkFontStyle&) const override {
return nullptr;
}
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int) const override {
SkTypeface* onCreateFromData(SkData*, int) const override {
return nullptr;
}
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* stream, int) const override {
delete stream;
return nullptr;
}
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
const SkFontArguments&) const override {
SkTypeface* onCreateFromFile(const char[], int) const override {
return nullptr;
}
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 {
SkTypeface* onLegacyCreateTypeface(const char [], SkFontStyle) const override {
return nullptr;
}
};
@ -123,106 +118,55 @@ SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
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) {
return nullptr;
}
return this->onMakeFromData(std::move(data), ttcIndex);
return this->onCreateFromData(data, ttcIndex);
}
sk_sp<SkTypeface> SkFontMgr::makeFromStream(std::unique_ptr<SkStreamAsset> stream,
int ttcIndex) const {
SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, int ttcIndex) const {
if (nullptr == stream) {
return nullptr;
}
return this->onMakeFromStreamIndex(std::move(stream), ttcIndex);
return this->onCreateFromStream(stream, ttcIndex);
}
sk_sp<SkTypeface> SkFontMgr::makeFromStream(std::unique_ptr<SkStreamAsset> stream,
const SkFontArguments& args) const {
SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, const SkFontArguments& args) const {
if (nullptr == stream) {
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) {
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) {
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 {
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() {
static SkOnce once;
static sk_sp<SkFontMgr> singleton;

View File

@ -40,7 +40,7 @@ namespace {
class SkEmptyTypeface : public SkTypeface {
public:
static sk_sp<SkTypeface> Make() { return sk_sp<SkTypeface>(new SkEmptyTypeface); }
static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
protected:
SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
@ -88,15 +88,15 @@ protected:
SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
static SkOnce once[4];
static sk_sp<SkTypeface> defaults[4];
static SkTypeface* defaults[4];
SkASSERT((int)style < 4);
once[style]([style] {
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
auto t = fm->legacyMakeTypeface(nullptr, SkFontStyle::FromOldStyle(style));
defaults[style] = t ? t : SkEmptyTypeface::Make();
SkTypeface* t = fm->legacyCreateTypeface(nullptr, SkFontStyle::FromOldStyle(style));
defaults[style] = t ? t : SkEmptyTypeface::Create();
});
return defaults[style].get();
return defaults[style];
}
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 fm->legacyMakeTypeface(name, fontStyle);
return sk_sp<SkTypeface>(fm->legacyCreateTypeface(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 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<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<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) {
std::unique_ptr<SkStreamAsset> stream(dataTypeface->openStream(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;
}
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) {
return nullptr;
}
@ -158,21 +158,20 @@ SkTypeface* SkFontMgr_Indirect::onMatchFaceStyle(const SkTypeface* familyMember,
return this->matchFamilyStyle(familyName.c_str(), fontStyle);
}
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
int ttcIndex) const {
return fImpl->makeFromStream(std::move(stream), ttcIndex);
SkTypeface* SkFontMgr_Indirect::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const {
return fImpl->createFromStream(stream, ttcIndex);
}
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromFile(const char path[], int ttcIndex) const {
return fImpl->makeFromFile(path, ttcIndex);
SkTypeface* SkFontMgr_Indirect::onCreateFromFile(const char path[], int ttcIndex) const {
return fImpl->createFromFile(path, ttcIndex);
}
sk_sp<SkTypeface> SkFontMgr_Indirect::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const {
return fImpl->makeFromData(std::move(data), ttcIndex);
SkTypeface* SkFontMgr_Indirect::onCreateFromData(SkData* data, int ttcIndex) const {
return fImpl->createFromData(data, ttcIndex);
}
sk_sp<SkTypeface> SkFontMgr_Indirect::onLegacyMakeTypeface(const char familyName[],
SkFontStyle style) const {
SkTypeface* SkFontMgr_Indirect::onLegacyCreateTypeface(const char familyName[],
SkFontStyle style) const {
sk_sp<SkTypeface> face(this->matchFamilyStyle(familyName, style));
if (nullptr == face.get()) {
@ -184,5 +183,5 @@ sk_sp<SkTypeface> SkFontMgr_Indirect::onLegacyMakeTypeface(const char familyName
face.reset(this->createTypefaceFromFontId(fontId));
}
return face;
return face.release();
}

View File

@ -545,15 +545,15 @@ static bool find_by_CTFontRef(SkTypeface* cached, void* context) {
}
/** Creates a typeface, searching the cache if isLocalStream is false. */
static sk_sp<SkTypeface> create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
UniqueCFRef<CFTypeRef> resource,
bool isLocalStream) {
static 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 sk_sp<SkTypeface>(face);
return face;
}
}
@ -567,11 +567,11 @@ static sk_sp<SkTypeface> create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
if (!isLocalStream) {
SkTypefaceCache::Add(face);
}
return sk_sp<SkTypeface>(face);
return face;
}
/** 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));
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 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);
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).release();
false);
}
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
// Call must still manage its ownership of provider
static sk_sp<SkTypeface> create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider,
int ttcIndex) {
static SkTypeface* create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider, int ttcIndex) {
if (ttcIndex != 0) {
return nullptr;
}
@ -2263,14 +2262,14 @@ public:
SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray.get()));
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray.get(), index);
return create_from_desc(desc).release();
return create_from_desc(desc);
}
SkTypeface* matchStyle(const SkFontStyle& pattern) override {
if (0 == fCount) {
return nullptr;
}
return create_from_desc(findMatchingDesc(pattern)).release();
return create_from_desc(findMatchingDesc(pattern));
}
private:
@ -2366,7 +2365,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()).release();
return create_from_desc(desc.get());
}
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
@ -2389,7 +2388,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).release();
return create_from_CTFontRef(std::move(fallbackFont), nullptr, false);
}
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
@ -2397,16 +2396,16 @@ protected:
return nullptr;
}
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(std::move(data)));
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(sk_ref_sp(data)));
if (!pr) {
return nullptr;
}
return create_from_dataProvider(std::move(pr), ttcIndex);
}
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
int ttcIndex) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream(bareStream);
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::move(stream)));
if (!pr) {
return nullptr;
@ -2502,8 +2501,8 @@ protected:
}
return std::move(dict);
}
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> s,
const SkFontArguments& args) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* bs, const SkFontArguments& args) const override {
std::unique_ptr<SkStreamAsset> s(bs);
if (args.getCollectionIndex() != 0) {
return nullptr;
}
@ -2589,7 +2588,7 @@ protected:
}
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) {
return nullptr;
}
@ -2622,7 +2621,7 @@ protected:
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));
if (!pr) {
return nullptr;
@ -2630,12 +2629,12 @@ protected:
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) {
familyName = map_css_names(familyName);
}
sk_sp<SkTypeface> face = create_from_name(familyName, style);
SkTypeface* face = create_from_name(familyName, style);
if (face) {
return face;
}
@ -2644,9 +2643,9 @@ protected:
static SkOnce lookupDefault;
static const char FONT_DEFAULT_NAME[] = "Lucida Sans";
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.
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.
// Avoids collisions and access from CSS.
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.
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()) {
return nullptr;
}
@ -1919,7 +1919,7 @@ static sk_sp<SkTypeface> create_from_stream(std::unique_ptr<SkStreamAsset> strea
LOGFONT lf;
logfont_for_name(familyName, &lf);
return sk_sp<SkTypeface>(SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference));
return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference);
}
SkStreamAsset* LogFontTypeface::onOpenStream(int* ttcIndex) const {
@ -2449,27 +2449,25 @@ protected:
return this->matchFamilyStyle(familyName.c_str(), fontstyle);
}
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
int ttcIndex) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream(bareStream);
if (ttcIndex != 0) {
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
return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new 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 {
// could be in base impl
auto stream = SkStream::MakeFromFile(path);
return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
}
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
LOGFONT lf;
if (nullptr == familyName) {
lf = get_default_font();
@ -2479,7 +2477,7 @@ protected:
lf.lfWeight = style.weight();
lf.lfItalic = style.slant() == SkFontStyle::kUpright_Slant ? FALSE : TRUE;
return sk_sp<SkTypeface>(SkCreateTypefaceFromLOGFONT(lf));
return SkCreateTypefaceFromLOGFONT(lf);
}
private:

View File

@ -198,10 +198,10 @@ protected:
SkTypeface* onMatchFaceStyle(const SkTypeface*,
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,
int ttcIndex) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength();
if (!length) {
return nullptr;
@ -219,13 +219,12 @@ protected:
}
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),
style, isFixedPitch));
return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
}
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
const SkFontArguments& args) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* s, 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;
@ -252,17 +251,16 @@ protected:
args.getCollectionIndex(),
axisValues.get(),
axisDefinitions.count());
return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name),
style, isFixedPitch));
return SkTypeface_FCI::Create(std::move(fontData), std::move(name), 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);
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[],
SkFontStyle requestedStyle) const override
SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[],
SkFontStyle requestedStyle) const override
{
SkAutoMutexAcquire ama(fMutex);
@ -271,7 +269,7 @@ protected:
std::unique_ptr<Request> request(Request::Create(requestedFamilyName, requestedStyle));
SkTypeface* face = fCache.findAndRef(request.get());
if (face) {
return sk_sp<SkTypeface>(face);
return face;
}
SkFontConfigInterface::FontIdentity identity;
@ -293,7 +291,7 @@ protected:
// Add this request to the request cache.
fCache.add(face, request.release());
return sk_sp<SkTypeface>(face);
return face;
}
};

View File

@ -414,18 +414,17 @@ protected:
return nullptr;
}
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* onCreateFromData(SkData* data, int ttcIndex) const override {
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 {
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,
int ttcIndex) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream(bareStream);
bool isFixedPitch;
SkFontStyle style;
SkString name;
@ -433,13 +432,12 @@ protected:
return nullptr;
}
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
style, isFixedPitch, name));
return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
}
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
const SkFontArguments& args) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner;
std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
@ -456,11 +454,10 @@ protected:
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count());
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
style, isFixedPitch, name));
return new SkTypeface_AndroidStream(std::move(data), 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());
bool isFixedPitch;
SkFontStyle style;
@ -468,19 +465,18 @@ protected:
if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
style, isFixedPitch, name));
return new SkTypeface_AndroidStream(std::move(data), 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) {
// 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 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;
}
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::onCreateFromData(SkData* data, int ttcIndex) const {
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), 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* bareStream, int ttcIndex) const {
return this->createFromStream(bareStream, FontParameters().setCollectionIndex(ttcIndex));
}
sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
const SkFontArguments& args) const {
SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* s,
const SkFontArguments& args) const
{
using Scanner = SkTypeface_FreeType::Scanner;
std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
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(),
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;
SkFontStyle style;
SkString name;
if (!fScanner.scanFont(data->getStream(), data->getIndex(),
&name, &style, &isFixedPitch, nullptr)) {
&name, &style, &isFixedPitch, 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);
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[],
SkFontStyle style) const {
sk_sp<SkTypeface> tf;
SkTypeface* SkFontMgr_Custom::onLegacyCreateTypeface(const char familyName[],
SkFontStyle style) const
{
SkTypeface* tf = nullptr;
if (familyName) {
tf.reset(this->onMatchFamilyStyle(familyName, style));
tf = this->onMatchFamilyStyle(familyName, style);
}
if (nullptr == tf) {
tf.reset(fDefaultFamily->matchStyle(style));
tf = fDefaultFamily->matchStyle(style);
}
return tf;

View File

@ -142,12 +142,12 @@ protected:
SkUnichar character) const override;
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontStyle) 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;
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;
private:
Families fFamilies;

View File

@ -895,8 +895,8 @@ protected:
return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY), style);
}
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
int ttcIndex) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
return nullptr;
@ -910,13 +910,12 @@ protected:
}
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),
style, isFixedWidth));
return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedWidth);
}
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
const SkFontArguments& args) const override {
SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner;
std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
@ -933,19 +932,18 @@ protected:
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count());
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(data), std::move(name),
style, isFixedPitch));
return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedPitch);
}
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex);
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
}
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex);
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
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());
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
@ -960,17 +958,16 @@ protected:
return nullptr;
}
return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(fontData), std::move(name),
style, isFixedWidth));
return new SkTypeface_stream(std::move(fontData), std::move(name), 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));
if (typeface) {
return typeface;
if (typeface.get()) {
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 "SkFontMgr.h"
#include "SkHRESULT.h"
#include "SkMakeUnique.h"
#include "SkMutex.h"
#include "SkStream.h"
#include "SkTScopedComPtr.h"
@ -41,9 +40,8 @@ public:
IDWriteFontFileStream** fontFileStream);
// Takes ownership of stream.
static HRESULT Create(std::unique_ptr<SkStreamAsset> stream,
StreamFontFileLoader** streamFontFileLoader) {
*streamFontFileLoader = new StreamFontFileLoader(std::move(stream));
static HRESULT Create(SkStreamAsset* stream, StreamFontFileLoader** streamFontFileLoader) {
*streamFontFileLoader = new StreamFontFileLoader(stream);
if (nullptr == *streamFontFileLoader) {
return E_OUTOFMEMORY;
}
@ -53,9 +51,7 @@ public:
std::unique_ptr<SkStreamAsset> fStream;
private:
StreamFontFileLoader(std::unique_ptr<SkStreamAsset> stream)
: fStream(std::move(stream)), fRefCount(1)
{}
StreamFontFileLoader(SkStreamAsset* stream) : fStream(stream), fRefCount(1) { }
virtual ~StreamFontFileLoader() { }
ULONG fRefCount;
@ -295,19 +291,19 @@ protected:
SkUnichar character) const override;
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontstyle) 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;
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;
private:
HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFamily) const;
HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const;
/** Creates a typeface using a typeface cache. */
sk_sp<SkTypeface> makeTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
IDWriteFont* font,
IDWriteFontFamily* fontFamily) const;
SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
IDWriteFont* font,
IDWriteFontFamily* fontFamily) const;
SkTScopedComPtr<IDWriteFactory> fFactory;
SkTScopedComPtr<IDWriteFactory2> fFactory2;
@ -450,7 +446,7 @@ static bool FindByDWriteFont(SkTypeface* cached, void* ctx) {
wcscmp(cshFaceName.get(), ctxFaceName.get()) == 0;
}
sk_sp<SkTypeface> SkFontMgr_DirectWrite::makeTypefaceFromDWriteFont(
SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
IDWriteFontFace* fontFace,
IDWriteFont* font,
IDWriteFontFamily* fontFamily) const {
@ -463,7 +459,7 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::makeTypefaceFromDWriteFont(
fTFCache.add(face);
}
}
return sk_sp<SkTypeface>(face);
return face;
}
int SkFontMgr_DirectWrite::onCountFamilies() const {
@ -543,9 +539,9 @@ public:
if (exists) {
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
HRM(font->GetFontFamily(&fontFamily), "Could not get family.");
fResolvedTypeface = fOuter->makeTypefaceFromDWriteFont(glyphRun->fontFace,
font.get(),
fontFamily.get()).release();
fResolvedTypeface = fOuter->createTypefaceFromDWriteFont(glyphRun->fontFace,
font.get(),
fontFamily.get());
}
return S_OK;
@ -807,7 +803,7 @@ SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
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;
@ -876,11 +872,10 @@ private:
T* fUnregister;
};
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
int ttcIndex) const {
SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const {
SkTScopedComPtr<StreamFontFileLoader> fontFileLoader;
// 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()));
SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader(
fFactory.get(), fontFileLoader.get());
@ -913,10 +908,10 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<S
UINT32 faceIndex = fontFace->GetIndex();
if (faceIndex == ttcIndex) {
return sk_sp<SkTypeface>(DWriteFontTypeface::Create(fFactory.get(),
return DWriteFontTypeface::Create(fFactory.get(),
fontFace.get(), font.get(), fontFamily.get(),
autoUnregisterFontFileLoader.detatch(),
autoUnregisterFontCollectionLoader.detatch()));
autoUnregisterFontCollectionLoader.detatch());
}
}
}
@ -924,12 +919,12 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<S
return nullptr;
}
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::onCreateFromData(SkData* data, int ttcIndex) const {
return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
}
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromFile(const char path[], int ttcIndex) const {
return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex);
SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIndex) const {
return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
}
HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[],
@ -955,8 +950,8 @@ HRESULT SkFontMgr_DirectWrite::getDefaultFontFamily(IDWriteFontFamily** fontFami
return S_OK;
}
sk_sp<SkTypeface> SkFontMgr_DirectWrite::onLegacyMakeTypeface(const char familyName[],
SkFontStyle style) const {
SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[],
SkFontStyle style) const {
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
if (familyName) {
SkSMallocWCHAR wideFamilyName;
@ -984,7 +979,7 @@ sk_sp<SkTypeface> SkFontMgr_DirectWrite::onLegacyMakeTypeface(const char familyN
SkTScopedComPtr<IDWriteFontFace> fontFace;
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;
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) {
@ -1029,8 +1024,8 @@ SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) {
SkTScopedComPtr<IDWriteFontFace> fontFace;
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());
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -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->makeFromStream(std::move(distortable), params);
sk_sp<SkTypeface> typeface(fm->createFromStream(distortable.release(), 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->makeFromStream(std::move(distortable), params);
sk_sp<SkTypeface> typeface(fm->createFromStream(distortable.release(), 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.

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,
// so we reimplement its core logic here inline without the recursive aspect.
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
return fm->legacyMakeTypeface(name, style);
return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, style));
}
} else {
sub = &gSubFonts[gDefaultFontIndex];