diff options
author | reed <reed@google.com> | 2016-07-07 12:47:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-07 12:47:17 -0700 |
commit | 45561a0b15fe045ba272c328684c3f7ae290785a (patch) | |
tree | 185647ba5e92daf0899b1d8985dbf4a46a76f7b9 /gm | |
parent | a76a10b730ae3fb2abb7c06839ca9c5d14df5ca7 (diff) |
drawTextRSXform
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2130643004
Review-Url: https://codereview.chromium.org/2130643004
Diffstat (limited to 'gm')
-rw-r--r-- | gm/drawatlas.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp index a906cbedeb..ba71eaea57 100644 --- a/gm/drawatlas.cpp +++ b/gm/drawatlas.cpp @@ -100,3 +100,68 @@ private: typedef GM INHERITED; }; 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) { + SkPathMeasure meas(path, false); + + int count = paint.countText(text, length); + SkAutoSTArray<100, SkRSXform> xform(count); + + for (int i = 0; i < count; ++i) { + SkPoint pos; + SkVector tan; + if (!meas.getPosTan(xy[i].x(), &pos, &tan)) { + pos = xy[i]; + tan.set(1, 0); + } + xform[i].fSCos = tan.x(); + xform[i].fSSin = tan.y(); + xform[i].fTx = pos.x(); + xform[i].fTy = pos.y(); + } + + canvas->drawTextRSXform(text, length, &xform[0], nullptr, paint); +} + +DEF_SIMPLE_GM(drawTextRSXform, canvas, 510, 310) { + const char text[] = "ABCDFGHJKLMNOPQRSTUVWXYZ"; + const int N = sizeof(text) - 1; + SkPoint pos[N]; + SkRSXform xform[N]; + + canvas->translate(0, 30); + + SkScalar x = 20; + SkScalar dx = 20; + SkScalar rad = 0; + SkScalar drad = 2 * SK_ScalarPI / (N - 1); + for (int i = 0; i < N; ++i) { + xform[i].fSCos = SkScalarCos(rad); + xform[i].fSSin = SkScalarSin(rad); + xform[i].fTx = x; + xform[i].fTy = 0; + pos[i].set(x, 0); + x += dx; + rad += drad; + } + + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(20); + canvas->drawTextRSXform(text, N, xform, nullptr, paint); + + SkPath path; + path.addOval(SkRect::MakeXYWH(150, 50, 200, 200)); + + draw_text_on_path_rigid(canvas, text, N, pos, path, paint); + + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPath(path, paint); +} + + |