Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: gm/drawatlas.cpp

Issue 2130643004: drawTextRSXform (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update util canvases Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkCanvas.h » ('j') | include/core/SkCanvas.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkRSXform.h" 10 #include "SkRSXform.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 canvas->drawAtlas(fAtlas.get(), xform, tex, N, nullptr, &paint); 94 canvas->drawAtlas(fAtlas.get(), xform, tex, N, nullptr, &paint);
95 canvas->translate(0, 100); 95 canvas->translate(0, 100);
96 canvas->drawAtlas(fAtlas.get(), xform, tex, colors, N, SkXfermode::kSrcI n_Mode, nullptr, &paint); 96 canvas->drawAtlas(fAtlas.get(), xform, tex, colors, N, SkXfermode::kSrcI n_Mode, nullptr, &paint);
97 } 97 }
98 98
99 private: 99 private:
100 typedef GM INHERITED; 100 typedef GM INHERITED;
101 }; 101 };
102 DEF_GM( return new DrawAtlasGM; ) 102 DEF_GM( return new DrawAtlasGM; )
103
104 //////////////////////////////////////////////////////////////////////////////// ///////////////////
105 #include "SkPath.h"
106 #include "SkPathMeasure.h"
107
108 static void draw_text_on_path_rigid(SkCanvas* canvas, const void* text, size_t l ength,
109 const SkPoint xy[], const SkPath& path, cons t SkPaint& paint) {
110 SkPathMeasure meas(path, false);
111
112 int count = paint.countText(text, length);
113 SkAutoSTArray<100, SkRSXform> xform(count);
114
115 for (int i = 0; i < count; ++i) {
116 SkPoint pos;
117 SkVector tan;
118 if (!meas.getPosTan(xy[i].x(), &pos, &tan)) {
119 pos = xy[i];
120 tan.set(1, 0);
121 }
122 xform[i].fSCos = tan.x();
123 xform[i].fSSin = tan.y();
124 xform[i].fTx = pos.x();
125 xform[i].fTy = pos.y();
126 }
127
128 canvas->drawTextRSXform(text, length, &xform[0], nullptr, paint);
129 }
130
131 DEF_SIMPLE_GM(drawTextRSXform, canvas, 510, 310) {
132 const char text[] = "ABCDFGHJKLMNOPQRSTUVWXYZ";
133 const int N = sizeof(text) - 1;
134 SkPoint pos[N];
135 SkRSXform xform[N];
136
137 canvas->translate(0, 30);
138
139 SkScalar x = 20;
140 SkScalar dx = 20;
141 SkScalar rad = 0;
142 SkScalar drad = 2 * SK_ScalarPI / (N - 1);
143 for (int i = 0; i < N; ++i) {
144 xform[i].fSCos = SkScalarCos(rad);
145 xform[i].fSSin = SkScalarSin(rad);
146 xform[i].fTx = x;
147 xform[i].fTy = 0;
148 pos[i].set(x, 0);
149 x += dx;
150 rad += drad;
151 }
152
153 SkPaint paint;
154 paint.setAntiAlias(true);
155 paint.setTextSize(20);
156 canvas->drawTextRSXform(text, N, xform, nullptr, paint);
157
158 SkPath path;
159 path.addOval(SkRect::MakeXYWH(150, 50, 200, 200));
160
161 draw_text_on_path_rigid(canvas, text, N, pos, path, paint);
162
163 paint.setStyle(SkPaint::kStroke_Style);
164 canvas->drawPath(path, paint);
165 }
166
167
OLDNEW
« no previous file with comments | « no previous file | include/core/SkCanvas.h » ('j') | include/core/SkCanvas.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698