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