OLD | NEW |
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 Loading... |
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 |
OLD | NEW |