aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2018-03-02 10:41:43 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-02 16:03:20 +0000
commit080a928a249115ec425771dd055682edf74d5258 (patch)
treef90fb3234de2e92d0251960abba0957e2b9e9251
parente28f9c65f614b605afdfb17d345d386b35f3f3b1 (diff)
Various fixes for scaled emojis
Bug: skia:7562 Change-Id: I66cf290ca4541ceae7ee1009a1524046a2c5893e Reviewed-on: https://skia-review.googlesource.com/111481 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
-rw-r--r--gm/scaledemoji.cpp64
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp19
-rw-r--r--src/gpu/text/GrAtlasTextContext.h12
3 files changed, 79 insertions, 16 deletions
diff --git a/gm/scaledemoji.cpp b/gm/scaledemoji.cpp
index c4a4c34499..ac8b3c6d51 100644
--- a/gm/scaledemoji.cpp
+++ b/gm/scaledemoji.cpp
@@ -61,11 +61,75 @@ protected:
}
+private:
+ typedef GM INHERITED;
+};
+
+class ScaledEmojiPosGM : public GM {
+public:
+ ScaledEmojiPosGM() {}
+
+protected:
+ struct EmojiFont {
+ sk_sp<SkTypeface> fTypeface;
+ const char* fText;
+ } fEmojiFont;
+
+ void onOnceBeforeDraw() override {
+ fEmojiFont.fTypeface = sk_tool_utils::emoji_typeface();
+ fEmojiFont.fText = sk_tool_utils::emoji_sample_text();
+ }
+
+ SkString onShortName() override {
+ SkString name("scaledemojipos");
+ name.append(sk_tool_utils::platform_font_manager());
+ return name;
+ }
+
+ SkISize onISize() override { return SkISize::Make(1200, 1200); }
+
+ void onDraw(SkCanvas* canvas) override {
+
+ canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY));
+
+ SkPaint paint;
+ paint.setTypeface(fEmojiFont.fTypeface);
+ const char* text = fEmojiFont.fText;
+
+ // draw text at different point sizes
+ // Testing GPU bitmap path, SDF path with no scaling,
+ // SDF path with scaling, path rendering with scaling
+ SkPaint::FontMetrics metrics;
+ SkScalar y = 0;
+ for (SkScalar textSize : { 70, 180, 270, 340 }) {
+ paint.setTextSize(textSize);
+ paint.getFontMetrics(&metrics);
+ y += -metrics.fAscent;
+
+ int len = SkToInt(strlen(text));
+ SkAutoTArray<SkPoint> pos(len);
+ SkAutoTArray<SkScalar> widths(len);
+ paint.getTextWidths(text, len, &widths[0]);
+
+ SkScalar x = SkIntToScalar(10);
+ for (int i = 0; i < len; ++i) {
+ pos[i].set(x, y);
+ x += widths[i];
+ }
+
+ canvas->drawPosText(text, len, &pos[0], paint);
+ y += metrics.fDescent + metrics.fLeading;
+ }
+
+ }
+
+private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new ScaledEmojiGM;)
+DEF_GM(return new ScaledEmojiPosGM;)
}
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index ce1b52e0cd..5ac683e6f3 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -459,9 +459,7 @@ void GrAtlasTextContext::DrawBmpTextAsPaths(GrAtlasTextBlob* blob, int runIndex,
pathPaint.setPathEffect(nullptr);
GrTextUtils::PathTextIter iter(text, byteLength, pathPaint, true);
- FallbackTextHelper fallbackTextHelper(viewMatrix, pathPaint.getTextSize(),
- glyphCache->getGlyphSizeLimit(),
- iter.getPathScale());
+ FallbackTextHelper fallbackTextHelper(viewMatrix, pathPaint, glyphCache, iter.getPathScale());
const SkGlyph* iterGlyph;
const SkPath* iterPath;
@@ -499,8 +497,7 @@ void GrAtlasTextContext::DrawBmpPosTextAsPaths(GrAtlasTextBlob* blob, int runInd
// setup our std paint, in hopes of getting hits in the cache
SkPaint pathPaint(origPaint);
SkScalar matrixScale = pathPaint.setupForAsPaths();
- FallbackTextHelper fallbackTextHelper(viewMatrix, pathPaint.getTextSize(), matrixScale,
- glyphCache->getGlyphSizeLimit());
+ FallbackTextHelper fallbackTextHelper(viewMatrix, origPaint, glyphCache, matrixScale);
// Temporarily jam in kFill, so we only ever ask for the raw outline from the cache.
pathPaint.setStyle(SkPaint::kFill_Style);
@@ -773,10 +770,7 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(),
paint.skPaint().isAntiAlias(), hasWCoord);
- FallbackTextHelper fallbackTextHelper(viewMatrix,
- paint.skPaint().getTextSize(),
- glyphCache->getGlyphSizeLimit(),
- textRatio);
+ FallbackTextHelper fallbackTextHelper(viewMatrix, paint, glyphCache, textRatio);
sk_sp<GrTextStrike> currStrike;
@@ -867,7 +861,12 @@ void GrAtlasTextContext::FallbackTextHelper::appendText(const SkGlyph& glyph, in
fFallbackTxt.append(count, text);
if (fUseScaledFallback) {
- SkScalar glyphTextSize = SkScalarFloorToScalar(fMaxTextSize*fTextSize / maxDim);
+ // If there's a glyph in the font that's particularly large, it's possible
+ // that fScaledFallbackTextSize may end up minimizing too much. We'd rather skip
+ // that glyph than make the others pixelated, so we set a minimum size of half the
+ // maximum text size to avoid this case.
+ SkScalar glyphTextSize = SkTMax(SkScalarFloorToScalar(fMaxTextSize*fTextSize / maxDim),
+ 0.5f*fMaxTextSize);
fScaledFallbackTextSize = SkTMin(glyphTextSize, fScaledFallbackTextSize);
}
*fFallbackPos.append() = glyphPos;
diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h
index bcdc9fdd02..2f95d9a0c0 100644
--- a/src/gpu/text/GrAtlasTextContext.h
+++ b/src/gpu/text/GrAtlasTextContext.h
@@ -61,14 +61,14 @@ private:
class FallbackTextHelper {
public:
FallbackTextHelper(const SkMatrix& viewMatrix,
- SkScalar textSize,
- SkScalar maxTextSize,
+ const SkPaint& pathPaint,
+ const GrGlyphCache* glyphCache,
SkScalar textRatio)
: fViewMatrix(viewMatrix)
+ , fTextSize(pathPaint.getTextSize())
+ , fMaxTextSize(glyphCache->getGlyphSizeLimit())
, fTextRatio(textRatio)
- , fTextSize(textSize)
- , fMaxTextSize(maxTextSize)
- , fScaledFallbackTextSize(maxTextSize)
+ , fScaledFallbackTextSize(fMaxTextSize)
, fUseScaledFallback(false) {
fMaxScale = viewMatrix.getMaxScale();
}
@@ -82,9 +82,9 @@ private:
SkTDArray<SkPoint> fFallbackPos;
const SkMatrix& fViewMatrix;
- SkScalar fTextRatio;
SkScalar fTextSize;
SkScalar fMaxTextSize;
+ SkScalar fTextRatio;
SkScalar fScaledFallbackTextSize;
SkScalar fMaxScale;
bool fUseScaledFallback;