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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 SkString onShortName() override { | 85 SkString onShortName() override { |
86 return SkString("textblob"); | 86 return SkString("textblob"); |
87 } | 87 } |
88 | 88 |
89 SkISize onISize() override { | 89 SkISize onISize() override { |
90 return SkISize::Make(640, 480); | 90 return SkISize::Make(640, 480); |
91 } | 91 } |
92 | 92 |
93 void onDraw(SkCanvas* canvas) override { | 93 void onDraw(SkCanvas* canvas) override { |
94 for (unsigned b = 0; b < SK_ARRAY_COUNT(blobConfigs); ++b) { | 94 for (unsigned b = 0; b < SK_ARRAY_COUNT(blobConfigs); ++b) { |
95 SkAutoTUnref<const SkTextBlob> blob(this->makeBlob(b)); | 95 sk_sp<SkTextBlob> blob(this->makeBlob(b)); |
96 | 96 |
97 SkPaint p; | 97 SkPaint p; |
98 SkPoint offset = SkPoint::Make(SkIntToScalar(10 + 300 * (b % 2)), | 98 SkPoint offset = SkPoint::Make(SkIntToScalar(10 + 300 * (b % 2)), |
99 SkIntToScalar(20 + 150 * (b / 2))); | 99 SkIntToScalar(20 + 150 * (b / 2))); |
100 | 100 |
101 canvas->drawTextBlob(blob, offset.x(), offset.y(), p); | 101 canvas->drawTextBlob(blob, offset.x(), offset.y(), p); |
102 | 102 |
103 p.setColor(SK_ColorBLUE); | 103 p.setColor(SK_ColorBLUE); |
104 p.setStyle(SkPaint::kStroke_Style); | 104 p.setStyle(SkPaint::kStroke_Style); |
105 SkRect box = blob->bounds(); | 105 SkRect box = blob->bounds(); |
106 box.offset(offset); | 106 box.offset(offset); |
107 canvas->drawRect(box, p); | 107 canvas->drawRect(box, p); |
108 | 108 |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
113 const SkTextBlob* makeBlob(unsigned blobIndex) { | 113 sk_sp<SkTextBlob> makeBlob(unsigned blobIndex) { |
114 SkTextBlobBuilder builder; | 114 SkTextBlobBuilder builder; |
115 | 115 |
116 SkPaint font; | 116 SkPaint font; |
117 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 117 font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
118 font.setAntiAlias(true); | 118 font.setAntiAlias(true); |
119 font.setSubpixelText(true); | 119 font.setSubpixelText(true); |
120 font.setTypeface(fTypeface); | 120 font.setTypeface(fTypeface); |
121 | 121 |
122 for (unsigned l = 0; l < SK_ARRAY_COUNT(blobConfigs[blobIndex]); ++l) { | 122 for (unsigned l = 0; l < SK_ARRAY_COUNT(blobConfigs[blobIndex]); ++l) { |
123 unsigned currentGlyph = 0; | 123 unsigned currentGlyph = 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 memcpy(buf.pos, pos.begin(), count * sizeof(SkScalar) * 2); | 170 memcpy(buf.pos, pos.begin(), count * sizeof(SkScalar) * 2); |
171 } break; | 171 } break; |
172 default: | 172 default: |
173 SK_ABORT("unhandled pos value"); | 173 SK_ABORT("unhandled pos value"); |
174 } | 174 } |
175 | 175 |
176 currentGlyph += count; | 176 currentGlyph += count; |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 return builder.build(); | 180 return builder.make(); |
181 } | 181 } |
182 | 182 |
183 SkTDArray<uint16_t> fGlyphs; | 183 SkTDArray<uint16_t> fGlyphs; |
184 sk_sp<SkTypeface> fTypeface; | 184 sk_sp<SkTypeface> fTypeface; |
185 const char* fText; | 185 const char* fText; |
186 typedef skiagm::GM INHERITED; | 186 typedef skiagm::GM INHERITED; |
187 }; | 187 }; |
188 | 188 |
189 DEF_GM(return new TextBlobGM("hamburgefons");) | 189 DEF_GM(return new TextBlobGM("hamburgefons");) |
OLD | NEW |