From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C Date: Wed, 23 Oct 2024 20:39:29 +0300 Message-ID: <86ed46en1q.fsf@gnu.org> References: <86sesndz8v.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31025"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Jimmy Yuen Ho Wong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Oct 23 19:40:25 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t3fLM-0007vN-Gr for ged-emacs-devel@m.gmane-mx.org; Wed, 23 Oct 2024 19:40:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3fKY-0004D3-HL; Wed, 23 Oct 2024 13:39:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3fKV-0004Ce-TF for emacs-devel@gnu.org; Wed, 23 Oct 2024 13:39:32 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3fKV-0000Tl-A6; Wed, 23 Oct 2024 13:39:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=i4I2Ep2CjulspedtHcNYoN9LTzSwFk7akz0v+C+yV+4=; b=aVLRAheB5zb/wkI7pKPR 8EwT7FtyjufJoSYaer1RnSFoyFTSKJtKbu9Jpd+G7J+sCEYLbPdWDAEvNmkHjq5xIrAxD1JMZ66Ou XDSypRehuJumDLnUhctGdcbp+JjWvLONpu97JwEBBG2FoiRVZj/VXiUbbmcAVr5HCY9vGBn6o1LhP c69bZBeqfdV3BxXIoECHi07+8TE1XLl3fC0suZY4VtJqVC3kGQxObdxA0H/4DxNxBnuaPaaXoUCTU 4+mRGVA6Fe7Ef32Rv+6hYgQ8RgYYPBjD+t0Pq4ogCB2j/0X8hlQfLFIfV8ZPfKctV7GLuFRdYyvzs lBXuUi0Bo/CFYA==; In-Reply-To: (message from Jimmy Yuen Ho Wong on Wed, 23 Oct 2024 14:52:53 +0100) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324797 Archived-At: > From: Jimmy Yuen Ho Wong > Date: Wed, 23 Oct 2024 14:52:53 +0100 > Cc: emacs-devel@gnu.org > > On Wed, Oct 23, 2024 at 9:01 AM Eli Zaretskii 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. Thanks, but that doesn't explain enough. Please tell more about the need to truncate completion candidates "inside a confined pop up box". If that box is displayed, why doesn't Emacs truncate the text automatically? Or maybe I don't understand how this "pop up box", whatever it is, is displayed? > 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. So the issue is not "pixel-wise truncation", the issue is to take variable-width display elements into account when truncating, is that right?