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

Side by Side Diff: samplecode/SampleFontScalerTest.cpp

Issue 2142033002: Factor code to rotate a canvas about a point. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move to canvas. 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
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 "SkTypeface.h" 10 #include "SkTypeface.h"
(...skipping 26 matching lines...) Expand all
37 37
38 class FontScalerTestView : public SampleView { 38 class FontScalerTestView : public SampleView {
39 sk_sp<SkTypeface> fFaces[gFaceCount]; 39 sk_sp<SkTypeface> fFaces[gFaceCount];
40 40
41 public: 41 public:
42 FontScalerTestView() { 42 FontScalerTestView() {
43 for (int i = 0; i < gFaceCount; i++) { 43 for (int i = 0; i < gFaceCount; i++) {
44 fFaces[i] = SkTypeface::MakeFromName( 44 fFaces[i] = SkTypeface::MakeFromName(
45 gFaces[i].fName, SkFontStyle::FromOldStyle(gFaces[i].fStyle)); 45 gFaces[i].fName, SkFontStyle::FromOldStyle(gFaces[i].fStyle));
46 } 46 }
47 // this->setBGColor(0xFFDDDDDD);
48 } 47 }
49 48
50 protected: 49 protected:
51 // overrides from SkEventSink 50 // overrides from SkEventSink
52 virtual bool onQuery(SkEvent* evt) { 51 virtual bool onQuery(SkEvent* evt) {
53 if (SampleCode::TitleQ(*evt)) { 52 if (SampleCode::TitleQ(*evt)) {
54 SampleCode::TitleR(evt, "FontScaler Test"); 53 SampleCode::TitleR(evt, "FontScaler Test");
55 return true; 54 return true;
56 } 55 }
57 return this->INHERITED::onQuery(evt); 56 return this->INHERITED::onQuery(evt);
58 } 57 }
59 58
60 static void rotate_about(SkCanvas* canvas, SkScalar degrees, SkScalar px, Sk Scalar py) {
61 canvas->translate(px, py);
62 canvas->rotate(degrees);
63 canvas->translate(-px, -py);
64 }
65
66 virtual void onDrawContent(SkCanvas* canvas) { 59 virtual void onDrawContent(SkCanvas* canvas) {
67 SkPaint paint; 60 SkPaint paint;
68 61
69 // test handling of obscene cubic values (currently broken) 62 // test handling of obscene cubic values (currently broken)
70 if (false) { 63 if (false) {
71 SkPoint pts[4]; 64 SkPoint pts[4];
72 pts[0].set(1.61061274e+09f, 6291456); 65 pts[0].set(1.61061274e+09f, 6291456);
73 pts[1].set(-7.18397061e+15f, 66 pts[1].set(-7.18397061e+15f,
74 -1.53091184e+13f); 67 -1.53091184e+13f);
75 pts[2].set(-1.30077315e+16f, 68 pts[2].set(-1.30077315e+16f,
(...skipping 17 matching lines...) Expand all
93 const size_t textLen = strlen(text); 86 const size_t textLen = strlen(text);
94 87
95 for (int j = 0; j < 2; ++j) { 88 for (int j = 0; j < 2; ++j) {
96 for (int i = 0; i < 6; ++i) { 89 for (int i = 0; i < 6; ++i) {
97 SkScalar x = SkIntToScalar(10); 90 SkScalar x = SkIntToScalar(10);
98 SkScalar y = SkIntToScalar(20); 91 SkScalar y = SkIntToScalar(20);
99 92
100 SkAutoCanvasRestore acr(canvas, true); 93 SkAutoCanvasRestore acr(canvas, true);
101 canvas->translate(SkIntToScalar(50 + i * 230), 94 canvas->translate(SkIntToScalar(50 + i * 230),
102 SkIntToScalar(20)); 95 SkIntToScalar(20));
103 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); 96 canvas->rotate(SkIntToScalar(i * 5), x, y * 10);
104 97
105 { 98 {
106 SkPaint p; 99 SkPaint p;
107 p.setAntiAlias(true); 100 p.setAntiAlias(true);
108 SkRect r; 101 SkRect r;
109 r.set(x-3, 15, x-1, 280); 102 r.set(x-3, 15, x-1, 280);
110 canvas->drawRect(r, p); 103 canvas->drawRect(r, p);
111 } 104 }
112 105
113 int index = 0; 106 int index = 0;
(...skipping 10 matching lines...) Expand all
124 } 117 }
125 118
126 private: 119 private:
127 typedef SkView INHERITED; 120 typedef SkView INHERITED;
128 }; 121 };
129 122
130 ////////////////////////////////////////////////////////////////////////////// 123 //////////////////////////////////////////////////////////////////////////////
131 124
132 static SkView* MyFactory() { return new FontScalerTestView; } 125 static SkView* MyFactory() { return new FontScalerTestView; }
133 static SkViewRegister reg(MyFactory); 126 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleDither.cpp ('k') | samplecode/SampleHT.cpp » ('j') | src/core/SkCanvas.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698