Subject: bug#78621: Pixelwise display specified spaces less precise than min-width

From: Jim Porter <[email-masked]>
Date: Wed, 28 May 2025 13:14:35 -0700

On 5/28/2025 12:44 PM, Ship Mints wrote:
> You can see this in text-scaled buffers when attempting to pad a string 
> to a specific pixel boundary.  If a pixelwise specified-width space is 
> inserted after a string with variable-pitch glyphs, it doesn't honor the 
> net pixel width.  That same string padded using min-width with the same 
> number of pixels works fine.

Are you sure that your implementation of 'string-pixel-width-scaled' is 
correct? From a brief look, I'd expect that you get some jitter when 
dividing '(default-font-width)' by '(frame-char-width)', since both are 
rounded to the nearest whole number.

If I instead replace that call with:

   (string-pixel-width str (current-buffer))

then everything looks ok to me. As of Emacs 31, passing a buffer does this:

   If BUFFER is non-nil, use the face remappings, alternative and default
   properties from that buffer when determining the width.

That should handle all the necessary work to get the string width after 
applying text-scale remappings. I added that argument so I could use it 
in 'visual-wrap-prefix-mode' for a very similar issue you're seeing. See 
commit f70a6ea0ea86ef461e40d20664a75a92d02679ea.