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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 { { 4, kPoint_Pos, 1 }, { 4, kDefault_Pos, .75f }, { 4, kScalar_
Pos, 1.25f } }, | 60 { { 4, kPoint_Pos, 1 }, { 4, kDefault_Pos, .75f }, { 4, kScalar_
Pos, 1.25f } }, |
61 }, | 61 }, |
62 }; | 62 }; |
63 | 63 |
64 const SkScalar kFontSize = 16; | 64 const SkScalar kFontSize = 16; |
65 } | 65 } |
66 | 66 |
67 class TextBlobGM : public skiagm::GM { | 67 class TextBlobGM : public skiagm::GM { |
68 public: | 68 public: |
69 TextBlobGM(const char* txt) | 69 TextBlobGM(const char* txt) |
70 : fTypeface(sk_tool_utils::create_portable_typeface("Times", SkTypeface:
:kNormal)) { | 70 : fText(txt) { |
71 SkPaint p; | |
72 p.setTypeface(fTypeface); | |
73 size_t txtLen = strlen(txt); | |
74 int glyphCount = p.textToGlyphs(txt, txtLen, NULL); | |
75 | |
76 fGlyphs.append(glyphCount); | |
77 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); | |
78 } | 71 } |
79 | 72 |
80 protected: | 73 protected: |
| 74 void onOnceBeforeDraw() override { |
| 75 fTypeface.reset(sk_tool_utils::create_portable_typeface("Times", SkTypef
ace::kNormal)); |
| 76 SkPaint p; |
| 77 p.setTypeface(fTypeface); |
| 78 size_t txtLen = strlen(fText); |
| 79 int glyphCount = p.textToGlyphs(fText, txtLen, NULL); |
| 80 |
| 81 fGlyphs.append(glyphCount); |
| 82 p.textToGlyphs(fText, txtLen, fGlyphs.begin()); |
| 83 } |
| 84 |
81 SkString onShortName() override { | 85 SkString onShortName() override { |
82 return SkString("textblob"); | 86 return SkString("textblob"); |
83 } | 87 } |
84 | 88 |
85 SkISize onISize() override { | 89 SkISize onISize() override { |
86 return SkISize::Make(640, 480); | 90 return SkISize::Make(640, 480); |
87 } | 91 } |
88 | 92 |
89 void onDraw(SkCanvas* canvas) override { | 93 void onDraw(SkCanvas* canvas) override { |
90 for (unsigned b = 0; b < SK_ARRAY_COUNT(blobConfigs); ++b) { | 94 for (unsigned b = 0; b < SK_ARRAY_COUNT(blobConfigs); ++b) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 175 |
172 currentGlyph += count; | 176 currentGlyph += count; |
173 } | 177 } |
174 } | 178 } |
175 | 179 |
176 return builder.build(); | 180 return builder.build(); |
177 } | 181 } |
178 | 182 |
179 SkTDArray<uint16_t> fGlyphs; | 183 SkTDArray<uint16_t> fGlyphs; |
180 SkAutoTUnref<SkTypeface> fTypeface; | 184 SkAutoTUnref<SkTypeface> fTypeface; |
181 | 185 const char* fText; |
182 typedef skiagm::GM INHERITED; | 186 typedef skiagm::GM INHERITED; |
183 }; | 187 }; |
184 | 188 |
185 DEF_GM( return SkNEW_ARGS(TextBlobGM, ("hamburgefons")); ) | 189 DEF_GM( return SkNEW_ARGS(TextBlobGM, ("hamburgefons")); ) |
OLD | NEW |