Eli Zaretskii <e...@gnu.org> writes:

>> From: Nicolas Goaziou <m...@nicolasgoaziou.fr>
>> Cc: shingo....@gmail.com,  48...@debbugs.gnu.org
>> Date: Sun, 02 May 2021 14:18:24 +0200
>> 
>> My problem is that I have some string, _which is not displayed anywhere_
>> yet. I need to obtain its real width along with the width of a single
>> character in order to compute the length argument in `make-string'.
>
> The width of any text on display is meaningless unless you also tell
> in what window will it be displayed.  That's because some of the
> factors that affect the display width depend on the window and the
> buffer shown by that window.

I understand. More than the width of the text, I'm interested in the
ratio between the width of the text and the width of an underline
character (assuming monospace).

> So assuming the string you have will eventually be displayed in some
> window -- and most strings in Emacs are of that kind -- you should use
> that window up front.  Otherwise, the value you get from other methods
> can only be an approximation, which will sometimes be close, and
> sometimes quite far from the truth.

The string may not be displayed at all. Since it is the output of an
export process, it could, e.g., be written to a file.

I applied Shingo Tanaka's suggestion using `string-width', which is the
best we can do considering our requirements.

Thank you for your answer, and to Shingo Tanaka for the report an the
patch.

Regards,




Reply via email to