OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 const char* fLabel; | 41 const char* fLabel; |
42 }; | 42 }; |
43 | 43 |
44 static const char kText[] = "B"; | 44 static const char kText[] = "B"; |
45 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; | 45 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; |
46 static const int kPointSize = 300; | 46 static const int kPointSize = 300; |
47 | 47 |
48 class ShaderText3GM : public GM { | 48 class ShaderText3GM : public GM { |
49 public: | 49 public: |
50 ShaderText3GM() { | 50 ShaderText3GM() { |
51 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 51 this->setBGColor(0xFFDDDDDD); |
52 } | 52 } |
53 | 53 |
54 protected: | 54 protected: |
55 | 55 |
56 SkString onShortName() override { | 56 SkString onShortName() override { |
57 return SkString("shadertext3"); | 57 return SkString("shadertext3"); |
58 } | 58 } |
59 | 59 |
60 SkISize onISize() override{ return SkISize::Make(800, 1000); } | 60 SkISize onISize() override{ return SkISize::Make(800, 1000); } |
61 | 61 |
62 void onOnceBeforeDraw() override { | 62 void onOnceBeforeDraw() override { |
63 makebm(&fBmp, kPointSize / 4, kPointSize / 4); | 63 makebm(&fBmp, kPointSize / 4, kPointSize / 4); |
64 } | 64 } |
65 | 65 |
66 void onDraw(SkCanvas* canvas) override { | 66 void onDraw(SkCanvas* canvas) override { |
67 | 67 |
68 SkPaint bmpPaint; | 68 SkPaint bmpPaint; |
69 bmpPaint.setAntiAlias(true); | 69 bmpPaint.setAntiAlias(true); |
70 bmpPaint.setFilterQuality(kLow_SkFilterQuality); | 70 bmpPaint.setFilterQuality(kLow_SkFilterQuality); |
71 bmpPaint.setAlpha(0x80); | 71 bmpPaint.setAlpha(0x80); |
72 canvas->drawBitmap(fBmp, 5.f, 5.f, &bmpPaint); | 72 canvas->drawBitmap(fBmp, 5.f, 5.f, &bmpPaint); |
73 | 73 |
74 SkPaint outlinePaint; | 74 SkPaint outlinePaint; |
75 outlinePaint.setAntiAlias(true); | 75 outlinePaint.setAntiAlias(true); |
76 sk_tool_utils::set_portable_typeface_always(&outlinePaint); | 76 sk_tool_utils::set_portable_typeface(&outlinePaint); |
77 outlinePaint.setTextSize(SkIntToScalar(kPointSize)); | 77 outlinePaint.setTextSize(SkIntToScalar(kPointSize)); |
78 outlinePaint.setStyle(SkPaint::kStroke_Style); | 78 outlinePaint.setStyle(SkPaint::kStroke_Style); |
79 outlinePaint.setStrokeWidth(0.f); | 79 outlinePaint.setStrokeWidth(0.f); |
80 | 80 |
81 canvas->translate(15.f, 15.f); | 81 canvas->translate(15.f, 15.f); |
82 | 82 |
83 // draw glyphs scaled up | 83 // draw glyphs scaled up |
84 canvas->scale(2.f, 2.f); | 84 canvas->scale(2.f, 2.f); |
85 | 85 |
86 static const SkShader::TileMode kTileModes[] = { | 86 static const SkShader::TileMode kTileModes[] = { |
(...skipping 13 matching lines...) Expand all Loading... |
100 localM.postRotate(20); | 100 localM.postRotate(20); |
101 localM.postScale(1.15f, .85f); | 101 localM.postScale(1.15f, .85f); |
102 | 102 |
103 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(fBmp, | 103 SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(fBmp, |
104 kTile
Modes[tm0], | 104 kTile
Modes[tm0], |
105 kTile
Modes[tm1], | 105 kTile
Modes[tm1], |
106 &loca
lM)); | 106 &loca
lM)); |
107 | 107 |
108 SkPaint fillPaint; | 108 SkPaint fillPaint; |
109 fillPaint.setAntiAlias(true); | 109 fillPaint.setAntiAlias(true); |
110 sk_tool_utils::set_portable_typeface_always(&fillPaint); | 110 sk_tool_utils::set_portable_typeface(&fillPaint); |
111 fillPaint.setTextSize(SkIntToScalar(kPointSize)); | 111 fillPaint.setTextSize(SkIntToScalar(kPointSize)); |
112 fillPaint.setFilterQuality(kLow_SkFilterQuality); | 112 fillPaint.setFilterQuality(kLow_SkFilterQuality); |
113 fillPaint.setShader(shader); | 113 fillPaint.setShader(shader); |
114 | 114 |
115 canvas->drawText(kText, kTextLen, 0, 0, fillPaint); | 115 canvas->drawText(kText, kTextLen, 0, 0, fillPaint); |
116 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint); | 116 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint); |
117 SkScalar w = fillPaint.measureText(kText, kTextLen); | 117 SkScalar w = fillPaint.measureText(kText, kTextLen); |
118 canvas->translate(w + 10.f, 0.f); | 118 canvas->translate(w + 10.f, 0.f); |
119 ++i; | 119 ++i; |
120 if (!(i % 2)) { | 120 if (!(i % 2)) { |
121 canvas->restore(); | 121 canvas->restore(); |
122 canvas->translate(0, 0.75f * kPointSize); | 122 canvas->translate(0, 0.75f * kPointSize); |
123 canvas->save(); | 123 canvas->save(); |
124 } | 124 } |
125 } | 125 } |
126 } | 126 } |
127 canvas->restore(); | 127 canvas->restore(); |
128 } | 128 } |
129 | 129 |
130 private: | 130 private: |
131 SkBitmap fBmp; | 131 SkBitmap fBmp; |
132 typedef GM INHERITED; | 132 typedef GM INHERITED; |
133 }; | 133 }; |
134 | 134 |
135 /////////////////////////////////////////////////////////////////////////////// | 135 /////////////////////////////////////////////////////////////////////////////// |
136 | 136 |
137 static GM* MyFactory(void*) { return new ShaderText3GM; } | 137 static GM* MyFactory(void*) { return new ShaderText3GM; } |
138 static GMRegistry reg(MyFactory); | 138 static GMRegistry reg(MyFactory); |
139 } | 139 } |
OLD | NEW |