Giter VIP home page Giter VIP logo

svg2polylines's Introduction

svg2polylines

CircleCI 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 library. SVG files are preprocessed / simplified using 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.

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:

fn svg2polylines::parse(svg: &str, tol: f64, preprocess: bool) -> Result<Vec<Polyline>, String>;

See examples/basic.rs 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

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.

svg2polylines's People

Contributors

dbrgn avatar enjmiah avatar naufraghi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

svg2polylines's Issues

Move after close

If a Z command is followed by more relative move / draw commands, the state is lost.

Wrong handling of relative movements in paths

This path:

M 10.505049,99.99963 40.505,70 h 10 m -20.000016,39.99963 9.999967,-20

...results in this image:

img

The relative movement is not handled correctly, the coordinates (-20,39) are treated as absolute.

Handle smooth curves (s/S)

For example this one:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg>
  <path d="M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80" stroke="black" fill="transparent" style="stroke:#000000;stroke-opacity:1;fill:none" />
</svg>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.