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 sk_tool_utils::set_portable_typeface(&p); | 23 sk_tool_utils::set_portable_typeface(&p); |
24 size_t txtLen = strlen(txt); | 24 size_t txtLen = strlen(txt); |
25 fGlyphs.append(p.textToGlyphs(txt, txtLen, NULL)); | 25 fGlyphs.append(p.textToGlyphs(txt, txtLen, nullptr)); |
26 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); | 26 p.textToGlyphs(txt, txtLen, fGlyphs.begin()); |
27 } | 27 } |
28 | 28 |
29 protected: | 29 protected: |
30 | 30 |
31 void onOnceBeforeDraw() override { | 31 void onOnceBeforeDraw() override { |
32 SkPaint p; | 32 SkPaint p; |
33 p.setAntiAlias(true); | 33 p.setAntiAlias(true); |
34 p.setSubpixelText(true); | 34 p.setSubpixelText(true); |
35 p.setTextSize(30); | 35 p.setTextSize(30); |
36 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 36 p.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
37 sk_tool_utils::set_portable_typeface(&p); | 37 sk_tool_utils::set_portable_typeface(&p); |
38 | 38 |
39 SkTextBlobBuilder builder; | 39 SkTextBlobBuilder builder; |
40 int glyphCount = fGlyphs.count(); | 40 int glyphCount = fGlyphs.count(); |
41 const SkTextBlobBuilder::RunBuffer* run; | 41 const SkTextBlobBuilder::RunBuffer* run; |
42 | 42 |
43 run = &builder.allocRun(p, glyphCount, 10, 10, NULL); | 43 run = &builder.allocRun(p, glyphCount, 10, 10, nullptr); |
44 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t)); | 44 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t)); |
45 | 45 |
46 run = &builder.allocRunPosH(p, glyphCount, 80, NULL); | 46 run = &builder.allocRunPosH(p, glyphCount, 80, nullptr); |
47 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t)); | 47 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t)); |
48 for (int i = 0; i < glyphCount; ++i) { | 48 for (int i = 0; i < glyphCount; ++i) { |
49 run->pos[i] = p.getTextSize() * i * .75f; | 49 run->pos[i] = p.getTextSize() * i * .75f; |
50 } | 50 } |
51 | 51 |
52 run = &builder.allocRunPos(p, glyphCount, NULL); | 52 run = &builder.allocRunPos(p, glyphCount, nullptr); |
53 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t)); | 53 memcpy(run->glyphs, fGlyphs.begin(), glyphCount * sizeof(uint16_t)); |
54 for (int i = 0; i < glyphCount; ++i) { | 54 for (int i = 0; i < glyphCount; ++i) { |
55 run->pos[i * 2] = p.getTextSize() * i * .75f; | 55 run->pos[i * 2] = p.getTextSize() * i * .75f; |
56 run->pos[i * 2 + 1] = 150 + 5 * sinf((float)i * 8 / glyphCount); | 56 run->pos[i * 2 + 1] = 150 + 5 * sinf((float)i * 8 / glyphCount); |
57 } | 57 } |
58 | 58 |
59 fBlob.reset(builder.build()); | 59 fBlob.reset(builder.build()); |
60 | 60 |
61 SkColor colors[2]; | 61 SkColor colors[2]; |
62 colors[0] = SK_ColorRED; | 62 colors[0] = SK_ColorRED; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 private: | 104 private: |
105 SkTDArray<uint16_t> fGlyphs; | 105 SkTDArray<uint16_t> fGlyphs; |
106 SkAutoTUnref<const SkTextBlob> fBlob; | 106 SkAutoTUnref<const SkTextBlob> fBlob; |
107 SkAutoTUnref<SkShader> fShader; | 107 SkAutoTUnref<SkShader> fShader; |
108 | 108 |
109 typedef skiagm::GM INHERITED; | 109 typedef skiagm::GM INHERITED; |
110 }; | 110 }; |
111 | 111 |
112 DEF_GM(return new TextBlobShaderGM("Blobber");) | 112 DEF_GM(return new TextBlobShaderGM("Blobber");) |
OLD | NEW |