Skip to content

Draw an overline as thick as the font's underline (#741) - #756

Open
gravitypdf-bot wants to merge 2 commits into
gravitypdffrom
fix/741-overline-thickness
Open

gravitypdf-bot wants to merge 2 commits into
gravitypdffrom
fix/741-overline-thickness

Conversation

@gravitypdf-bot

Copy link
Copy Markdown

Fixes #741

Found while working on #552

Problem

text-decoration: overline is drawn at a fixed 0.06 em, whatever the font, so it comes out heavier than the underline on the same text.

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<p style="font-size: 40pt; text-decoration: underline overline">Decorated</p>');
Browser Before After
Underline, 40pt DejaVu Serif Condensed font's underlineThickness (44/1000) 1.76 pt 1.76 pt
Overline, same text font's underlineThickness 2.40 pt 1.76 pt
Overline in a table shrunk to fit (autosize) thinned with the text 2.40 pt, unshrunk same as the underline beside it

Cause

The // OVERLINE block in Cell() read:

$decorationfontkey = (int) (((float) $this->textparam['o-decoration']['fontkey']) / $shrin_k);
$decorationfontsize = $this->textparam['o-decoration']['fontsize'];

The font key is a string such as dejavuserifcondensed; casting it to a number gives 0, so $this->fonts[0] was looked up, the font's ut and CapHeight were never found, and the 60/1000 and 700/1000 fallbacks were always used. The / $shrin_k that belongs on the size was on the key, so in a shrunk table the overline was measured at the unshrunk size.

Fix

Read the key and size as the underline and line-through blocks do: the key as is, the size divided by $shrin_k. The overline now takes the font's underline thickness, sits at the font's cap height (729/1000 for DejaVu Serif Condensed, rather than the 700 fallback, so it moves up slightly), and shrinks with its table.

Based on gravitypdf: #722 edits the same overline block, but only the lines after these two, so the two apply independently.

Legacy mode

This is a plain bug fix, so it applies in both cssModes.

Tests

  • tests/Mpdf/OverlineThicknessTest.php: in both modes, an overline at 40pt is drawn at the font's underline thickness, the same width as the underline, for a TrueType font (DejaVu Serif Condensed, 1.76 pt) and a core font (Times, 2.0 pt); and in a table shrunk to fit, the overline is thinned to the same width as the underline. All fail before the fix.
  • Snapshot overline-thickness: DejaVu Serif Condensed and DejaVu Sans Condensed text at 40pt with underline, overline and both, and a table shrunk to fit with both lines; each caption says the lines match. Fails before the fix (page RMSE 0.0587).
  • Refreshed fixtures decorations-amendment-legacy, decorations-amendment-standard and decorations-propagate: each draws overlined text, and the only change in their objects is the overline's width (0.720 → 0.528, 0.600 → 0.440) and its height on the page. Checked page by page.

Checks

🤖 Generated with Claude Code

gravitypdf-bot and others added 2 commits October 13, 2026 10:40
The overline block in Cell() divided the font key by the table's shrink
factor and cast it to an integer, so it looked up font 0, never found
the font's underline thickness or cap height, and fell back to 0.06 em
and 700/1000 em. The size it measured those against was also left
unshrunk. Read the key and size as the underline and line-through
blocks do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Draw the overline and the underline in one document, and take the CSS
modes from DrawnStyles rather than a copy of its provider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

text-decoration: overline ignores the font's underline thickness, so it is drawn heavier than underline

1 participant