Partial fix for issue #68: Managing GraphicsState with a Stack is unsafe #69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a partial fix. The idea here is similar to what was discussed in that Issue thread. We associate every Command with a "parent" CreateCommand linking to the VectorGraphics2D in which that command was emitted. Then, during rendering we can link to a clean GraphicsState to track the modifications made by those Commands only so rendering "within" each CreateCommand can happen independently.
Arguably it would be better for every Command to accept its parent via a constructor arg, but that would have made this PR big and unwieldy and harder to review. So this was kind of a way to introduce the concept in a more controlled way since it affects fewer call sites.
Also, this only fixes SVG and PDF but not EPS as that doesn't use the Stack concept directly. I'm not quite sure how to fix this for EPS, so hopefully someone else can pick it up from there.
Unfortunately, we're still seeing further bugs and their cause is not clear. Our project team has decided to stick with Batik after all since their latest release works with Java 9+ so I can't pursue this any more for now. It was really close but we just didn't have the resources to go further.
We may have to pick this up again for a different project, though, so I may be back with more fixes.
Thanks, hope this helps!