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

Side by Side Diff: gm/verttext2.cpp

Issue 1974783002: Revert of Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
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 7
8 8
9 /* Tests text vertical text rendering with different fonts and centering. 9 /* Tests text vertical text rendering with different fonts and centering.
10 */ 10 */
11 11
12 #include "gm.h" 12 #include "gm.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkTypeface.h" 14 #include "SkTypeface.h"
15 15
16 namespace skiagm { 16 namespace skiagm {
17 17
18 class VertText2GM : public GM { 18 class VertText2GM : public GM {
19 public: 19 public:
20 VertText2GM() {} 20 VertText2GM()
21 : fProp(nullptr)
22 , fMono(nullptr) {
23 }
24
25 virtual ~VertText2GM() {
26 SkSafeUnref(fProp);
27 SkSafeUnref(fMono);
28 }
21 29
22 protected: 30 protected:
23 void onOnceBeforeDraw() override { 31 void onOnceBeforeDraw() override {
24 const int pointSize = 24; 32 const int pointSize = 24;
25 textHeight = SkIntToScalar(pointSize); 33 textHeight = SkIntToScalar(pointSize);
26 fProp = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("sans -serif"), 34 fProp = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("sa ns-serif"),
27 SkTypeface::kNormal); 35 SkTypeface::kNormal);
28 fMono = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("mono space"), 36 fMono = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("mo nospace"),
29 SkTypeface::kNormal); 37 SkTypeface::kNormal);
30 } 38 }
31 39
32 SkString onShortName() override { 40 SkString onShortName() override {
33 SkString name("verttext2"); 41 SkString name("verttext2");
34 name.append(sk_tool_utils::major_platform_os_name()); 42 name.append(sk_tool_utils::major_platform_os_name());
35 return name; 43 return name;
36 } 44 }
37 45
38 SkISize onISize() override { return SkISize::Make(640, 480); } 46 SkISize onISize() override { return SkISize::Make(640, 480); }
(...skipping 20 matching lines...) Expand all
59 fMono, SkPaint::kCenter_Align); 67 fMono, SkPaint::kCenter_Align);
60 canvas->rotate(SkIntToScalar(-15)); 68 canvas->rotate(SkIntToScalar(-15));
61 canvas->translate(textHeight * 4, SkIntToScalar(50)); 69 canvas->translate(textHeight * 4, SkIntToScalar(50));
62 if (i > 0) { 70 if (i > 0) {
63 canvas->translate(0, SkIntToScalar(50)); 71 canvas->translate(0, SkIntToScalar(50));
64 } 72 }
65 } 73 }
66 } 74 }
67 75
68 void drawText(SkCanvas* canvas, const SkString& string, 76 void drawText(SkCanvas* canvas, const SkString& string,
69 sk_sp<SkTypeface> family, SkPaint::Align alignment) { 77 SkTypeface* family, SkPaint::Align alignment) {
70 SkPaint paint; 78 SkPaint paint;
71 paint.setColor(SK_ColorBLACK); 79 paint.setColor(SK_ColorBLACK);
72 paint.setAntiAlias(true); 80 paint.setAntiAlias(true);
73 paint.setVerticalText(true); 81 paint.setVerticalText(true);
74 paint.setTextAlign(alignment); 82 paint.setTextAlign(alignment);
75 paint.setTypeface(std::move(family)); 83 paint.setTypeface(family);
76 paint.setTextSize(textHeight); 84 paint.setTextSize(textHeight);
77 85
78 canvas->drawText(string.c_str(), string.size(), y, 86 canvas->drawText(string.c_str(), string.size(), y,
79 SkIntToScalar(alignment == SkPaint::kLeft_Align ? 10 : 240), 87 SkIntToScalar(alignment == SkPaint::kLeft_Align ? 10 : 240),
80 paint); 88 paint);
81 y += textHeight; 89 y += textHeight;
82 } 90 }
83 91
84 private: 92 private:
85 typedef GM INHERITED; 93 typedef GM INHERITED;
86 SkScalar y, textHeight; 94 SkScalar y, textHeight;
87 sk_sp<SkTypeface> fProp; 95 SkTypeface* fProp;
88 sk_sp<SkTypeface> fMono; 96 SkTypeface* fMono;
89 }; 97 };
90 98
91 /////////////////////////////////////////////////////////////////////////////// 99 ///////////////////////////////////////////////////////////////////////////////
92 100
93 static GM* MyFactory(void*) { return new VertText2GM; } 101 static GM* MyFactory(void*) { return new VertText2GM; }
94 static GMRegistry reg(MyFactory); 102 static GMRegistry reg(MyFactory);
95 103
96 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698