emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ligature support


From: Eli Zaretskii
Subject: Re: Ligature support
Date: Fri, 05 Nov 2021 16:33:16 +0200

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: gregory@heytings.org,  mattiase@acm.org,  emacs-devel@gnu.org,
>   schwab@linux-m68k.org,  stefankangas@gmail.com,  raman@google.com
> Date: Fri, 05 Nov 2021 14:42:39 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > We have font-shape-gstring.  If the font being used doesn't have a
> > ligature for the character sequence we pass to it, that function
> > returns nil, and we then display those characters "normally".  Isn't
> > that enough?
> 
> That's what I thought the design here was originally -- but that's not
> what's happening in general in Emacs.  If I instrument
> font-shape-gstring and start "emacs -Q", that function is never called.
> It's not until I insert something that we've set up something in...
> composition-function-table?...  that the function is called and harfbuzz
> is consulted.  (You can confirm by setting a breakpoint on
> hbfont_shape.)

Yes, because characters whose slot in composition-function-table is
nil aren't handed to the shaping engine; we display them directly.

> I thought we'd just send all the text through hb_shape_full, and it
> would handle all this stuff.  But we don't -- we only send a very small
> subset of the strings through that function, as far as I can tell.

Right, and by design.  Character composition is somewhat slow in
Emacs: the display code calls into Lisp, and Lisp then turns around
and calls into C.  Doing that for every piece of text would slow down
redisplay, so we don't do that unless composition-function-table tells
us we should.

So for having ligatures you need to set up composition-function-table
for the characters that could/should ligate.  This article is a good
starting point:

  https://en.wikipedia.org/wiki/Ligature_(writing)

But please read the TODO item: there are pitfalls here that we need to
solve before this could be considered a reasonable user-level
feature.  Setting up composition-function-table to produce ligatures
for, say, "fi" and "ff" is easy for testing, but if you do that in
production, every word with these characters, everywhere on display in
Emacs, will display as that ligature, and that is hardly TRT.  We need
to make this more fine-tunable.  TODO has the details.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]