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 21 matching lines...) Expand all Loading... |
32 SkTextBlobBuilder builder; | 32 SkTextBlobBuilder builder; |
33 | 33 |
34 const char* text = "The quick brown fox jumps over the lazy dog."; | 34 const char* text = "The quick brown fox jumps over the lazy dog."; |
35 | 35 |
36 // make textbloben | 36 // make textbloben |
37 SkPaint paint; | 37 SkPaint paint; |
38 paint.setTextSize(32); | 38 paint.setTextSize(32); |
39 paint.setLCDRenderText(true); | 39 paint.setLCDRenderText(true); |
40 | 40 |
41 // Setup our random scaler context | 41 // Setup our random scaler context |
42 sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("sans-ser
if", | 42 SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("s
ans-serif", |
43 SkTypefac
e::kBold)); | 43 Sk
Typeface::kBold)); |
44 if (nullptr == orig) { | 44 if (nullptr == orig) { |
45 orig = SkTypeface::MakeDefault(); | 45 orig.reset(SkTypeface::RefDefault()); |
46 } | 46 } |
47 paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, false)); | 47 SkAutoTUnref<SkTypeface> random(new SkRandomTypeface(orig, paint, false)
); |
| 48 paint.setTypeface(random); |
48 | 49 |
49 SkRect bounds; | 50 SkRect bounds; |
50 paint.measureText(text, strlen(text), &bounds); | 51 paint.measureText(text, strlen(text), &bounds); |
51 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); |
52 | 53 |
53 // A8 | 54 // A8 |
54 const char* bigtext1 = "The quick brown fox"; | 55 const char* bigtext1 = "The quick brown fox"; |
55 const char* bigtext2 = "jumps over the lazy dog."; | 56 const char* bigtext2 = "jumps over the lazy dog."; |
56 paint.setTextSize(160); | 57 paint.setTextSize(160); |
57 paint.setSubpixelText(false); | 58 paint.setSubpixelText(false); |
58 paint.setLCDRenderText(false); | 59 paint.setLCDRenderText(false); |
59 paint.measureText(bigtext1, strlen(bigtext1), &bounds); | 60 paint.measureText(bigtext1, strlen(bigtext1), &bounds); |
60 SkScalar offset = bounds.height(); | 61 SkScalar offset = bounds.height(); |
61 sk_tool_utils::add_to_text_blob(&builder, bigtext1, paint, 0, offset); | 62 sk_tool_utils::add_to_text_blob(&builder, bigtext1, paint, 0, offset); |
62 | 63 |
63 paint.measureText(bigtext2, strlen(bigtext2), &bounds); | 64 paint.measureText(bigtext2, strlen(bigtext2), &bounds); |
64 offset += bounds.height(); | 65 offset += bounds.height(); |
65 sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset); | 66 sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset); |
66 | 67 |
67 // color emoji | 68 // color emoji |
68 sk_sp<SkTypeface> origEmoji = sk_tool_utils::emoji_typeface(); | 69 SkAutoTUnref<SkTypeface> origEmoji; |
| 70 sk_tool_utils::emoji_typeface(&origEmoji); |
69 const char* osName = sk_tool_utils::platform_os_name(); | 71 const char* osName = sk_tool_utils::platform_os_name(); |
70 // The mac emoji string will break us | 72 // The mac emoji string will break us |
71 if (origEmoji && (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu"
))) { | 73 if (origEmoji && (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu"
))) { |
72 const char* emojiText = sk_tool_utils::emoji_sample_text(); | 74 const char* emojiText = sk_tool_utils::emoji_sample_text(); |
73 paint.measureText(emojiText, strlen(emojiText), &bounds); | 75 paint.measureText(emojiText, strlen(emojiText), &bounds); |
74 offset += bounds.height(); | 76 offset += bounds.height(); |
75 paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, false)); | 77 SkAutoTUnref<SkTypeface> randomEmoji(new SkRandomTypeface(orig, pain
t, false)); |
| 78 paint.setTypeface(randomEmoji); |
76 sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offse
t); | 79 sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offse
t); |
77 } | 80 } |
78 | 81 |
79 // build | 82 // build |
80 fBlob.reset(builder.build()); | 83 fBlob.reset(builder.build()); |
81 } | 84 } |
82 | 85 |
83 SkString onShortName() override { | 86 SkString onShortName() override { |
84 return SkString("textblobrandomfont"); | 87 return SkString("textblobrandomfont"); |
85 } | 88 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 static const int kHeight = 1600; | 148 static const int kHeight = 1600; |
146 | 149 |
147 typedef GM INHERITED; | 150 typedef GM INHERITED; |
148 }; | 151 }; |
149 | 152 |
150 ////////////////////////////////////////////////////////////////////////////// | 153 ////////////////////////////////////////////////////////////////////////////// |
151 | 154 |
152 DEF_GM(return new TextBlobRandomFont;) | 155 DEF_GM(return new TextBlobRandomFont;) |
153 } | 156 } |
154 #endif | 157 #endif |
OLD | NEW |