blob: 70ab8bd35945098790ae0c6bd8a4269cf5243935 [file] [log] [blame]
Cary Clark61313f32018-10-08 14:57:48 -04001#Topic Path_Overview
2
3Path contains Lines and Curves which can be stroked or filled. Contour is
4composed of a series of connected Lines and Curves. Path may contain zero,
5one, or more Contours.
6Each Line and Curve are described by Verb, Points, and optional Path_Conic_Weight.
7
8Each pair of connected Lines and Curves share common Point; for instance, Path
9containing two connected Lines are described the Path_Verb sequence:
10SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb; and a Point sequence
11with three entries, sharing
12the middle entry as the end of the first Line and the start of the second Line.
13
14Path components Arc, Rect, Round_Rect, Circle, and Oval are composed of
15Lines and Curves with as many Verbs and Points required
16for an exact description. Once added to Path, these components may lose their
17identity; although Path can be inspected to determine if it describes a single
18Rect, Oval, Round_Rect, and so on.
19
20#Example
21#Height 192
22#Description
23Path contains three Contours: Line, Circle, and Quad. Line is stroked but
24not filled. Circle is stroked and filled; Circle stroke forms a loop. Quad
25is stroked and filled, but since it is not closed, Quad does not stroke a loop.
26##
27void draw(SkCanvas* canvas) {
28 SkPaint paint;
29 paint.setAntiAlias(true);
30 SkPath path;
31 path.moveTo(124, 108);
32 path.lineTo(172, 24);
33 path.addCircle(50, 50, 30);
34 path.moveTo(36, 148);
35 path.quadTo(66, 188, 120, 136);
36 canvas->drawPath(path, paint);
37 paint.setStyle(SkPaint::kStroke_Style);
38 paint.setColor(SK_ColorBLUE);
39 paint.setStrokeWidth(3);
40 canvas->drawPath(path, paint);
41}
42##
43
44Path contains a Path_Fill_Type which determines whether overlapping Contours
45form fills or holes. Path_Fill_Type also determines whether area inside or outside
46Lines and Curves is filled.
47
48#Example
49#Height 192
50#Description
51Path is drawn filled, then stroked, then stroked and filled.
52##
53void draw(SkCanvas* canvas) {
54 SkPaint paint;
55 paint.setAntiAlias(true);
56 SkPath path;
57 path.moveTo(36, 48);
58 path.quadTo(66, 88, 120, 36);
59 canvas->drawPath(path, paint);
60 paint.setStyle(SkPaint::kStroke_Style);
61 paint.setColor(SK_ColorBLUE);
62 paint.setStrokeWidth(8);
63 canvas->translate(0, 50);
64 canvas->drawPath(path, paint);
65 paint.setStyle(SkPaint::kStrokeAndFill_Style);
66 paint.setColor(SK_ColorRED);
67 canvas->translate(0, 50);
68 canvas->drawPath(path, paint);
69}
70##
71
72Path contents are never shared. Copying Path by value effectively creates
73a new Path independent of the original. Internally, the copy does not duplicate
74its contents until it is edited, to reduce memory use and improve performance.
75
76#Subtopic Contour
77#Alias Path_Contour ##
78#Alias Contour ##
79#Alias Contours ##
80#Line # loop of lines and curves ##
81
82Contour contains one or more Verbs, and as many Points as
83are required to satisfy Path_Verb_Array. First Path_Verb in Path is always
84SkPath::kMove_Verb; each SkPath::kMove_Verb that follows starts a new Contour.
85
86#Example
87#Description
88Each SkPath::moveTo starts a new Contour, and content after SkPath::close()
89also starts a new Contour. Since SkPath::conicTo is not preceded by
90SkPath::moveTo, the first Point of the third Contour starts at the last Point
91of the second Contour.
92##
93#Height 192
94 SkPaint paint;
95 paint.setAntiAlias(true);
96 canvas->drawString("1st contour", 150, 100, paint);
97 canvas->drawString("2nd contour", 130, 160, paint);
98 canvas->drawString("3rd contour", 40, 30, paint);
99 paint.setStyle(SkPaint::kStroke_Style);
100 SkPath path;
101 path.moveTo(124, 108);
102 path.lineTo(172, 24);
103 path.moveTo(36, 148);
104 path.quadTo(66, 188, 120, 136);
105 path.close();
106 path.conicTo(70, 20, 110, 40, 0.6f);
107 canvas->drawPath(path, paint);
108##
109
110If final Path_Verb in Contour is SkPath::kClose_Verb, Line connects Path_Last_Point in
111Contour with first Point. A closed Contour, stroked, draws
112Paint_Stroke_Join at Path_Last_Point and first Point. Without SkPath::kClose_Verb
113as final Verb, Path_Last_Point and first Point are not connected; Contour
114remains open. An open Contour, stroked, draws Paint_Stroke_Cap at
115Path_Last_Point and first Point.
116
117#Example
118#Height 160
119#Description
120Path is drawn stroked, with an open Contour and a closed Contour.
121##
122void draw(SkCanvas* canvas) {
123 SkPaint paint;
124 paint.setAntiAlias(true);
125 paint.setStyle(SkPaint::kStroke_Style);
126 paint.setStrokeWidth(8);
127 SkPath path;
128 path.moveTo(36, 48);
129 path.quadTo(66, 88, 120, 36);
130 canvas->drawPath(path, paint);
131 path.close();
132 canvas->translate(0, 50);
133 canvas->drawPath(path, paint);
134}
135##
136
137#Subtopic Zero_Length
138#Alias Zero_Length_Contour ##
139#Line # consideration when contour has no length ##
140Contour length is distance traveled from first Point to Path_Last_Point,
141plus, if Contour is closed, distance from Path_Last_Point to first Point.
142Even if Contour length is zero, stroked Lines are drawn if Paint_Stroke_Cap
143makes them visible.
144
145#Example
146#Height 64
147 SkPaint paint;
148 paint.setAntiAlias(true);
149 paint.setStyle(SkPaint::kStroke_Style);
150 paint.setStrokeWidth(8);
151 paint.setStrokeCap(SkPaint::kRound_Cap);
152 SkPath path;
153 path.moveTo(36, 48);
154 path.lineTo(36, 48);
155 canvas->drawPath(path, paint);
156 path.reset();
157 paint.setStrokeCap(SkPaint::kSquare_Cap);
158 path.moveTo(56, 48);
159 path.close();
160 canvas->drawPath(path, paint);
161##
162
163#Subtopic Zero_Length ##
164
165#Subtopic Contour ##
166
167# ------------------------------------------------------------------------------
168
169#Topic Path_Overview ##