Skip to content

fix: resolve core-14 font aliases to their standard metrics#294

Open
pablopupo wants to merge 1 commit into
docling-project:mainfrom
pablopupo:fix/180-standard-font-widths
Open

fix: resolve core-14 font aliases to their standard metrics#294
pablopupo wants to merge 1 commit into
docling-project:mainfrom
pablopupo:fix/180-standard-font-widths

Conversation

@pablopupo

Copy link
Copy Markdown

Standard Type1 fonts can be referenced by a common family alias like Arial or Times New Roman and legally ship without a /Widths table. docling-parse only found the bundled metrics when a canonical PostScript name (Helvetica, Times-Roman and so on) was a substring of the font name, so those aliases matched nothing and every glyph fell back to a flat 500 units/em. At 10pt that advances each character 5.00pt instead of its real width, which leaves word bounding boxes off and drifting further along the line the longer the string. On a 92 character Arial line the last glyph lands about 71pt away from where it should.

This is the remaining piece of #180. The canonical base-14 names from that report already resolve on current main (Courier gives the correct 6.00pt, Helvetica and Times-Roman give their real varying widths), so the change binds the Arial, Times New Roman and Courier New aliases to the Core-14 metrics that PDF viewers substitute. Arial now matches Helvetica glyph for glyph (A 6.67, W 9.44, i 2.22, m 8.33 at 10pt) instead of a flat 5.00. Fonts with an explicit /Widths table and names that already contain a canonical family keep their existing behavior, and a bundled real metric like ArialMT still wins over the alias. No new font data is added, the aliases reuse the Core-14 AFM files already shipped in pdf_resources.

Added tests/test_standard_font_widths.py, which builds its minimal PDFs in memory so it needs no external data. It covers Courier at 6.00pt, a proportional font with varying non-500 widths, the alias resolution for Arial and Times, and an explicit /Widths table taking precedence. The full test suite passes locally (81 passed).

A PDF may reference a standard Type1 font by a common family alias such as
Arial or Times New Roman and legally omit the /Widths table. The width
resolver only matched when a canonical PostScript name (Helvetica,
Times-Roman, ...) was a substring of the font name, so these aliases missed
every bundled AFM and fell back to a flat 500 units/em. At 10pt that
advances every glyph 5.00pt instead of the real width, leaving word bounding
boxes about 20 percent too narrow and drifting progressively left in long
strings.

Bind the common Arial, Times New Roman and Courier New aliases to the
core-14 metrics that PDF viewers substitute, so their advances come from the
real Helvetica, Times and Courier AFM data. Fonts with an explicit /Widths
table, and names that already contain a canonical family, keep their
existing behavior.

Signed-off-by: pablopupo <145598901+pablopupo@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @pablopupo, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@PeterStaar-IBM

Copy link
Copy Markdown
Member

@pablopupo I have resolved already quite a few issues regarding this with the latest renderer. Can you attach here a PDF that does not work on main but that this PR solves?

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