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

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: 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"
11 #include "SkPath.h" 11 #include "SkPath.h"
12 #include "SkRegion.h" 12 #include "SkRegion.h"
13 #include "SkShader.h" 13 #include "SkShader.h"
14 #include "SkUtils.h" 14 #include "SkUtils.h"
15 #include "Sk1DPathEffect.h" 15 #include "Sk1DPathEffect.h"
16 #include "SkCornerPathEffect.h" 16 #include "SkCornerPathEffect.h"
17 #include "SkPathMeasure.h" 17 #include "SkPathMeasure.h"
18 #include "SkRandom.h" 18 #include "SkRandom.h"
19 #include "SkColorPriv.h" 19 #include "SkColorPriv.h"
20 #include "SkColorFilter.h" 20 #include "SkColorFilter.h"
21 #include "SkDither.h" 21 #include "SkDither.h"
22 #include "sk_tool_utils.h"
22 23
23 static const struct { 24 static const struct {
24 const char* fName; 25 const char* fName;
25 SkTypeface::Style fStyle; 26 SkTypeface::Style fStyle;
26 } gFaces[] = { 27 } gFaces[] = {
27 { nullptr, SkTypeface::kNormal }, 28 { nullptr, SkTypeface::kNormal },
28 { nullptr, SkTypeface::kBold }, 29 { nullptr, SkTypeface::kBold },
29 { "serif", SkTypeface::kNormal }, 30 { "serif", SkTypeface::kNormal },
30 { "serif", SkTypeface::kBold }, 31 { "serif", SkTypeface::kBold },
31 { "serif", SkTypeface::kItalic }, 32 { "serif", SkTypeface::kItalic },
32 { "serif", SkTypeface::kBoldItalic }, 33 { "serif", SkTypeface::kBoldItalic },
33 { "monospace", SkTypeface::kNormal } 34 { "monospace", SkTypeface::kNormal }
34 }; 35 };
35 36
36 static const int gFaceCount = SK_ARRAY_COUNT(gFaces); 37 static const int gFaceCount = SK_ARRAY_COUNT(gFaces);
37 38
38 class FontScalerTestView : public SampleView { 39 class FontScalerTestView : public SampleView {
39 sk_sp<SkTypeface> fFaces[gFaceCount]; 40 sk_sp<SkTypeface> fFaces[gFaceCount];
40 41
41 public: 42 public:
42 FontScalerTestView() { 43 FontScalerTestView() {
43 for (int i = 0; i < gFaceCount; i++) { 44 for (int i = 0; i < gFaceCount; i++) {
44 fFaces[i] = SkTypeface::MakeFromName( 45 fFaces[i] = SkTypeface::MakeFromName(
45 gFaces[i].fName, SkFontStyle::FromOldStyle(gFaces[i].fStyle)); 46 gFaces[i].fName, SkFontStyle::FromOldStyle(gFaces[i].fStyle));
46 } 47 }
47 // this->setBGColor(0xFFDDDDDD);
48 } 48 }
49 49
50 protected: 50 protected:
51 // overrides from SkEventSink 51 // overrides from SkEventSink
52 virtual bool onQuery(SkEvent* evt) { 52 virtual bool onQuery(SkEvent* evt) {
53 if (SampleCode::TitleQ(*evt)) { 53 if (SampleCode::TitleQ(*evt)) {
54 SampleCode::TitleR(evt, "FontScaler Test"); 54 SampleCode::TitleR(evt, "FontScaler Test");
55 return true; 55 return true;
56 } 56 }
57 return this->INHERITED::onQuery(evt); 57 return this->INHERITED::onQuery(evt);
58 } 58 }
59 59
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) { 60 virtual void onDrawContent(SkCanvas* canvas) {
67 SkPaint paint; 61 SkPaint paint;
68 62
69 // test handling of obscene cubic values (currently broken) 63 // test handling of obscene cubic values (currently broken)
70 if (false) { 64 if (false) {
71 SkPoint pts[4]; 65 SkPoint pts[4];
72 pts[0].set(1.61061274e+09f, 6291456); 66 pts[0].set(1.61061274e+09f, 6291456);
73 pts[1].set(-7.18397061e+15f, 67 pts[1].set(-7.18397061e+15f,
74 -1.53091184e+13f); 68 -1.53091184e+13f);
75 pts[2].set(-1.30077315e+16f, 69 pts[2].set(-1.30077315e+16f,
(...skipping 17 matching lines...) Expand all
93 const size_t textLen = strlen(text); 87 const size_t textLen = strlen(text);
94 88
95 for (int j = 0; j < 2; ++j) { 89 for (int j = 0; j < 2; ++j) {
96 for (int i = 0; i < 6; ++i) { 90 for (int i = 0; i < 6; ++i) {
97 SkScalar x = SkIntToScalar(10); 91 SkScalar x = SkIntToScalar(10);
98 SkScalar y = SkIntToScalar(20); 92 SkScalar y = SkIntToScalar(20);
99 93
100 SkAutoCanvasRestore acr(canvas, true); 94 SkAutoCanvasRestore acr(canvas, true);
101 canvas->translate(SkIntToScalar(50 + i * 230), 95 canvas->translate(SkIntToScalar(50 + i * 230),
102 SkIntToScalar(20)); 96 SkIntToScalar(20));
103 rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10); 97 sk_tool_utils::rotate_about(canvas, SkIntToScalar(i * 5), x, y * 10);
104 98
105 { 99 {
106 SkPaint p; 100 SkPaint p;
107 p.setAntiAlias(true); 101 p.setAntiAlias(true);
108 SkRect r; 102 SkRect r;
109 r.set(x-3, 15, x-1, 280); 103 r.set(x-3, 15, x-1, 280);
110 canvas->drawRect(r, p); 104 canvas->drawRect(r, p);
111 } 105 }
112 106
113 int index = 0; 107 int index = 0;
(...skipping 10 matching lines...) Expand all
124 } 118 }
125 119
126 private: 120 private:
127 typedef SkView INHERITED; 121 typedef SkView INHERITED;
128 }; 122 };
129 123
130 ////////////////////////////////////////////////////////////////////////////// 124 //////////////////////////////////////////////////////////////////////////////
131 125
132 static SkView* MyFactory() { return new FontScalerTestView; } 126 static SkView* MyFactory() { return new FontScalerTestView; }
133 static SkViewRegister reg(MyFactory); 127 static SkViewRegister reg(MyFactory);
OLDNEW
« gm/strokes.cpp ('K') | « samplecode/SampleDither.cpp ('k') | samplecode/SampleHT.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698