LibrePDF / OpenPDF

OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.
Other
3.53k stars 580 forks source link

Bold fonts not working #665

Open nikosdimitrakas opened 2 years ago

nikosdimitrakas commented 2 years ago

Up until version 1.3.17 bold fonts were working fine. From version 1.3.18 all the way to 1.3 26 they are not. Here is an example of two fonts that became identical in version 1.3.18: new Font(Font.HELVETICA, 16f, Font.BOLD) new Font(Font.HELVETICA, 16f) Just in case it matters, the fonts above were used in a chunk in a paragraph. No special characters and nothing special otherwise.

andreasrosdal commented 2 years ago

Thanks for reporting this issue. Do you think this PR is related to this bug? https://github.com/LibrePDF/OpenPDF/pull/374

nikosdimitrakas commented 2 years ago

Of all the things included in the release notes of 1.3.18, this is probably the one that relates to this.

arnthom commented 2 years ago

using new Font(baseFont, size, style, color) bold fonts do work in OPenPdf 1.3.26

nikosdimitrakas commented 2 years ago

After some more testing, I have identified that the problem with bold not working depends on whether or not the string in the chunk or paragraph contains a new line character \n. When there is a \n in the string, bold does not work. I hope this helps identify the issue in the code.

bgK commented 3 months ago

It seems like #374 introduced a code path where the font style is ignored: https://github.com/LibrePDF/OpenPDF/blob/b6f81c1d4c8d19010184788219e24a3c34565079/openpdf/src/main/java/com/lowagie/text/pdf/PdfChunk.java#L239

The code should probably select the appropriate LiberationSans font variant according to the style flags, or at least set the fake bold / italic attributes.

The behavior introduced in #374 is very questionable in that it changes the font based on the characters used in the text. This is bound to create visual inconsistencies in the generated output. Helvetica and Liberation Sans are not so similar: http://www.identifont.com/differences?first=Helvetica&second=Liberation+Sans&q=Go