Skip to content

Initialise the OTL Plus tag before font-variant-position appends to it (mirrors mpdf/mpdf#2136) - #16

Merged
jakejackson1 merged 1 commit into
gravitypdffrom
mirror/2136-font-variant-position
Sep 7, 2026
Merged

Initialise the OTL Plus tag before font-variant-position appends to it (mirrors mpdf/mpdf#2136)#16
jakejackson1 merged 1 commit into
gravitypdffrom
mirror/2136-font-variant-position

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Summary

This mirrors mpdf#2136, so the fork carries the fix while the upstream PR sits open.

setCSS() clears $this->OTLtags to [] between elements. The FONT-VARIANT-POSITION case then does $this->OTLtags['Plus'] .= ' sups' — appending to a key that is not there. It guards the str_replace() above it with isset() but leaves the append unguarded, so the first font-variant-position: super or sub in a document raises Undefined array key "Plus" on PHP 8, Undefined index: Plus before that.

Its four siblings — FONT-VARIANT-CAPS, -LIGATURES, -NUMERIC and -ALTERNATES — all open by defaulting Plus to an empty string. This case now does the same, so the str_replace() no longer needs a guard of its own.

Try it

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<p style="font-variant-position: super">x</p>');
$mpdf->Output();

On gravitypdf, with display_errors on:

Warning: Undefined array key "Plus" in src/Mpdf.php on line 18838

On this branch, nothing.

Test plan

  • composer test1049 tests, 2535 assertions, green (gravitypdf is at 1048).
  • composer cs — clean.
  • PHPStan — same 33 findings as gravitypdf, none new.
  • tests/Mpdf/FontVariantPositionTest.php fails on gravitypdf and passes here.
More info

Where it differs from upstream

Upstream Here
Adds a second if after the existing isset() block, indented with spaces in a tab-indented file (composer cs rejects it) Turns the existing isset() into the !isset() default its siblings use, so there is one guard rather than two
No test Adds one

The test

Asserting "no warning" alone would pass against a fix that broke the feature, so the test checks that the keywords still reach the OTL layer. FreeSerif carries both the sups and subs GSUB features, and rendering all three keywords in one document makes the subset glyph ids comparable:

'<span style="font-variant-position: super">1</span>'
. '<span style="font-variant-position: sub">1</span>'
. '<span style="font-variant-position: normal">1</span>'

comes out as three different glyphs, with the last one the plain digit. That covers the whole case in one pass: the append for super, the str_replace() for sub clearing the previous sups, and normal clearing both.

mpdf/font-bundle-all is a dev dependency, so FreeSerif is present in CI.

setCSS() clears OTLtags to [] between elements, so the first
font-variant-position: super or sub in a document appends to an unset
key: "Undefined array key" on PHP 8, "Undefined index" before that.

Every sibling case — FONT-VARIANT-CAPS, -LIGATURES, -NUMERIC and
-ALTERNATES — already opens by defaulting Plus to an empty string;
FONT-VARIANT-POSITION guarded the str_replace() instead, which leaves
the append below it unprotected. Use the same shape as its siblings.

Mirrors mpdf#2136.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jakejackson1 jakejackson1 added bug Something isn't working fork-only labels Sep 7, 2026
@jakejackson1
jakejackson1 merged commit f8ec556 into gravitypdf Sep 7, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fork-only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant