diff options
author | 2017-09-25 20:00:31 +0000 | |
---|---|---|
committer | 2017-09-25 20:00:41 +0000 | |
commit | f40ae1a4b5365620463bd63b5140bd3fc78894a1 (patch) | |
tree | 3070160f98d80ea9e2ab53eb8b06035d70582701 /src | |
parent | a3ab53b93a40185d7f29409264f91b835ae8929e (diff) |
Revert "migrate to sk_sp for SkFontMgr API"
This reverts commit 4bf296be2821d2bdd0afabae9fdfe18e7e9b59cb.
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkFontMgr.cpp | 124 | ||||
-rw-r--r-- | src/core/SkTypeface.cpp | 18 | ||||
-rw-r--r-- | src/fonts/SkFontMgr_indirect.cpp | 23 | ||||
-rw-r--r-- | src/ports/SkFontHost_mac.cpp | 51 | ||||
-rw-r--r-- | src/ports/SkFontHost_win.cpp | 26 | ||||
-rw-r--r-- | src/ports/SkFontMgr_FontConfigInterface.cpp | 28 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 34 | ||||
-rw-r--r-- | src/ports/SkFontMgr_custom.cpp | 39 | ||||
-rw-r--r-- | src/ports/SkFontMgr_custom.h | 12 | ||||
-rw-r--r-- | src/ports/SkFontMgr_fontconfig.cpp | 35 | ||||
-rw-r--r-- | src/ports/SkFontMgr_win_dw.cpp | 65 |
11 files changed, 192 insertions, 263 deletions
diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp index 4f18dd25f4..8ce0b39682 100644 --- a/src/core/SkFontMgr.cpp +++ b/src/core/SkFontMgr.cpp @@ -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 { - return nullptr; - } - sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int) const override { - return nullptr; - } - sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, - const SkFontArguments&) const override { + SkTypeface* onCreateFromData(SkData*, int) const override { return nullptr; } - sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const override { + SkTypeface* onCreateFromStream(SkStreamAsset* stream, int) const override { + delete stream; return nullptr; } - sk_sp<SkTypeface> onMakeFromFile(const char[], int) const override { + SkTypeface* onCreateFromFile(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,105 +118,54 @@ 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 { - if (nullptr == path) { - return nullptr; - } - return this->onMakeFromFile(path, ttcIndex); +// 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()); } -sk_sp<SkTypeface> SkFontMgr::legacyMakeTypeface(const char familyName[], SkFontStyle style) const { - return this->onLegacyMakeTypeface(familyName, style); +// 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()); } -#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(); + if (nullptr == path) { + return nullptr; + } + return this->onCreateFromFile(path, ttcIndex); } -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()); +SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], SkFontStyle style) const { + return this->onLegacyCreateTypeface(familyName, style); } -#endif sk_sp<SkFontMgr> SkFontMgr::RefDefault() { static SkOnce once; diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 83edea9775..33ad8d4db0 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -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)); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/fonts/SkFontMgr_indirect.cpp b/src/fonts/SkFontMgr_indirect.cpp index 98889b6abd..c04c2b851d 100644 --- a/src/fonts/SkFontMgr_indirect.cpp +++ b/src/fonts/SkFontMgr_indirect.cpp @@ -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(); } diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index d19ac5b6b4..d8bac13cdd 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -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); } }; diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 5cd02a4f73..42785e9f1b 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -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: diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp index c60e3efff2..bfc600e74e 100644 --- a/src/ports/SkFontMgr_FontConfigInterface.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface.cpp @@ -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; } }; diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 0e12ce2c30..637d2f3182 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -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); } diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp index 5b782abaef..f5aa7a3aa5 100644 --- a/src/ports/SkFontMgr_custom.cpp +++ b/src/ports/SkFontMgr_custom.cpp @@ -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; diff --git a/src/ports/SkFontMgr_custom.h b/src/ports/SkFontMgr_custom.h index e204c0aba0..f8d083c049 100644 --- a/src/ports/SkFontMgr_custom.h +++ b/src/ports/SkFontMgr_custom.h @@ -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; diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index c2ba1c038d..1524fc9f98 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -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); } }; diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp index c2d9fefdc5..eca20d94b7 100644 --- a/src/ports/SkFontMgr_win_dw.cpp +++ b/src/ports/SkFontMgr_win_dw.cpp @@ -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()); } //////////////////////////////////////////////////////////////////////////////// |