Make SkFont a bit more useable
Split out of https://codereview.chromium.org/2163483002/ (Use SkFont in GrStencilAndCoverTextContext)
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2163633002
Review-Url: https://codereview.chromium.org/2163633002
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 25b6aec..528b1d0 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -661,7 +661,9 @@
return cache->getGlyphIDAdvance(glyphID);
}
-SkPaint::GlyphCacheProc SkPaint::getGlyphCacheProc(bool needFullMetrics) const {
+SkPaint::GlyphCacheProc SkPaint::GetGlyphCacheProc(TextEncoding encoding,
+ bool isDevKern,
+ bool needFullMetrics) {
static const GlyphCacheProc gGlyphCacheProcs[] = {
sk_getMetrics_utf8_next,
sk_getMetrics_utf16_next,
@@ -674,9 +676,9 @@
sk_getAdvance_glyph_next,
};
- unsigned index = this->getTextEncoding();
+ unsigned index = encoding;
- if (!needFullMetrics && !this->isDevKernText()) {
+ if (!needFullMetrics && !isDevKern) {
index += 4;
}
@@ -774,7 +776,9 @@
return 0;
}
- GlyphCacheProc glyphCacheProc = this->getGlyphCacheProc(nullptr != bounds);
+ GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(this->getTextEncoding(),
+ this->isDevKernText(),
+ nullptr != bounds);
int xyIndex;
JoinBoundsProc joinBoundsProc;
@@ -892,7 +896,9 @@
SkAutoGlyphCache autoCache(paint, nullptr, nullptr);
SkGlyphCache* cache = autoCache.getCache();
- GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(false);
+ GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
+ paint.isDevKernText(),
+ false);
const int xyIndex = paint.isVerticalText() ? 1 : 0;
SkScalar width = 0;
@@ -1005,7 +1011,9 @@
SkAutoGlyphCache autoCache(paint, nullptr, nullptr);
SkGlyphCache* cache = autoCache.getCache();
- GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(nullptr != bounds);
+ GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
+ paint.isDevKernText(),
+ nullptr != bounds);
const char* text = (const char*)textData;
const char* stop = text + byteLength;
@@ -2182,7 +2190,9 @@
const SkPaint& paint,
bool applyStrokeAndPathEffects)
: fPaint(paint) {
- fGlyphCacheProc = paint.getGlyphCacheProc(true);
+ fGlyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
+ paint.isDevKernText(),
+ true);
fPaint.setLinearText(true);
fPaint.setMaskFilter(nullptr); // don't want this affecting our path-cache lookup