OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Resources.h" | 10 #include "Resources.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("s
ans-serif", | 42 SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("s
ans-serif", |
43 Sk
Typeface::kBold)); | 43 Sk
Typeface::kBold)); |
44 if (NULL == orig) { | 44 if (NULL == orig) { |
45 orig.reset(SkTypeface::RefDefault()); | 45 orig.reset(SkTypeface::RefDefault()); |
46 } | 46 } |
47 SkAutoTUnref<SkTypeface> random(SkNEW_ARGS(SkRandomTypeface, (orig, pain
t, false))); | 47 SkAutoTUnref<SkTypeface> random(SkNEW_ARGS(SkRandomTypeface, (orig, pain
t, false))); |
48 paint.setTypeface(random); | 48 paint.setTypeface(random); |
49 | 49 |
50 SkRect bounds; | 50 SkRect bounds; |
51 paint.measureText(text, strlen(text), &bounds); | 51 paint.measureText(text, strlen(text), &bounds); |
52 | |
53 SkScalar yOffset = bounds.height(); | |
54 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0); | 52 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0); |
55 | 53 |
56 // A8 | 54 // A8 |
| 55 const char* bigtext1 = "The quick brown fox"; |
| 56 const char* bigtext2 = "jumps over the lazy dog."; |
| 57 paint.setTextSize(160); |
57 paint.setSubpixelText(false); | 58 paint.setSubpixelText(false); |
58 paint.setLCDRenderText(false); | 59 paint.setLCDRenderText(false); |
59 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 32); | 60 paint.measureText(bigtext1, strlen(bigtext1), &bounds); |
| 61 SkScalar offset = bounds.height(); |
| 62 sk_tool_utils::add_to_text_blob(&builder, bigtext1, paint, 0, offset); |
| 63 |
| 64 paint.measureText(bigtext2, strlen(bigtext2), &bounds); |
| 65 offset += bounds.height(); |
| 66 sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset); |
| 67 |
| 68 // color emoji |
| 69 SkAutoTUnref<SkTypeface> origEmoji; |
| 70 sk_tool_utils::emoji_typeface(&origEmoji); |
| 71 const char* osName = sk_tool_utils::platform_os_name(); |
| 72 // The mac emoji string will break us |
| 73 if (origEmoji && (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu"
))) { |
| 74 const char* emojiText = sk_tool_utils::emoji_sample_text(); |
| 75 paint.measureText(emojiText, strlen(emojiText), &bounds); |
| 76 offset += bounds.height(); |
| 77 SkAutoTUnref<SkTypeface> randomEmoji(SkNEW_ARGS(SkRandomTypeface, (o
rig, paint, |
| 78 f
alse))); |
| 79 paint.setTypeface(randomEmoji); |
| 80 sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offse
t); |
| 81 } |
60 | 82 |
61 // build | 83 // build |
62 fBlob.reset(builder.build()); | 84 fBlob.reset(builder.build()); |
63 } | 85 } |
64 | 86 |
65 SkString onShortName() override { | 87 SkString onShortName() override { |
66 return SkString("textblobrandomfont"); | 88 return SkString("textblobrandomfont"); |
67 } | 89 } |
68 | 90 |
69 SkISize onISize() override { | 91 SkISize onISize() override { |
(...skipping 11 matching lines...) Expand all Loading... |
81 | 103 |
82 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); | 104 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); |
83 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 105 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
84 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info, &props)); | 106 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info, &props)); |
85 if (surface) { | 107 if (surface) { |
86 SkPaint paint; | 108 SkPaint paint; |
87 paint.setAntiAlias(true); | 109 paint.setAntiAlias(true); |
88 | 110 |
89 SkCanvas* c = surface->getCanvas(); | 111 SkCanvas* c = surface->getCanvas(); |
90 | 112 |
91 int stride = SkScalarCeilToInt(fBlob->bounds().height() / 2) + 10; | 113 int stride = SkScalarCeilToInt(fBlob->bounds().height()); |
92 int yOffset = stride; | 114 int yOffset = stride / 8; |
93 for (int i = 0; i < 10; i++) { | 115 for (int i = 0; i < 1; i++) { |
94 // fiddle the canvas to force regen of textblobs | 116 // fiddle the canvas to force regen of textblobs |
95 canvas->rotate(i % 2 ? 0.0f : -0.05f); | 117 canvas->rotate(i % 2 ? 0.0f : -0.05f); |
96 canvas->drawTextBlob(fBlob, 10.0f, SkIntToScalar(yOffset), paint
); | 118 canvas->drawTextBlob(fBlob, 10.0f, SkIntToScalar(yOffset), paint
); |
97 yOffset += stride; | 119 yOffset += stride; |
98 | 120 |
99 // This will draw as black boxes | 121 // This will draw as black boxes |
100 c->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint); | 122 c->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint); |
101 surface->draw(canvas, 0, 0, nullptr); | 123 surface->draw(canvas, 0, 0, nullptr); |
102 | 124 |
103 // free gpu resources and verify | 125 // free gpu resources and verify |
104 yOffset += stride; | 126 yOffset += stride; |
105 canvas->getGrContext()->freeGpuResources(); | 127 canvas->getGrContext()->freeGpuResources(); |
106 canvas->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint); | 128 canvas->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint); |
107 | 129 |
108 yOffset += stride; | 130 yOffset += stride; |
109 } | 131 } |
110 | 132 |
111 } else { | 133 } else { |
112 const char* text = "This test requires a surface"; | 134 const char* text = "This test requires a surface"; |
113 size_t len = strlen(text); | 135 size_t len = strlen(text); |
114 SkPaint paint; | 136 SkPaint paint; |
115 canvas->drawText(text, len, 10, 100, paint); | 137 canvas->drawText(text, len, 10, 100, paint); |
116 } | 138 } |
117 } | 139 } |
118 | 140 |
119 private: | 141 private: |
120 SkAutoTUnref<const SkTextBlob> fBlob; | 142 SkAutoTUnref<const SkTextBlob> fBlob; |
121 | 143 |
122 static const int kWidth = 1000; | 144 static const int kWidth = 2000; |
123 static const int kHeight = 1000; | 145 static const int kHeight = 1600; |
124 | 146 |
125 typedef GM INHERITED; | 147 typedef GM INHERITED; |
126 }; | 148 }; |
127 | 149 |
128 ////////////////////////////////////////////////////////////////////////////// | 150 ////////////////////////////////////////////////////////////////////////////// |
129 | 151 |
130 DEF_GM( return SkNEW(TextBlobRandomFont); ) | 152 DEF_GM( return SkNEW(TextBlobRandomFont); ) |
131 } | 153 } |
132 #endif | 154 #endif |
OLD | NEW |