@@ -46,7 +46,7 @@ class Stroke {
4646
4747 void _updatePolygon () {
4848 _polygon = _getPolygon ();
49- _path = Path ().. addPolygon (_polygon, true );
49+ _path = _getPath ( );
5050 _polygonNeedsUpdating = false ;
5151 }
5252
@@ -174,6 +174,9 @@ class Stroke {
174174
175175 final minDistance = options.size * thresholdMultiplier;
176176
177+ // Remove points with null pressure because they were duplicates
178+ points.removeWhere ((point) => point.pressure == null );
179+
177180 for (int i = 1 ; i < points.length - 1 ; i++ ) {
178181 final point = points[i];
179182 final prev = points[i - 1 ];
@@ -203,8 +206,6 @@ class Stroke {
203206 if (rememberSimulatedPressure) {
204207 // Ensure we don't simulate pressure again
205208 options.simulatePressure = false ;
206- // Remove points with null pressure because they were duplicates
207- points.removeWhere ((point) => point.pressure == null );
208209 // Remove points that are too close together
209210 optimisePoints ();
210211 // Get polygon again with slightly different input
@@ -214,6 +215,29 @@ class Stroke {
214215 return polygon;
215216 }
216217
218+ /// Returns a [Path] that represents the stroke.
219+ ///
220+ /// If the stroke is not complete,
221+ /// the path will just follow the polygon for performance.
222+ ///
223+ /// If the stroke is complete,
224+ /// the path will be a smooth curve between the points.
225+ Path _getPath () {
226+ if (! options.isComplete) {
227+ return Path ()..addPolygon (_polygon, true );
228+ }
229+
230+ final path = Path ();
231+ path.moveTo (_polygon.first.dx, _polygon.first.dy);
232+ for (int i = 1 ; i < _polygon.length - 1 ; i++ ) {
233+ final p1 = _polygon[i];
234+ final p2 = _polygon[i + 1 ];
235+ final mid = (p1 + p2) / 2 ;
236+ path.quadraticBezierTo (p1.dx, p1.dy, mid.dx, mid.dy);
237+ }
238+ return path..close ();
239+ }
240+
217241 String toSvgPath (Size pageSize) {
218242 String toSvgPoint (Offset point) {
219243 return '${point .dx } '
0 commit comments