Skip to content

Support fonts that use MarkGlyphSets - #1

Merged
jakejackson1 merged 1 commit into
gravitypdffrom
fix/mark-glyph-sets
Sep 7, 2026
Merged

Support fonts that use MarkGlyphSets#1
jakejackson1 merged 1 commit into
gravitypdffrom
fix/mark-glyph-sets

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Summary

mPDF rejects any font whose GSUB lookups use a mark filtering set. That takes out every current release of Noto Sans Sinhala, among others, at any non-zero useOTL — the exception is Font "..." contains MarkGlyphSets which is not supported.

The support is already written. A GSUB lookup can set the UseMarkFilteringSet flag (0x0010) to ignore every mark except those in a GDEF mark glyph set; mPDF parses those sets when it reads GDEF, and both TTFontFile::_checkGSUBignore() and Otl::_checkGCOMignore() consult them. Only the two functions that build the ignore pattern refuse — and in both, the throw sits directly above a working implementation the author left unreachable, commented "Not tested yet" and "Change also in ttfontsuni.php".

This drops those two throws so the existing code runs, keeping a guard for the one case that is genuinely broken: a filtering set GDEF does not define. Four lines of src/.

This was originally committed to the Font Packages PR, where it does not belong — it is independent of font packages. It is split out here.

Try it

$mpdf = new \Mpdf\Mpdf([
    'fontDir'  => [__DIR__ . '/tests/data/ttf'],
    'fontdata' => ['sinhalasubset' => ['R' => 'NotoSansSinhala-Subset.ttf', 'useOTL' => 0xFF]],
    'default_font' => 'sinhalasubset',
]);

$mpdf->WriteHTML('<p>සිංහල අකුරු ශ්‍රී ලංකා</p>');
$mpdf->Output('sinhala.pdf', \Mpdf\Output\Destination::FILE);

On gravitypdf-7.0 that throws. On this branch it renders, and the ශ්‍රී conjunct matches what HarfBuzz produces for the same font and string.

Test plan

  • composer test — 1000 tests, 2291 assertions, green.
  • composer cs — clean.
  • Both new tests fail without the src/ change, and they fail on different throws: reverting only Otl.php leaves TTFontFileTest::testGetMetricsWithMarkGlyphSets passing and MarkGlyphSetsTest failing. Neither change is redundant.
More info

The two call sites

Function Was Now
TTFontFile::_getGSUBignoreString() (src/TTFontFile.php) throw new FontException('... contains MarkGlyphSets which is not supported'), with $str = $this->MarkGlyphSets[$MarkFilteringSet]; unreachable beneath it assigns $str, throwing only if GDEF defines no such set
Otl::_getGCOMignoreString() (src/Otl.php) throw new MpdfException('... contains MarkGlyphSets - Not tested yet'), with a $MarkFilteringSet == '' guard and the assignment unreachable beneath it keeps the existing guard, widened to cover an undefined set, then assigns $str

$ignoreflag is dead in both functions — it survives only in the commented-out [IGNORE$ignoreflag] scheme the author never finished — so the assignment to $str is the whole behaviour.

Why this shows up now

fontmake sets the flag routinely, so it is not a corner case: it is most current Google/Noto releases with mark positioning. The existing tests/data/ttf/NotoSans-Regular.ttf fixture does define four mark glyph sets, but only its GPOS lookups reference them, and neither throw is on a GPOS path — which is why the suite has been green while the bug was live.

The fixture

tests/data/ttf/NotoSansSinhala-Subset.ttf is Noto Sans Sinhala (OFL 1.1, no reserved font name) subsetted with fontTools to the sample text with --layout-features='*'. 7,656 bytes, 32 glyphs, retaining 2 mark glyph sets and 7 GSUB lookups that carry the flag — an order of magnitude smaller than the other fixtures in that directory.

A GSUB lookup can set the UseMarkFilteringSet flag (0x0010) to ignore every
mark except those in a GDEF mark glyph set. mPDF parses those sets already, and
_checkGSUBignore()/_checkGCOMignore() consult them, but the two functions that
build the ignore pattern threw instead — in both cases directly above a working
implementation left unreachable and commented "Not tested yet".

Drop the two throws so the existing code runs, keeping a guard for a filtering
set GDEF does not define. Fonts built by fontmake use the flag routinely: every
current Noto Sans Sinhala release is rejected today.

tests/data/ttf/NotoSansSinhala-Subset.ttf is Noto Sans Sinhala (OFL 1.1, no
reserved font name) subsetted to the sample text, 7.5 KB, keeping 7 GSUB
lookups that carry the flag. Both new tests fail without the change, and each
covers one of the two throws.
@jakejackson1
jakejackson1 merged commit 08af490 into gravitypdf Sep 7, 2026
23 of 27 checks passed
@jakejackson1 jakejackson1 added the bug Something isn't working label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working create-upstream-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant