aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2016-05-12 06:22:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-12 06:22:30 -0700
commit9a9a7b29e5e5916a7b6453cd124ca437f14b9da4 (patch)
treead5b560f6ed5da12040e5665282fd2227c305ff8 /src
parenta1b283345b27fef91908b104a30cb89e6fbdaade (diff)
Revert of Move SkTypeface to sk_sp. (patchset #5 id:80001 of https://codereview.chromium.org/1933393002/ )
Reason for revert: fontmgr_iterAndroid failing to draw emoji. E.g. 6296da736fbf40aae881650c239420f64e576c3f&unt=true&head=true&query=source_type%3Dgm">https://gold.skia.org/search2?blame=6296da736fbf40aae881650c239420f64e576c3f&unt=true&head=true&query=source_type%3Dgm Original issue's description: > Move SkTypeface to sk_sp. > > Committed: https://skia.googlesource.com/skia/+/6296da736fbf40aae881650c239420f64e576c3f TBR=reed@google.com,fmalita@chromium.org,tomhudson@google.com,bungeman@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review-Url: https://codereview.chromium.org/1974783002
Diffstat (limited to 'src')
-rw-r--r--src/animator/SkDrawPaint.cpp2
-rw-r--r--src/animator/SkPaintPart.h3
-rw-r--r--src/core/SkFont.cpp35
-rw-r--r--src/core/SkPaint.cpp4
-rw-r--r--src/core/SkPictureData.cpp6
-rw-r--r--src/core/SkTextBlob.cpp4
-rw-r--r--src/core/SkTypeface.cpp45
-rw-r--r--src/core/SkTypefacePriv.h10
-rw-r--r--src/fonts/SkGScalerContext.cpp11
-rw-r--r--src/fonts/SkGScalerContext.h9
-rw-r--r--src/fonts/SkRandomScalerContext.cpp8
-rw-r--r--src/fonts/SkRandomScalerContext.h11
-rw-r--r--src/pdf/SkPDFFont.cpp2
-rw-r--r--src/ports/SkFontMgr_android.cpp5
-rw-r--r--src/svg/SkSVGDevice.cpp4
-rw-r--r--src/utils/SkLua.cpp9
-rw-r--r--src/utils/SkWhitelistTypefaces.cpp20
17 files changed, 105 insertions, 83 deletions
diff --git a/src/animator/SkDrawPaint.cpp b/src/animator/SkDrawPaint.cpp
index 1026630eb1..1336ea2dc4 100644
--- a/src/animator/SkDrawPaint.cpp
+++ b/src/animator/SkDrawPaint.cpp
@@ -259,7 +259,7 @@ void SkDrawPaint::setupPaint(SkPaint* paint) const {
if (typeface == nullptr)
paint->setTypeface(nullptr);
else if (typeface != (SkDrawTypeface*) -1)
- paint->setTypeface(typeface->getTypeface());
+ SkSafeUnref(paint->setTypeface(typeface->getTypeface()));
if (underline != -1)
paint->setUnderlineText(SkToBool(underline));
if (xfermode != -1)
diff --git a/src/animator/SkPaintPart.h b/src/animator/SkPaintPart.h
index 5d94f049e8..a7e28ed3e2 100644
--- a/src/animator/SkPaintPart.h
+++ b/src/animator/SkPaintPart.h
@@ -62,7 +62,8 @@ class SkDrawTypeface : public SkPaintPart {
#ifdef SK_DUMP_ENABLED
void dump(SkAnimateMaker *) override;
#endif
- sk_sp<SkTypeface> getTypeface() { return SkTypeface::MakeFromName(fontName.c_str(), style); }
+ SkTypeface* getTypeface() {
+ return SkTypeface::CreateFromName(fontName.c_str(), style); }
protected:
bool add() override;
SkString fontName;
diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp
index 1300011ec4..c39cc185d3 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -9,9 +9,13 @@
#include "SkTypeface.h"
#include "SkUtils.h"
-SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType mt,
+static SkTypeface* ref_or_default(SkTypeface* face) {
+ return face ? SkRef(face) : SkTypeface::RefDefault();
+}
+
+SkFont::SkFont(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType mt,
uint32_t flags)
- : fTypeface(face ? std::move(face) : SkTypeface::MakeDefault())
+ : fTypeface(ref_or_default(face))
, fSize(size)
, fScaleX(scaleX)
, fSkewX(skewX)
@@ -24,8 +28,8 @@ SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar
SkASSERT(0 == (flags & ~kAllFlags));
}
-sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX,
- MaskType mt, uint32_t flags) {
+SkFont* SkFont::Create(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScalar skewX,
+ MaskType mt, uint32_t flags) {
if (size <= 0 || !SkScalarIsFinite(size)) {
return nullptr;
}
@@ -36,20 +40,24 @@ sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, SkScalar scale
return nullptr;
}
flags &= kAllFlags;
- return sk_sp<SkFont>(new SkFont(std::move(face), size, scaleX, skewX, mt, flags));
+ return new SkFont(face, size, scaleX, skewX, mt, flags);
}
-sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, MaskType mt, uint32_t flags) {
- return SkFont::Make(std::move(face), size, 1, 0, mt, flags);
+SkFont* SkFont::Create(SkTypeface* face, SkScalar size, MaskType mt, uint32_t flags) {
+ return SkFont::Create(face, size, 1, 0, mt, flags);
}
-sk_sp<SkFont> SkFont::makeWithSize(SkScalar newSize) const {
- return SkFont::Make(sk_ref_sp(this->getTypeface()), newSize, this->getScaleX(),
- this->getSkewX(), this->getMaskType(), this->getFlags());
+SkFont* SkFont::cloneWithSize(SkScalar newSize) const {
+ return SkFont::Create(this->getTypeface(), newSize, this->getScaleX(), this->getSkewX(),
+ this->getMaskType(), this->getFlags());
}
///////////////////////////////////////////////////////////////////////////////////////////////////
+SkFont::~SkFont() {
+ SkSafeUnref(fTypeface);
+}
+
int SkFont::textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
uint16_t glyphs[], int maxGlyphCount) const {
if (0 == byteLength) {
@@ -110,7 +118,7 @@ SkScalar SkFont::measureText(const void* text, size_t byteLength, SkTextEncoding
#include "SkPaint.h"
-sk_sp<SkFont> SkFont::Testing_CreateFromPaint(const SkPaint& paint) {
+SkFont* SkFont::Testing_CreateFromPaint(const SkPaint& paint) {
uint32_t flags = 0;
if (paint.isVerticalText()) {
flags |= kVertical_Flag;
@@ -142,6 +150,7 @@ sk_sp<SkFont> SkFont::Testing_CreateFromPaint(const SkPaint& paint) {
maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType;
}
- return Make(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTextScaleX(),
- paint.getTextSkewX(), maskType, flags);
+ return Create(paint.getTypeface(),
+ paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX(),
+ maskType, flags);
}
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 25b6aec1ec..67bbda1665 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -369,9 +369,7 @@ void SkPaint::setLooper(sk_sp<SkDrawLooper> looper) { fLooper = std::move(looper
this->f##Field.reset(SkSafeRef(f)); \
return f; \
}
-#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
SET_PTR(Typeface)
-#endif
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SET_PTR(Rasterizer)
#endif
@@ -1898,7 +1896,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
if (flatFlags & kHasTypeface_FlatFlag) {
- this->setTypeface(sk_ref_sp(buffer.readTypeface()));
+ this->setTypeface(buffer.readTypeface());
} else {
this->setTypeface(nullptr);
}
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index 873c0c4a1d..ed32c6c029 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -405,13 +405,13 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
const int count = SkToInt(size);
fTFPlayback.setCount(count);
for (int i = 0; i < count; i++) {
- sk_sp<SkTypeface> tf(SkTypeface::MakeDeserialize(stream));
+ SkAutoTUnref<SkTypeface> tf(SkTypeface::Deserialize(stream));
if (!tf.get()) { // failed to deserialize
// fTFPlayback asserts it never has a null, so we plop in
// the default here.
- tf = SkTypeface::MakeDefault();
+ tf.reset(SkTypeface::RefDefault());
}
- fTFPlayback.set(i, tf.get());
+ fTFPlayback.set(i, tf);
}
} break;
case SK_PICT_PICTURE_TAG: {
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index 1cbb2b6d6d..463312aa6d 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -27,7 +27,7 @@ public:
void applyToPaint(SkPaint* paint) const {
paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- paint->setTypeface(fTypeface);
+ paint->setTypeface(fTypeface.get());
paint->setTextSize(fSize);
paint->setTextScaleX(fScaleX);
paint->setTextSkewX(fSkewX);
@@ -73,7 +73,7 @@ private:
// Keep this SkAutoTUnref off the first position, to avoid interfering with SkNoncopyable
// empty baseclass optimization (http://code.google.com/p/skia/issues/detail?id=3694).
- sk_sp<SkTypeface> fTypeface;
+ SkAutoTUnref<SkTypeface> fTypeface;
SkScalar fSkewX;
static_assert(SkPaint::kAlignCount < 4, "insufficient_align_bits");
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 3c15878f73..75bb05c2b1 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -27,9 +27,9 @@ extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* );
#define SK_TYPEFACE_DELEGATE nullptr
#endif
-sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr;
+SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr;
void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE_DELEGATE;
-sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
+SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
///////////////////////////////////////////////////////////////////////////////
@@ -98,8 +98,8 @@ SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
return defaults[style];
}
-sk_sp<SkTypeface> SkTypeface::MakeDefault(Style style) {
- return sk_ref_sp(GetDefaultTypeface(style));
+SkTypeface* SkTypeface::RefDefault(Style style) {
+ return SkRef(GetDefaultTypeface(style));
}
uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
@@ -115,46 +115,47 @@ bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
///////////////////////////////////////////////////////////////////////////////
-sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) {
+SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
if (gCreateTypefaceDelegate) {
- sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style);
+ SkTypeface* result = (*gCreateTypefaceDelegate)(name, style);
if (result) {
return result;
}
}
if (nullptr == name) {
- return MakeDefault(style);
+ return RefDefault(style);
}
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style)));
+ return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style));
}
-sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) {
+SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
if (!family) {
- return SkTypeface::MakeDefault(s);
+ return SkTypeface::RefDefault(s);
}
if (family->style() == s) {
- return sk_ref_sp(family);
+ family->ref();
+ return const_cast<SkTypeface*>(family);
}
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return sk_sp<SkTypeface>(fm->matchFaceStyle(family, SkFontStyle::FromOldStyle(s)));
+ return fm->matchFaceStyle(family, SkFontStyle::FromOldStyle(s));
}
-sk_sp<SkTypeface> SkTypeface::MakeFromStream(SkStreamAsset* stream, int index) {
+SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return sk_sp<SkTypeface>(fm->createFromStream(stream, index));
+ return fm->createFromStream(stream, index);
}
-sk_sp<SkTypeface> SkTypeface::MakeFromFontData(SkFontData* data) {
+SkTypeface* SkTypeface::CreateFromFontData(SkFontData* data) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return sk_sp<SkTypeface>(fm->createFromFontData(data));
+ return fm->createFromFontData(data);
}
-sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) {
+SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return sk_sp<SkTypeface>(fm->createFromFile(path, index));
+ return fm->createFromFile(path, index);
}
///////////////////////////////////////////////////////////////////////////////
@@ -175,7 +176,7 @@ void SkTypeface::serialize(SkWStream* wstream) const {
desc.serialize(wstream);
}
-sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) {
+SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
if (gDeserializeTypefaceDelegate) {
return (*gDeserializeTypefaceDelegate)(stream);
}
@@ -187,12 +188,12 @@ sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) {
SkFontData* data = desc.detachFontData();
if (data) {
- sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
+ SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
if (typeface) {
return typeface;
}
}
- return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle());
+ return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle());
}
///////////////////////////////////////////////////////////////////////////////
@@ -334,7 +335,7 @@ bool SkTypeface::onComputeBounds(SkRect* bounds) const {
const SkScalar invTextSize = 1 / textSize;
SkPaint paint;
- paint.setTypeface(sk_ref_sp(const_cast<SkTypeface*>(this)));
+ paint.setTypeface(const_cast<SkTypeface*>(this));
paint.setTextSize(textSize);
paint.setLinearText(true);
diff --git a/src/core/SkTypefacePriv.h b/src/core/SkTypefacePriv.h
index f8d7e63efd..dc993d0890 100644
--- a/src/core/SkTypefacePriv.h
+++ b/src/core/SkTypefacePriv.h
@@ -16,23 +16,23 @@
* If the parameter is non-null, it will be ref'd and returned, otherwise
* it will be the default typeface.
*/
-static inline sk_sp<SkTypeface> ref_or_default(SkTypeface* face) {
- return face ? sk_ref_sp(face) : SkTypeface::MakeDefault();
+static inline SkTypeface* ref_or_default(SkTypeface* face) {
+ return face ? SkRef(face) : SkTypeface::RefDefault();
}
/**
* Always resolves to a non-null typeface, either the value passed to its
* constructor, or the default typeface if null was passed.
*/
-class SkAutoResolveDefaultTypeface : public sk_sp<SkTypeface> {
+class SkAutoResolveDefaultTypeface : public SkAutoTUnref<SkTypeface> {
public:
- SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::MakeDefault()) {}
+ SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::RefDefault()) {}
SkAutoResolveDefaultTypeface(SkTypeface* face)
: INHERITED(ref_or_default(face)) {}
private:
- typedef sk_sp<SkTypeface> INHERITED;
+ typedef SkAutoTUnref<SkTypeface> INHERITED;
};
#endif
diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp
index 1d34536cbe..0a9601bd7e 100644
--- a/src/fonts/SkGScalerContext.cpp
+++ b/src/fonts/SkGScalerContext.cpp
@@ -151,11 +151,14 @@ void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
#include "SkTypefaceCache.h"
-SkGTypeface::SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint)
+SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint)
: SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
- , fProxy(std::move(proxy))
- , fPaint(paint)
-{}
+ , fProxy(SkRef(proxy))
+ , fPaint(paint) {}
+
+SkGTypeface::~SkGTypeface() {
+ fProxy->unref();
+}
SkScalerContext* SkGTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
diff --git a/src/fonts/SkGScalerContext.h b/src/fonts/SkGScalerContext.h
index 3eb25a81da..69d02ddf11 100644
--- a/src/fonts/SkGScalerContext.h
+++ b/src/fonts/SkGScalerContext.h
@@ -13,9 +13,10 @@
class SkGTypeface : public SkTypeface {
public:
- SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint&);
+ SkGTypeface(SkTypeface* proxy, const SkPaint&);
+ virtual ~SkGTypeface();
- SkTypeface* proxy() const { return fProxy.get(); }
+ SkTypeface* proxy() const { return fProxy; }
const SkPaint& paint() const { return fPaint; }
protected:
@@ -42,8 +43,8 @@ protected:
size_t length, void* data) const override;
private:
- sk_sp<SkTypeface> fProxy;
- SkPaint fPaint;
+ SkTypeface* fProxy;
+ SkPaint fPaint;
};
#endif
diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
index 6d3718cbef..245052053e 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -190,12 +190,16 @@ void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
#include "SkTypefaceCache.h"
-SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint, bool fakeIt)
+SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint, bool fakeIt)
: SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
- , fProxy(std::move(proxy))
+ , fProxy(SkRef(proxy))
, fPaint(paint)
, fFakeIt(fakeIt) {}
+SkRandomTypeface::~SkRandomTypeface() {
+ fProxy->unref();
+}
+
SkScalerContext* SkRandomTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
return new SkRandomScalerContext(const_cast<SkRandomTypeface*>(this), effects, desc, fFakeIt);
diff --git a/src/fonts/SkRandomScalerContext.h b/src/fonts/SkRandomScalerContext.h
index 076689d93a..0e08f4b1ae 100644
--- a/src/fonts/SkRandomScalerContext.h
+++ b/src/fonts/SkRandomScalerContext.h
@@ -18,9 +18,10 @@
class SkRandomTypeface : public SkTypeface {
public:
- SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint&, bool fakeit);
+ SkRandomTypeface(SkTypeface* proxy, const SkPaint&, bool fakeit);
+ virtual ~SkRandomTypeface();
- SkTypeface* proxy() const { return fProxy.get(); }
+ SkTypeface* proxy() const { return fProxy; }
const SkPaint& paint() const { return fPaint; }
protected:
@@ -47,9 +48,9 @@ protected:
size_t length, void* data) const override;
private:
- sk_sp<SkTypeface> fProxy;
- SkPaint fPaint;
- bool fFakeIt;
+ SkTypeface* fProxy;
+ SkPaint fPaint;
+ bool fFakeIt;
};
#endif
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 97be32c41d..7a66bcd1e9 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -1327,7 +1327,7 @@ SkPDFType3Font::~SkPDFType3Font() {}
bool SkPDFType3Font::populate(uint16_t glyphID) {
SkPaint paint;
- paint.setTypeface(sk_ref_sp(this->typeface()));
+ paint.setTypeface(typeface());
paint.setTextSize(1000);
const SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
SkAutoGlyphCache autoCache(paint, &props, nullptr);
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 3e6e0da18a..4aea047cde 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -371,7 +371,7 @@ protected:
{
for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) {
SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet;
- sk_sp<SkTypeface_AndroidSystem> face(family->matchStyle(style));
+ SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style));
if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) {
continue;
@@ -387,6 +387,9 @@ protected:
uint16_t glyphID;
paint.textToGlyphs(&character, sizeof(character), &glyphID);
+ if (glyphID != 0) {
+ return face.release();
+ }
}
return nullptr;
}
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp
index f0805b5432..4c679dfee7 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -534,8 +534,8 @@ void SkSVGDevice::AutoElement::addTextAttributes(const SkPaint& paint) {
SkString familyName;
SkTHashSet<SkString> familySet;
- sk_sp<const SkTypeface> tface(paint.getTypeface() ?
- sk_ref_sp(paint.getTypeface()) : SkTypeface::MakeDefault());
+ SkAutoTUnref<const SkTypeface> tface(paint.getTypeface() ?
+ SkRef(paint.getTypeface()) : SkTypeface::RefDefault());
SkASSERT(tface);
SkTypeface::Style style = tface->style();
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 4409e477e5..886f3d4ffd 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -925,7 +925,7 @@ static int lpaint_getTypeface(lua_State* L) {
}
static int lpaint_setTypeface(lua_State* L) {
- get_obj<SkPaint>(L, 1)->setTypeface(sk_ref_sp(get_ref<SkTypeface>(L, 2)));
+ get_obj<SkPaint>(L, 1)->setTypeface(get_ref<SkTypeface>(L, 2));
return 0;
}
@@ -2049,12 +2049,13 @@ static int lsk_newTypeface(lua_State* L) {
}
}
- sk_sp<SkTypeface> face(SkTypeface::MakeFromName(name, (SkTypeface::Style)style));
+ SkTypeface* face = SkTypeface::CreateFromName(name,
+ (SkTypeface::Style)style);
// SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, face->getRefCnt());
if (nullptr == face) {
- face = SkTypeface::MakeDefault();
+ face = SkTypeface::RefDefault();
}
- push_ref(L, std::move(face));
+ push_ref(L, face)->unref();
return 1;
}
diff --git a/src/utils/SkWhitelistTypefaces.cpp b/src/utils/SkWhitelistTypefaces.cpp
index 3368178769..66d32188a0 100644
--- a/src/utils/SkWhitelistTypefaces.cpp
+++ b/src/utils/SkWhitelistTypefaces.cpp
@@ -18,7 +18,7 @@
#define WHITELIST_DEBUG 0
extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* );
-sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* );
+extern SkTypeface* WhitelistDeserializeTypeface(SkStream* );
extern bool CheckChecksums();
extern bool GenerateChecksums();
@@ -32,8 +32,8 @@ static bool font_name_is_local(const char* fontName, SkTypeface::Style style) {
if (!strcmp(fontName, "DejaVu Sans")) {
return true;
}
- sk_sp<SkTypeface> defaultFace(SkTypeface::MakeFromName(nullptr, style));
- sk_sp<SkTypeface> foundFace(SkTypeface::MakeFromName(fontName, style));
+ SkTypeface* defaultFace = SkTypeface::CreateFromName(nullptr, style);
+ SkTypeface* foundFace = SkTypeface::CreateFromName(fontName, style);
return defaultFace != foundFace;
}
@@ -183,7 +183,7 @@ void WhitelistSerializeTypeface(const SkTypeface* tf, SkWStream* wstream) {
serialize_sub(fontName, tf->style(), wstream);
}
-sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) {
+SkTypeface* WhitelistDeserializeTypeface(SkStream* stream) {
SkFontDescriptor desc;
if (!SkFontDescriptor::Deserialize(stream, &desc)) {
return nullptr;
@@ -191,7 +191,7 @@ sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) {
SkFontData* data = desc.detachFontData();
if (data) {
- sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
+ SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
if (typeface) {
return typeface;
}
@@ -200,14 +200,14 @@ sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) {
if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) {
familyName += sizeof(SUBNAME_PREFIX) - 1;
}
- return SkTypeface::MakeFromName(familyName, desc.getStyle());
+ return SkTypeface::CreateFromName(familyName, desc.getStyle());
}
bool CheckChecksums() {
for (int i = 0; i < whitelistCount; ++i) {
const char* fontName = whitelist[i].fFontName;
- sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNormal));
- uint32_t checksum = compute_checksum(tf.get());
+ SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNormal);
+ uint32_t checksum = compute_checksum(tf);
if (whitelist[i].fChecksum != checksum) {
return false;
}
@@ -261,8 +261,8 @@ bool GenerateChecksums() {
sk_fwrite(line.c_str(), line.size(), file);
for (int i = 0; i < whitelistCount; ++i) {
const char* fontName = whitelist[i].fFontName;
- sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNormal));
- uint32_t checksum = compute_checksum(tf.get());
+ SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNormal);
+ uint32_t checksum = compute_checksum(tf);
line.printf(checksumEntry, fontName, checksum);
sk_fwrite(line.c_str(), line.size(), file);
}