hundredrabbits / Dotgrid

Minimalist Vector Tool
https://hundredrabbits.itch.io/dotgrid
Other
1.04k stars 75 forks source link

Minimal viewBox for SVG exports #69

Open fkettelhoit opened 4 years ago

fkettelhoit commented 4 years ago

When I export to svg, I usually want the file to have the same dimensions as the content, without any empty space around it. Right now this is only possible by manually editing the .svg output and adding a viewBox attribute, which requires calculating the minimal x and y values as well as the width and height of the content while taking into account the line thickness. The whole process can be quite time-consuming and error-prone for larger files.

The PR automatically calculates and saves the viewBox and tries to make sure that the resulting svg fits into these bounds. In the case of round or beveled line joins this is quite easy, but in the case of miter line joins (which could theoretically overshoot the angle point by quite a large amount in the case of sharp angles) an offset equivalent to the line thickness is used (which should give an acceptable result in most cases).

Ledmington commented 1 year ago

Any updates on this?