photopea / Typr.js

Typr.js - process fonts in Javascript
MIT License
914 stars 73 forks source link

Fix ligature sequences longer than 4 #30

Closed lojjic closed 5 years ago

lojjic commented 5 years ago

Typr.U._applySubs was applying a hard upper limit that ignored any ligature chains longer than 4. This breaks some fonts that use longer ligatures, such as the Material Icons font, causing some sequences to go unmatched or to incorrectly match a different sequence of shorter length.

A few examples of how this manifested in Material Icons:

Removing the hard limit fixes these cases.

photopea commented 5 years ago

Hi, I am planning to push a new version of Typr.js, which ignores ligatures or any advanced shaping (GPOS, GSUB) completely. For advanced shaping, I will recommend combining it with a WASM port of HarfBuzz library. That is what I currently do with Photopea.

The problem was, that I needed to implement Khmer and Urdu shaping rules, which are very complex, and would probably took me hundreds of hours. Combining Typr.js with HarfBuzz (120 kB WASM file) solved all these problems, so I could throw away 30% of Typr.js code.

Would you be ok with such solution?

lojjic commented 5 years ago

I'm disappointed to hear that. I've nearly completed swapping out opentype.js for Typr.js and have been very happy with the results and smaller file size so far, but this new plan will likely make it unusable for my needs. WebAssembly isn't yet an option in my target browsers list and that large wasm file would negate the file size savings anyway.

Would you consider keeping a pure-js branch going with minor fixes like this? Otherwise I guess I'll have to consider either maintaining a fork or switching back to opentype.

photopea commented 5 years ago

I am also thinking about maintainint a fork. There are like 1000 hours of work, which I threw away (mostly GPOS and GSUB processing), because it is done by HarfBuzz.

But if you need to render Khmer, Urdu or any other complex text in the future, you will see, that Typr.js can not be easily "fixed" to support those.

Ok, I will merge it for now and keep it as it is.

lojjic commented 5 years ago

Thanks! I totally understand about the scope of work involved and I'd make the same decision to use HarfBuzz or similar if I needed those more complex features. Perhaps someday I will. Anyway thanks for all the work you did put into Typr to get it that far.

If you're curious, Typr is now being used in my WebGL text rendering utility for glyph positioning and generating SDF textures on the fly: https://troika-examples.netlify.com/#text

photopea commented 5 years ago

I would like to let you know, that the latest optimized HarfBuzz WASM is only 70 kB ZIPped and extremely simple to use. So I am really considering throwing away advanced shaping from Typr.js .