[jira] [Created] (BATIK-1290) AbstractGraphicsNode.paint() somethings does not dispose a Graphics2D child context
Emmeran Seehuber created BATIK-1290:
Summary: AbstractGraphicsNode.paint() somethings does not dispose a Graphics2D child context
URL: https://issues.apache.org/jira/browse/BATIK-1290 Project: Batik
Issue Type: Bug
Affects Versions: 1.12, 1.13
Reporter: Emmeran Seehuber
Attachments: batik_gvt_fix_danlging_gfx.patch, openhtml_536.svg
In some (rare?) cases, org.apache.batik.gvt.AbstractGraphicsNode::paint() calls g2d.create() twice, but only calls dispose() on one of the child Graphics2D.
Because a clip is set, in line 456 the first child Graphics2D is created. Later in line 503 useOffscreen is true. This causes in line 535 the baseG2d (which was stored to be later be dispose()ed) is overridden the the child created in line 456. Then in line 539 a new child Graphics2D is created. And only this second child is disposed in line 552, the first child is never disposed.
This is a problem if the used Graphics2D needs the dispose() calls to be "balanced" and correct. Which is the case when using it with my PdfBoxGraphics2D-Adapter ([https://github.com/rototor/pdfbox-graphics2d]). The child Graphics2D write a "q" (Save State) into the PDF stream and therefore need a matching "Q" (Restore State) - which is written when calling dispose(). Otherwise the PDF would be invalid.
The attached patch fixes this by only creating a child Graphics2D if not already one exists.
I also attached the SVG file that triggers the problem. It has transparency, so it is rendered to an offscreen image first but also has a clip set.