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

Side by Side Diff: samplecode/SampleTextOnPath.cpp

Issue 933483002: add Method param to drawTextOnPath, supporting SVG spec Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 10 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 | « samplecode/SampleSlides.cpp ('k') | src/animator/SkTextOnPath.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurDrawLooper.h" 10 #include "SkBlurDrawLooper.h"
(...skipping 24 matching lines...) Expand all
35 35
36 canvas->drawPath(path, paint); 36 canvas->drawPath(path, paint);
37 37
38 paint.setLooper(SkBlurDrawLooper::Create(SK_ColorBLACK, 38 paint.setLooper(SkBlurDrawLooper::Create(SK_ColorBLACK,
39 SkBlurMask::ConvertRadiusToSigma(0. 002f), 39 SkBlurMask::ConvertRadiusToSigma(0. 002f),
40 0.0f, 40 0.0f,
41 0.0f))->unref(); 41 0.0f))->unref();
42 42
43 const char* text = "DRAWING STROKED TEXT WITH A BLUR ON A PATH"; 43 const char* text = "DRAWING STROKED TEXT WITH A BLUR ON A PATH";
44 size_t len = strlen(text); 44 size_t len = strlen(text);
45 SkMatrix matrix;
46 SkCanvas::TextOnPathMethod method = SkCanvas::kStretch_TextOnPathMethod;
45 47
46 canvas->drawTextOnPathHV(text, len, path, 0, 48 matrix.setTranslate(0, -0.025f);
47 -0.025f, paint); 49 canvas->drawTextOnPath(text, len, path, &matrix, method, paint);
48 canvas->restore(); 50 canvas->restore();
49 } 51 }
50 52
51 static void textPathMatrix(SkCanvas* canvas) { 53 static void textPathMatrix(SkCanvas* canvas) {
52 SkPaint paint; 54 SkPaint paint;
53 SkPath path; 55 SkPath path;
54 SkMatrix matrix; 56 SkMatrix matrix;
55 57
56 path.moveTo(SkIntToScalar(050), SkIntToScalar(200)); 58 path.moveTo(SkIntToScalar(050), SkIntToScalar(200));
57 path.quadTo(SkIntToScalar(250), SkIntToScalar(000), 59 path.quadTo(SkIntToScalar(250), SkIntToScalar(000),
58 SkIntToScalar(450), SkIntToScalar(200)); 60 SkIntToScalar(450), SkIntToScalar(200));
59 61
60 paint.setAntiAlias(true); 62 paint.setAntiAlias(true);
61 63
62 paint.setStyle(SkPaint::kStroke_Style); 64 paint.setStyle(SkPaint::kStroke_Style);
63 canvas->drawPath(path, paint); 65 canvas->drawPath(path, paint);
64 paint.setStyle(SkPaint::kFill_Style); 66 paint.setStyle(SkPaint::kFill_Style);
65 paint.setTextSize(SkIntToScalar(48)); 67 paint.setTextSize(SkIntToScalar(48));
66 paint.setTextAlign(SkPaint::kRight_Align); 68 paint.setTextAlign(SkPaint::kRight_Align);
67 69
68 const char* text = "Reflection"; 70 const char* text = "Reflection";
69 size_t len = strlen(text); 71 size_t len = strlen(text);
70 72
71 SkPathMeasure meas(path, false); 73 SkPathMeasure meas(path, false);
72 SkScalar pathLen = meas.getLength(); 74 SkScalar pathLen = meas.getLength();
75 SkCanvas::TextOnPathMethod method = SkCanvas::kStretch_TextOnPathMethod;
73 76
74 canvas->drawTextOnPath(text, len, path, NULL, paint); 77 canvas->drawTextOnPath(text, len, path, NULL, method, paint);
75 78
76 paint.setColor(SK_ColorRED); 79 paint.setColor(SK_ColorRED);
77 matrix.setScale(-SK_Scalar1, SK_Scalar1); 80 matrix.setScale(-SK_Scalar1, SK_Scalar1);
78 matrix.postTranslate(pathLen, 0); 81 matrix.postTranslate(pathLen, 0);
79 canvas->drawTextOnPath(text, len, path, &matrix, paint); 82 canvas->drawTextOnPath(text, len, path, &matrix, method, paint);
80 83
81 paint.setColor(SK_ColorBLUE); 84 paint.setColor(SK_ColorBLUE);
82 matrix.setScale(SK_Scalar1, -SK_Scalar1); 85 matrix.setScale(SK_Scalar1, -SK_Scalar1);
83 canvas->drawTextOnPath(text, len, path, &matrix, paint); 86 canvas->drawTextOnPath(text, len, path, &matrix, method, paint);
84 87
85 paint.setColor(SK_ColorGREEN); 88 paint.setColor(SK_ColorGREEN);
86 matrix.setScale(-SK_Scalar1, -SK_Scalar1); 89 matrix.setScale(-SK_Scalar1, -SK_Scalar1);
87 matrix.postTranslate(pathLen, 0); 90 matrix.postTranslate(pathLen, 0);
88 canvas->drawTextOnPath(text, len, path, &matrix, paint); 91 canvas->drawTextOnPath(text, len, path, &matrix, method, paint);
89 } 92 }
90 93
91 class TextOnPathView : public SampleView { 94 class TextOnPathView : public SampleView {
92 public: 95 public:
93 SkPath fPath; 96 SkPath fPath;
94 SkScalar fHOffset; 97 SkScalar fHOffset;
95 98
96 TextOnPathView() { 99 TextOnPathView() {
97 SkRect r; 100 SkRect r;
98 r.set(SkIntToScalar(100), SkIntToScalar(100), 101 r.set(SkIntToScalar(100), SkIntToScalar(100),
(...skipping 14 matching lines...) Expand all
113 return this->INHERITED::onQuery(evt); 116 return this->INHERITED::onQuery(evt);
114 } 117 }
115 118
116 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { 119 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
117 SkPaint paint; 120 SkPaint paint;
118 paint.setAntiAlias(true); 121 paint.setAntiAlias(true);
119 paint.setTextSize(SkIntToScalar(48)); 122 paint.setTextSize(SkIntToScalar(48));
120 123
121 const char* text = "Hamburgefons"; 124 const char* text = "Hamburgefons";
122 size_t len = strlen(text); 125 size_t len = strlen(text);
123 126 SkCanvas::TextOnPathMethod method = SkCanvas::kStretch_TextOnPathMethod;
127 SkMatrix matrix;
128
124 for (int j = 0; j < REPEAT_COUNT; j++) { 129 for (int j = 0; j < REPEAT_COUNT; j++) {
125 SkScalar x = fHOffset; 130 SkScalar x = fHOffset;
126 131
127 paint.setColor(SK_ColorBLACK); 132 paint.setColor(SK_ColorBLACK);
128 canvas->drawTextOnPathHV(text, len, fPath, 133 matrix.setTranslate(x, paint.getTextSize()/2);
129 x, paint.getTextSize()/2, paint); 134 canvas->drawTextOnPath(text, len, fPath, &matrix, method, paint);
130 135
131 paint.setColor(SK_ColorRED); 136 paint.setColor(SK_ColorRED);
132 canvas->drawTextOnPathHV(text, len, fPath, 137 matrix.setTranslate(x + 50, 0);
133 x + SkIntToScalar(50), 0, paint); 138 canvas->drawTextOnPath(text, len, fPath, &matrix, method, paint);
134 139
135 paint.setColor(SK_ColorBLUE); 140 paint.setColor(SK_ColorBLUE);
136 canvas->drawTextOnPathHV(text, len, fPath, 141 matrix.setTranslate(x + 100, -paint.getTextSize()/2);
137 x + SkIntToScalar(100), -paint.getTextSize()/2, paint); 142 canvas->drawTextOnPath(text, len, fPath, &matrix, method, paint);
138 } 143 }
139 144
140 paint.setColor(SK_ColorGREEN); 145 paint.setColor(SK_ColorGREEN);
141 paint.setStyle(SkPaint::kStroke_Style); 146 paint.setStyle(SkPaint::kStroke_Style);
142 canvas->drawPath(fPath, paint); 147 canvas->drawPath(fPath, paint);
143 148
144 canvas->translate(SkIntToScalar(275), 0); 149 canvas->translate(SkIntToScalar(275), 0);
145 textStrokePath(canvas); 150 textStrokePath(canvas);
146 151
147 canvas->translate(SkIntToScalar(-275), SkIntToScalar(250)); 152 canvas->translate(SkIntToScalar(-275), SkIntToScalar(250));
(...skipping 18 matching lines...) Expand all
166 typedef SampleView INHERITED; 171 typedef SampleView INHERITED;
167 }; 172 };
168 173
169 ////////////////////////////////////////////////////////////////////////////// 174 //////////////////////////////////////////////////////////////////////////////
170 175
171 static SkView* MyFactory() { 176 static SkView* MyFactory() {
172 return new TextOnPathView; 177 return new TextOnPathView;
173 } 178 }
174 179
175 static SkViewRegister reg(MyFactory); 180 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleSlides.cpp ('k') | src/animator/SkTextOnPath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698