all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: cpitclaudel@gmail.com, alan@idiocy.org, emacs-devel@gnu.org
Subject: Re: Ligatures (was: Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY))
Date: Thu, 21 May 2020 16:26:13 +0000	[thread overview]
Message-ID: <CAOqdjBduGE_LwVihcV5BnUF1P1KjH4DQwJa_60rU0Mms9qRz8Q@mail.gmail.com> (raw)
In-Reply-To: <837dx55qff.fsf@gnu.org>

On Thu, May 21, 2020 at 2:11 PM Eli Zaretskii <eliz@gnu.org> wrote:
> > From: Pip Cet <pipcet@gmail.com>
> > Date: Thu, 21 May 2020 10:01:03 +0000
> > Cc: cpitclaudel@gmail.com, alan@idiocy.org, emacs-devel@gnu.org
> > > but
> > > if we really want this only for these limited cases, we will need to
> > > somehow indicate to the display engine which ligatures are to be
> > > handled like this and which aren't.
> >
> > Well, we now know that fonts can provide information about how a
> > ligature is to be split into one-dimensional slices;
>
> The question is: do we want to show those carets for all the character
> compositions, even if the information is provided?  If not, we will
> have to indicate somehow whether they should or shouldn't be shown for
> each particular grapheme cluster.

Oh. I hadn't thought about fonts providing such caret information in
cases where they shouldn't, but of course that's a valid concern.

> > Of course that means that Emacs behavior would depend on the font
> > tables in ways it currently doesn't. That's a problem.
>
> It isn't a problem to depend on that if most fonts provide this
> information.

> Then we could simply say this is not supported when the
> information is not in the font.

I'm not sure how simple that would be: we could treat ligatures
without carets as atomic, or we could tell harfbuzz not to apply
ligatures without carets, or maybe make that decision depend on
whether the ligature is required or discretionary...

> But if many fonts that support
> ligatures don't provide this information, we will need to have some
> fallback, like assume that every codepoint has the same share of the
> ligature's width.  the fact that other applications use a simplistic
> heuristic and not the information in the fonts suggests that either
> the information is not readily available or there are some other
> problems with using it.

Correct, it does. I'm not sure which one is the case.

> > > Right, the actual implementation will have to be different.  In
> > > particular, I think that if ligatures will use automatic compositions,
> > > the information you need is already stored in the composition table
> > > and reachable from the glyph string, so you don't need to invoke the
> > > shaper again.
> >
> > Well, I'm sorry to bring up a different (though somewhat related
> > issue), but kerning is also an issue: we need a shaper to get that
> > right, not just a composition table, right?
>
> Automatic compositions already use the shaper, see autocmp_chars.

I'm not sure I understand how kerning would work using automatic compositions.

> > > I see you implemented this for static compositions, which are
> > > semi-obsolete.
> >
> > I'm sorry, I'm afraid I don't understand. This should handle any
> > composition the shaper does, and only those, but slices up everything
> > horizontally by default.
>
> I'm talking about the changes in gui_produce_glyphs.  Its high-level
> structure is basically
>
>   if (it->what == IT_CHARACTER)
>     {
>     ... /* handles character glyphs */
>     }
>   else if (it->what == IT_COMPOSITION && it->cmp_it.ch < 0)
>     {
>     ... /* A static compositions. */
>     }
>   else if (it->what == IT_COMPOSITION)
>     {
>       /* A dynamic (automatic) composition.  */
>     }
>   [...]
>
> You made changes only in the "static compositions" part.

No. I didn't touch the "static compositions" part at all, except for
passing an extra NULL pointer to an API I'd extended. (At least,
that's what I intended, for all the changes to be in the IT_CHARACTER
part).

> That code
> handles compositions created by compose-region.  The "modern" way of
> composing text in Emacs uses automatic compositions, which are
> controlled by data in composition-function-table.  This is where we
> call the shaping engine to produce the glyphs according to rules
> stored in the font.  I don't see in your patch any changes that affect
> ligatures created by automatic compositions; did I miss something?

I don't think so; I went for a third route, that of leaving all
compositions handling to the shaper and doing none of it in Emacs
itself.

> If you use the automatic compositions route, then the information you
> need, i.e. the number of clusters in the shaped text and the overall
> width of the ligature, is already produced by the shaper and stored in
> the "gstring" object in the composition table, see the description of
> that object in the doc string of composition-get-gstring.  So there
> should be no need to invoke the shaper inside gui_produce_glyphs and
> elsewhere.  (If we want to use the carets information from the font,
> we will probably need to extend the gstring object to store that as
> well, and extend the shape method to extract this information when
> available.)

Yes, and that seemed too complicated for me for something that I
thought wouldn't handle kerning anyway...

> > > Also, I don't see the code which moves point inside
> > > the ligature; Emacs will not allow doing that by default.  In
> > > particular, how did you tell the display code to show the cursor on
> > > the middle 'f', not on the first one?  Did I miss something?
> >
> > I produce three "struct glyph"s for "ffi": each has width one third of
> > the actual font glyph, and stores, in convoluted form, information
> > about which slice of the font glyph is to be actually drawn.
>
> Ah, okay, I missed that.  But producing 3 glyphs instead of just one
> is not necessarily the best idea, I think.

I agree! I'd be happy to hear better ideas, and I think for now "use
fixed-width fonts" is a better idea...

> As you point out, one
> problem will be with splitting the ligature across lines.  Another
> problem is more expensive display.

You mean the actual "copy the glyph bitmap to the glass" display?
Because I don't think that's relevant. Overall redisplay() time really
goes up calling the shaper on 32 characters for every character
displayed, though, so that's a concern I agree with.

> And we won't be able to display
> the ligature as a single glyph, for those who want that, at least not
> easily.

But that's what they can do now, with the IT_COMPOSITION case, right?
Because I did not touch that code so I didn't expect that to break
(famous last words).

> > > And finally, you said you intended to do this via row->clip, but this
> > > patch does something very different.  What changed your mind?
> >
> > I was surprised this no longer seemed to be strictly necessary: as far
> > as the display code is concerned, we're dealing with three separate
> > glyphs with overhang areas, and those are already handled by the
> > cursor-drawing code.
>
> Yes.  But if we return to a single glyph, then we'd need to do some
> clipping.

As I said, we need to do the clipping to render antialiased pixels properly.

It's just two lines of code in ftcrfont_draw:

  cairo_rectangle (cr, x, y - FONT_BASE (face->font),
           s->width, FONT_HEIGHT (face->font));
  cairo_clip (cr);

> > On the other hand, it deals with kerning as well as ligatures.
>
> You mean, kerning of simple characters, for which we don't produce
> ligatures?

Yes, that's what I mean.

> Or kerning within ligatures?  If the latter, then I don't
> see why we'd need that: font designers already design the ligatures to
> have the optimal kerning, no?

It's certainly not our job to fix that if they don't!

Perhaps I can digress a little and describe what I think the
interaction with the shaper should be like:

Emacs: I'd like to display codepoint 'f'
Harfbuzz: you'll have to tell me the codepoint before that
Emacs: 'f'
Harfbuzz: and the one after those two
Emacs: 'i'
Harfbuzz: and the one before all of those
Emacs: That's too expensive for me to compute / it's the beginning of
paragraph / a bidi boundary / an object without an assigned codepoint
/ ...
Harfbuzz: okay, display it as the middle slice of the "ffi" glyph

I.e., I'd like Harfbuzz to be asynchronous, and request more
information, parsimoniously, about the context of the codepoint we're
describing, rather than working in one go from "complete" information
to an indefinitely-long line of glyphs. And deal well with us deciding
it's too expensive to perform that much look-back/look-ahead. (Because
in real life, ligatures depend on knowing some amount of the context,
but not all of it, or people could never start writing.)

Of course, all this doesn't change that the "struct it" design is
somewhat difficult to extend to handling look-ahead: it's easy enough
to create a copy of the iterator and advance that while leaving the
actual iterator intact, but it's also really slow. In fact I suspect
the best way would be to make struct it a heap-allocated pseudovector
(not necessarily one ordinarily garbage-collected, though), and cache
"future" iterator states once we compute them.

You're correct when you say that some major redesign is needed in this
area, but I don't think that's the subject of the current discussion.



  reply	other threads:[~2020-05-21 16:26 UTC|newest]

Thread overview: 145+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 10:41 Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY) Julius Pfrommer
2020-05-17 14:09 ` Arthur Miller
2020-05-17 14:30   ` Eli Zaretskii
2020-05-17 15:06     ` Arthur Miller
2020-05-17 15:56       ` Eli Zaretskii
2020-05-17 16:50         ` Arthur Miller
2020-05-17 17:06           ` Eli Zaretskii
2020-05-17 14:35 ` Eli Zaretskii
2020-05-17 14:59   ` Julius Pfrommer
2020-05-17 15:55     ` Eli Zaretskii
2020-05-17 16:28       ` Pip Cet
2020-05-17 17:00         ` Eli Zaretskii
2020-05-17 18:50           ` Pip Cet
2020-05-17 19:17             ` Eli Zaretskii
2020-05-18 16:08               ` Ligatures (was: Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY)) Eli Zaretskii
2020-05-18 16:45                 ` tomas
2020-05-18 16:49                   ` Eli Zaretskii
2020-05-18 17:05                 ` Ligatures Stefan Monnier
2020-05-18 17:18                   ` Ligatures Eli Zaretskii
2020-05-18 19:19                     ` Ligatures Pip Cet
2020-05-18 19:25                       ` Ligatures tomas
2020-05-18 19:41                         ` Ligatures Pip Cet
2020-05-18 20:20                           ` Ligatures tomas
2020-05-18 19:33                       ` Ligatures Eli Zaretskii
2020-05-18 19:44                         ` Ligatures Clément Pit-Claudel
2020-05-19  2:25                           ` Ligatures Eli Zaretskii
2020-05-19  2:44                             ` Ligatures Clément Pit-Claudel
2020-05-19 13:59                               ` Ligatures Eli Zaretskii
2020-05-19 14:35                                 ` Ligatures Clément Pit-Claudel
2020-05-19 15:21                                   ` Ligatures Eli Zaretskii
2020-05-19 15:44                                     ` Ligatures Clément Pit-Claudel
2020-05-19 16:15                                       ` Ligatures Eli Zaretskii
2020-05-19 15:36                                 ` Ligatures Tassilo Horn
2020-05-19 16:08                                   ` Ligatures Eli Zaretskii
2020-05-19 16:14                                   ` Ligatures Stefan Monnier
2020-05-19  3:47                             ` Ligatures Stefan Monnier
2020-05-19  4:51                               ` Ligatures Clément Pit-Claudel
2020-05-18 19:38                       ` Ligatures Clément Pit-Claudel
2020-05-19 14:55                         ` Ligatures Pip Cet
2020-05-19 15:30                           ` Ligatures Clément Pit-Claudel
2020-05-19 15:52                             ` Ligatures Pip Cet
2020-05-18 17:24                   ` Ligatures tomas
2020-05-18 17:41                     ` Ligatures Eli Zaretskii
2020-05-18 19:07                       ` Ligatures tomas
2020-05-18 19:17                         ` Ligatures Eli Zaretskii
2020-05-18 20:33                     ` Ligatures Stefan Monnier
2020-05-18 17:31                 ` Ligatures (was: Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY)) Clément Pit-Claudel
2020-05-18 17:39                   ` Eli Zaretskii
2020-05-18 19:01                     ` Clément Pit-Claudel
2020-05-18 19:15                       ` Eli Zaretskii
2020-05-18 19:18                       ` tomas
2020-05-18 20:37                       ` Ligatures Stefan Monnier
2020-05-18 21:59                       ` Ligatures (was: Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY)) Alan Third
2020-05-19 13:56                         ` Eli Zaretskii
2020-05-19 14:39                           ` Clément Pit-Claudel
2020-05-19 21:43                             ` Pip Cet
2020-05-20  1:41                               ` Clément Pit-Claudel
2020-05-20  2:07                               ` Ligatures Stefan Monnier
2020-05-20  7:14                               ` Ligatures (was: Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY)) tomas
2020-05-20 15:18                               ` Eli Zaretskii
2020-05-20 17:31                                 ` Clément Pit-Claudel
2020-05-20 18:01                                   ` Eli Zaretskii
2020-05-20 18:33                                     ` Clément Pit-Claudel
2020-05-20 18:49                                       ` Eli Zaretskii
2020-05-20 18:53                                         ` Clément Pit-Claudel
2020-05-20 19:02                                           ` Eli Zaretskii
2020-05-20 23:19                                   ` Ligatures Stefan Monnier
2020-05-21 10:01                                 ` Ligatures (was: Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY)) Pip Cet
2020-05-21 14:11                                   ` Eli Zaretskii
2020-05-21 16:26                                     ` Pip Cet [this message]
2020-05-21 19:08                                       ` Eli Zaretskii
2020-05-21 20:51                                         ` Clément Pit-Claudel
2020-05-21 21:16                                           ` Pip Cet
2020-05-22  6:12                                             ` Eli Zaretskii
2020-05-22  9:25                                               ` Pip Cet
2020-05-22 11:23                                                 ` Eli Zaretskii
2020-05-22 12:52                                                   ` Pip Cet
2020-05-22 13:15                                                     ` Eli Zaretskii
2020-05-22 13:29                                                       ` Clément Pit-Claudel
2020-05-22 14:30                                                         ` Eli Zaretskii
2020-05-22 14:34                                                           ` Clément Pit-Claudel
2020-05-22 19:01                                                             ` Eli Zaretskii
2020-05-22 19:33                                                               ` Clément Pit-Claudel
2020-05-22 19:44                                                                 ` Eli Zaretskii
2020-05-22 20:02                                                                   ` Clément Pit-Claudel
     [not found]                                                                     ` <83mu5z171j.fsf@gnu.org>
2020-05-23 14:34                                                                       ` Clément Pit-Claudel
2020-05-23 16:18                                                                         ` Eli Zaretskii
2020-05-23 16:37                                                                           ` Clément Pit-Claudel
2020-05-22 13:56                                                       ` Pip Cet
     [not found]                                                         ` <83lflj16jn.fsf@gnu.org>
     [not found]                                                           ` <AF222EA0-FE05-4224-8459-2BF82CE27266@vasilij.de>
     [not found]                                                             ` <834ks7110w.fsf@gnu.org>
2020-05-23 11:24                                                               ` Vasilij Schneidermann
2020-05-23 13:04                                                                 ` Eli Zaretskii
     [not found]                                                           ` <83eerb145r.fsf@gnu.org>
     [not found]                                                             ` <CAOqdjBeef8Fa596raEyBUwv0Zr+41LSiYvHW39EdoaXpyxCXVw@mail.gmail.com>
     [not found]                                                               ` <831rnb0zld.fsf@gnu.org>
2020-05-23 12:36                                                                 ` Pip Cet
2020-05-23 14:08                                                                   ` Eli Zaretskii
2020-05-23 15:13                                                                     ` Pip Cet
2020-05-23 16:34                                                                       ` Eli Zaretskii
2020-05-23 22:38                                                                         ` Pip Cet
2020-05-24 15:33                                                                           ` Eli Zaretskii
2020-05-26 18:13                                                                             ` Pip Cet
2020-05-26 19:46                                                                               ` Eli Zaretskii
2020-05-27  9:36                                                                                 ` Pip Cet
2020-05-27 17:13                                                                                   ` Eli Zaretskii
2020-05-27 18:42                                                                                     ` Pip Cet
2020-05-27 19:19                                                                                       ` Eli Zaretskii
2020-05-23 17:32                                                                       ` Eli Zaretskii
2020-05-23 21:29                                                                         ` Pip Cet
2020-05-24 15:19                                                                           ` Eli Zaretskii
2020-05-23 12:47                                                                 ` Ligatures Stefan Monnier
2020-05-23 13:10                                                                   ` Ligatures Eli Zaretskii
2020-05-23 13:45                                                                     ` Ligatures Stefan Monnier
2020-05-23 14:12                                                                       ` Ligatures Eli Zaretskii
2020-05-23 13:36                                                                   ` Ligatures 조성빈
2020-05-23 14:15                                                                     ` Ligatures Stefan Monnier
2020-05-23 14:37                                                                   ` Ligatures Pip Cet
2020-05-22 11:44                                           ` Ligatures (was: Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY)) Eli Zaretskii
2020-05-22 13:26                                             ` Clément Pit-Claudel
2020-05-22 14:29                                               ` Eli Zaretskii
2020-05-22 14:32                                                 ` Clément Pit-Claudel
2020-05-22 19:00                                                   ` Eli Zaretskii
2020-05-21 21:06                                         ` Pip Cet
2020-05-22  6:06                                           ` Eli Zaretskii
2020-05-22  9:34                                             ` Pip Cet
2020-05-22 11:33                                               ` Eli Zaretskii
2020-05-19 20:26                           ` Alan Third
2020-05-19 10:09                   ` Trevor Spiteri
2020-05-19 14:22                     ` Eli Zaretskii
2020-05-19  5:43                 ` Ligatures ASSI
2020-05-19  7:22                   ` Ligatures tomas
2020-05-19  7:55                     ` Ligatures Joost Kremers
2020-05-19  8:07                       ` Ligatures tomas
2020-05-19 10:17                         ` Ligatures Yuri Khan
2020-05-19 14:26                           ` Ligatures Eli Zaretskii
2020-05-19 19:00                             ` Ligatures Yuri Khan
2020-05-19 10:43                         ` Ligatures Werner LEMBERG
2020-05-19 10:48                           ` Ligatures tomas
2020-05-19 14:18                   ` Ligatures Eli Zaretskii
2020-05-19 14:52                     ` Ligatures Eli Zaretskii
2020-05-19 15:11                       ` Ligatures Pip Cet
2020-05-19 15:36                         ` Ligatures Eli Zaretskii
2020-05-19 16:16                           ` Ligatures Pip Cet
2020-05-19 16:41                             ` Ligatures Eli Zaretskii
2020-05-19 17:00                             ` Ligatures Eli Zaretskii
2020-05-17 18:28       ` Unify the Platforms: Cairo+FreeType+Harfbuzz Everywhere (except TTY) Julius Pfrommer
2020-05-17 18:45         ` Eli Zaretskii
2020-05-17 22:28         ` chad
2020-05-18 22:08         ` Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOqdjBduGE_LwVihcV5BnUF1P1KjH4DQwJa_60rU0Mms9qRz8Q@mail.gmail.com \
    --to=pipcet@gmail.com \
    --cc=alan@idiocy.org \
    --cc=cpitclaudel@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.