OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "gm.h" | 8 #include "gm.h" |
8 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
9 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
10 | 11 |
11 namespace skiagm { | |
12 | |
13 static void makebm(SkBitmap* bm, int w, int h) { | 12 static void makebm(SkBitmap* bm, int w, int h) { |
14 bm->allocN32Pixels(w, h); | 13 bm->allocN32Pixels(w, h); |
15 bm->eraseColor(SK_ColorTRANSPARENT); | 14 bm->eraseColor(SK_ColorTRANSPARENT); |
16 | 15 |
17 SkCanvas canvas(*bm); | 16 SkCanvas canvas(*bm); |
18 SkScalar s = SkIntToScalar(SkMin32(w, h)); | 17 SkScalar s = SkIntToScalar(SkMin32(w, h)); |
19 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; | 18 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; |
20 static const SkPoint kPts1[] = { { s, 0 }, { 0, s } }; | 19 static const SkPoint kPts1[] = { { s, 0 }, { 0, s } }; |
21 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; | 20 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
22 static const SkColor kColors0[] = {0x40FF00FF, 0xF0FFFF00, 0x4000FFFF }; | 21 static const SkColor kColors0[] = {0x40FF00FF, 0xF0FFFF00, 0x4000FFFF }; |
(...skipping 10 matching lines...) Expand all Loading... |
33 canvas.drawPaint(paint); | 32 canvas.drawPaint(paint); |
34 } | 33 } |
35 | 34 |
36 /////////////////////////////////////////////////////////////////////////////// | 35 /////////////////////////////////////////////////////////////////////////////// |
37 | 36 |
38 struct LabeledMatrix { | 37 struct LabeledMatrix { |
39 SkMatrix fMatrix; | 38 SkMatrix fMatrix; |
40 const char* fLabel; | 39 const char* fLabel; |
41 }; | 40 }; |
42 | 41 |
43 class ShaderText2GM : public GM { | 42 class ShaderText2GM : public skiagm::GM { |
| 43 SkCanvas::TextOnPathMethod fMethod; |
| 44 SkString fName; |
| 45 |
44 public: | 46 public: |
45 ShaderText2GM() { | 47 ShaderText2GM(SkCanvas::TextOnPathMethod method) : fMethod(method) { |
46 this->setBGColor(0xFFDDDDDD); | 48 this->setBGColor(0xFFDDDDDD); |
| 49 |
| 50 fName.set("shadertext2"); |
| 51 if (SkCanvas::kAlign_TextOnPathMethod == fMethod) { |
| 52 fName.append("_align"); |
| 53 } |
47 } | 54 } |
48 | 55 |
49 protected: | 56 protected: |
50 | 57 |
51 SkString onShortName() SK_OVERRIDE { | 58 SkString onShortName() SK_OVERRIDE { return fName; } |
52 return SkString("shadertext2"); | |
53 } | |
54 | 59 |
55 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1800, 900); } | 60 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1800, 900); } |
56 | 61 |
57 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 62 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
58 static const char kText[] = "SKIA"; | 63 static const char kText[] = "SKIA"; |
59 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; | 64 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; |
60 static const int kPointSize = 55; | 65 static const int kPointSize = 55; |
61 | 66 |
62 SkTDArray<LabeledMatrix> matrices; | 67 SkTDArray<LabeledMatrix> matrices; |
63 matrices.append()->fMatrix.reset(); | 68 matrices.append()->fMatrix.reset(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 1.2f * w, 2.f * kPointSize), | 172 1.2f * w, 2.f * kPointSize), |
168 225.f, 359.f, | 173 225.f, 359.f, |
169 false); | 174 false); |
170 path.close(); | 175 path.close(); |
171 | 176 |
172 canvas->translate(0.f, kPointSize + kPadY); | 177 canvas->translate(0.f, kPointSize + kPadY); |
173 columnH += kPointSize + kPadY; | 178 columnH += kPointSize + kPadY; |
174 | 179 |
175 canvas->save(); | 180 canvas->save(); |
176 canvas->concat(matrices[m].fMatrix); | 181 canvas->concat(matrices[m].fMatrix); |
177 canvas->drawTextOnPath(kText, kTextLen, path, NULL, pain
t); | 182 canvas->drawTextOnPath(kText, kTextLen, path, NULL, fMet
hod, paint); |
178 canvas->drawTextOnPath(kText, kTextLen, path, NULL, outl
inePaint); | 183 canvas->drawTextOnPath(kText, kTextLen, path, NULL, fMet
hod, outlinePaint); |
179 canvas->restore(); | 184 canvas->restore(); |
180 SkPaint stroke; | 185 SkPaint stroke; |
181 stroke.setStyle(SkPaint::kStroke_Style); | 186 stroke.setStyle(SkPaint::kStroke_Style); |
182 canvas->translate(0.f, kPointSize + kPadY); | 187 canvas->translate(0.f, kPointSize + kPadY); |
183 columnH += kPointSize + kPadY; | 188 columnH += kPointSize + kPadY; |
184 } | 189 } |
185 canvas->restore(); | 190 canvas->restore(); |
186 canvas->translate(w + kPadX, 0.f); | 191 canvas->translate(w + kPadX, 0.f); |
187 } | 192 } |
188 if (0 == s) { | 193 if (0 == s) { |
189 canvas->drawLine(0.f, -kPadY, 0.f, columnH + kPadY, outlinePaint
); | 194 canvas->drawLine(0.f, -kPadY, 0.f, columnH + kPadY, outlinePaint
); |
190 canvas->translate(kPadX / 2, 0.f); | 195 canvas->translate(kPadX / 2, 0.f); |
191 static const char kFillLabel[] = "Filled"; | 196 static const char kFillLabel[] = "Filled"; |
192 static const char kStrokeLabel[] = "Stroked"; | 197 static const char kStrokeLabel[] = "Stroked"; |
193 SkScalar y = columnH + kPadY / 2; | 198 SkScalar y = columnH + kPadY / 2; |
194 SkScalar fillX = -outlinePaint.measureText(kFillLabel, strlen(kF
illLabel)) - kPadX; | 199 SkScalar fillX = -outlinePaint.measureText(kFillLabel, strlen(kF
illLabel)) - kPadX; |
195 SkScalar strokeX = kPadX; | 200 SkScalar strokeX = kPadX; |
196 canvas->drawText(kFillLabel, strlen(kFillLabel), fillX, y, label
Paint); | 201 canvas->drawText(kFillLabel, strlen(kFillLabel), fillX, y, label
Paint); |
197 canvas->drawText(kStrokeLabel, strlen(kStrokeLabel), strokeX, y,
labelPaint); | 202 canvas->drawText(kStrokeLabel, strlen(kStrokeLabel), strokeX, y,
labelPaint); |
198 } | 203 } |
199 } | 204 } |
200 } | 205 } |
201 | 206 |
202 private: | 207 private: |
203 typedef GM INHERITED; | 208 typedef skiagm::GM INHERITED; |
204 }; | 209 }; |
205 | 210 |
206 /////////////////////////////////////////////////////////////////////////////// | 211 DEF_GM( return new ShaderText2GM(SkCanvas::kAlign_TextOnPathMethod); ) |
207 | 212 DEF_GM( return new ShaderText2GM(SkCanvas::kStretch_TextOnPathMethod); ) |
208 static GM* MyFactory(void*) { return new ShaderText2GM; } | |
209 static GMRegistry reg(MyFactory); | |
210 } | |
OLD | NEW |