brechtm / rinohtype

The Python document processor
http://www.mos6581.org/rinohtype
GNU Affero General Public License v3.0
498 stars 59 forks source link

Consider using harfbuzz/uharfbuzz for line layout #137

Open justvanrossum opened 5 years ago

justvanrossum commented 5 years ago

harfbuzz is the de-facto standard for opentype line layout processing, supporting all features of opentype including complex scripts. There's a lovely new Python interface for it on pypi:

https://pypi.org/project/uharfbuzz/ https://github.com/trufont/uharfbuzz

It's fast, relatively easy to use, and incredibly complete and versatile.

brechtm commented 5 years ago

An important design choice for rinohtype was for it to be implemented in pure Python and have as little dependencies as possible. A dependency on a package that requires a C library is therefore problematic.

However, looking at Text Layout Requirements for the Arabic Script, it is obvious that adding support for Arabic alone is already a whole lot of work. Therefore, I would not be opposed to adding support for Harfbuzz in addition to the (very basic) built-in text shaping engine.

justvanrossum commented 5 years ago

Thank you, that is great to know. I don't think there's another choice if rich typographic quality is a priority.

Practically, adopting harfbuzz would mean to enhance the styling infrastructure to allow passing arbitrary opentype feature tags down to the shaper, and to allow more sophisticated glyph placement. Right now, there's only kerning, but every single glyph can have an x/y positioning offset, and a vertical advance in addition to the horizontal advance.