svgpath 1.1.0

  • Readme
  • Changelog
  • Installing
  • 55

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 Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:svgpath/svgpath.dart.

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. (-1 points)

Analysis of lib/src/svgpath.dart reported 2 hints:

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

line 350 col 57: Use = to separate a named parameter from its default value.

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.

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

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

line 324 col 9: Use contains instead of indexOf

Format lib/src/a2c.dart.

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

Format lib/src/transform_parse.dart.

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

Maintenance suggestions

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