unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jimmy Yuen Ho Wong <wyuenho@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
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 14:52:53 +0100	[thread overview]
Message-ID: <CAKDRQS4d4OaFpqO+2uJgm-X1URJ7SDs-Kt5s1=fPrJ0aduz_Ew@mail.gmail.com> (raw)
In-Reply-To: <86sesndz8v.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1689 bytes --]

On Wed, Oct 23, 2024 at 9:01 AM Eli Zaretskii <eliz@gnu.org> wrote:

> 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.
>

Corfu is like Company, it's a completion frontend that formats a list of
completion candidates to fit inside a confined pop up box.


> 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.
>

As described, `truncate-string-to-width` doesn't even truncate at grapheme
cluster granularity correctly.

A `truncate-string-to-pixel-width` function is needed because propertized
strings may consist of display space text properties, images, emojis in a
different font, and faces in variable fonts, which all affect glyph widths,
you can't simply assume every glyph will take up 1 column. As a result,
when you calculate some `end-column` and whether it has reached the width
constraint in pixels, one would necessarily need to know the exact width in
pixels for each glyph. Converting the width constraint in pixels to columns
in order to supply it as the second parameter to a correctly implemented
`truncate-string-to-width` amounts to the exact same procedure. Therefore,
either a `truncate-string-to-pixel-width` or `glyph-pixel-width` function
is needed, because `string-pixel-width` is very expensive.

[-- Attachment #2: Type: text/html, Size: 2282 bytes --]

  reply	other threads:[~2024-10-23 13:52 UTC|newest]

Thread overview: 6+ 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
2024-10-23 13:52   ` Jimmy Yuen Ho Wong [this message]
2024-10-23 17:39     ` Eli Zaretskii
2024-10-23 20:03       ` Jimmy Yuen Ho Wong
2024-10-24  9:55         ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='CAKDRQS4d4OaFpqO+2uJgm-X1URJ7SDs-Kt5s1=fPrJ0aduz_Ew@mail.gmail.com' \
    --to=wyuenho@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).