1 #Topic Path_Overview 2 3 Path contains Lines and Curves which can be stroked or filled. Contour is 4 composed of a series of connected Lines and Curves. Path may contain zero, 5 one, or more Contours. 6 Each Line and Curve are described by Verb, Points, and optional Path_Conic_Weight. 7 8 Each pair of connected Lines and Curves share common Point; for instance, Path 9 containing two connected Lines are described the Path_Verb sequence: 10 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb; and a Point sequence 11 with three entries, sharing 12 the middle entry as the end of the first Line and the start of the second Line. 13 14 Path components Arc, Rect, Round_Rect, Circle, and Oval are composed of 15 Lines and Curves with as many Verbs and Points required 16 for an exact description. Once added to Path, these components may lose their 17 identity; although Path can be inspected to determine if it describes a single 18 Rect, Oval, Round_Rect, and so on. 19 20 #Example 21 #Height 192 22 #Description 23 Path contains three Contours: Line, Circle, and Quad. Line is stroked but 24 not filled. Circle is stroked and filled; Circle stroke forms a loop. Quad 25 is stroked and filled, but since it is not closed, Quad does not stroke a loop. 26 ## 27 void 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 44 Path contains a Path_Fill_Type which determines whether overlapping Contours 45 form fills or holes. Path_Fill_Type also determines whether area inside or outside 46 Lines and Curves is filled. 47 48 #Example 49 #Height 192 50 #Description 51 Path is drawn filled, then stroked, then stroked and filled. 52 ## 53 void 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 72 Path contents are never shared. Copying Path by value effectively creates 73 a new Path independent of the original. Internally, the copy does not duplicate 74 its 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 82 Contour contains one or more Verbs, and as many Points as 83 are required to satisfy Path_Verb_Array. First Path_Verb in Path is always 84 SkPath::kMove_Verb; each SkPath::kMove_Verb that follows starts a new Contour. 85 86 #Example 87 #Description 88 Each SkPath::moveTo starts a new Contour, and content after SkPath::close() 89 also starts a new Contour. Since SkPath::conicTo is not preceded by 90 SkPath::moveTo, the first Point of the third Contour starts at the last Point 91 of 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 110 If final Path_Verb in Contour is SkPath::kClose_Verb, Line connects Path_Last_Point in 111 Contour with first Point. A closed Contour, stroked, draws 112 Paint_Stroke_Join at Path_Last_Point and first Point. Without SkPath::kClose_Verb 113 as final Verb, Path_Last_Point and first Point are not connected; Contour 114 remains open. An open Contour, stroked, draws Paint_Stroke_Cap at 115 Path_Last_Point and first Point. 116 117 #Example 118 #Height 160 119 #Description 120 Path is drawn stroked, with an open Contour and a closed Contour. 121 ## 122 void 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 ## 140 Contour length is distance traveled from first Point to Path_Last_Point, 141 plus, if Contour is closed, distance from Path_Last_Point to first Point. 142 Even if Contour length is zero, stroked Lines are drawn if Paint_Stroke_Cap 143 makes 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 ## 170