Graphite icon indicating copy to clipboard operation
Graphite copied to clipboard

Exporting with auto bounds doesn't account for outer stroke

Open paul-fornage opened this issue 11 months ago • 4 comments

When exporting an SVG with transperancy, the bounding box doesn't seem to include the outer stroke weight. So if you export a square with a stroke width of 8 px, the exported image will have the outer stroke cut off.

This is also the case in the dev deployment.

The exported svg: (notice how the borders are visibly cut off) Spelling bee cell

The project file (renamed to have .txt so github lets me upload it): Spelling bee cell.graphite.txt

Changing the SVG viewbox, width, height, and remoxing the transformation to restore the boundaries to those present in the project (1000px^2 for me) fixed the issue completely.

paul-fornage avatar Dec 06 '24 05:12 paul-fornage

Duplicate of #2113.

0HyperCube avatar Dec 07 '24 21:12 0HyperCube

I'm actually going to make #2113 a duplicate of this, even though this is more recent, because it more clearly describes the problem.

Keavon avatar Dec 24 '24 00:12 Keavon

Apologies for the duplicate, I tried looking for SVG errors, not realizing the issue applied to other formats too (as described by #2113) It's really not that big of a deal for me, but I figured you could decide if it's worth fixing.

paul-fornage avatar Dec 24 '24 03:12 paul-fornage

In renderer.rs, we have

fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]>;

The include_stroke option can potentially let us acquire the bounding box with the stroke factored into the calculation. But I'm suspicious that our current usages of that are somewhat flawed and potentially buggy. There might also be another way to measure bounding boxes in use at the moment in other places. So this might not be trivial to implement, but in the best case, it could just be a matter of using true instead of false in the correct location. But other fixes are probably necessary, and certainly thorough testing (including cases where strokes are pre- and post-transformed).

Keavon avatar May 09 '25 00:05 Keavon