| OLD | NEW |
| 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 } | |
| 29 | 21 |
| 30 protected: | 22 protected: |
| 31 void onOnceBeforeDraw() override { | 23 void onOnceBeforeDraw() override { |
| 32 const int pointSize = 24; | 24 const int pointSize = 24; |
| 33 textHeight = SkIntToScalar(pointSize); | 25 textHeight = SkIntToScalar(pointSize); |
| 34 fProp = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("sa
ns-serif"), | 26 fProp = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("sans
-serif"), |
| 35 SkTypeface::kNormal); | 27 SkTypeface::kNormal); |
| 36 fMono = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("mo
nospace"), | 28 fMono = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("mono
space"), |
| 37 SkTypeface::kNormal); | 29 SkTypeface::kNormal); |
| 38 } | 30 } |
| 39 | 31 |
| 40 SkString onShortName() override { | 32 SkString onShortName() override { |
| 41 SkString name("verttext2"); | 33 SkString name("verttext2"); |
| 42 name.append(sk_tool_utils::major_platform_os_name()); | 34 name.append(sk_tool_utils::major_platform_os_name()); |
| 43 return name; | 35 return name; |
| 44 } | 36 } |
| 45 | 37 |
| 46 SkISize onISize() override { return SkISize::Make(640, 480); } | 38 SkISize onISize() override { return SkISize::Make(640, 480); } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 fMono, SkPaint::kCenter_Align); | 59 fMono, SkPaint::kCenter_Align); |
| 68 canvas->rotate(SkIntToScalar(-15)); | 60 canvas->rotate(SkIntToScalar(-15)); |
| 69 canvas->translate(textHeight * 4, SkIntToScalar(50)); | 61 canvas->translate(textHeight * 4, SkIntToScalar(50)); |
| 70 if (i > 0) { | 62 if (i > 0) { |
| 71 canvas->translate(0, SkIntToScalar(50)); | 63 canvas->translate(0, SkIntToScalar(50)); |
| 72 } | 64 } |
| 73 } | 65 } |
| 74 } | 66 } |
| 75 | 67 |
| 76 void drawText(SkCanvas* canvas, const SkString& string, | 68 void drawText(SkCanvas* canvas, const SkString& string, |
| 77 SkTypeface* family, SkPaint::Align alignment) { | 69 sk_sp<SkTypeface> family, SkPaint::Align alignment) { |
| 78 SkPaint paint; | 70 SkPaint paint; |
| 79 paint.setColor(SK_ColorBLACK); | 71 paint.setColor(SK_ColorBLACK); |
| 80 paint.setAntiAlias(true); | 72 paint.setAntiAlias(true); |
| 81 paint.setVerticalText(true); | 73 paint.setVerticalText(true); |
| 82 paint.setTextAlign(alignment); | 74 paint.setTextAlign(alignment); |
| 83 paint.setTypeface(family); | 75 paint.setTypeface(std::move(family)); |
| 84 paint.setTextSize(textHeight); | 76 paint.setTextSize(textHeight); |
| 85 | 77 |
| 86 canvas->drawText(string.c_str(), string.size(), y, | 78 canvas->drawText(string.c_str(), string.size(), y, |
| 87 SkIntToScalar(alignment == SkPaint::kLeft_Align ? 10 : 240), | 79 SkIntToScalar(alignment == SkPaint::kLeft_Align ? 10 : 240), |
| 88 paint); | 80 paint); |
| 89 y += textHeight; | 81 y += textHeight; |
| 90 } | 82 } |
| 91 | 83 |
| 92 private: | 84 private: |
| 93 typedef GM INHERITED; | 85 typedef GM INHERITED; |
| 94 SkScalar y, textHeight; | 86 SkScalar y, textHeight; |
| 95 SkTypeface* fProp; | 87 sk_sp<SkTypeface> fProp; |
| 96 SkTypeface* fMono; | 88 sk_sp<SkTypeface> fMono; |
| 97 }; | 89 }; |
| 98 | 90 |
| 99 /////////////////////////////////////////////////////////////////////////////// | 91 /////////////////////////////////////////////////////////////////////////////// |
| 100 | 92 |
| 101 static GM* MyFactory(void*) { return new VertText2GM; } | 93 static GM* MyFactory(void*) { return new VertText2GM; } |
| 102 static GMRegistry reg(MyFactory); | 94 static GMRegistry reg(MyFactory); |
| 103 | 95 |
| 104 } | 96 } |
| OLD | NEW |