On Wed, May 28, 2025 at 4:14 PM Jim Porter <jporterbugs@gmail.com> wrote:
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.

Thanks for that.  I think I'm using that in other places.

But... Did you run the repro in question and it worked for you, or are you saying that this worked for your case?

AFAICT, the repro demonstrates a different issue.  With the identical string-pixel-width, padding using specified-width spaces vs. min-width behave differently, so this isn't due to jitter as the widths used are the same for both cases.

-Stephane