OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 #include "SkTextBlob.h" | 14 #include "SkTextBlob.h" |
15 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
17 | 17 |
18 // This GM exercises drawTextBlob offset vs. shader space behavior. | 18 // This GM exercises drawTextBlob offset vs. shader space behavior. |
19 class TextBlobShaderGM : public skiagm::GM { | 19 class TextBlobShaderGM : public skiagm::GM { |
20 public: | 20 public: |
21 TextBlobShaderGM(const char* txt) { | 21 TextBlobShaderGM(const char* txt) { |
22 SkPaint p; | 22 SkPaint p; |
23 size_t txtLen = strlen(txt); | 23 size_t txtLen = strlen(txt); |
24 fGlyphs.append(p.textToGlyphs(txt, txtLen, NULL)); | 24 fGlyphs.append(p.textToGlyphs(txt, txtLen, NULL)); |
25 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); | 25 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); |
26 } | 26 } |
27 | 27 |
28 protected: | 28 protected: |
29 | 29 |
30 void onOnceBeforeDraw() SK_OVERRIDE { | 30 void onOnceBeforeDraw() override { |
31 SkPaint p; | 31 SkPaint p; |
32 p.setAntiAlias(true); | 32 p.setAntiAlias(true); |
33 p.setSubpixelText(true); | 33 p.setSubpixelText(true); |
34 p.setTextSize(30); | 34 p.setTextSize(30); |
35 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 35 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
36 | 36 |
37 SkTextBlobBuilder builder; | 37 SkTextBlobBuilder builder; |
38 int glyphCount = fGlyphs.count(); | 38 int glyphCount = fGlyphs.count(); |
39 const SkTextBlobBuilder::RunBuffer* run; | 39 const SkTextBlobBuilder::RunBuffer* run; |
40 | 40 |
(...skipping 25 matching lines...) Expand all Loading... |
66 } | 66 } |
67 | 67 |
68 SkISize sz = this->onISize(); | 68 SkISize sz = this->onISize(); |
69 fShader.reset(SkGradientShader::CreateRadial(SkPoint::Make(SkIntToScalar
(sz.width() / 2), | 69 fShader.reset(SkGradientShader::CreateRadial(SkPoint::Make(SkIntToScalar
(sz.width() / 2), |
70 SkIntToScalar
(sz.height() / 2)), | 70 SkIntToScalar
(sz.height() / 2)), |
71 sz.width() * .66f, colors,
pos, | 71 sz.width() * .66f, colors,
pos, |
72 SK_ARRAY_COUNT(colors), | 72 SK_ARRAY_COUNT(colors), |
73 SkShader::kRepeat_TileMode)
); | 73 SkShader::kRepeat_TileMode)
); |
74 } | 74 } |
75 | 75 |
76 SkString onShortName() SK_OVERRIDE { | 76 SkString onShortName() override { |
77 return SkString("textblobshader"); | 77 return SkString("textblobshader"); |
78 } | 78 } |
79 | 79 |
80 SkISize onISize() SK_OVERRIDE { | 80 SkISize onISize() override { |
81 return SkISize::Make(640, 480); | 81 return SkISize::Make(640, 480); |
82 } | 82 } |
83 | 83 |
84 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 84 void onDraw(SkCanvas* canvas) override { |
85 SkPaint p; | 85 SkPaint p; |
86 p.setStyle(SkPaint::kFill_Style); | 86 p.setStyle(SkPaint::kFill_Style); |
87 p.setShader(fShader); | 87 p.setShader(fShader); |
88 | 88 |
89 SkISize sz = this->onISize(); | 89 SkISize sz = this->onISize(); |
90 static const int kXCount = 4; | 90 static const int kXCount = 4; |
91 static const int kYCount = 3; | 91 static const int kYCount = 3; |
92 for (int i = 0; i < kXCount; ++i) { | 92 for (int i = 0; i < kXCount; ++i) { |
93 for (int j = 0; j < kYCount; ++j) { | 93 for (int j = 0; j < kYCount; ++j) { |
94 canvas->drawTextBlob(fBlob, | 94 canvas->drawTextBlob(fBlob, |
95 SkIntToScalar(i * sz.width() / kXCount), | 95 SkIntToScalar(i * sz.width() / kXCount), |
96 SkIntToScalar(j * sz.height() / kYCount), | 96 SkIntToScalar(j * sz.height() / kYCount), |
97 p); | 97 p); |
98 } | 98 } |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 private: | 102 private: |
103 SkTDArray<uint16_t> fGlyphs; | 103 SkTDArray<uint16_t> fGlyphs; |
104 SkAutoTUnref<const SkTextBlob> fBlob; | 104 SkAutoTUnref<const SkTextBlob> fBlob; |
105 SkAutoTUnref<SkShader> fShader; | 105 SkAutoTUnref<SkShader> fShader; |
106 | 106 |
107 typedef skiagm::GM INHERITED; | 107 typedef skiagm::GM INHERITED; |
108 }; | 108 }; |
109 | 109 |
110 DEF_GM( return SkNEW_ARGS(TextBlobShaderGM, ("Blobber")); ) | 110 DEF_GM( return SkNEW_ARGS(TextBlobShaderGM, ("Blobber")); ) |
OLD | NEW |