You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The PdfPrinterGraphics2D class inherits the create method from PdfGraphics2D, which in turn overrides. The method is declared as abstract in Graphics and is convenient to create equivalent copies that can be modified without modifying the original object, just like the classic clone method.
Because PdfPrinterGraphics2D does not override create, it returns a PdfGraphics2D instead of a PdfPrinterGraphics2D, which is unexpected.
class com.lowagie.text.pdf.PdfPrinterGraphics2D
class com.lowagie.text.pdf.PdfPrinterGraphics2D
But it prints:
class com.lowagie.text.pdf.PdfPrinterGraphics2D
class com.lowagie.text.pdf.PdfGraphics2D
It also throws an exception, but that is a problem with the example code and therefore expected and not the point of this issue.
System (please complete the following information):
OS: Windows 11
Used Font: not relevant
Additional context
You might want to consider to make it easier to override PdfGraphics2D.create. At the moment, it creates a new empty PdfGraphics2D and then copies all own fields to the copy. When overriding the method, you would need to create an empty PdfPrinterGraphics2D object instead. Then, you would still need to copy the fields of the base class to the new copy in addition to any field of the derived class, but you cannot use super.create() for that.
It would be much easier if create were implemented by two separate hooks (possibly protected): one for creating an empty copy, and another for copying all fields to a copy that is given as a parameter.
Alternatively, PdfGraphics2D could also implement the Cloneable interface, move the implementation of create() to clone() and implement create() on top of that.
The text was updated successfully, but these errors were encountered:
Describe the bug
The
PdfPrinterGraphics2D
class inherits thecreate
method fromPdfGraphics2D
, which in turn overrides. The method is declared as abstract inGraphics
and is convenient to create equivalent copies that can be modified without modifying the original object, just like the classicclone
method.Because PdfPrinterGraphics2D does not override create, it returns a PdfGraphics2D instead of a PdfPrinterGraphics2D, which is unexpected.
To Reproduce
Expected behavior
The above code should print:
But it prints:
It also throws an exception, but that is a problem with the example code and therefore expected and not the point of this issue.
System (please complete the following information):
Additional context
You might want to consider to make it easier to override
PdfGraphics2D.create
. At the moment, it creates a new emptyPdfGraphics2D
and then copies all own fields to the copy. When overriding the method, you would need to create an empty PdfPrinterGraphics2D object instead. Then, you would still need to copy the fields of the base class to the new copy in addition to any field of the derived class, but you cannot usesuper.create()
for that.It would be much easier if create were implemented by two separate hooks (possibly protected): one for creating an empty copy, and another for copying all fields to a copy that is given as a parameter.
Alternatively, PdfGraphics2D could also implement the
Cloneable
interface, move the implementation ofcreate()
toclone()
and implementcreate()
on top of that.The text was updated successfully, but these errors were encountered: