diff options
author | Mike Reed <reed@google.com> | 2018-01-29 13:33:06 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-29 19:20:31 +0000 |
commit | 488fbd13a6a241f2b74f6fa770ae3497af33dbce (patch) | |
tree | c9b4be839bc58b56b810180eac9c0c6a8a0a2d0c /gm/drawatlas.cpp | |
parent | 58acd74f55f2ffd233053a5b06901ed0251fb32c (diff) |
compare textonpath techniques
Bug: skia:7554
Change-Id: I8d41c4962c6ff8f9733527301af68041f0e6ef40
Reviewed-on: https://skia-review.googlesource.com/101340
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'gm/drawatlas.cpp')
-rw-r--r-- | gm/drawatlas.cpp | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp index afb197eeef..d916451430 100644 --- a/gm/drawatlas.cpp +++ b/gm/drawatlas.cpp @@ -101,8 +101,9 @@ DEF_GM( return new DrawAtlasGM; ) #include "SkPath.h" #include "SkPathMeasure.h" -static void draw_text_on_path_rigid(SkCanvas* canvas, const void* text, size_t length, - const SkPoint xy[], const SkPath& path, const SkPaint& paint) { +static void draw_text_on_path(SkCanvas* canvas, const void* text, size_t length, + const SkPoint xy[], const SkPath& path, const SkPaint& paint, + float baseline_offset, bool useRSX) { SkPathMeasure meas(path, false); int count = paint.countText(text, length); @@ -111,30 +112,36 @@ static void draw_text_on_path_rigid(SkCanvas* canvas, const void* text, size_t l SkRSXform* xform = (SkRSXform*)storage.get(); SkScalar* widths = (SkScalar*)(xform + count); - paint.getTextWidths(text, length, widths); - - for (int i = 0; i < count; ++i) { - // we want to position each character on the center of its advance - const SkScalar offset = SkScalarHalf(widths[i]); - SkPoint pos; - SkVector tan; - if (!meas.getPosTan(xy[i].x() + offset, &pos, &tan)) { - pos = xy[i]; - tan.set(1, 0); - } - xform[i].fSCos = tan.x(); - xform[i].fSSin = tan.y(); - xform[i].fTx = pos.x() - tan.y() * xy[i].y() - tan.x() * offset; - xform[i].fTy = pos.y() + tan.x() * xy[i].y() - tan.y() * offset; - } - // Compute a conservative bounds so we can cull the draw const SkRect font = paint.getFontBounds(); const SkScalar max = SkTMax(SkTMax(SkScalarAbs(font.fLeft), SkScalarAbs(font.fRight)), SkTMax(SkScalarAbs(font.fTop), SkScalarAbs(font.fBottom))); const SkRect bounds = path.getBounds().makeOutset(max, max); - canvas->drawTextRSXform(text, length, &xform[0], &bounds, paint); + if (useRSX) { + paint.getTextWidths(text, length, widths); + + for (int i = 0; i < count; ++i) { + // we want to position each character on the center of its advance + const SkScalar offset = SkScalarHalf(widths[i]); + SkPoint pos; + SkVector tan; + if (!meas.getPosTan(xy[i].x() + offset, &pos, &tan)) { + pos = xy[i]; + tan.set(1, 0); + } + pos += SkVector::Make(-tan.fY, tan.fX) * baseline_offset; + + xform[i].fSCos = tan.x(); + xform[i].fSSin = tan.y(); + xform[i].fTx = pos.x() - tan.y() * xy[i].y() - tan.x() * offset; + xform[i].fTy = pos.y() + tan.x() * xy[i].y() - tan.y() * offset; + } + + canvas->drawTextRSXform(text, length, &xform[0], &bounds, paint); + } else { + canvas->drawTextOnPathHV(text, length, path, 0, baseline_offset, paint); + } if (true) { SkPaint p; @@ -143,7 +150,7 @@ static void draw_text_on_path_rigid(SkCanvas* canvas, const void* text, size_t l } } -DEF_SIMPLE_GM(drawTextRSXform, canvas, 860, 860) { +static void drawTextPath(SkCanvas* canvas, bool useRSX) { const char text0[] = "ABCDFGHJKLMNOPQRSTUVWXYZ"; const int N = sizeof(text0) - 1; SkPoint pos[N]; @@ -159,14 +166,28 @@ DEF_SIMPLE_GM(drawTextRSXform, canvas, 860, 860) { } SkPath path; - path.addOval(SkRect::MakeXYWH(160, 160, 540, 540)); + const float baseline_offset = -5; - draw_text_on_path_rigid(canvas, text0, N, pos, path, paint); + const SkPath::Direction dirs[] = { + SkPath::kCW_Direction, SkPath::kCCW_Direction, + }; + for (auto d : dirs) { + path.reset(); + path.addOval(SkRect::MakeXYWH(160, 160, 540, 540), d); + draw_text_on_path(canvas, text0, N, pos, path, paint, baseline_offset, useRSX); + } paint.setStyle(SkPaint::kStroke_Style); canvas->drawPath(path, paint); } +DEF_SIMPLE_GM(drawTextRSXform, canvas, 860, 430) { + canvas->scale(0.5f, 0.5f); + drawTextPath(canvas, false); + canvas->translate(860, 0); + drawTextPath(canvas, true); +} + #include "Resources.h" #include "SkColorFilter.h" #include "SkVertices.h" |