Skip to content

Insert glyphs at the end of the text in morx insertion subtables - #436

Open
iliev-blnk wants to merge 3 commits into
foliojs:masterfrom
iliev-blnk:morx-eot-insertion
Open

iliev-blnk wants to merge 3 commits into
foliojs:masterfrom
iliev-blnk:morx-eot-insertion

Conversation

@iliev-blnk

Copy link
Copy Markdown
Contributor

Follow-up to #434. Its end-of-text transition still skipped glyph insertion subtables, while HarfBuzz inserts glyphs there.

Cause

processGlyphInsertion returns early when there is no current glyph, so a font's insertions in its end-of-text transitions are dropped. And the state machine ignored the index a processor returns at the end of the text, so once glyphs were inserted there, it would go on to the second inserted glyph instead of stopping or, with DontAdvance, processing the first one.

None of the text-rendering-tests fonts insert glyphs at the end of the text, so I built a test font from MORX-32 with fontTools. Only its end-of-text transitions insert glyphs:

  • after A: current insertion of I N S, which goes at the end of the text
  • after B (with SetMark): marked insertion of I N S after the B
  • after C: current insertion of B with DontAdvance, so the inserted B is processed too and gets its own I N S

Fix

  • Glyph insertion now takes the end-of-text transition in subtables processed in forward order. A current insertion there goes at the end of the glyphs, and a marked insertion goes at the mark as usual.
  • At the end of the text, the state machine now takes the index the processor returns, like it does for other glyphs. It stops if that index is still at or past the end. Otherwise (DontAdvance after an insertion) it goes on to the inserted glyphs, like HarfBuzz. Other subtables return no index there, so for them nothing changes.
#434 this PR HarfBuzz 15.0.0
A A A I N S A I N S
AYY A Y Y A Y Y I N S A Y Y I N S
BYY B Y Y B I N S Y Y B I N S Y Y
C C C B I N S C B I N S
AC A C A C B I N S A C B I N S
AX, BX (no insertion) unchanged unchanged unchanged

Across all 174 MORT/MORX cases of text-rendering-tests, nothing changes (165 passing on top of #434).

Not covered: subtables processed in reverse order still skip insertion at the end of the text. Their insertion already differs from HarfBuzz in the middle of the text (HarfBuzz inserts the glyphs on the other side and in reverse order), so I'd rather fix both together in a separate change.

This builds on #434, which builds on #433. Only the last commit is new here.

Tests

  • test/shaping.js: seven inputs for the new font. The five that insert glyphs fail without the fix, and C and AC also fail with only the insertion change, without the state machine one.
  • test/data/fonttest/TestMORXEndOfTextInsertion.ttf is MORX-32 from text-rendering-tests with its insertion subtable rebuilt, so it is under the Apache License 2.0 in test/data/fonttest/LICENSE.txt.
  • npm test: 750 passing. npm run format:check passes.

…#142, foliojs#143)

Skip a rearrangement verb when nothing has been marked yet or when the
marked range is shorter than the glyphs the verb moves, like CoreText and
HarfBuzz. Clamp the end of the range at the end of the text.
Like HarfBuzz, insertion subtables processed in forward order now take
the end-of-text transition: a current insertion goes at the end of the
glyphs and a marked insertion at the mark. The state machine takes the
index the processor returns there, and stops unless it points at
inserted glyphs the machine doesn't skip.
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.

1 participant