You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "valerybokov (via GitHub)" <gi...@apache.org> on 2026/04/16 20:31:04 UTC
[PR] reset graphics state in PDFPrintable.print method [pdfbox]
valerybokov opened a new pull request, #443:
URL: https://github.com/apache/pdfbox/pull/443
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "xzel23 (via GitHub)" <gi...@apache.org>.
xzel23 commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4408010117
@valerybokov I think you should really follow the graphics.create() suggestion. It's the established standard way to assert the value graphics is not changed and will perform better and IMHO it's also more readable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4384911747
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "valerybokov (via GitHub)" <gi...@apache.org>.
valerybokov commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4391611392
> 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.
1. If the graphics variable isn't a Graphics2D, a ClassCastException will occur.
2. There's an out-of-bounds error on line 223 (printerGraphics.getTransform).
3. The graphics parameter is null. Then there will be a null pointer exception.
For all these cases, the result is the same: the finality block will be triggered, and the printerGraphics and callerTransform variables will be null.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4267017356
You're focusing on the border painting, but the transform is also changed previously elsewhere.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4378695941
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?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "xzel23 (via GitHub)" <gi...@apache.org>.
xzel23 commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4394779791
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "asf-gitbox-commits (via GitHub)" <gi...@apache.org>.
asf-gitbox-commits closed pull request #443: reset graphics state in PDFPrintable.print method
URL: https://github.com/apache/pdfbox/pull/443
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4393842528
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4397185920
Yes, there is an SO answer about this
https://stackoverflow.com/questions/901046/
and ChatGPT agrees, and suggests this
```
Graphics2D g2 = (Graphics2D) graphics.create();
try {
// modify freely
} finally {
g2.dispose();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4408033581
I also support that. I didn't know it before, but I almost never do printing except here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org
Re: [PR] reset graphics state in PDFPrintable.print method [pdfbox]
Posted by "valerybokov (via GitHub)" <gi...@apache.org>.
valerybokov commented on PR #443:
URL: https://github.com/apache/pdfbox/pull/443#issuecomment-4382454769
> 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: 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org