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

Side by Side Diff: samplecode/ClockFaceView.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. Created 4 years, 7 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 | « public.bzl ('k') | samplecode/SampleAll.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 * 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 #include "SampleCode.h" 7 #include "SampleCode.h"
8 #include "SkView.h" 8 #include "SkView.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 SkLayerRasterizer::Builder rastBuilder; 163 SkLayerRasterizer::Builder rastBuilder;
164 164
165 p.setAntiAlias(true); 165 p.setAntiAlias(true);
166 r7(&rastBuilder, p, scale); 166 r7(&rastBuilder, p, scale);
167 paint->setRasterizer(rastBuilder.detach()); 167 paint->setRasterizer(rastBuilder.detach());
168 168
169 paint->setColor(SK_ColorBLUE); 169 paint->setColor(SK_ColorBLUE);
170 } 170 }
171 171
172 class ClockFaceView : public SkView { 172 class ClockFaceView : public SkView {
173 SkTypeface* fFace; 173 sk_sp<SkTypeface> fFace;
174 SkScalar fInterp; 174 SkScalar fInterp;
175 SkScalar fDx; 175 SkScalar fDx;
176 176
177 public: 177 public:
178 ClockFaceView() { 178 ClockFaceView() {
179 fFace = SkTypeface::CreateFromFile("/Users/reed/Downloads/p052024l.pfb") ; 179 fFace = SkTypeface::MakeFromFile("/Users/reed/Downloads/p052024l.pfb");
180 fInterp = 0; 180 fInterp = 0;
181 fDx = SK_Scalar1/64; 181 fDx = SK_Scalar1/64;
182 } 182 }
183 183
184 virtual ~ClockFaceView() {
185 SkSafeUnref(fFace);
186 }
187
188 protected: 184 protected:
189 // overrides from SkEventSink 185 // overrides from SkEventSink
190 virtual bool onQuery(SkEvent* evt) { 186 virtual bool onQuery(SkEvent* evt) {
191 if (SampleCode::TitleQ(*evt)) { 187 if (SampleCode::TitleQ(*evt)) {
192 SampleCode::TitleR(evt, "Text Effects"); 188 SampleCode::TitleR(evt, "Text Effects");
193 return true; 189 return true;
194 } 190 }
195 return this->INHERITED::onQuery(evt); 191 return this->INHERITED::onQuery(evt);
196 } 192 }
197 193
(...skipping 20 matching lines...) Expand all
218 214
219 virtual void onDraw(SkCanvas* canvas) { 215 virtual void onDraw(SkCanvas* canvas) {
220 this->drawBG(canvas); 216 this->drawBG(canvas);
221 217
222 SkScalar x = SkIntToScalar(20); 218 SkScalar x = SkIntToScalar(20);
223 SkScalar y = SkIntToScalar(300); 219 SkScalar y = SkIntToScalar(300);
224 SkPaint paint; 220 SkPaint paint;
225 221
226 paint.setAntiAlias(true); 222 paint.setAntiAlias(true);
227 paint.setTextSize(SkIntToScalar(240)); 223 paint.setTextSize(SkIntToScalar(240));
228 paint.setTypeface(SkTypeface::CreateFromName("sans-serif", 224 paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkTypeface::kBo ld));
229 SkTypeface::kBold));
230 225
231 SkString str("9"); 226 SkString str("9");
232 227
233 paint.setTypeface(fFace); 228 paint.setTypeface(fFace);
234 229
235 apply_shader(&paint, SkScalarToFloat(fInterp)); 230 apply_shader(&paint, SkScalarToFloat(fInterp));
236 canvas->drawText(str.c_str(), str.size(), x, y, paint); 231 canvas->drawText(str.c_str(), str.size(), x, y, paint);
237 232
238 // drawdots(canvas, paint); 233 // drawdots(canvas, paint);
239 234
(...skipping 11 matching lines...) Expand all
251 } 246 }
252 247
253 private: 248 private:
254 typedef SkView INHERITED; 249 typedef SkView INHERITED;
255 }; 250 };
256 251
257 ////////////////////////////////////////////////////////////////////////////// 252 //////////////////////////////////////////////////////////////////////////////
258 253
259 static SkView* MyFactory() { return new ClockFaceView; } 254 static SkView* MyFactory() { return new ClockFaceView; }
260 static SkViewRegister reg(MyFactory); 255 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « public.bzl ('k') | samplecode/SampleAll.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698