Subject: Re: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width`

From: Eli Zaretskii <[email-masked]>
Date: Tue, 13 Apr 2021 15:23:22 +0300

> Cc: [email-masked]
> From: martin rudalics <[email-masked]>
> Date: Tue, 13 Apr 2021 09:06:06 +0200
> 
> (defun string-pixel-width (string)
>    (let ((buffer (get-buffer-create "*foo*"))
> 	(old-buffer (window-buffer)))
>      (with-current-buffer buffer
>        (erase-buffer)
>        (insert string)
>        (set-window-buffer (selected-window) buffer)
>        (prog1
> 	  (window-text-pixel-size nil (point-min) (point-max))
> 	(set-window-buffer (selected-window) old-buffer)))))

Thanks.  This produces correct results, and takes 35-37 usec per call
here.