From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jimmy Yuen Ho Wong Newsgroups: gmane.emacs.devel Subject: Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C Date: Mon, 28 Oct 2024 20:21:29 +0000 Message-ID: References: <86sesndz8v.fsf@gnu.org> <86ed46en1q.fsf@gnu.org> <86seslddvs.fsf@gnu.org> <86msitd0oy.fsf@gnu.org> <86h691cwuv.fsf@gnu.org> <86frolcrl2.fsf@gnu.org> <865xpgd4vi.fsf@gnu.org> <86iktgb4l5.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ea1ddf06258f384d" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11518"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 28 21:23:12 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 1t5WGd-0002qY-Jq for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Oct 2024 21:23:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5WFe-00052m-8z; Mon, 28 Oct 2024 16:22:10 -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 1t5WFc-00052Y-Q5 for emacs-devel@gnu.org; Mon, 28 Oct 2024 16:22:08 -0400 Original-Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t5WFb-0007Rd-GR; Mon, 28 Oct 2024 16:22:08 -0400 Original-Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7b152a23e9aso366804085a.0; Mon, 28 Oct 2024 13:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730146926; x=1730751726; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5JbTiPN1/HaL25ImX97tzFUTwqLpnerOMYB9sD8+xVM=; b=ZTTzH74n2FNMoMEj8phbXtlKa4kgNZNCcDNWbrfTj8cRgwV1OEdFPypYG+TlID/UK1 /+lseHsJX7OaK21xBDw1EWeP2Mm4IFgfFqX7HNe1Tq45YmQSVcJY92jmQK99tfTcGo+8 JJWSma6JVn5Kj+JqB5gT24dUFy8GnZf9wTYN+uJuyn5HeuWf03YnU0Ij4pTtOacLgAeY DBXRNaac2wbrUy/4Mv/VBYtZLRdhYEC7EI/6MjQo9iEE5swaTI2Z+vl5K2IkXI7BYcWV 4MABDEnHfEIneYdBBmEVFyiU5NivwSjC6EissXAPavwC4ZHeud0dlyqemReohDmPsma9 dPvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730146926; x=1730751726; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5JbTiPN1/HaL25ImX97tzFUTwqLpnerOMYB9sD8+xVM=; b=g1gSAViw7nnIMCOrjdGANPBwTNhDhTL4SKAu/zQYLEp+qeBR8o191TkyDYPqgS1kGZ dCtTc1jaRf1PrtW/dwoW+E15OZxUbvuK83RITtQsiq5hY4rItkyd6IRlF1QD2+Vd37Bl n9lqcIxGAYtpgfZQrQ65nMtW3twPrpstdubwS/Xb5UEB0L0+IW4IcDqxIRCxOr8W5lzz XlfnldF9dANw/Mt/Rx12fbAgMpPvVbzMSULbivL0E6YKMK3+ECDMK8nWvxqD3useLTQV scOwZrEBouMN5ZROgfbFnMhcW2XCxUgSKRmx2ADyOl2Go2xNYliZCpA8bnIUE8dx3VTM CS9A== X-Gm-Message-State: AOJu0Yx0LwF9E3MgeDdfqis+vpFRKbJI/mY657UGPrMXE6Tx3pL7S9JT sQcK68uvQpFq29jyj53yS1WphdOmNrIDr0V6egcOEgOqx9gzaXLTQRdhfvPmf79NHVLwTLzB5S1 q1CcJpOkZ23+z5dLaJqHBIX1v3B3jzA== X-Google-Smtp-Source: AGHT+IHgomSOSRHPiqccSEjqglxSJr2+JRDpLiVAtSYHB5KhKoIjr87VW9Y00P81/E6ByufDZ87qWE2cGqTG8UwxzxU= X-Received: by 2002:a05:6214:5348:b0:6d1:7453:f96b with SMTP id 6a1803df08f44-6d1856fb9a8mr147972356d6.30.1730146925679; Mon, 28 Oct 2024 13:22:05 -0700 (PDT) In-Reply-To: <86iktgb4l5.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=wyuenho@gmail.com; helo=mail-qk1-x735.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:324904 Archived-At: --000000000000ea1ddf06258f384d Content-Type: text/plain; charset="UTF-8" > > Bottom line: string-pixel-width is hardly efficient enough when > invoked in a tight loop, so if you need to call it many times for many > strings, perhaps a better idea would be to insert all the strings into > a work buffer, then measure their width one by one using > window-text-pixel-size, each time calling it with different FROM and > TO values? That involves switching a window's buffer and then > switching it back, but maybe it will be faster? > > Alternatively, if you only need the width of the widest string in a > collection, you could concatenate them separated by newlines, then > call string-pixel-width on the result. > It took me a while to understand what this means, that's some leaky abstraction we have here :) I've found a solution after some refactoring. The simplest solution is just don't use relative :align-to. As long as it's not used, `string-pixel-width` will behave as expected. Thanks for all your help. --000000000000ea1ddf06258f384d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Bottom line: string-pixel-width is hardly efficient enou= gh when
invoked in a tight loop, so if you need to call it many times for many
strings, perhaps a better idea would be to insert all the strings into
a work buffer, then measure their width one by one using
window-text-pixel-size, each time calling it with different FROM and
TO values?=C2=A0 That involves switching a window's buffer and then
switching it back, but maybe it will be faster?

Alternatively, if you only need the width of the widest string in a
collection, you could concatenate them separated by newlines, then
call string-pixel-width on the result.

It took me = a while to understand what this means, that's some leaky abstraction we= have here :)

I've found a solution after some refactoring. The = simplest=C2=A0solution is just don't use relative :align-to. As long as= it's not used, `string-pixel-width` will behave as expected.

Th= anks for all=C2=A0your help.
--000000000000ea1ddf06258f384d--