svgpath 1.1.0

  • Readme
  • Changelog
  • Installing
  • 48

svgpath #

This is a Dart port of Fontello's svgpath JavaScript library.

Low level toolkit for SVG paths transformations. Sometime you can't use transform attributes and have to apply changes to svg paths directly. Then this package is for you :) !

This package works both in browser and on server.


new SvgPath(path) #

Constructor. Creates new SvgPath class instance.

.abs() #

Converts all path commands to absolute.

.rel() #

Converts all path commands to relative. Useful to reduce output size.

.scale(sx [, sy]) #

Rescale path (the same as SVG scale transformation). sy = sx by default.

.translate(x [, y]) #

Translate path (the same as SVG translate transformation). y = 0 by default.

.rotate(angle [, rx, ry]) #

Rotate path to angle degrees around (rx, ry) point. If rotation center not set, (0, 0) used. The same as SVG rotate transformation.

.skewX(degrees) #

Skew path along the X axis by degrees angle.

.skewY(degrees) #

Skew path along the Y axis by degrees angle.

.matrix([ m1, m2, m3, m4, m5, m6 ]) #

Apply 2x3 affine transform matrix to path. Params - array. The same as SVG matrix transformation.

.transform(string) #

Any SVG transform or their combination. For example rotate(90) scale(2,3). The same format, as described in SVG standard for transform attribute.

.unshort() #

Converts smooth curves T/t/S/s with "missed" control point to generic curves (Q/q/C/c).

.unarc() #

Replaces all arcs with bezier curves.

.toString() -> String #

Returns final path string.

.round(precision) #

Round all coordinates to given decimal precision. By default round to integer. Useful to reduce resulting output string size.

.iterate(function(segment, index, x, y) [, keepLazyStack]) #

Apply iterator to all path segments.

  • Each iterator receives segment, index, x and y params. Where (x, y) - absolute coordinates of segment start point.
  • Iterator can modify current segment directly (return nothing in this case).
  • Iterator can return array of new segments to replace current one ([] means that current segment should be deleted).

If second param keepLazyStack set to true, then iterator will not evaluate stacked transforms prior to run. That can be useful to optimize calculations.

Changelog #

1.0.0 #

  • Fix matrix value helper function.

0.1.0 #

  • Implement BoundingBox

0.0.1 #

  • Initial version

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  svgpath: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:svgpath/svgpath.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health issues and suggestions

Document public APIs. (-0.02 points)

57 out of 59 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/svgpath.dart. (-6.31 points)

Analysis of lib/src/svgpath.dart reported 13 hints, including:

line 86 col 25: Unnecessary new keyword.

line 163 col 13: Unnecessary new keyword.

line 197 col 13: Unnecessary new keyword.

line 206 col 16: Unnecessary new keyword.

line 212 col 26: Don't explicitly initialize variables to null.

Fix lib/src/path_parse.dart. (-2.48 points)

Analysis of lib/src/path_parse.dart reported 5 hints:

line 4 col 22: Avoid const keyword.

line 18 col 17: Avoid const keyword.

line 314 col 15: Unnecessary new keyword.

line 324 col 9: Use contains instead of indexOf

line 332 col 10: Unnecessary new keyword.

Fix lib/src/transform_parse.dart. (-1.99 points)

Analysis of lib/src/transform_parse.dart reported 4 hints:

line 6 col 20: Avoid const keyword.

line 19 col 16: Unnecessary new keyword.

line 24 col 36: Unnecessary new keyword.

line 38 col 25: Unnecessary new keyword.

Fix lib/src/matrix.dart. (-0.50 points)

Analysis of lib/src/matrix.dart reported 1 hint:

line 106 col 48: Use = to separate a named parameter from its default value.

Format lib/src/a2c.dart.

Run dartfmt to format lib/src/a2c.dart.

Maintenance suggestions

Package is getting outdated. (-37.26 points)

The package was last published 71 weeks ago.

The package description is too short. (-18 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and svgpath.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.3 <3.0.0
dart2_constant ^1.0.0 1.0.2+dart2
Dev dependencies
path ^1.0.0
test >=0.12.30 <2.0.0