https://github.com/dbrgn/svg2polylines
Rust library to convert SVG data to a list of flattened polylines. Also includes FFI bindings.
https://github.com/dbrgn/svg2polylines
converter polyline rust svg
Last synced: about 1 year ago
JSON representation
Rust library to convert SVG data to a list of flattened polylines. Also includes FFI bindings.
- Host: GitHub
- URL: https://github.com/dbrgn/svg2polylines
- Owner: dbrgn
- License: apache-2.0
- Created: 2017-03-12T11:47:24.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-11-02T20:31:17.000Z (over 1 year ago)
- Last Synced: 2025-03-30T06:06:12.531Z (over 1 year ago)
- Topics: converter, polyline, rust, svg
- Language: Rust
- Homepage:
- Size: 120 KB
- Stars: 30
- Watchers: 2
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# svg2polylines
[![CircleCI][circle-ci-badge]][circle-ci]
[![Crates.io][crates-io-badge]][crates-io]
Convert SVG data to a list of polylines (aka polygonal chains or polygonal
paths).
This can be used e.g. for simple drawing robot that just support drawing
straight lines and liftoff / drop pen commands.
Flattening of Bézier curves is done using the
[Lyon](https://github.com/nical/lyon) library. SVG files are preprocessed /
simplified using [usvg](https://docs.rs/usvg/).
**Note: Currently the path style is completely ignored. Only the path itself is
returned.**
## Preview
There is a small preview tool to view the generated polylines. It's simple and
hacky, but helps to debug stuff.
```shell
cargo run --release --example preview path/to/file.svg
```
The `--release` parameter is important, otherwise it's going to be very slow.
Use the mouse to drag / zoom the image and the `Esc` key to close the window.
## Usage: Rust
Signature:
```rust
fn svg2polylines::parse(svg: &str, tol: f64, preprocess: bool) -> Result, String>;
```
See [`examples/basic.rs`][example-src] for a full usage example.
## FFI
This crate used to contain FFI bindings. These have been dropped as of version
0.8.0. If you need them, open an issue on GitHub and I might bring them back.
## License
Licensed under either of
* Apache License, Version 2.0 (LICENSE-APACHE or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license (LICENSE-MIT or
http://opensource.org/licenses/MIT) at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.
[circle-ci]: https://circleci.com/gh/dbrgn/svg2polylines/tree/main
[circle-ci-badge]: https://circleci.com/gh/dbrgn/svg2polylines/tree/main.svg?style=shield
[crates-io]: https://crates.io/crates/svg2polylines
[crates-io-badge]: https://img.shields.io/crates/v/svg2polylines.svg
[example-src]: https://github.com/dbrgn/svg2polylines/blob/main/examples/basic.rs