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 "SkPathPriv.h" | 10 #include "SkPathPriv.h" |
| 11 #include "SkTextFormatParams.h" |
11 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
12 | 13 |
13 namespace skiagm { | 14 namespace skiagm { |
14 | 15 |
| 16 /* Generated on a Mac with: |
| 17 * paint.setTypeface(SkTypeface::CreateByName("Papyrus")); |
| 18 * paint.getTextPath("H", 1, 100, 80, &textPath); |
| 19 */ |
| 20 static SkPath papyrus_hello() { |
| 21 SkPath path; |
| 22 path.moveTo(169.824f, 83.4102f); |
| 23 path.lineTo(167.285f, 85.6074f); |
| 24 path.lineTo(166.504f, 87.2188f); |
| 25 path.lineTo(165.82f, 86.7793f); |
| 26 path.lineTo(165.186f, 87.1211f); |
| 27 path.lineTo(164.6f, 88.1953f); |
| 28 path.lineTo(161.914f, 89.416f); |
| 29 path.lineTo(161.719f, 89.2207f); |
| 30 path.lineTo(160.596f, 88.8789f); |
| 31 path.lineTo(160.498f, 87.6094f); |
| 32 path.lineTo(160.693f, 86.3887f); |
| 33 path.lineTo(161.621f, 84.6797f); |
| 34 path.lineTo(161.279f, 83.2148f); |
| 35 path.lineTo(161.523f, 81.9941f); |
| 36 path.lineTo(162.012f, 79.1133f); |
| 37 path.lineTo(162.695f, 76.623f); |
| 38 path.lineTo(162.305f, 73.4004f); |
| 39 path.lineTo(162.207f, 72.4238f); |
| 40 path.lineTo(163.477f, 71.4961f); |
| 41 path.quadTo(163.525f, 71.0078f, 163.525f, 70.2754f); |
| 42 path.quadTo(163.525f, 68.8594f, 162.793f, 67.1992f); |
| 43 path.lineTo(163.623f, 64.6113f); |
| 44 path.lineTo(162.598f, 63.6836f); |
| 45 path.lineTo(163.184f, 61.0957f); |
| 46 path.lineTo(162.695f, 60.8027f); |
| 47 path.lineTo(162.988f, 52.5996f); |
| 48 path.lineTo(162.402f, 52.1113f); |
| 49 path.lineTo(161.914f, 50.1094f); |
| 50 path.lineTo(161.523f, 50.5f); |
| 51 path.quadTo(160.645f, 50.5f, 160.327f, 50.6465f); |
| 52 path.quadTo(160.01f, 50.793f, 159.424f, 51.4766f); |
| 53 path.lineTo(158.203f, 52.7949f); |
| 54 path.lineTo(156.299f, 52.0137f); |
| 55 path.quadTo(154.346f, 52.5996f, 154.004f, 52.5996f); |
| 56 path.quadTo(154.053f, 52.5996f, 152.783f, 52.4043f); |
| 57 path.quadTo(151.465f, 51.3789f, 150.488f, 51.3789f); |
| 58 path.quadTo(150.342f, 51.3789f, 150.269f, 51.4033f); |
| 59 path.quadTo(150.195f, 51.4277f, 150.098f, 51.4766f); |
| 60 path.lineTo(145.02f, 51.916f); |
| 61 path.lineTo(139.893f, 51.2812f); |
| 62 path.lineTo(135.693f, 51.623f); |
| 63 path.lineTo(133.594f, 51.0859f); |
| 64 path.lineTo(130.42f, 52.0137f); |
| 65 path.lineTo(125.488f, 51.4766f); |
| 66 path.lineTo(124.219f, 51.623f); |
| 67 path.lineTo(122.705f, 50.5f); |
| 68 path.lineTo(122.217f, 51.7207f); |
| 69 path.lineTo(116.211f, 51.623f); |
| 70 path.quadTo(114.99f, 52.7949f, 114.99f, 53.8203f); |
| 71 path.lineTo(115.576f, 57.6777f); |
| 72 path.quadTo(115.723f, 58.2148f, 115.723f, 59.2891f); |
| 73 path.quadTo(115.723f, 60.2656f, 115.186f, 61.1934f); |
| 74 path.lineTo(115.479f, 64.2207f); |
| 75 path.quadTo(114.795f, 64.6602f, 114.648f, 65.0752f); |
| 76 path.quadTo(114.502f, 65.4902f, 114.502f, 66.3203f); |
| 77 path.quadTo(114.893f, 66.9551f, 115.918f, 67.1992f); |
| 78 path.lineTo(116.016f, 69.2988f); |
| 79 path.lineTo(116.016f, 75.6953f); |
| 80 path.lineTo(116.016f, 75.9883f); |
| 81 path.lineTo(116.113f, 77.209f); |
| 82 path.quadTo(116.113f, 77.6484f, 115.479f, 78.0879f); |
| 83 path.lineTo(115.576f, 79.1133f); |
| 84 path.lineTo(116.309f, 82.0918f); |
| 85 path.lineTo(116.406f, 83.1172f); |
| 86 path.quadTo(116.406f, 85.2656f, 114.404f, 86.291f); |
| 87 path.lineTo(111.914f, 87.5117f); |
| 88 path.lineTo(109.717f, 88.7812f); |
| 89 path.lineTo(108.398f, 89.416f); |
| 90 path.lineTo(108.105f, 88.9766f); |
| 91 path.lineTo(107.617f, 88.9766f); |
| 92 path.quadTo(107.08f, 87.9023f, 107.08f, 87.0234f); |
| 93 path.quadTo(107.08f, 85.998f, 107.324f, 85.6074f); |
| 94 path.lineTo(108.398f, 83.1172f); |
| 95 path.lineTo(108.887f, 81.4082f); |
| 96 path.lineTo(109.619f, 81.1152f); |
| 97 path.lineTo(109.717f, 79.5039f); |
| 98 path.lineTo(108.887f, 78.7227f); |
| 99 path.quadTo(109.619f, 77.3555f, 109.619f, 77.1113f); |
| 100 path.quadTo(109.619f, 76.8672f, 108.887f, 75.5977f); |
| 101 path.lineTo(108.789f, 74.7188f); |
| 102 path.lineTo(109.18f, 66.6133f); |
| 103 path.lineTo(108.691f, 64.416f); |
| 104 path.quadTo(108.691f, 63.293f, 109.521f, 62.707f); |
| 105 path.lineTo(110.205f, 62.1211f); |
| 106 path.quadTo(110.449f, 61.877f, 110.596f, 60.998f); |
| 107 path.quadTo(109.082f, 60.4609f, 109.082f, 59.1914f); |
| 108 path.lineTo(109.082f, 58.9961f); |
| 109 path.lineTo(109.424f, 55.2852f); |
| 110 path.lineTo(108.789f, 53.7227f); |
| 111 path.lineTo(108.789f, 48.1074f); |
| 112 path.lineTo(108.594f, 45.3242f); |
| 113 path.lineTo(108.691f, 43.8105f); |
| 114 path.lineTo(107.91f, 43.9082f); |
| 115 path.lineTo(107.715f, 44.1035f); |
| 116 path.lineTo(107.324f, 42.7852f); |
| 117 path.lineTo(107.715f, 43.1758f); |
| 118 path.lineTo(107.91f, 41.3203f); |
| 119 path.quadTo(109.717f, 40.2949f, 109.717f, 39.2207f); |
| 120 path.quadTo(109.717f, 37.707f, 107.715f, 37.4141f); |
| 121 path.lineTo(106.982f, 33.9961f); |
| 122 path.lineTo(106.982f, 33.2148f); |
| 123 path.lineTo(106.689f, 29.3086f); |
| 124 path.lineTo(106.689f, 26.1836f); |
| 125 path.lineTo(107.91f, 25.6953f); |
| 126 path.lineTo(109.521f, 24.5234f); |
| 127 path.lineTo(112.109f, 23.3027f); |
| 128 path.lineTo(114.014f, 22.5215f); |
| 129 path.lineTo(115.479f, 23.1074f); |
| 130 path.quadTo(115.479f, 24.0352f, 116.113f, 25.1094f); |
| 131 path.quadTo(115.381f, 25.8906f, 115.259f, 26.3789f); |
| 132 path.quadTo(115.137f, 26.8672f, 114.99f, 28.8203f); |
| 133 path.lineTo(114.893f, 29.9922f); |
| 134 path.lineTo(115.82f, 33.4102f); |
| 135 path.lineTo(116.016f, 35.4121f); |
| 136 path.lineTo(115.576f, 35.4121f); |
| 137 path.lineTo(114.697f, 37.707f); |
| 138 path.lineTo(115.381f, 38.4883f); |
| 139 path.lineTo(115.186f, 39.5137f); |
| 140 path.lineTo(114.697f, 40.3926f); |
| 141 path.lineTo(114.209f, 41.418f); |
| 142 path.lineTo(114.404f, 42.4922f); |
| 143 path.lineTo(114.795f, 43.3223f); |
| 144 path.quadTo(115.186f, 44.1035f, 115.186f, 46.4961f); |
| 145 path.lineTo(116.309f, 46.7891f); |
| 146 path.lineTo(125, 47.2773f); |
| 147 path.lineTo(126.318f, 48.2051f); |
| 148 path.lineTo(129.59f, 48.5957f); |
| 149 path.lineTo(130.615f, 48.498f); |
| 150 path.lineTo(130.908f, 48.0098f); |
| 151 path.lineTo(134.277f, 48.2051f); |
| 152 path.lineTo(134.717f, 48.3027f); |
| 153 path.quadTo(135.4f, 47.7168f, 136.084f, 47.7168f); |
| 154 path.lineTo(137.109f, 47.8145f); |
| 155 path.lineTo(137.109f, 48.2051f); |
| 156 path.lineTo(137.695f, 48.5957f); |
| 157 path.lineTo(138.818f, 48.498f); |
| 158 path.lineTo(144.189f, 48.4004f); |
| 159 path.lineTo(146.191f, 48.2051f); |
| 160 path.lineTo(147.998f, 48.791f); |
| 161 path.quadTo(148.877f, 47.5215f, 150.098f, 47.5215f); |
| 162 path.lineTo(150.293f, 47.5215f); |
| 163 path.lineTo(152.783f, 47.7168f); |
| 164 path.lineTo(157.52f, 47.2773f); |
| 165 path.lineTo(160.303f, 47.4238f); |
| 166 path.lineTo(161.279f, 47.1797f); |
| 167 path.lineTo(161.621f, 46.1055f); |
| 168 path.lineTo(162.5f, 43.9082f); |
| 169 path.lineTo(162.305f, 38.293f); |
| 170 path.lineTo(162.5f, 37.1211f); |
| 171 path.lineTo(161.816f, 35.998f); |
| 172 path.lineTo(160.596f, 34.7773f); |
| 173 path.lineTo(160.596f, 32.6777f); |
| 174 path.lineTo(160.303f, 30.4805f); |
| 175 path.lineTo(160.889f, 29.4062f); |
| 176 path.quadTo(160.303f, 27.4043f, 160.303f, 26.2812f); |
| 177 path.quadTo(160.303f, 25.3535f, 160.889f, 25.207f); |
| 178 path.lineTo(162.207f, 25.0117f); |
| 179 path.lineTo(163.721f, 23.8887f); |
| 180 path.lineTo(164.893f, 23.8887f); |
| 181 path.quadTo(165.625f, 23.6934f, 166.797f, 22.5215f); |
| 182 path.lineTo(168.213f, 23.2051f); |
| 183 path.lineTo(168.701f, 25.5f); |
| 184 path.lineTo(169.092f, 26.8184f); |
| 185 path.lineTo(167.676f, 31.9941f); |
| 186 path.lineTo(168.018f, 34.6797f); |
| 187 path.lineTo(167.822f, 35.8027f); |
| 188 path.lineTo(167.285f, 35.8027f); |
| 189 path.quadTo(166.602f, 35.8027f, 166.602f, 36.7793f); |
| 190 path.quadTo(166.846f, 37.3652f, 167.578f, 37.707f); |
| 191 path.lineTo(168.506f, 38.1953f); |
| 192 path.lineTo(168.799f, 39.5137f); |
| 193 path.lineTo(169.092f, 41.5156f); |
| 194 path.lineTo(168.994f, 42.1016f); |
| 195 path.lineTo(168.213f, 43.6152f); |
| 196 path.lineTo(168.408f, 52.502f); |
| 197 path.lineTo(168.213f, 60.1191f); |
| 198 path.lineTo(168.994f, 61.291f); |
| 199 path.quadTo(168.604f, 63.0488f, 168.604f, 63.9766f); |
| 200 path.lineTo(168.604f, 64.123f); |
| 201 path.lineTo(168.604f, 64.3184f); |
| 202 path.lineTo(168.604f, 64.9043f); |
| 203 path.lineTo(168.604f, 66.0762f); |
| 204 path.quadTo(167.578f, 67.1504f, 167.578f, 67.5898f); |
| 205 path.quadTo(167.578f, 67.7852f, 167.676f, 67.7852f); |
| 206 path.lineTo(168.994f, 70.0801f); |
| 207 path.lineTo(168.701f, 76.7207f); |
| 208 path.lineTo(169.824f, 83.4102f); |
| 209 path.close(); |
| 210 return path; |
| 211 } |
| 212 |
| 213 /* Generated on a Mac with: |
| 214 * paint.setTypeface(SkTypeface::CreateByName("Hiragino Maru Gothic Pro")); |
| 215 * const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC }; |
| 216 * paint.getTextPath(hyphen, SK_ARRAY_COUNT(hyphen), 400, 80, &textPath); |
| 217 */ |
| 218 static SkPath hiragino_maru_gothic_pro_dash() { |
| 219 SkPath path; |
| 220 path.moveTo(488, 55.1f); |
| 221 path.cubicTo(490.5f, 55.1f, 491.9f, 53.5f, 491.9f, 50.8f); |
| 222 path.cubicTo(491.9f, 48.2f, 490.5f, 46.3f, 487.9f, 46.3f); |
| 223 path.lineTo(412, 46.3f); |
| 224 path.cubicTo(409.4f, 46.3f, 408, 48.2f, 408, 50.8f); |
| 225 path.cubicTo(408, 53.5f, 409.4f, 55.1f, 411.9f, 55.1f); |
| 226 path.lineTo(488, 55.1f); |
| 227 path.close(); |
| 228 return path; |
| 229 } |
| 230 |
15 class StrokeFillGM : public GM { | 231 class StrokeFillGM : public GM { |
16 public: | 232 public: |
17 StrokeFillGM() { | 233 StrokeFillGM() { |
18 | 234 |
19 } | 235 } |
20 | 236 |
21 protected: | 237 protected: |
22 | 238 |
23 SkString onShortName() override { | 239 SkString onShortName() override { |
24 return SkString("stroke-fill"); | 240 return SkString("stroke-fill"); |
25 } | 241 } |
26 | 242 |
27 SkISize onISize() override { | 243 SkISize onISize() override { |
28 return SkISize::Make(640, 480); | 244 return SkISize::Make(640, 480); |
29 } | 245 } |
30 | 246 |
31 static void show_bold(SkCanvas* canvas, const void* text, int len, | 247 static void show_bold(SkCanvas* canvas, const void* text, int len, |
32 SkScalar x, SkScalar y, const SkPaint& paint) { | 248 SkScalar x, SkScalar y, const SkPaint& paint) { |
33 SkPaint p(paint); | 249 SkPaint p(paint); |
34 canvas->drawText(text, len, x, y, p); | 250 canvas->drawText(text, len, x, y, p); |
35 p.setFakeBoldText(true); | 251 p.setFakeBoldText(true); |
36 canvas->drawText(text, len, x, y + SkIntToScalar(120), p); | 252 canvas->drawText(text, len, x, y + SkIntToScalar(120), p); |
37 } | 253 } |
38 | 254 |
| 255 static void path_bold(SkCanvas* canvas, const SkPath& path, const SkPaint& p
aint) { |
| 256 SkPaint p(paint); |
| 257 canvas->drawPath(path, p); |
| 258 p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 259 SkScalar fakeBoldScale = SkScalarInterpFunc(p.getTextSize(), |
| 260 kStdFakeBoldInterpKeys, kStdFakeBoldInterpValues, |
| 261 kStdFakeBoldInterpLength); |
| 262 SkScalar extra = SkScalarMul(p.getTextSize(), fakeBoldScale); |
| 263 p.setStrokeWidth(extra); |
| 264 canvas->save(); |
| 265 canvas->translate(0, 120); |
| 266 canvas->drawPath(path, p); |
| 267 canvas->restore(); |
| 268 } |
| 269 |
39 void onDraw(SkCanvas* canvas) override { | 270 void onDraw(SkCanvas* canvas) override { |
40 SkScalar x = SkIntToScalar(100); | 271 SkScalar x = SkIntToScalar(100); |
41 SkScalar y = SkIntToScalar(88); | 272 SkScalar y = SkIntToScalar(88); |
42 | 273 |
43 SkPaint paint; | 274 SkPaint paint; |
44 paint.setAntiAlias(true); | 275 paint.setAntiAlias(true); |
45 paint.setTextSize(SkIntToScalar(100)); | 276 paint.setTextSize(SkIntToScalar(100)); |
46 paint.setStrokeWidth(SkIntToScalar(5)); | 277 paint.setStrokeWidth(SkIntToScalar(5)); |
47 | 278 |
48 sk_tool_utils::set_portable_typeface(&paint, "Papyrus"); | 279 // use paths instead of text to test the path data on all platforms, sin
ce the |
49 show_bold(canvas, "Hello", 5, x, y, paint); | 280 // Mac-specific font may change or is not available everywhere |
50 | 281 path_bold(canvas, papyrus_hello(), paint); |
51 sk_tool_utils::set_portable_typeface(&paint, "Hiragino Maru Gothic Pro")
; | 282 path_bold(canvas, hiragino_maru_gothic_pro_dash(), paint); |
52 const unsigned char hyphen[] = { 0xE3, 0x83, 0xBC }; | 283 |
53 show_bold(canvas, hyphen, SK_ARRAY_COUNT(hyphen), x + SkIntToScalar(300)
, y, paint); | 284 // use the portable typeface to generically test the fake bold code ever
ywhere |
| 285 // (as long as the freetype option to do the bolding itself isn't enable
d) |
| 286 sk_tool_utils::set_portable_typeface_always(&paint, "serif"); |
| 287 const unsigned char hiThere[] = "Hi There"; |
| 288 show_bold(canvas, hiThere, SK_ARRAY_COUNT(hiThere), x + SkIntToScalar(43
0), y, paint); |
54 | 289 |
55 paint.setStyle(SkPaint::kStrokeAndFill_Style); | 290 paint.setStyle(SkPaint::kStrokeAndFill_Style); |
56 | 291 |
57 SkPath path; | 292 SkPath path; |
58 path.setFillType(SkPath::kWinding_FillType); | 293 path.setFillType(SkPath::kWinding_FillType); |
59 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW
_Direction); | 294 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(50), SkPath::kCW
_Direction); |
60 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCC
W_Direction); | 295 path.addCircle(x, y + SkIntToScalar(200), SkIntToScalar(40), SkPath::kCC
W_Direction); |
61 canvas->drawPath(path, paint); | 296 canvas->drawPath(path, paint); |
62 | 297 |
63 SkPath path2; | 298 SkPath path2; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 351 |
117 private: | 352 private: |
118 typedef GM INHERITED; | 353 typedef GM INHERITED; |
119 }; | 354 }; |
120 | 355 |
121 ////////////////////////////////////////////////////////////////////////////// | 356 ////////////////////////////////////////////////////////////////////////////// |
122 | 357 |
123 DEF_GM(return SkNEW(StrokeFillGM);) | 358 DEF_GM(return SkNEW(StrokeFillGM);) |
124 | 359 |
125 } | 360 } |
OLD | NEW |