https://github.com/marklagodych/svg_path_simplifier
Converts any SVG to move,line,cubic_bezier commands for robotic plotters
https://github.com/marklagodych/svg_path_simplifier
plotter rust-lang svg vector-graphics
Last synced: 11 months ago
JSON representation
Converts any SVG to move,line,cubic_bezier commands for robotic plotters
- Host: GitHub
- URL: https://github.com/marklagodych/svg_path_simplifier
- Owner: MarkLagodych
- License: mit
- Created: 2023-01-11T20:59:19.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-18T18:37:08.000Z (about 3 years ago)
- Last Synced: 2025-03-23T23:16:10.739Z (11 months ago)
- Topics: plotter, rust-lang, svg, vector-graphics
- Language: Rust
- Homepage:
- Size: 264 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SVG Path Simplifier
The `svgps` program converts `.svg` images into MoveTo/LineTo/CubicBezierTo commands
contained in a [`.svgcom`](#svgcom-format) file.
The initial goal was to prettify and simplify SVG for plotters.
It utilizes [usvg](https://github.com/RazrFalcon/resvg/tree/master/usvg) for SVG parsing and simplification
and [kurbo](https://github.com/linebender/kurbo) for geometric calculations.
## Demos
| `XXXXXXXXXXXXXXXXX` | `XXXXXXXXXXXXXXXXX` | `XXXXXXXXXXXXXXXXX` |
| --- | --- | --- |
| Original SVG | Converted | Converted+autocut |
|  |  |  |
|  |  |  |
See [demo/gen.sh](./demo/gen.sh).
## Features
* Generating `.svgcom` from `.svg`
* Rendering `.svgcom` to `.svg` for previewing
* Selecting only stroked paths for the conversion
* Autocutting path segments that are not visible because of being covered by other figures
(think of this as of a depth test)
## Installation
This requires [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html), the Rust package manager.
```sh
cargo install svg_path_simplifier
```
## Usage
```sh
svgps help generate # Try this first to see all the options
svgps generate INPUT.svg OUTPUT.svgcom [OPTIONS...]
svgps render INPUT.svgcom OUTPUT.svg [OPTIONS...]
```
## Autocutting behavior
The `-a` (`--autocut`) flag makes the program cut the covered segments of the paths contained in the input SVG image.
Only closed filled paths can cover other paths.
## SvgCom format
SvgCom is a text format for vector graphics outline representation that borrows a lot from the
[``](https://www.w3.org/TR/SVG/paths.html#TheDProperty) format of SVG.
The file extension is `.svgcom`.
The file content is of the form:
```
... (not delimited)
... (delimited by )
[ ]
```
where `` is ``, not ``, and `` is a *single* ASCII space.
Additional ("garbage") lines in the end of the file are optional and are never read by the converter.
The coordinate list specifies 2D point coordinates, thus the number of coordinates must be even.
### Example 0
`example.svgcom`
```
720 480 2 4
ML
0 0 100 100
```
This file defines an image of size `720`x`480`
with `2` commands (`M`ove and `L`ine)
and `4` coordinates (`0.0`, `0.0`, `100.0`, `100.0`), which form two points.
### Example 1
`input.svg`
```xml
```
`output.svgcom`
```
250 200 5 10
MLLLL
0 0 100 0 100 70 0 70 0 0
```
### Example 2
`input.svg`
```xml
```
`output.svgcom`
```
800 600 5 26
MCCCC
150 100 150 133.1370849898476 127.61423749153967 160 100 160 72.38576250846033 160 50.00000000000001 133.1370849898476 50 100.00000000000001 49.99999999999999 66.86291501015242 72.38576250846032 39.99999999999999 99.99999999999999 39.999999999999986 127.61423749153965 39.99999999999997 150 66.86291501015239 150 100
```