Skip to content

Accept fonts without an OS/2 table in add_font() - #2191

Merged
andersonhc merged 4 commits into
py-pdf:masterfrom
RavSinghChandan:ttf-without-os2-table
Nov 14, 2026
Merged

andersonhc merged 4 commits into
py-pdf:masterfrom
RavSinghChandan:ttf-without-os2-table

Conversation

@RavSinghChandan

Copy link
Copy Markdown

add_font() fails on the Courier.ttc and LastResort.otf of macOS:

KeyError: 'OS/2'

The OS/2 table is required on Windows but optional in Apple fonts (TrueType Reference Manual), and these two fonts don't have one. TTFFont read four things from it: the cap height, which already falls back to hhea.ascent, the weight class, and the strikeout position and size.

Without an OS/2 table, the weight now comes from the bold bit of head.macStyle (700 or 400), the cap height falls back to hhea.ascent as before, and strikethrough uses the same position and size as the core fonts (250 and 50). Fonts with an OS/2 table are read as before.

test_add_font_without_os2_table removes the OS/2 table of DejaVuSans and DejaVuSans-Bold at run time, so no font file is added. It draws struck-out text and checks the strikeout metrics and the FORCE_BOLD flag; both cases fail on master. Changelog entry under 2.9.1 / Fixed.

@andersonhc
andersonhc merged commit 4fa738b into py-pdf:master Nov 14, 2026
35 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants