foliojs / fontkit

An advanced font engine for Node and the browser
1.45k stars 213 forks source link

Ligatures in AAT #259

Open mikeday opened 2 years ago

mikeday commented 2 years ago

Hi, we're looking into ligatures in AAT and noticed there is some code in fontkit that doesn't seem to be described in the spec for the morx table, such as replacing deleted glyphs in the input buffer as they are popped off the stack:

https://github.com/foliojs/fontkit/blob/master/src/aat/AATMorxProcessor.js#L204

and pushing substituted ligature glyphs back onto the stack for possible inclusion into future ligatures:

https://github.com/foliojs/fontkit/blob/master/src/aat/AATMorxProcessor.js#L209

Is there a spec for this behaviour or was it derived by reverse engineering CoreText or taken from HarfBuzz? And are there any test suites for AAT that you might know of?

Also I'm curious about pushing ligatures back onto the ligature stack, we've found it's necessary for the "ffi" ligature in Zapfino for example, which first substitutes "ff" as a ligature and then "ff"+"i" as a second ligature, but what if the input buffer simply contained "fffffff..." would it keep pushing the generated "ff" ligatures onto the stack and never pop them off? That seems like it could be a problem for implementations that limit stack size!

Any insight you have on these issues would be much appreciated.