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: Jimmy Yuen Ho Wong
Subject: Re: Need `truncate-string-to-pixel-width` and `glyph-pixel-width` functions in C
Date: Mon, 28 Oct 2024 20:21:29 +0000

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.

reply via email to

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