Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Font in PdfGraphics2D not working / PdfGraphics2D manipulates set Font (not expected) #587

Closed
mppperez opened this issue Aug 12, 2021 · 1 comment · Fixed by #588
Closed
Labels

Comments

@mppperez
Copy link

mppperez commented Aug 12, 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 in PdfGraphics2D choose the font "Deja Vu Bold" instead of "Helvetica Bold". Note: since the DefaultFontMapper 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-L193

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
Screenshot_562

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?

@mppperez
Copy link
Author

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 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 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
@asturio asturio linked a pull request Aug 19, 2021 that will close this issue
@asturio asturio closed this as completed Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants