AuburnSounds / printed

Generate PDF/SVG/HTML with D, with a Canvas-style API. Now with a flow document emitter.
36 stars 7 forks source link

save/restore is broken in SVG #28

Closed a-ludi closed 3 years ago

a-ludi commented 3 years ago

The current implementation of SVGDocument.restore() pops the entire stack but all other operations on the stack just push a single element/group onto it.

I am irritated by this behavior and would expect that it pops all elements until the level that save() was called is reached. Is the current behavior intended? I am no PDF expert but to me it looks like the PDFDocument has a different implementation that acts more like my expectation.

Here is an example of what I would like to do: Draw several objects into a "content area" of the page which is the page minus some padding on all sides. I would try to do it like this:

enum paddingTop = 42f;
enum paddingLeft = 42f;

renderer.translate(paddingLeft, paddingTop);
renderer.save();

// plot object1
// plot object2
// ...

renderer.restore();

But if I use the save/restore pattern inside one of the objects, the rest will not be transformed by the initial translate.

p0nce commented 3 years ago

For SVG this does look buggy. save() should push in a real stack the current number of opened <g> (they are opened by scale/translate/rotate mostly) and eventually needed state, and restore should only close with N x </g> up to that last, saved point in a stack.

p0nce commented 3 years ago

Fixed in v1.0.3

p0nce commented 3 years ago

Thanks for reporting !

a-ludi commented 3 years ago

Great, thanks!