emacs-devel
[Top][All Lists]
Advanced

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

Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functi


From: Eli Zaretskii
Subject: Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C
Date: Wed, 23 Oct 2024 11:01:20 +0300

> 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 via email to

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