[HarfBuzz] Ligatures

Eli Zaretskii eliz at gnu.org
Sat May 23 18:34:50 UTC 2020


> From: Khaled Hosny <dr.khaled.hosny at gmail.com>
> Date: Sat, 23 May 2020 20:18:33 +0200
> Cc: harfbuzz at lists.freedesktop.org
> 
> > The Emacs display engine examines the text to be displayed and laid
> > out one character at a time, and makes layout decisions after each
> > character or grapheme cluster it lays out.  Its design is therefore
> > fundamentally incompatible with shaping large substrings of buffer
> > text at once.  We do support that for short sequences of characters,
> > which seems to work well enough for complex shaping (a.k.a. "character
> > compositions") of scripts that require that, but we still do that one
> > grapheme cluster at a time.  
> 
> That wouldn’t work for Arabic. You can’t shape Arabic one grapheme cluster at a time (or any other text actually, but the brokenness in Arabic will be immediately obvious), so I’m most certain that is not exactly how Arabic is handled in Emacs right now.

We pass to the shaper the part of text that matches the regexps you
can see at the end of misc-lang.el, then display the glyphs the shaper
returns.  The above description is a high-level overview; there are
many details that I cannot describe in a short message.  For example,
for Arabic, when we get back the grapheme clusters, we lay them out,
then skip to the end of the text that we passed to the shaper.

> > The character composition is implemented
> > in Lisp, which is called by the display engine, and which then calls
> > back into C to invoke the shaper.  This implementation is meant to
> > allow a great deal of control on what should be composed and how.  But
> > it is also relatively slow, which is another reason why doing that for
> > all the text to be laid out is impractical: it slows down redisplay to
> > the degree that it becomes annoying to users.
> 
> Having more control should not be at the price of doing things wrong.

No one said it should, that's just how things are.

> The whole composition concept of Emacs does not make any sense to me, all text is “composed”. You can have a special mode that would disable shaping for specific purposes (opening huge log files, wanting to see raw text with no bidi or shaping, etc), but this can be done in cooperation with HarfBuzz and not by bypassing it entirely.

We are talking about a piece of software designed 21 years ago.  I
realize that it makes no sense to you, but that's what we have, and
will probably have for the next 10 years or so.  We must make the most
out of what we have.


More information about the HarfBuzz mailing list