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
So this won't have direct affect in the test but if a custom mapper is used that is not restricting to only those 3 fonts you may encounter a problem. It is not expected that the PdfGraphics2D is changing the specified font on it's own although it was correctly used. It looks like a project specific issue was built into OpenPDF (see below).
To Reproduce
Execute above mentioned test on a machine without Helvetica installed.
Expected behavior
Use the provided font (backwards compatibility is missing) in OpenPDF.
Screenshots
System (please complete the following information):
OS: Ubuntu 20.04
Used Font: Helvetica
Update
Unfortunately I cannot reconstruct why this fix (see commit above) for Windows was built... or initially Windows and then changed to Mac (see commit history). It looks like a project specific issue that was implemented in OpenPDF rather than in the appropriate project. At least making the FontDrawer a configurable property seems to be the more proper solution or just using the library with correct fonts instead of logical ones that may not be found.
Furthermore PdfGraphics2D.CompositeFontDrawer#splitStringIntoDisplayableParts will even use different fonts just because they are in the same family as the specified one. If the user of the library wants to write text to a pdf and specifies a font that is not containing (some) characters specified in the text then this should be handled on the users side (may throw an exception? logging and skip? ...) but not in OpenPDF itself?
The text was updated successfully, but these errors were encountered:
update: I've edited the initial post and added the most recent comment so that it is more clear.
the created PR contains a workaround for now until there is some more feedback from community / developers.
mppperez
changed the title
If font not installed but embedded it still won't be used if composite
Set Font in Graphics2D not working
Aug 17, 2021
mppperez
changed the title
Set Font in Graphics2D not working
Set Font in PdfGraphics2D not working / PdfGraphics2D manipulates set Font (not expected)
Aug 17, 2021
Describe the bug
We didn't update for a while but the changes from 2019 (commit 15e89ca) break all generated PDFs (wrong font used).
This can be reproduced with an existing test :
com.lowagie.text.pdf.fonts.FontTest#testBoldSimulationAndStrokeWidth
.Executing the test on my machine (Ubuntu, Java 11) let the
compositeFontDrawer
inPdfGraphics2D
choose the font "Deja Vu Bold" instead of "Helvetica Bold". Note: since theDefaultFontMapper
from OpenPDF is used it will always fallback to Helvetica anyways (logicalName
is Deja Vu...): https://github.com/mppperez/OpenPDF/blob/f773081d4f169c6d84579a855ebbed1e93cfd8e9/openpdf/src/main/java/com/lowagie/text/pdf/DefaultFontMapper.java#L123-L193So this won't have direct affect in the test but if a custom mapper is used that is not restricting to only those 3 fonts you may encounter a problem. It is not expected that the PdfGraphics2D is changing the specified font on it's own although it was correctly used. It looks like a project specific issue was built into OpenPDF (see below).
To Reproduce
Execute above mentioned test on a machine without Helvetica installed.
Expected behavior
Use the provided font (backwards compatibility is missing) in OpenPDF.
Screenshots
System (please complete the following information):
Update
Unfortunately I cannot reconstruct why this fix (see commit above) for Windows was built... or initially Windows and then changed to Mac (see commit history). It looks like a project specific issue that was implemented in OpenPDF rather than in the appropriate project. At least making the FontDrawer a configurable property seems to be the more proper solution or just using the library with correct fonts instead of logical ones that may not be found.
Furthermore
PdfGraphics2D.CompositeFontDrawer#splitStringIntoDisplayableParts
will even use different fonts just because they are in the same family as the specified one. If the user of the library wants to write text to a pdf and specifies a font that is not containing (some) characters specified in the text then this should be handled on the users side (may throw an exception? logging and skip? ...) but not in OpenPDF itself?The text was updated successfully, but these errors were encountered: