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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 }; | 280 }; |
281 static const CapAndName gCaps[] = { | 281 static const CapAndName gCaps[] = { |
282 {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, | 282 {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
283 {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, | 283 {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
284 {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} | 284 {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
285 }; | 285 }; |
286 | 286 |
287 SkPaint titlePaint; | 287 SkPaint titlePaint; |
288 titlePaint.setColor(SK_ColorBLACK); | 288 titlePaint.setColor(SK_ColorBLACK); |
289 titlePaint.setAntiAlias(true); | 289 titlePaint.setAntiAlias(true); |
290 sk_tool_utils::set_portable_typeface(&titlePaint); | 290 sk_tool_utils::set_portable_typeface_always(&titlePaint); |
291 titlePaint.setLCDRenderText(true); | |
292 titlePaint.setTextSize(15 * SK_Scalar1); | 291 titlePaint.setTextSize(15 * SK_Scalar1); |
293 const char title[] = "Random Paths Drawn Into Rectangle Clips With " | 292 const char title[] = "Random Paths Drawn Into Rectangle Clips With " |
294 "Indicated Style, Fill and Linecaps, " | 293 "Indicated Style, Fill and Linecaps, " |
295 "with Stroke width 6"; | 294 "with Stroke width 6"; |
296 canvas->drawText(title, strlen(title), | 295 canvas->drawText(title, strlen(title), |
297 20 * SK_Scalar1, | 296 20 * SK_Scalar1, |
298 20 * SK_Scalar1, | 297 20 * SK_Scalar1, |
299 titlePaint); | 298 titlePaint); |
300 | 299 |
301 SkRandom rand; | 300 SkRandom rand; |
302 SkRect rect = SkRect::MakeWH(220*SK_Scalar1, 50*SK_Scalar1); | 301 SkRect rect = SkRect::MakeWH(220*SK_Scalar1, 50*SK_Scalar1); |
303 canvas->save(); | 302 canvas->save(); |
304 canvas->translate(2*SK_Scalar1, 30 * SK_Scalar1); // The title | 303 canvas->translate(2*SK_Scalar1, 30 * SK_Scalar1); // The title |
305 canvas->save(); | 304 canvas->save(); |
306 unsigned numSegments = SK_ARRAY_COUNT(gSegmentFunctions); | 305 unsigned numSegments = SK_ARRAY_COUNT(gSegmentFunctions); |
307 unsigned numCaps = SK_ARRAY_COUNT(gCaps); | 306 unsigned numCaps = SK_ARRAY_COUNT(gCaps); |
308 unsigned numStyles = SK_ARRAY_COUNT(gStyles); | 307 unsigned numStyles = SK_ARRAY_COUNT(gStyles); |
309 unsigned numFills = SK_ARRAY_COUNT(gFills); | 308 unsigned numFills = SK_ARRAY_COUNT(gFills); |
310 for (size_t row = 0; row < 6; ++row) { | 309 for (size_t row = 0; row < 6; ++row) { |
311 if (0 < row) { | 310 if (0 < row) { |
312 canvas->translate(0, rect.height() + 100*SK_Scalar1); | 311 canvas->translate(0, rect.height() + 100*SK_Scalar1); |
313 } | 312 } |
314 canvas->save(); | 313 canvas->save(); |
315 for (size_t column = 0; column < 4; ++column) { | 314 for (size_t column = 0; column < 4; ++column) { |
316 if (0 < column) { | 315 if (0 < column) { |
317 canvas->translate(rect.width() + 4*SK_Scalar1, 0); | 316 canvas->translate(rect.width() + 4*SK_Scalar1, 0); |
318 } | 317 } |
319 | 318 |
320 SkColor color = 0xff007000; | 319 SkColor color = sk_tool_utils::color_to_565(0xff007000); |
321 StyleAndName style = gStyles[(rand.nextU() >> 16) % numStyles]; | 320 StyleAndName style = gStyles[(rand.nextU() >> 16) % numStyles]; |
322 CapAndName cap = gCaps[(rand.nextU() >> 16) % numCaps]; | 321 CapAndName cap = gCaps[(rand.nextU() >> 16) % numCaps]; |
323 FillAndName fill = gFills[(rand.nextU() >> 16) % numFills]; | 322 FillAndName fill = gFills[(rand.nextU() >> 16) % numFills]; |
324 SkPath path; | 323 SkPath path; |
325 unsigned s1 = (rand.nextU() >> 16) % numSegments; | 324 unsigned s1 = (rand.nextU() >> 16) % numSegments; |
326 unsigned s2 = (rand.nextU() >> 16) % numSegments; | 325 unsigned s2 = (rand.nextU() >> 16) % numSegments; |
327 unsigned s3 = (rand.nextU() >> 16) % numSegments; | 326 unsigned s3 = (rand.nextU() >> 16) % numSegments; |
328 unsigned s4 = (rand.nextU() >> 16) % numSegments; | 327 unsigned s4 = (rand.nextU() >> 16) % numSegments; |
329 unsigned s5 = (rand.nextU() >> 16) % numSegments; | 328 unsigned s5 = (rand.nextU() >> 16) % numSegments; |
330 SkPoint pt = SkPoint::Make(10*SK_Scalar1, 0); | 329 SkPoint pt = SkPoint::Make(10*SK_Scalar1, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
341 SkPaint rectPaint; | 340 SkPaint rectPaint; |
342 rectPaint.setColor(SK_ColorBLACK); | 341 rectPaint.setColor(SK_ColorBLACK); |
343 rectPaint.setStyle(SkPaint::kStroke_Style); | 342 rectPaint.setStyle(SkPaint::kStroke_Style); |
344 rectPaint.setStrokeWidth(-1); | 343 rectPaint.setStrokeWidth(-1); |
345 rectPaint.setAntiAlias(true); | 344 rectPaint.setAntiAlias(true); |
346 canvas->drawRect(rect, rectPaint); | 345 canvas->drawRect(rect, rectPaint); |
347 | 346 |
348 SkPaint labelPaint; | 347 SkPaint labelPaint; |
349 labelPaint.setColor(color); | 348 labelPaint.setColor(color); |
350 labelPaint.setAntiAlias(true); | 349 labelPaint.setAntiAlias(true); |
351 sk_tool_utils::set_portable_typeface(&labelPaint); | 350 sk_tool_utils::set_portable_typeface_always(&labelPaint); |
352 labelPaint.setLCDRenderText(true); | |
353 labelPaint.setTextSize(10 * SK_Scalar1); | 351 labelPaint.setTextSize(10 * SK_Scalar1); |
354 canvas->drawText(style.fName, | 352 canvas->drawText(style.fName, |
355 strlen(style.fName), | 353 strlen(style.fName), |
356 0, rect.height() + 12 * SK_Scalar1, | 354 0, rect.height() + 12 * SK_Scalar1, |
357 labelPaint); | 355 labelPaint); |
358 canvas->drawText(fill.fName, | 356 canvas->drawText(fill.fName, |
359 strlen(fill.fName), | 357 strlen(fill.fName), |
360 0, rect.height() + 24 * SK_Scalar1, | 358 0, rect.height() + 24 * SK_Scalar1, |
361 labelPaint); | 359 labelPaint); |
362 canvas->drawText(cap.fName, | 360 canvas->drawText(cap.fName, |
(...skipping 30 matching lines...) Expand all Loading... |
393 private: | 391 private: |
394 typedef GM INHERITED; | 392 typedef GM INHERITED; |
395 }; | 393 }; |
396 | 394 |
397 ////////////////////////////////////////////////////////////////////////////// | 395 ////////////////////////////////////////////////////////////////////////////// |
398 | 396 |
399 static GM* MyFactory(void*) { return new DegenerateSegmentsGM; } | 397 static GM* MyFactory(void*) { return new DegenerateSegmentsGM; } |
400 static GMRegistry reg(MyFactory); | 398 static GMRegistry reg(MyFactory); |
401 | 399 |
402 } | 400 } |
OLD | NEW |