-
Notifications
You must be signed in to change notification settings - Fork 28
Managing GraphicsState with a Stack is unsafe #68
Description
Both SVGDocument and PDFDocument use a Stack to manage the current GraphicState instance while processing starting at a CreateCommand through the DisposeCommand. This is unsafe, though, because there's no guarantee the corresponding Graphics.create and Graphics.dispose calls will be made in nested pairs, or even that dispose will be called at all. Since this is a garbage-collected environment, this may happen behind the scenes through the finalize() method long after the SVG export.
This can lead to the wrong GraphicsState to be active during rendering. In our project, this is sometimes causing an issue with scrambled layouts: all the panels seem to be rendered properly but their layout in the document is incorrect.
The two SVG images in snapshots.zip show the issue. The 'orig' snapshot shows the scrambling, while 'fix' is a manual edit with the correct clip-path translations copied from a similar unscrambled snapshot.
I propose to attach the current GraphicsState to the StateCommand as an instance field instead, which can just be queried as needed during processing by SVGDoc and PDFDoc. I think this makes processing of CreateCommand and DisposeCommand into a no-op but haven't totally worked that out yet. It's possible there needs to be some transition-switch there.
I also haven't looked at the effect on EPS yet.
It could be kind of a big PR in terms of touching a large number of classes. The changes themselves ought to be pretty small, I think. I'm still working on it.
Hope this makes sense...
- David