blob: e272d8d03080087d3555f9adbfda7d85156550bc [file] [log] [blame]
reed@google.com3e71a882012-01-10 18:44:37 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
Mike Reed92f6eb12020-08-25 11:48:41 -040012#include "include/core/SkPathBuilder.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkRect.h"
14#include "include/core/SkString.h"
reed@google.com3e71a882012-01-10 18:44:37 +000015
caryclarkcae3ca62015-07-15 08:58:12 -070016/* The hiragino_maru_goth_pro_e path was generated with Mac-specific code:
17 *
18 * paint.setTextSize(SkIntToScalar(100));
19 * paint.setTypeface(SkTypeface::CreateFromName("Hiragino Maru Gothic Pro"));
20 * paint.getTextPath("e", 1, 50, 50, &path);
halcanary9d524f22016-03-29 09:03:52 -070021 *
caryclarkcae3ca62015-07-15 08:58:12 -070022 * The path data is duplicated here to allow the test to
23 * run on all platforms and to remove the bug dependency
24 * should future Macs edit or delete the font.
25 */
26static SkPath hiragino_maru_goth_pro_e() {
Mike Reed92f6eb12020-08-25 11:48:41 -040027 SkPathBuilder path;
caryclarkcae3ca62015-07-15 08:58:12 -070028 path.moveTo(98.6f, 24.7f);
29 path.cubicTo(101.7f, 24.7f, 103.6f, 22.8f, 103.6f, 19.2f);
30 path.cubicTo(103.6f, 18.9f, 103.6f, 18.7f, 103.6f, 18.4f);
31 path.cubicTo(102.6f, 5.3f, 94.4f, -6.1f, 79.8f, -6.1f);
32 path.cubicTo(63.5f, -6.1f, 54.5f, 6, 54.5f, 23.3f);
33 path.cubicTo(54.5f, 40.6f, 64, 52.2f, 80.4f, 52.2f);
34 path.cubicTo(93.4f, 52.2f, 99.2f, 45.6f, 102.4f, 39);
35 path.cubicTo(102.8f, 38.4f, 102.9f, 37.8f, 102.9f, 37.2f);
36 path.cubicTo(102.9f, 35.4f, 101.5f, 34.2f, 99.8f, 33.7f);
37 path.cubicTo(99.1f, 33.5f, 98.4f, 33.3f, 97.7f, 33.3f);
38 path.cubicTo(96.3f, 33.3f, 95, 34, 94.1f, 35.8f);
39 path.cubicTo(91.7f, 41.1f, 87.7f, 44.7f, 80.5f, 44.7f);
40 path.cubicTo(69.7f, 44.7f, 63.6f, 37, 63.4f, 24.7f);
41 path.lineTo(98.6f, 24.7f);
42 path.close();
43 path.moveTo(63.7f, 17.4f);
44 path.cubicTo(65, 7.6f, 70.2f, 1.2f, 79.8f, 1.2f);
45 path.cubicTo(89, 1.2f, 93.3f, 8.5f, 94.5f, 15.6f);
46 path.cubicTo(94.5f, 15.8f, 94.5f, 16, 94.5f, 16.1f);
47 path.cubicTo(94.5f, 17, 94.1f, 17.4f, 93, 17.4f);
48 path.lineTo(63.7f, 17.4f);
49 path.close();
Mike Reed92f6eb12020-08-25 11:48:41 -040050 return path.detach();
caryclarkcae3ca62015-07-15 08:58:12 -070051}
52
reed@google.com3e71a882012-01-10 18:44:37 +000053static void test_path(SkCanvas* canvas, const SkPath& path) {
54 SkPaint paint;
55 paint.setAntiAlias(true);
56 canvas->drawPath(path, paint);
rmistry@google.comd6176b02012-08-23 18:14:13 +000057
reed@google.com3e71a882012-01-10 18:44:37 +000058 paint.setStyle(SkPaint::kStroke_Style);
59 paint.setColor(SK_ColorRED);
60 canvas->drawPath(path, paint);
61}
62
63static void test_rev(SkCanvas* canvas, const SkPath& path) {
64 test_path(canvas, path);
65
66 SkPath rev;
67 rev.reverseAddPath(path);
68 canvas->save();
69 canvas->translate(150, 0);
70 test_path(canvas, rev);
71 canvas->restore();
72}
73
halcanary2a243382015-09-09 08:16:41 -070074DEF_SIMPLE_GM_BG_NAME(pathreverse, canvas, 640, 480, SK_ColorWHITE,
75 SkString("path-reverse")) {
reed@google.com3e71a882012-01-10 18:44:37 +000076 SkRect r = { 10, 10, 100, 60 };
rmistry@google.comd6176b02012-08-23 18:14:13 +000077
reed@google.com3e71a882012-01-10 18:44:37 +000078 SkPath path;
rmistry@google.comd6176b02012-08-23 18:14:13 +000079
reed@google.com3e71a882012-01-10 18:44:37 +000080 path.addRect(r); test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000081
reed@google.com3e71a882012-01-10 18:44:37 +000082 canvas->translate(0, 100);
83 path.offset(20, 20);
84 path.addRect(r); test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000085
reed@google.com3e71a882012-01-10 18:44:37 +000086 canvas->translate(0, 100);
87 path.reset();
88 path.moveTo(10, 10); path.lineTo(30, 30);
89 path.addOval(r);
90 r.offset(50, 20);
91 path.addOval(r);
92 test_rev(canvas, path);
rmistry@google.comd6176b02012-08-23 18:14:13 +000093
caryclarkcae3ca62015-07-15 08:58:12 -070094 path = hiragino_maru_goth_pro_e();
reed@google.com3e71a882012-01-10 18:44:37 +000095 canvas->translate(0, 100);
96 test_rev(canvas, path);
reed@google.com3e71a882012-01-10 18:44:37 +000097}