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.5k stars 581 forks source link

[Build] `testFontStyleOfStyledFont` causes builds to fail with default Maven configuration on OSX 13.0 and higher #1158

Open kurt-r2c opened 4 months ago

kurt-r2c commented 4 months ago

Describe the bug

On OS X Ventura (13.0) or later, the Courier font is missing its OS/2 table, probably due to licensing decisions made by Apple.

This causes the testFontStyleOfStyledFont test to fail: https://github.com/LibrePDF/OpenPDF/blob/0a92bcc7ea9a41f919e093f774a3104865d92a42/openpdf/src/test/java/com/lowagie/text/pdf/fonts/FontTest.java#L81-L92

To Reproduce

Run mvn clean install on OSX 13.0 or newer. The build will fail due to an exception com.lowagie.text.DocumentException: Table 'OS/2' does not exist in /System/Library/Fonts/Courier.ttc in testFontStyleOfStyledFont.

Setting maven.test.failure.ignore to true allows you to build the project but, for obvious reasons, this is a bad workaround for anything other than trivial changes.

Expected behavior

It would be nice if this test failed gracefully if the font is not present or readable on the system.

System

(please complete the following information)

Your real name

Kurt Boberg

asturio commented 4 months ago

Which version of maven are you using:

mvn -version
kurt-r2c commented 3 months ago

@asturio 3.9.6

asturio commented 3 months ago

I'd like to find a font provided by all OS. Are there any other Mac-Users who can confirm, that this test also fails on their computer? Which font could be used instead. Alternatively, the test could be disabled on MacOS.

asturio commented 3 months ago

Just checked, that courier is also bundled with OpenPDF. So even a more strange behavior here.

asturio commented 3 months ago

The call of FontFactory.registerDirectories(); was made only in one of the tests. It could be, that the order of the tests are different in MacOS, and this call is necessary for all.

I just commited a little change. @kurt-r2c, can you please try, if the test passes now?

bwolff commented 3 weeks ago

I'm also a Mac-user and can confirm that the aforementioned test still fails consistently on MacOs 14.6.1.

The test contains the beforeAll() with FontFactory.registerDirectories(); call, so this doesn't seem to fix this issue. It indeed seems that the Courier font of the os is not compatible with the tests or the styles expectations.

Building it on Mac requires skipping this test. Unfortunately I'm not sure of any font to be consistently used on all os. Such a dependency on the local os setup will probably always cause flakey tests, since they may break after any update or change of the os.