SvgPathParser
-
Cmn
class SvgPathParser
Converts each command (beside move to) of a svg path to a list of Cubics by calling SvgPathParser.parseCubics. Any svg path complying to the specification found at https://www.w3.org/TR/SVG/paths.html is supported. Parameters can either be split by whitespace or by commas. There is very little error handling, so use with valid paths and consult the debug logs for unexpected Cubic objects.
Summary
Public companion functions |
||
|---|---|---|
List<Feature> |
parseFeatures(svgPath: String)Converts an SVG path string into a list of |
Cmn
|
Public companion functions
parseFeatures
fun parseFeatures(svgPath: String): List<Feature>
Converts an SVG path string into a list of Feature objects. The polygon described in the path should be representing a single, closed, non-self-intersecting polygon. Otherwise, either an error is thrown or the Morph that the polygon is used in will be distorted.
Note:
-
Only the first shape within the SVG path is processed. Subsequent shapes or holes are ignored.
-
This method is primarily intended for development and testing purposes. For production use, serialize and parse the
Featureobjects withFeatureSerializer.
Usage:
// Do the following three *once*
val triangleSVGPath: String = "M0,0 0.5,1 1,0Z"
val triangleFeatures: List<Feature> = SvgPathParser.parseFeatures(triangleSVGPath)
val serializedTriangle: String = FeatureSerializer.serialize(triangleFeatures)
// Parse the serialized triangle features in your production code.
// You can adjust them (e.g. the type) however you want before parsing.
val features: List<Feature> = FeatureSerializer.parse(serializedTriangle)
val triangle: RoundedPolygon = RoundedPolygon(features, centerX = 0.5f, centerY = 0.5f)
Morph(triangle, ...)| Parameters | |
|---|---|
svgPath: String |
The SVG path string, typically extracted from the |
| Returns | |
|---|---|
List<Feature> |
A list of |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
|