Only reposition the fallback vertices once.

We were shifting the verticies for the fallback subrun
twice when using paths to render. Once in regenerate,
and once using MapPoints.

BUG=chromium:913057

Change-Id: I4d2e977b0edbec22cbd57c45fe47c959d172908f
Reviewed-on: https://skia-review.googlesource.com/c/177920
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2018-12-14 16:47:45 -05:00 committed by Skia Commit-Bot
parent 5e276a6376
commit 5f7b014f29
3 changed files with 25 additions and 15 deletions

View File

@ -11,6 +11,7 @@
#include "Resources.h"
#include "SkCanvas.h"
#include "SkStream.h"
#include "SkTextBlob.h"
#include "SkTo.h"
#include "SkTypeface.h"
@ -94,7 +95,8 @@ protected:
canvas->drawColor(SK_ColorGRAY);
SkPaint paint;
paint.setTypeface(fEmojiFont.fTypeface);
SkFont font;
font.setTypeface(fEmojiFont.fTypeface);
const char* text = fEmojiFont.fText;
// draw text at different point sizes
@ -103,22 +105,28 @@ protected:
SkFontMetrics metrics;
SkScalar y = 0;
for (SkScalar textSize : { 70, 180, 270, 340 }) {
paint.setTextSize(textSize);
paint.getFontMetrics(&metrics);
font.setSize(textSize);
font.getMetrics(&metrics);
y += -metrics.fAscent;
int len = SkToInt(strlen(text));
SkAutoTArray<SkPoint> pos(len);
SkAutoTArray<SkScalar> widths(len);
paint.getTextWidths(text, len, &widths[0]);
SkAutoTArray<SkScalar> pos(len);
SkAutoTArray<SkGlyphID> glyphs(len);
SkScalar x = SkIntToScalar(10);
for (int i = 0; i < len; ++i) {
pos[i].set(x, y);
x += widths[i];
}
// Draw using text blobs!!!!
font.textToGlyphs(text, len, SkTextEncoding::kUTF8, glyphs.get(), len);
font.getXPos(glyphs.get(), len, pos.get());
auto blob = SkTextBlob::MakeFromPosTextH(text, len, pos.get(), 0, font);
// Draw with an origin.
canvas->drawTextBlob(blob, 10, y, paint);
// Draw with shifted canvas.
canvas->save();
canvas->translate(750, 0);
canvas->drawTextBlob(blob, 10, y, paint);
canvas->restore();
canvas->drawPosText(text, len, &pos[0], paint);
y += metrics.fDescent + metrics.fLeading;
}

View File

@ -468,8 +468,9 @@ void GrTextBlob::AssertEqual(const GrTextBlob& l, const GrTextBlob& r) {
void GrTextBlob::SubRun::computeTranslation(const SkMatrix& viewMatrix,
SkScalar x, SkScalar y, SkScalar* transX,
SkScalar* transY) {
calculate_translation(!this->drawAsDistanceFields(), viewMatrix, x, y,
fCurrentViewMatrix, fX, fY, transX, transY);
// Don't use the matrix to translate on distance field for fallback subruns.
calculate_translation(!this->drawAsDistanceFields() && !this->isFallback(), viewMatrix,
x, y, fCurrentViewMatrix, fX, fY, transX, transY);
fCurrentViewMatrix = viewMatrix;
fX = x;
fY = y;

View File

@ -345,7 +345,8 @@ private:
bool hasWCoord() const { return fFlags.hasWCoord; }
void setNeedsTransform(bool needsTransform) { fFlags.needsTransform = needsTransform; }
bool needsTransform() const { return fFlags.needsTransform; }
void setFallback() {fFlags.argbFallback = true;}
void setFallback() { fFlags.argbFallback = true; }
bool isFallback() { return fFlags.argbFallback; }
const SkDescriptor* desc() const { return fDesc.getDesc(); }