Skip to content

Swap a Sinhala al-lakuna against a Consonant + Halant post-base Lookup as the other viramas are (#435) - #501

Merged
jakejackson1 merged 1 commit into
gravitypdffrom
fix/435-sinhala-virama-swap
Sep 26, 2026
Merged

jakejackson1 merged 1 commit into
gravitypdffrom
fix/435-sinhala-virama-swap

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

The old-spec compatibility swap (_OTL_OLD_SPEC_COMPAT_1) in Otl::applyGSUBlookupOverRun() identified a virama by searching a hard-coded string that covered Devanagari to Malayalam only. The parser already reads the Sinhala al-lakuna, U+0DCA, from TTFontFile::$viramas. As a result, a Sinhala font whose pref, blwf or pstf ligature is written Consonant + Halant had the consonant's class read by the parser, but the shaper never formed the ligature.

Fix

The list moves to Mpdf\Shaper\Indic::$viramas, and the parser (TTFontFile::indicConsonant()) and the swap in Otl now both read it. The hard-coded string is gone. A test checks that the list matches the virama column of Indic::$indic_configs from Devanagari to Sinhala. Khmer's coeng and Javanese's pangkon are left out deliberately, because neither script's classes are read this way.

Test and fixture

tests/data/ttf/NotoSansSinhala-OldOrderBlwf-Synthetic.ttf (6,416 bytes) was built with fontTools 4.59.2 in the same way as the #331 and #385 fixtures. It keeps the glyphs, cmap and GDEF of NotoSansSinhala-Subset.ttf, drops GPOS, and has a GSUB written by hand. That GSUB has one feature, blwf under sinh, with one ligature in the old order: uni0DBB uni0DCA -> glyph00022. A sibling font with the same ligature in the new order (uni0DCA uni0DBB) was built for comparison and is not committed.

tests/Mpdf/SinhalaOldOrderPostBaseFormTest.php:

Run gravitypdf This PR hb-shape 14.3.1, new-order font
KA ZWJ AL-LAKUNA RA KA, AL-LAKUNA, RA KA, glyph00022 KA, (ZWJ), glyph00022
LA ZWJ AL-LAKUNA RA LA, AL-LAKUNA, RA LA, glyph00022 LA, (ZWJ), glyph00022
KA ZWJ AL-LAKUNA RA AA KA, AL-LAKUNA, RA, AA KA, glyph00022, AA KA, (ZWJ), glyph00022, AA
KA AL-LAKUNA ZWJ RA KA, AL-LAKUNA, RA unchanged KA, AL-LAKUNA, (ZWJ), RA

The first three fail on gravitypdf. HarfBuzz does not swap, so on the old-order font it draws all four runs unchanged.

The swap only reaches Sinhala when AL-LAKUNA comes directly before the consonant. mPDF's Sinhala syllable grammar joins consonants only through AL-LAKUNA + ZWJ or ZWJ + AL-LAKUNA. So the ZWJ + AL-LAKUNA order is the one where the Halant is followed directly by a consonant after the base.

The font also joins the four golden-master corpora (fontcache, otldump, shaping, subset). No existing fixture or snapshot changed.

Font survey

Every font in packages/, tests/data/ttf, /System/Library/Fonts, /Library/Fonts and ~/Library/Fonts with a sinh GSUB script and a U+0DCA glyph (fontTools, counting two-glyph Type 4 ligatures with AL-LAKUNA under pref/blwf/pstf):

Font Post-base features AL-LAKUNA ligatures under pref/blwf/pstf
FreeSerif, FreeSerifBold (sinh) none 0
Kaputa Unicode pstf (Type 1 single substitutions on split vowel signs) 0
NotoSansSinhala-Subset none (rakaransaya and yansaya come from vatu) 0
Sinhala MN, regular and bold (macOS) none (vatu, psts) 0
Sinhala Sangam MN, regular and bold (macOS) none (vatu, psts) 0
NotoSansSinhala-OldOrderBlwf-Synthetic (new) blwf 1, Consonant + Halant

I shaped 7,954 generated runs through mPDF in each of these nine fonts before and after the change. The runs were C+H+C, C+H+ZWJ+C and C+ZWJ+H+C for every pair of consonants, repaya + ZWJ-joined conjuncts, and C+H(+ZWJ)+YA/RA with five vowel signs.

  • No real font changes. Every run in FreeSerif, FreeSerifBold, Kaputa, the Noto subset and the four Sinhala MN / Sangam MN faces is identical before and after.
  • Only the fixture changes, in 287 runs, all with ZWJ + AL-LAKUNA + RA. I compared the 180 runs whose characters the fixture covers with hb-shape on the new-order sibling. All 24 of those that change now match it, and none of them matched before. In total, 157 of the 180 match after the change, against 133 before.
  • The other 23 runs in the fixture that differ from HarfBuzz differ both before and after the change, for reasons outside this change:
    • C + AL-LAKUNA + RA with no joiner, optionally followed by a vowel sign (18 runs). HarfBuzz keeps these in one syllable and forms the below-base RA from the new-order font. mPDF's Sinhala syllable grammar ends the syllable at the AL-LAKUNA, so neither font order forms it.
    • A repaya followed by an RA conjunct (5 runs). HarfBuzz and mPDF read the base and the reph differently here.

So no bundled or system Sinhala font is affected. The change is still worth making because it keeps the parser and the shaper from reading different virama sets.

Gates

  • composer test: 4,078 tests, 5 skipped. The skips are outside this change.
  • composer cs: clean.
  • PHPStan: no errors.

Upstream

mpdf/mpdf development has the same hard-coded string in this branch, so this should be mirrored upstream. That PR will need a changelog entry.

Fixes #435

🤖 Generated with Claude Code

…p as the other viramas are

The old-spec compatibility swap in Otl recognised a virama from a hard-coded
string that stopped at Malayalam, while the parser read Sinhala's U+0DCA from
its own list. The list now lives on Shaper\Indic and both read it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1
jakejackson1 merged commit fd735e4 into gravitypdf Sep 26, 2026
30 checks passed
@jakejackson1
jakejackson1 deleted the fix/435-sinhala-virama-swap branch September 30, 2026 01:13
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.

The old-spec compatibility swap misses the Sinhala virama, U+0DCA

1 participant