aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHerb Derby <herb@google.com>2019-01-22 14:45:16 -0500
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2019-01-23 18:52:09 +0000
commit087fad7900d21ac938b7628051fcd48e2b4f538b (patch)
tree02f22f29711c8b2f3f77538994c9040c5409c9d3 /src
parent08b0b7fd5bd5c2b6ab746246167b1f0f446c9830 (diff)
downloadskqp-087fad7900d21ac938b7628051fcd48e2b4f538b.tar.gz
Add getTypefaceOrDefault and refTypefaceOrDefault
* Remove GetTypefaceOrDefault from SkPaint and SkFont * Remove RefTypefaceOrDefault from SkPaint and SkFont Change-Id: I04ae777142c2bdec849508b611b844418bbaedff Reviewed-on: https://skia-review.googlesource.com/c/185781 Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkFont.cpp15
-rw-r--r--src/core/SkFontPriv.h8
-rw-r--r--src/core/SkPaintPriv.h1
-rw-r--r--src/core/SkRemoteGlyphCache.cpp4
-rw-r--r--src/core/SkScalerContext.cpp2
-rw-r--r--src/core/SkStrikeCache.cpp6
-rw-r--r--src/gpu/text/GrTextBlob.cpp3
-rw-r--r--src/pdf/SkPDFDevice.cpp3
-rw-r--r--src/svg/SkSVGDevice.cpp4
-rw-r--r--src/utils/SkLua.cpp4
10 files changed, 21 insertions, 29 deletions
diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp
index f9896de73a..ec1a405082 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -199,8 +199,7 @@ int SkFont::textToGlyphs(const void* text, size_t byteLength, SkTextEncoding enc
return count;
}
- (void)SkFontPriv::GetTypefaceOrDefault(*this)->charsToGlyphs(text, typefaceEncoding, glyphs,
- count);
+ (void) this->getTypefaceOrDefault()->charsToGlyphs(text, typefaceEncoding, glyphs,count);
return count;
}
@@ -209,7 +208,7 @@ void SkFont::glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar tex
return;
}
- auto typeface = SkFontPriv::GetTypefaceOrDefault(*this);
+ auto typeface = this->getTypefaceOrDefault();
const unsigned numGlyphsInTypeface = typeface->countGlyphs();
SkAutoTArray<SkUnichar> unichars(numGlyphsInTypeface);
typeface->getGlyphToUnicodeMap(unichars.get());
@@ -487,6 +486,14 @@ SkScalar SkFont::getMetrics(SkFontMetrics* metrics) const {
return metrics->fDescent - metrics->fAscent + metrics->fLeading;
}
+SkTypeface* SkFont::getTypefaceOrDefault() const {
+ return fTypeface ? fTypeface.get() : SkTypeface::GetDefaultTypeface();
+}
+
+sk_sp<SkTypeface> SkFont::refTypefaceOrDefault() const {
+ return fTypeface ? fTypeface : SkTypeface::MakeDefault();
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "SkPaint.h"
@@ -594,7 +601,7 @@ SkRect SkFontPriv::GetFontBounds(const SkFont& font) {
m.setScale(font.getSize() * font.getScaleX(), font.getSize());
m.postSkew(font.getSkewX(), 0);
- SkTypeface* typeface = SkFontPriv::GetTypefaceOrDefault(font);
+ SkTypeface* typeface = font.getTypefaceOrDefault();
SkRect bounds;
m.mapRect(&bounds, typeface->getBounds());
diff --git a/src/core/SkFontPriv.h b/src/core/SkFontPriv.h
index dea2d78a3e..370138bfcb 100644
--- a/src/core/SkFontPriv.h
+++ b/src/core/SkFontPriv.h
@@ -59,14 +59,6 @@ public:
// returns -1 if buffer is invalid for specified encoding
static int ValidCountText(const void* text, size_t length, SkTextEncoding);
- static SkTypeface* GetTypefaceOrDefault(const SkFont& font) {
- return font.getTypeface() ? font.getTypeface() : SkTypeface::GetDefaultTypeface();
- }
-
- static sk_sp<SkTypeface> RefTypefaceOrDefault(const SkFont& font) {
- return font.getTypeface() ? font.refTypeface() : SkTypeface::MakeDefault();
- }
-
typedef const SkGlyph& (*GlyphCacheProc)(SkStrike*, const char**, const char*);
static GlyphCacheProc GetGlyphCacheProc(SkTextEncoding encoding, bool needFullMetrics);
diff --git a/src/core/SkPaintPriv.h b/src/core/SkPaintPriv.h
index 03a3af15f6..462ad99d9c 100644
--- a/src/core/SkPaintPriv.h
+++ b/src/core/SkPaintPriv.h
@@ -14,7 +14,6 @@
#include "SkTypeface.h"
class SkBitmap;
-class SkFont;
class SkImage;
class SkReadBuffer;
class SkWriteBuffer;
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index f628560d53..b530e2c22c 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -358,7 +358,7 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache(
fRemoteGlyphStateMap.erase(it);
}
- auto* tf = font.getTypeface();
+ auto* tf = font.getTypefaceOrDefault();
const SkFontID typefaceId = tf->uniqueID();
if (!fCachedTypefaces.contains(typefaceId)) {
fCachedTypefaces.add(typefaceId);
@@ -512,7 +512,7 @@ const SkGlyph& SkStrikeServer::SkGlyphCacheState::findGlyph(SkPackedGlyphID glyp
void SkStrikeServer::SkGlyphCacheState::ensureScalerContext() {
if (fContext == nullptr) {
- auto tf = fFont->getTypeface();
+ auto tf = fFont->getTypefaceOrDefault();
fContext = tf->createScalerContext(fEffects, fDeviceDescriptor.getDesc());
}
}
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 163d0ce1e6..12b81bac17 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -904,7 +904,7 @@ void SkScalerContext::MakeRecAndEffects(const SkFont& font, const SkPaint& paint
sk_bzero(rec, sizeof(SkScalerContextRec));
- SkTypeface* typeface = SkFontPriv::GetTypefaceOrDefault(font);
+ SkTypeface* typeface = font.getTypefaceOrDefault();
rec->fFontID = typeface->uniqueID();
rec->fTextSize = font.getSize();
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index ae3aec1c05..f667322d30 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -9,7 +9,6 @@
#include <cctype>
-#include "SkFontPriv.h"
#include "SkGlyphRunPainter.h"
#include "SkGraphics.h"
#include "SkMutex.h"
@@ -17,7 +16,6 @@
#include "SkTemplates.h"
#include "SkTraceMemoryDump.h"
#include "SkTypeface.h"
-#include "SkPaintPriv.h"
class SkStrikeCache::Node final : public SkStrikeInterface {
public:
@@ -192,7 +190,7 @@ auto SkStrikeCache::findOrCreateStrike(
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
font, paint, surfaceProps, scalerContextFlags, deviceMatrix, &ad, &effects);
- auto tf = SkFontPriv::GetTypefaceOrDefault(font);
+ auto tf = font.getTypefaceOrDefault();
return this->findOrCreateStrike(*desc, effects, *tf);
}
@@ -208,7 +206,7 @@ SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(cons
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(font, paint,
SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
kFakeGammaAndBoostContrast, SkMatrix::I(), &ad, &effects);
- auto typeface = SkFontPriv::GetTypefaceOrDefault(font);
+ auto typeface = font.getTypefaceOrDefault();
return SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface);
}
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 4a74a39a9d..b83a0a0db3 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -14,7 +14,6 @@
#include "GrTextTarget.h"
#include "SkColorFilter.h"
#include "SkMaskFilterBase.h"
-#include "SkPaintPriv.h"
#include "SkTextToPathIter.h"
#include "ops/GrAtlasTextOp.h"
@@ -60,7 +59,7 @@ sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount, int runCount, GrColor color)
void GrTextBlob::Run::setupFont(const SkPaint& skPaint,
const SkFont& skFont,
const SkDescriptor& cacheDescriptor) {
- fTypeface = SkFontPriv::RefTypefaceOrDefault(skFont);
+ fTypeface = skFont.refTypefaceOrDefault();
SkScalerContextEffects effects{skPaint};
fPathEffect = sk_ref_sp(effects.fPathEffect);
fMaskFilter = sk_ref_sp(effects.fMaskFilter);
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 135f5332ad..74c2ca69a9 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -17,7 +17,6 @@
#include "SkColor.h"
#include "SkColorFilter.h"
#include "SkDraw.h"
-#include "SkFontPriv.h"
#include "SkGlyphRun.h"
#include "SkImageFilterCache.h"
#include "SkJpegEncoder.h"
@@ -1085,7 +1084,7 @@ void SkPDFDevice::internalDrawGlyphRun(
this->drawGlyphRunAsPath(glyphRun, offset, runPaint);
return;
}
- SkTypeface* typeface = SkFontPriv::GetTypefaceOrDefault(glyphRunFont);
+ SkTypeface* typeface = glyphRunFont.getTypefaceOrDefault();
if (!typeface) {
SkDebugf("SkPDF: SkTypeface::MakeDefault() returned nullptr.\n");
return;
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp
index e83908bc53..c93fc13466 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -17,12 +17,10 @@
#include "SkColorFilter.h"
#include "SkData.h"
#include "SkDraw.h"
-#include "SkFontPriv.h"
#include "SkImage.h"
#include "SkImageEncoder.h"
#include "SkJpegCodec.h"
#include "SkPaint.h"
-#include "SkPaintPriv.h"
#include "SkParsePath.h"
#include "SkPngCodec.h"
#include "SkShader.h"
@@ -594,7 +592,7 @@ void SkSVGDevice::AutoElement::addTextAttributes(const SkFont& font) {
SkString familyName;
SkTHashSet<SkString> familySet;
- sk_sp<SkTypeface> tface = SkFontPriv::RefTypefaceOrDefault(font);
+ sk_sp<SkTypeface> tface = font.refTypefaceOrDefault();
SkASSERT(tface);
SkFontStyle style = tface->fontStyle();
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index c755b61e18..8083e1eac1 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -951,7 +951,7 @@ static int lfont_setSize(lua_State* L) {
}
static int lfont_getTypeface(lua_State* L) {
- push_ref(L, get_obj<SkFont>(L, 1)->getTypeface());
+ push_ref(L, get_obj<SkFont>(L, 1)->getTypefaceOrDefault());
return 1;
}
@@ -966,7 +966,7 @@ static int lfont_getHinting(lua_State* L) {
}
static int lfont_getFontID(lua_State* L) {
- SkTypeface* face = get_obj<SkFont>(L, 1)->getTypeface();
+ SkTypeface* face = get_obj<SkFont>(L, 1)->getTypefaceOrDefault();
SkLua(L).pushU32(SkTypeface::UniqueID(face));
return 1;
}