reset graphics state in PDFPrintable.print method#443
reset graphics state in PDFPrintable.print method#443valerybokov wants to merge 2 commits intoapache:trunkfrom
Conversation
|
You're focusing on the border painting, but the transform is also changed previously elsewhere. |
|
Why check both? I assume with "cast" you mean "printerGraphics = (Graphics2D) graphics". Shouldn't it be enough to check only "printerGraphics", and if not, why not? |
I hope I understood you correctly. Line 298 (new version): the graphics2D reference doesn't always refer to the same object as the printerGraphics reference. Therefore, we only dispose the object if a new graphics object has been created. |
|
I'm not asking about the dispose, I'm asking about the line "if (printerGraphics != null && callerTransform != null)". printerGraphics is no longer null as soon as the assignment on line 221 is successful. So why check whether callerTransform isn't null? It will always be non null if the casted assignment was successful. |
Let's say this is a standard check, but it's really unlikely. Here are three cases:
For all these cases, the result is the same: the finality block will be triggered, and the I can simplify the check if you want. |
|
Re (2) you're really going to extremes. If there is an OOM we're doomed anyway, it won't matter that we restore printerGraphics settings. Re (1) I've never heard of the cast to Graphics2D failing. A google search finds nothing, ChatGPT says it's historical. |
|
Isn't the standard in Swing to simply work on a temporary context obtained by calling context.create() if you don't want changes to transformation etc to persist? When done, simply forget about it. No need to try to reset the original context to its former state. Should also be more performant. |
|
Yes, there is an SO answer about this |
No description provided.