OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "gm.h" | |
9 | |
10 #include "Resources.h" | |
11 #include "SkCanvas.h" | |
12 #include "SkGradientShader.h" | |
13 #include "SkStream.h" | |
14 #include "SkTextBlob.h" | |
15 #include "SkTypeface.h" | |
16 | |
17 namespace skiagm { | |
18 | |
19 static void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const SkPaint& origPaint, | |
bsalomon
2015/04/13 15:16:38
This looks familiar... should we add this to some
| |
20 SkScalar x, SkScalar y) { | |
21 SkPaint paint(origPaint); | |
22 SkTDArray<uint16_t> glyphs; | |
23 | |
24 size_t len = strlen(text); | |
25 glyphs.append(paint.textToGlyphs(text, len, NULL)); | |
26 paint.textToGlyphs(text, len, glyphs.begin()); | |
27 | |
28 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
29 const SkTextBlobBuilder::RunBuffer& run = builder->allocRun(paint, glyphs.co unt(), x, y, | |
30 NULL); | |
31 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); | |
32 } | |
33 | |
34 class TextBlobColorTrans : public GM { | |
bsalomon
2015/04/13 15:16:38
// This GM tests some stuff about gamma text blah
| |
35 public: | |
36 TextBlobColorTrans() { } | |
37 | |
38 protected: | |
39 void onOnceBeforeDraw() override { | |
40 SkTextBlobBuilder builder; | |
41 | |
42 // make textblob | |
43 // Text so large we draw as paths. This is mostly done to trigger atlas eviction on small | |
44 // atlases | |
45 SkPaint paint; | |
46 paint.setTextSize(384); | |
47 const char* text = "AB"; | |
48 sk_tool_utils::set_portable_typeface(&paint); | |
49 | |
50 SkRect bounds; | |
51 paint.measureText(text, strlen(text), &bounds); | |
52 | |
53 SkScalar yOffset = bounds.height(); | |
54 add_to_text_blob(&builder, text, paint, 0, yOffset - 30); | |
55 | |
56 // A8 | |
57 paint.setTextSize(28); | |
58 text = "The quick brown fox jumps over the lazy dog."; | |
59 paint.setSubpixelText(false); | |
60 paint.setLCDRenderText(false); | |
61 paint.measureText(text, strlen(text), &bounds); | |
62 add_to_text_blob(&builder, text, paint, 0, yOffset - 8); | |
63 | |
64 // build | |
65 fBlob.reset(builder.build()); | |
66 } | |
67 | |
68 SkString onShortName() override { | |
69 return SkString("textblobcolortrans"); | |
70 } | |
71 | |
72 SkISize onISize() override { | |
73 return SkISize::Make(kWidth, kHeight); | |
74 } | |
75 | |
76 void onDraw(SkCanvas* canvas) override { | |
77 | |
78 canvas->drawColor(SK_ColorGRAY); | |
79 | |
80 SkPaint paint; | |
81 canvas->translate(10, 40); | |
82 | |
83 SkRect bounds = fBlob->bounds(); | |
84 | |
85 // Colors were chosen to map to pairs of canonical colors | |
bsalomon
2015/04/13 15:16:38
not obvious to me what canonical colors are.
| |
86 SkColor colors[] = {SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorYELLOW, SK_Col orWHITE}; | |
87 | |
88 size_t count = SK_ARRAY_COUNT(colors); | |
89 size_t colorIndex = 0; | |
90 for (int y = 0; y + SkScalarFloorToInt(bounds.height()) < kHeight; | |
91 y += SkScalarFloorToInt(bounds.height())) { | |
92 paint.setColor(colors[colorIndex++ % count]); | |
93 canvas->save(); | |
94 canvas->translate(0, SkIntToScalar(y)); | |
95 canvas->drawTextBlob(fBlob, 0, 0, paint); | |
96 canvas->restore(); | |
97 } | |
98 } | |
99 | |
100 private: | |
101 SkAutoTUnref<const SkTextBlob> fBlob; | |
102 | |
103 static const int kWidth = 675; | |
104 static const int kHeight = 1600; | |
105 | |
106 typedef GM INHERITED; | |
107 }; | |
108 | |
109 ////////////////////////////////////////////////////////////////////////////// | |
110 | |
111 DEF_GM( return SkNEW(TextBlobColorTrans); ) | |
112 } | |
OLD | NEW |