@@ -68,9 +68,14 @@ abstract class PathCommand {
68
68
69
69
/// Returns a new path command transformed by `matrix` .
70
70
PathCommand transformed (AffineMatrix matrix);
71
+
72
+ /// A representation of this path command for dart:ui.
73
+ String toFlutterString ();
71
74
}
72
75
76
+ /// A straight line from the current point to x,y.
73
77
class LineToCommand extends PathCommand {
78
+ /// Creates a straight line command from the current point to x,y.
74
79
const LineToCommand (this .x, this .y) : super ._(PathCommandType .line);
75
80
76
81
/// The absolute offset of the destination point for this path from the x
@@ -96,12 +101,15 @@ class LineToCommand extends PathCommand {
96
101
}
97
102
98
103
@override
99
- String toString () {
100
- return '..lineTo($x , $y )' ;
101
- }
104
+ String toFlutterString () => '..lineTo($x , $y )' ;
105
+
106
+ @override
107
+ String toString () => 'LineToCommand($x , $y )' ;
102
108
}
103
109
110
+ /// Moves the current point to x,y as if picking up the pen.
104
111
class MoveToCommand extends PathCommand {
112
+ /// Creates a new command that moves the current point to x,y without drawing.
105
113
const MoveToCommand (this .x, this .y) : super ._(PathCommandType .move);
106
114
107
115
/// The absolute offset of the destination point for this path from the x
@@ -127,12 +135,17 @@ class MoveToCommand extends PathCommand {
127
135
}
128
136
129
137
@override
130
- String toString () {
131
- return '..moveTo($x , $y )' ;
132
- }
138
+ String toFlutterString () => '..moveTo($x , $y )' ;
139
+
140
+ @override
141
+ String toString () => 'MoveToCommand($x , $y )' ;
133
142
}
134
143
144
+ /// A command describing a cubic Bezier command from the current point to
145
+ /// x3,y3 using control points x1,y1 and x2,y2.
135
146
class CubicToCommand extends PathCommand {
147
+ /// Creates a new cubic Bezier command from the current point to x3,y3 using
148
+ /// control points x1,y1 and x2,y2.
136
149
const CubicToCommand (this .x1, this .y1, this .x2, this .y2, this .x3, this .y3)
137
150
: super ._(PathCommandType .cubic);
138
151
@@ -183,12 +196,16 @@ class CubicToCommand extends PathCommand {
183
196
}
184
197
185
198
@override
186
- String toString () {
187
- return '..cubicTo($x1 , $y1 , $x2 , $y2 , $x3 , $y3 )' ;
188
- }
199
+ String toFlutterString () => '..cubicTo($x1 , $y1 , $x2 , $y2 , $x3 , $y3 )' ;
200
+
201
+ @override
202
+ String toString () => 'CubicToCommand($x1 , $y1 , $x2 , $y2 , $x3 , $y3 )' ;
189
203
}
190
204
205
+ /// A straight line from the current point to the current contour start point.
191
206
class CloseCommand extends PathCommand {
207
+ /// Creates a new straight line from the current point to the current contour
208
+ /// start point.
192
209
const CloseCommand () : super ._(PathCommandType .close);
193
210
194
211
@override
@@ -205,9 +222,9 @@ class CloseCommand extends PathCommand {
205
222
}
206
223
207
224
@override
208
- String toString () {
209
- return '..close()' ;
210
- }
225
+ String toFlutterString () => '..close()' ;
226
+ @override
227
+ String toString () => 'CloseCommand()' ;
211
228
}
212
229
213
230
/// Creates a new builder of [Path] objects.
@@ -311,7 +328,7 @@ class PathBuilder implements PathProxy {
311
328
return ;
312
329
}
313
330
314
- final magicRadius = Point (rx, ry) * _kArcApproximationMagic;
331
+ final Point magicRadius = Point (rx, ry) * _kArcApproximationMagic;
315
332
316
333
moveTo (rect.left + rx, rect.top);
317
334
@@ -379,13 +396,9 @@ class PathBuilder implements PathProxy {
379
396
/// path objects with the same commands. By default, the builder will reset
380
397
/// to an initial state.
381
398
Path toPath ({bool reset = true }) {
382
- // TODO: bounds
383
- Rect bounds = Rect .zero;
384
-
385
399
final Path path = Path (
386
400
commands: _commands,
387
401
fillType: fillType,
388
- bounds: bounds,
389
402
);
390
403
391
404
if (reset) {
@@ -402,7 +415,6 @@ class Path {
402
415
Path ({
403
416
List <PathCommand > commands = const < PathCommand > [],
404
417
this .fillType = PathFillType .nonZero,
405
- required this .bounds,
406
418
}) {
407
419
_commands.addAll (commands);
408
420
}
@@ -418,9 +430,7 @@ class Path {
418
430
/// The fill type of this path, defaulting to [PathFillType.nonZero] .
419
431
final PathFillType fillType;
420
432
421
- /// The bounds of this path object.
422
- final Rect bounds;
423
-
433
+ /// Creates a new path whose commands and points are transformed by `matrix` .
424
434
Path transformed (AffineMatrix matrix) {
425
435
final List <PathCommand > commands = < PathCommand > [];
426
436
for (final PathCommand command in _commands) {
@@ -429,9 +439,6 @@ class Path {
429
439
return Path (
430
440
commands: commands,
431
441
fillType: fillType,
432
- // TODO: is this safe? What the commands have degenerated? Should probably
433
- // recalculate this.
434
- bounds: matrix.transformRect (bounds),
435
442
);
436
443
}
437
444
@@ -442,28 +449,40 @@ class Path {
442
449
bool operator == (Object other) {
443
450
return other is Path &&
444
451
listEquals (_commands, other._commands) &&
445
- other.fillType == fillType &&
446
- other.bounds == bounds;
452
+ other.fillType == fillType;
447
453
}
448
454
449
- @override
450
- String toString () {
455
+ /// Returns a string that prints the dart:ui code to create this path.
456
+ String toFlutterString () {
451
457
final StringBuffer buffer = StringBuffer ('Path()' );
452
458
if (fillType != PathFillType .nonZero) {
453
459
buffer.write ('\n ..fillType = $fillType ' );
454
460
}
455
- for (final command in commands) {
456
- buffer.write ('\n $command ' );
461
+ for (final PathCommand command in commands) {
462
+ buffer.write ('\n ${ command . toFlutterString ()} ' );
457
463
}
458
464
buffer.write (';' );
459
465
return buffer.toString ();
460
466
}
467
+
468
+ @override
469
+ String toString () {
470
+ final StringBuffer buffer = StringBuffer ('Path(' );
471
+ if (commands.isNotEmpty) {
472
+ buffer.write ('\n commands: <PathCommand>$commands ,' );
473
+ }
474
+ if (fillType != PathFillType .nonZero) {
475
+ buffer.write ('\n fillType: $fillType ,' );
476
+ }
477
+ buffer.write ('\n )' );
478
+ return buffer.toString ();
479
+ }
461
480
}
462
481
463
482
/// Creates a new [Path] object from an SVG path data string.
464
483
Path parseSvgPathData (String svg) {
465
484
if (svg == '' ) {
466
- return Path (bounds : Rect .zero );
485
+ return Path ();
467
486
}
468
487
469
488
final SvgPathStringSource parser = SvgPathStringSource (svg);
0 commit comments