pathreverse.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2011 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. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkPaint.h"
  11. #include "include/core/SkPath.h"
  12. #include "include/core/SkRect.h"
  13. #include "include/core/SkString.h"
  14. /* The hiragino_maru_goth_pro_e path was generated with Mac-specific code:
  15. *
  16. * paint.setTextSize(SkIntToScalar(100));
  17. * paint.setTypeface(SkTypeface::CreateFromName("Hiragino Maru Gothic Pro"));
  18. * paint.getTextPath("e", 1, 50, 50, &path);
  19. *
  20. * The path data is duplicated here to allow the test to
  21. * run on all platforms and to remove the bug dependency
  22. * should future Macs edit or delete the font.
  23. */
  24. static SkPath hiragino_maru_goth_pro_e() {
  25. SkPath path;
  26. path.moveTo(98.6f, 24.7f);
  27. path.cubicTo(101.7f, 24.7f, 103.6f, 22.8f, 103.6f, 19.2f);
  28. path.cubicTo(103.6f, 18.9f, 103.6f, 18.7f, 103.6f, 18.4f);
  29. path.cubicTo(102.6f, 5.3f, 94.4f, -6.1f, 79.8f, -6.1f);
  30. path.cubicTo(63.5f, -6.1f, 54.5f, 6, 54.5f, 23.3f);
  31. path.cubicTo(54.5f, 40.6f, 64, 52.2f, 80.4f, 52.2f);
  32. path.cubicTo(93.4f, 52.2f, 99.2f, 45.6f, 102.4f, 39);
  33. path.cubicTo(102.8f, 38.4f, 102.9f, 37.8f, 102.9f, 37.2f);
  34. path.cubicTo(102.9f, 35.4f, 101.5f, 34.2f, 99.8f, 33.7f);
  35. path.cubicTo(99.1f, 33.5f, 98.4f, 33.3f, 97.7f, 33.3f);
  36. path.cubicTo(96.3f, 33.3f, 95, 34, 94.1f, 35.8f);
  37. path.cubicTo(91.7f, 41.1f, 87.7f, 44.7f, 80.5f, 44.7f);
  38. path.cubicTo(69.7f, 44.7f, 63.6f, 37, 63.4f, 24.7f);
  39. path.lineTo(98.6f, 24.7f);
  40. path.close();
  41. path.moveTo(63.7f, 17.4f);
  42. path.cubicTo(65, 7.6f, 70.2f, 1.2f, 79.8f, 1.2f);
  43. path.cubicTo(89, 1.2f, 93.3f, 8.5f, 94.5f, 15.6f);
  44. path.cubicTo(94.5f, 15.8f, 94.5f, 16, 94.5f, 16.1f);
  45. path.cubicTo(94.5f, 17, 94.1f, 17.4f, 93, 17.4f);
  46. path.lineTo(63.7f, 17.4f);
  47. path.close();
  48. return path;
  49. }
  50. static void test_path(SkCanvas* canvas, const SkPath& path) {
  51. SkPaint paint;
  52. paint.setAntiAlias(true);
  53. canvas->drawPath(path, paint);
  54. paint.setStyle(SkPaint::kStroke_Style);
  55. paint.setColor(SK_ColorRED);
  56. canvas->drawPath(path, paint);
  57. }
  58. static void test_rev(SkCanvas* canvas, const SkPath& path) {
  59. test_path(canvas, path);
  60. SkPath rev;
  61. rev.reverseAddPath(path);
  62. canvas->save();
  63. canvas->translate(150, 0);
  64. test_path(canvas, rev);
  65. canvas->restore();
  66. }
  67. DEF_SIMPLE_GM_BG_NAME(pathreverse, canvas, 640, 480, SK_ColorWHITE,
  68. SkString("path-reverse")) {
  69. SkRect r = { 10, 10, 100, 60 };
  70. SkPath path;
  71. path.addRect(r); test_rev(canvas, path);
  72. canvas->translate(0, 100);
  73. path.offset(20, 20);
  74. path.addRect(r); test_rev(canvas, path);
  75. canvas->translate(0, 100);
  76. path.reset();
  77. path.moveTo(10, 10); path.lineTo(30, 30);
  78. path.addOval(r);
  79. r.offset(50, 20);
  80. path.addOval(r);
  81. test_rev(canvas, path);
  82. path = hiragino_maru_goth_pro_e();
  83. canvas->translate(0, 100);
  84. test_rev(canvas, path);
  85. }