aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-09-25 13:21:45 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-25 19:45:09 +0000
commit4bf296be2821d2bdd0afabae9fdfe18e7e9b59cb (patch)
treeada1341d6943d4e8b91b5d9da331ac82873c3677 /src/ports
parentd6c04d9a05c1b4066c09083a673d7d3cf61a3aa6 (diff)
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>
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkFontHost_mac.cpp51
-rw-r--r--src/ports/SkFontHost_win.cpp26
-rw-r--r--src/ports/SkFontMgr_FontConfigInterface.cpp28
-rw-r--r--src/ports/SkFontMgr_android.cpp34
-rw-r--r--src/ports/SkFontMgr_custom.cpp39
-rw-r--r--src/ports/SkFontMgr_custom.h12
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp35
-rw-r--r--src/ports/SkFontMgr_win_dw.cpp65
8 files changed, 152 insertions, 138 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index d8bac13cdd..d19ac5b6b4 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 SkTypeface* create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
- UniqueCFRef<CFTypeRef> resource,
- bool isLocalStream) {
+static sk_sp<SkTypeface> create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
+ UniqueCFRef<CFTypeRef> resource,
+ bool isLocalStream) {
SkASSERT(font);
if (!isLocalStream) {
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (void*)font.get());
if (face) {
- return face;
+ return sk_sp<SkTypeface>(face);
}
}
@@ -567,11 +567,11 @@ static SkTypeface* create_from_CTFontRef(UniqueCFRef<CTFontRef> font,
if (!isLocalStream) {
SkTypefaceCache::Add(face);
}
- return face;
+ return sk_sp<SkTypeface>(face);
}
/** Creates a typeface from a descriptor, searching the cache. */
-static SkTypeface* create_from_desc(CTFontDescriptorRef desc) {
+static sk_sp<SkTypeface> create_from_desc(CTFontDescriptorRef desc) {
UniqueCFRef<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, nullptr));
if (!ctFont) {
return nullptr;
@@ -646,7 +646,7 @@ static UniqueCFRef<CTFontDescriptorRef> create_descriptor(const char familyName[
}
/** Creates a typeface from a name, searching the cache. */
-static SkTypeface* create_from_name(const char familyName[], const SkFontStyle& style) {
+static sk_sp<SkTypeface> create_from_name(const char familyName[], const SkFontStyle& style) {
UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style);
if (!desc) {
return nullptr;
@@ -666,7 +666,7 @@ SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef font, CFTypeRef resource) {
}
return create_from_CTFontRef(UniqueCFRef<CTFontRef>(font),
UniqueCFRef<CFTypeRef>(resource),
- false);
+ false).release();
}
static const char* map_css_names(const char* name) {
@@ -1394,7 +1394,8 @@ void SkScalerContext_Mac::CTPathElement(void *info, const CGPathElement *element
// Returns nullptr on failure
// Call must still manage its ownership of provider
-static SkTypeface* create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider, int ttcIndex) {
+static sk_sp<SkTypeface> create_from_dataProvider(UniqueCFRef<CGDataProviderRef> provider,
+ int ttcIndex) {
if (ttcIndex != 0) {
return nullptr;
}
@@ -2262,14 +2263,14 @@ public:
SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray.get()));
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray.get(), index);
- return create_from_desc(desc);
+ return create_from_desc(desc).release();
}
SkTypeface* matchStyle(const SkFontStyle& pattern) override {
if (0 == fCount) {
return nullptr;
}
- return create_from_desc(findMatchingDesc(pattern));
+ return create_from_desc(findMatchingDesc(pattern)).release();
}
private:
@@ -2365,7 +2366,7 @@ protected:
SkTypeface* onMatchFamilyStyle(const char familyName[],
const SkFontStyle& style) const override {
UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style);
- return create_from_desc(desc.get());
+ return create_from_desc(desc.get()).release();
}
SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
@@ -2388,7 +2389,7 @@ protected:
CFRange range = CFRangeMake(0, CFStringGetLength(string.get())); // in UniChar units.
UniqueCFRef<CTFontRef> fallbackFont(
CTFontCreateForString(currentFont.get(), string.get(), range));
- return create_from_CTFontRef(std::move(fallbackFont), nullptr, false);
+ return create_from_CTFontRef(std::move(fallbackFont), nullptr, false).release();
}
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
@@ -2396,16 +2397,16 @@ protected:
return nullptr;
}
- SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
- UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(sk_ref_sp(data)));
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
+ UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromData(std::move(data)));
if (!pr) {
return nullptr;
}
return create_from_dataProvider(std::move(pr), ttcIndex);
}
- SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
+ int ttcIndex) const override {
UniqueCFRef<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::move(stream)));
if (!pr) {
return nullptr;
@@ -2501,8 +2502,8 @@ protected:
}
return std::move(dict);
}
- SkTypeface* onCreateFromStream(SkStreamAsset* bs, const SkFontArguments& args) const override {
- std::unique_ptr<SkStreamAsset> s(bs);
+ sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> s,
+ const SkFontArguments& args) const override {
if (args.getCollectionIndex() != 0) {
return nullptr;
}
@@ -2588,7 +2589,7 @@ protected:
}
return std::move(dict);
}
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
+ sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fontData) const override {
if (fontData->getIndex() != 0) {
return nullptr;
}
@@ -2621,7 +2622,7 @@ protected:
return create_from_CTFontRef(std::move(ct), std::move(cg), true);
}
- SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
UniqueCFRef<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(path));
if (!pr) {
return nullptr;
@@ -2629,12 +2630,12 @@ protected:
return create_from_dataProvider(std::move(pr), ttcIndex);
}
- SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
if (familyName) {
familyName = map_css_names(familyName);
}
- SkTypeface* face = create_from_name(familyName, style);
+ sk_sp<SkTypeface> face = create_from_name(familyName, style);
if (face) {
return face;
}
@@ -2643,9 +2644,9 @@ protected:
static SkOnce lookupDefault;
static const char FONT_DEFAULT_NAME[] = "Lucida Sans";
lookupDefault([]{
- gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle());
+ gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle()).release();
});
- return SkSafeRef(gDefaultFace);
+ return sk_ref_sp(gDefaultFace);
}
};
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 42785e9f1b..5cd02a4f73 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 SkTypeface* create_from_stream(SkStreamAsset* stream) {
+static sk_sp<SkTypeface> create_from_stream(std::unique_ptr<SkStreamAsset> stream) {
// Create a unique and unpredictable font name.
// Avoids collisions and access from CSS.
char familyName[BASE64_GUID_ID_LEN];
@@ -1904,7 +1904,7 @@ static SkTypeface* create_from_stream(SkStreamAsset* stream) {
}
// Change the name of the font.
- sk_sp<SkData> rewrittenFontData(SkOTUtils::RenameFont(stream, familyName, familyNameSize-1));
+ sk_sp<SkData> rewrittenFontData(SkOTUtils::RenameFont(stream.get(), familyName, familyNameSize-1));
if (nullptr == rewrittenFontData.get()) {
return nullptr;
}
@@ -1919,7 +1919,7 @@ static SkTypeface* create_from_stream(SkStreamAsset* stream) {
LOGFONT lf;
logfont_for_name(familyName, &lf);
- return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference);
+ return sk_sp<SkTypeface>(SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference));
}
SkStreamAsset* LogFontTypeface::onOpenStream(int* ttcIndex) const {
@@ -2449,25 +2449,27 @@ protected:
return this->matchFamilyStyle(familyName.c_str(), fontstyle);
}
- SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
+ int ttcIndex) const override {
if (ttcIndex != 0) {
return nullptr;
}
- return create_from_stream(stream.get());
+ return create_from_stream(std::move(stream));
}
- SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
// could be in base impl
- return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
+ return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data))),
+ ttcIndex);
}
- SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
// could be in base impl
- return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
+ auto stream = SkStream::MakeFromFile(path);
+ return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
}
- SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
LOGFONT lf;
if (nullptr == familyName) {
lf = get_default_font();
@@ -2477,7 +2479,7 @@ protected:
lf.lfWeight = style.weight();
lf.lfItalic = style.slant() == SkFontStyle::kUpright_Slant ? FALSE : TRUE;
- return SkCreateTypefaceFromLOGFONT(lf);
+ return sk_sp<SkTypeface>(SkCreateTypefaceFromLOGFONT(lf));
}
private:
diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp
index bfc600e74e..c60e3efff2 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; }
- SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; }
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override { return nullptr; }
- SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
+ int ttcIndex) const override {
const size_t length = stream->getLength();
if (!length) {
return nullptr;
@@ -219,12 +219,13 @@ protected:
}
auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
- return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
+ return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name),
+ style, isFixedPitch));
}
- SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
+ sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
+ const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- std::unique_ptr<SkStreamAsset> stream(s);
const size_t length = stream->getLength();
if (!length) {
return nullptr;
@@ -251,16 +252,17 @@ protected:
args.getCollectionIndex(),
axisValues.get(),
axisDefinitions.count());
- return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
+ return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name),
+ style, isFixedPitch));
}
- SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
- return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
+ return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
}
- SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[],
- SkFontStyle requestedStyle) const override
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char requestedFamilyName[],
+ SkFontStyle requestedStyle) const override
{
SkAutoMutexAcquire ama(fMutex);
@@ -269,7 +271,7 @@ protected:
std::unique_ptr<Request> request(Request::Create(requestedFamilyName, requestedStyle));
SkTypeface* face = fCache.findAndRef(request.get());
if (face) {
- return face;
+ return sk_sp<SkTypeface>(face);
}
SkFontConfigInterface::FontIdentity identity;
@@ -291,7 +293,7 @@ protected:
// Add this request to the request cache.
fCache.add(face, request.release());
- return face;
+ return sk_sp<SkTypeface>(face);
}
};
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 637d2f3182..0e12ce2c30 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -414,17 +414,18 @@ protected:
return nullptr;
}
- SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
- return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
+ return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data))),
+ ttcIndex);
}
- SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
- return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
+ return stream.get() ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
}
- SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
+ int ttcIndex) const override {
bool isFixedPitch;
SkFontStyle style;
SkString name;
@@ -432,12 +433,13 @@ protected:
return nullptr;
}
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
- return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
+ return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
+ style, isFixedPitch, name));
}
- SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
+ sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
+ const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
@@ -454,10 +456,11 @@ protected:
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count());
- return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
+ return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
+ style, isFixedPitch, name));
}
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override {
+ sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> data) const override {
SkStreamAsset* stream(data->getStream());
bool isFixedPitch;
SkFontStyle style;
@@ -465,18 +468,19 @@ protected:
if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
+ return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
+ style, isFixedPitch, name));
}
- SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
if (familyName) {
// On Android, we must return nullptr when we can't find the requested
// named typeface so that the system/app can provide their own recovery
// mechanism. On other platforms we'd provide a typeface from the
// default family instead.
- return this->onMatchFamilyStyle(familyName, style);
+ return sk_sp<SkTypeface>(this->onMatchFamilyStyle(familyName, style));
}
- return fDefaultStyleSet->matchStyle(style);
+ return sk_sp<SkTypeface>(fDefaultStyleSet->matchStyle(style));
}
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index f5aa7a3aa5..5b782abaef 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -192,19 +192,18 @@ SkTypeface* SkFontMgr_Custom::onMatchFaceStyle(const SkTypeface* familyMember,
return nullptr;
}
-SkTypeface* SkFontMgr_Custom::onCreateFromData(SkData* data, int ttcIndex) const {
- return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
+sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const {
+ return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex);
}
-SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const {
- return this->createFromStream(bareStream, FontParameters().setCollectionIndex(ttcIndex));
+sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
+ int ttcIndex) const {
+ return this->makeFromStream(std::move(stream), SkFontArguments().setCollectionIndex(ttcIndex));
}
-SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* s,
- const SkFontArguments& args) const
-{
+sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
+ const SkFontArguments& args) const {
using Scanner = SkTypeface_FreeType::Scanner;
- std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
@@ -221,37 +220,35 @@ SkTypeface* SkFontMgr_Custom::onCreateFromStream(SkStreamAsset* s,
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count());
- return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
+ return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name));
}
-SkTypeface* SkFontMgr_Custom::onCreateFromFontData(std::unique_ptr<SkFontData> data) const {
+sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFontData(std::unique_ptr<SkFontData> data) const {
bool isFixedPitch;
SkFontStyle style;
SkString name;
if (!fScanner.scanFont(data->getStream(), data->getIndex(),
- &name, &style, &isFixedPitch, nullptr))
- {
+ &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
+ return sk_sp<SkTypeface>(new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name));
}
-SkTypeface* SkFontMgr_Custom::onCreateFromFile(const char path[], int ttcIndex) const {
+sk_sp<SkTypeface> SkFontMgr_Custom::onMakeFromFile(const char path[], int ttcIndex) const {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
- return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
+ return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
}
-SkTypeface* SkFontMgr_Custom::onLegacyCreateTypeface(const char familyName[],
- SkFontStyle style) const
-{
- SkTypeface* tf = nullptr;
+sk_sp<SkTypeface> SkFontMgr_Custom::onLegacyMakeTypeface(const char familyName[],
+ SkFontStyle style) const {
+ sk_sp<SkTypeface> tf;
if (familyName) {
- tf = this->onMatchFamilyStyle(familyName, style);
+ tf.reset(this->onMatchFamilyStyle(familyName, style));
}
if (nullptr == tf) {
- tf = fDefaultFamily->matchStyle(style);
+ tf.reset(fDefaultFamily->matchStyle(style));
}
return tf;
diff --git a/src/ports/SkFontMgr_custom.h b/src/ports/SkFontMgr_custom.h
index f8d083c049..e204c0aba0 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;
- SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
- SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override;
- SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override;
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override;
- SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
- SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override;
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override;
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override;
+ sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, const SkFontArguments&) const override;
+ sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> data) const override;
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override;
private:
Families fFamilies;
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 1524fc9f98..c2ba1c038d 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);
}
- SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
+ int ttcIndex) const override {
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
return nullptr;
@@ -910,12 +910,13 @@ protected:
}
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
- return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedWidth);
+ return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(data), std::move(name),
+ style, isFixedWidth));
}
- SkTypeface* onCreateFromStream(SkStreamAsset* s, const SkFontArguments& args) const override {
+ sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
+ const SkFontArguments& args) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
@@ -932,18 +933,19 @@ protected:
auto data = skstd::make_unique<SkFontData>(std::move(stream), args.getCollectionIndex(),
axisValues.get(), axisDefinitions.count());
- return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedPitch);
+ return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(data), std::move(name),
+ style, isFixedPitch));
}
- SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
- return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
+ return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex);
}
- SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
- return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
+ return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex);
}
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
+ sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fontData) const override {
SkStreamAsset* stream(fontData->getStream());
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
@@ -958,16 +960,17 @@ protected:
return nullptr;
}
- return new SkTypeface_stream(std::move(fontData), std::move(name), style, isFixedWidth);
+ return sk_sp<SkTypeface>(new SkTypeface_stream(std::move(fontData), std::move(name),
+ style, isFixedWidth));
}
- SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
sk_sp<SkTypeface> typeface(this->matchFamilyStyle(familyName, style));
- if (typeface.get()) {
- return typeface.release();
+ if (typeface) {
+ return typeface;
}
- return this->matchFamilyStyle(nullptr, style);
+ return sk_sp<SkTypeface>(this->matchFamilyStyle(nullptr, style));
}
};
diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp
index eca20d94b7..c2d9fefdc5 100644
--- a/src/ports/SkFontMgr_win_dw.cpp
+++ b/src/ports/SkFontMgr_win_dw.cpp
@@ -12,6 +12,7 @@
#include "SkDWriteFontFileStream.h"
#include "SkFontMgr.h"
#include "SkHRESULT.h"
+#include "SkMakeUnique.h"
#include "SkMutex.h"
#include "SkStream.h"
#include "SkTScopedComPtr.h"
@@ -40,8 +41,9 @@ public:
IDWriteFontFileStream** fontFileStream);
// Takes ownership of stream.
- static HRESULT Create(SkStreamAsset* stream, StreamFontFileLoader** streamFontFileLoader) {
- *streamFontFileLoader = new StreamFontFileLoader(stream);
+ static HRESULT Create(std::unique_ptr<SkStreamAsset> stream,
+ StreamFontFileLoader** streamFontFileLoader) {
+ *streamFontFileLoader = new StreamFontFileLoader(std::move(stream));
if (nullptr == *streamFontFileLoader) {
return E_OUTOFMEMORY;
}
@@ -51,7 +53,9 @@ public:
std::unique_ptr<SkStreamAsset> fStream;
private:
- StreamFontFileLoader(SkStreamAsset* stream) : fStream(stream), fRefCount(1) { }
+ StreamFontFileLoader(std::unique_ptr<SkStreamAsset> stream)
+ : fStream(std::move(stream)), fRefCount(1)
+ {}
virtual ~StreamFontFileLoader() { }
ULONG fRefCount;
@@ -291,19 +295,19 @@ protected:
SkUnichar character) const override;
SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontstyle) const override;
- SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override;
- SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override;
- SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override;
- SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const override;
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override;
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override;
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override;
private:
HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFamily) const;
HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const;
/** Creates a typeface using a typeface cache. */
- SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
- IDWriteFont* font,
- IDWriteFontFamily* fontFamily) const;
+ sk_sp<SkTypeface> makeTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
+ IDWriteFont* font,
+ IDWriteFontFamily* fontFamily) const;
SkTScopedComPtr<IDWriteFactory> fFactory;
SkTScopedComPtr<IDWriteFactory2> fFactory2;
@@ -446,7 +450,7 @@ static bool FindByDWriteFont(SkTypeface* cached, void* ctx) {
wcscmp(cshFaceName.get(), ctxFaceName.get()) == 0;
}
-SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
+sk_sp<SkTypeface> SkFontMgr_DirectWrite::makeTypefaceFromDWriteFont(
IDWriteFontFace* fontFace,
IDWriteFont* font,
IDWriteFontFamily* fontFamily) const {
@@ -459,7 +463,7 @@ SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
fTFCache.add(face);
}
}
- return face;
+ return sk_sp<SkTypeface>(face);
}
int SkFontMgr_DirectWrite::onCountFamilies() const {
@@ -539,9 +543,9 @@ public:
if (exists) {
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
HRM(font->GetFontFamily(&fontFamily), "Could not get family.");
- fResolvedTypeface = fOuter->createTypefaceFromDWriteFont(glyphRun->fontFace,
- font.get(),
- fontFamily.get());
+ fResolvedTypeface = fOuter->makeTypefaceFromDWriteFont(glyphRun->fontFace,
+ font.get(),
+ fontFamily.get()).release();
}
return S_OK;
@@ -803,7 +807,7 @@ SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font.");
- return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
+ return this->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get()).release();
}
SkTScopedComPtr<IDWriteTextFormat> fallbackFormat;
@@ -872,10 +876,11 @@ private:
T* fUnregister;
};
-SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const {
+sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
+ int ttcIndex) const {
SkTScopedComPtr<StreamFontFileLoader> fontFileLoader;
// This transfers ownership of stream to the new object.
- HRN(StreamFontFileLoader::Create(stream, &fontFileLoader));
+ HRN(StreamFontFileLoader::Create(std::move(stream), &fontFileLoader));
HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get()));
SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader(
fFactory.get(), fontFileLoader.get());
@@ -908,10 +913,10 @@ SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int
UINT32 faceIndex = fontFace->GetIndex();
if (faceIndex == ttcIndex) {
- return DWriteFontTypeface::Create(fFactory.get(),
+ return sk_sp<SkTypeface>(DWriteFontTypeface::Create(fFactory.get(),
fontFace.get(), font.get(), fontFamily.get(),
autoUnregisterFontFileLoader.detatch(),
- autoUnregisterFontCollectionLoader.detatch());
+ autoUnregisterFontCollectionLoader.detatch()));
}
}
}
@@ -919,12 +924,12 @@ SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int
return nullptr;
}
-SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex) const {
- return this->createFromStream(new SkMemoryStream(sk_ref_sp(data)), ttcIndex);
+sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const {
+ return this->makeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), ttcIndex);
}
-SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIndex) const {
- return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
+sk_sp<SkTypeface> SkFontMgr_DirectWrite::onMakeFromFile(const char path[], int ttcIndex) const {
+ return this->makeFromStream(SkStream::MakeFromFile(path), ttcIndex);
}
HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[],
@@ -950,8 +955,8 @@ HRESULT SkFontMgr_DirectWrite::getDefaultFontFamily(IDWriteFontFamily** fontFami
return S_OK;
}
-SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[],
- SkFontStyle style) const {
+sk_sp<SkTypeface> SkFontMgr_DirectWrite::onLegacyMakeTypeface(const char familyName[],
+ SkFontStyle style) const {
SkTScopedComPtr<IDWriteFontFamily> fontFamily;
if (familyName) {
SkSMallocWCHAR wideFamilyName;
@@ -979,7 +984,7 @@ SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
SkTScopedComPtr<IDWriteFontFace> fontFace;
HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
- return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
+ return this->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get());
}
///////////////////////////////////////////////////////////////////////////////
@@ -995,7 +1000,7 @@ SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) {
SkTScopedComPtr<IDWriteFontFace> fontFace;
HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
- return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontFamily.get());
+ return fFontMgr->makeTypefaceFromDWriteFont(fontFace.get(), font.get(), fFontFamily.get()).release();
}
void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString* styleName) {
@@ -1024,8 +1029,8 @@ SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) {
SkTScopedComPtr<IDWriteFontFace> fontFace;
HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
- return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(),
- fFontFamily.get());
+ return fFontMgr->makeTypefaceFromDWriteFont(fontFace.get(), font.get(),
+ fFontFamily.get()).release();
}
////////////////////////////////////////////////////////////////////////////////