all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Jimmy Yuen Ho Wong <wyuenho@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C
Date: Wed, 23 Oct 2024 11:01:20 +0300	[thread overview]
Message-ID: <86sesndz8v.fsf@gnu.org> (raw)
In-Reply-To: <CAKDRQS7n_DZMm0G+EfBqG8NWGXwbuZ1+j+PLFJ4+UMZLNbyPDw@mail.gmail.com> (message from Jimmy Yuen Ho Wong on Wed, 23 Oct 2024 06:01:18 +0100)

> From: Jimmy Yuen Ho Wong <wyuenho@gmail.com>
> Date: Wed, 23 Oct 2024 06:01:18 +0100
> 
> Recently I've been trying to mold Corfu to render every string in every face in pixel precision but I've run into
> some slight performance issues when truncating strings. The motivation for this is `truncate-string-to-width`
> not only does not speak pixels, but also doesn't understand composed characters such as emojis. It just
> chops off the emoji byte sequence in the middle as described in the PR, so I had to write a custom
> `truncate-string-to-pixel-width` function using `string-glyph-split` and `string-pixel-width` to measure character
> widths, which seems... silly.
> 
> I've looked into how to get the width of a glyph from a font object by employing some dark magic of
> undocumented internal functions and wrongly documented functions such as `char-displayable-p`, `font-info`,
> `lglyth-width`, `lgstring-glyph`, `open-font` etc in combination of `composition-get-gstring`, which is correct and
> fast enough.... for glyph strings with no faces. Then I looked into reverse engineering the face font selection
> process, which quickly pushed the run time up 2 orders of magnitude due to the anonymous face + face
> attribute inheritance + face lists madness. Then when I realized I still didn't deal with display text properties, I
> threw my hands up.
> 
> It'd be really nice if we could have a really performant C function that can truncate strings correctly and
> preferably in pixel precision. Alternatively, a `glyph-pixel-width` that implements a fast path in C that's
> somewhat akin to the process I described above, but also handles display text properties correctly would be
> nice.
> 
> I don't really know enough about Emacs C internals WRT to font rendering to implement this so I'm just
> throwing this idea out there.

I know next to nothing about Corfu, so I have hard time understanding
what you are trying to do and why.  Basically, the Emacs display
engine already truncates stuff it displays, so it is completely
unclear to me why you'd need to do that in Lisp.

In particular, "truncate strings in pixel precision" makes no sense to
me, since strings on display are made of characters (more accurately,
"grapheme clusters"), so any reasonable truncation will always work at
the grapheme-cluster granularity, not at pixel granularity.

So please describe your problem in much more detail, assuming that I
know nothing about Corfu and its display-related tricks.

Thanks.



  reply	other threads:[~2024-10-23  8:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-23  5:01 Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C Jimmy Yuen Ho Wong
2024-10-23  8:01 ` Eli Zaretskii [this message]
2024-10-23 13:52   ` Jimmy Yuen Ho Wong
2024-10-23 17:39     ` Eli Zaretskii
2024-10-23 20:03       ` Jimmy Yuen Ho Wong
2024-10-24  9:55         ` Eli Zaretskii
2024-10-24 14:26           ` Jimmy Yuen Ho Wong
2024-10-24 14:39             ` Eli Zaretskii
2024-10-24 15:33               ` Jimmy Yuen Ho Wong
2024-10-24 16:02                 ` Eli Zaretskii
2024-10-24 16:49                   ` Jimmy Yuen Ho Wong
2024-10-24 17:56                     ` Eli Zaretskii
2024-10-24 21:11                       ` Jimmy Yuen Ho Wong
2024-10-25  7:21                         ` Eli Zaretskii
2024-10-25 13:35                           ` Jimmy Yuen Ho Wong
2024-10-25 15:11                             ` Eli Zaretskii
2024-10-28 20:21                               ` Jimmy Yuen Ho Wong

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=86sesndz8v.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=wyuenho@gmail.com \
    /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.