Skip to content

Commit ba78a9a

Browse files
committed
Allow Flags without seperators in cubic beizer curves
Added tests for #6 and #7 Fixes #6
1 parent bce3e5c commit ba78a9a

6 files changed

Lines changed: 84 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
## [1.1.1] - 19-July-2021
2+
3+
* Allow Flags without separators in cubic Bézier curves
4+
see details here: [issue#6](https://github.com/masterashu/svg_path_parser/issues/6)
5+
16
## [1.1.0] - 19-July-2021
27

38
* Fixed an issue where using an absolute command after
49
a relative command will lead to wrong parsing behavior.
5-
See details here: [issue#6](https://github.com/masterashu/svg_path_parser/issues/6)
10+
See details here: [issue#7](https://github.com/masterashu/svg_path_parser/issues/7)
611

712
## [1.0.0] - 7-March-2021
813

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Add this to your package's **pubspec.yaml** file:
1010

1111
```yaml
1212
dependencies:
13-
svg_path_parser: ^1.1.0
13+
svg_path_parser: ^1.1.1
1414
```
1515
1616
Now in your Dart code, you can use:

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ packages:
120120
path: ".."
121121
relative: true
122122
source: path
123-
version: "1.0.0"
123+
version: "1.1.1"
124124
term_glyph:
125125
dependency: transitive
126126
description:

lib/src/scanner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Scanner {
5050
RegExp(r'[+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?');
5151

5252
/// The [RegExp] pattern to match a boolean flag (`1` or `0`).
53-
static final flagPattern = RegExp(r'(0|1)(?=[,\s])');
53+
static final flagPattern = RegExp(r'(0|1)');
5454

5555
/// Queue of tokens generated to be returned.
5656
final _tokens = Queue<Token>();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: svg_path_parser
22
description: >
33
A Flutter/Dart utility to parse an SVG path into a
44
equivalent Path object from dart:ui library.
5-
version: 1.1.0
5+
version: 1.1.1
66
homepage: https://github.com/masterashu/svg_path_parser
77
repository: https://github.com/masterashu/svg_path_parser
88
issue_tracker: https://github.com/masterashu/svg_path_parser/issues

test/parser_test.dart

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
77
// Tests the scanner for correctly parses the input.
88
main() {
99
final testingArea =
10-
Rect.fromCenter(center: Offset.zero, width: 10, height: 10);
10+
Rect.fromCenter(center: Offset.zero, width: 15, height: 15);
1111
group('Testing paths from commands', () {
1212
group('test moveTo commands', () {
1313
test('test consecutive arguments act as lineTo commands.', () {
@@ -216,4 +216,77 @@ main() {
216216
});
217217
});
218218
});
219+
220+
group('Testing combination of relative and absolute commands', () {
221+
final testingArea =
222+
Rect.fromCenter(center: Offset.zero, width: 20, height: 20);
223+
224+
group('Test Flag pattern on cubic curves', () {
225+
final testingArea =
226+
Rect.fromCenter(center: Offset.zero, width: 20, height: 20);
227+
group('test ellipticalArcTo commands', () {
228+
test('test ellipticalArtTo absolute', () {
229+
var expectedPath = Path()
230+
..moveTo(0, 4)
231+
..arcToPoint(Offset(7, 1),
232+
radius: Radius.elliptical(5, 8),
233+
rotation: 0.12,
234+
largeArc: true,
235+
clockwise: true);
236+
expect(
237+
parseSvgPath('M0,4A5,8,.12 11 7 1'),
238+
coversSameAreaAs(expectedPath,
239+
areaToCompare: testingArea, sampleSize: 400));
240+
});
241+
242+
test('test ellipticalArtTo relative', () {
243+
var expectedPath = Path()
244+
..moveTo(0, 0)
245+
..arcToPoint(Offset(5, 5),
246+
radius: Radius.elliptical(11, 7),
247+
largeArc: true,
248+
clockwise: true)
249+
..close();
250+
// Note: Make a check for out of range parameters:
251+
// https://www.w3.org/TR/SVG11/implnote.html#ArcOutOfRangeParameters
252+
expect(
253+
parseSvgPath('a11,7, 0 115,5z'),
254+
coversSameAreaAs(expectedPath,
255+
areaToCompare: testingArea, sampleSize: 400));
256+
});
257+
});
258+
});
259+
});
260+
261+
group('Test square path on different combinations', () {
262+
test('Testing flags without any spaces', () {
263+
var expectedPath = Path()
264+
..moveTo(0, 0)
265+
..lineTo(0, 5)
266+
..lineTo(5, 5)
267+
..lineTo(5, 0)
268+
..close();
269+
270+
expect(
271+
parseSvgPath('M 0 0 V5 H5 V0z'),
272+
coversSameAreaAs(expectedPath,
273+
areaToCompare: testingArea, sampleSize: 400));
274+
expect(
275+
parseSvgPath('M0 0 v5 h5 V0z'),
276+
coversSameAreaAs(expectedPath,
277+
areaToCompare: testingArea, sampleSize: 400));
278+
expect(
279+
parseSvgPath('M0 0 V5 h5 v-5z'),
280+
coversSameAreaAs(expectedPath,
281+
areaToCompare: testingArea, sampleSize: 400));
282+
expect(
283+
parseSvgPath('M0 0 h5 V5 H0 z'),
284+
coversSameAreaAs(expectedPath,
285+
areaToCompare: testingArea, sampleSize: 400));
286+
expect(
287+
parseSvgPath('M0 0 v5 H5 v-5z'),
288+
coversSameAreaAs(expectedPath,
289+
areaToCompare: testingArea, sampleSize: 400));
290+
});
291+
});
219292
}

0 commit comments

Comments
 (0)