bug#81570: 31.0.90; window-text-pixel-size sometimes does not correctly determine the width of characters with face attribute :box

Markus Triska <[email protected]> Thu, 06 Aug 2026 20:50:15 +0200 (CEST)
Newsgroups gmane.emacs.bugs
Message-ID <20260806185015.7FE35F08652@triska-ser8>
To reproduce this issue, please launch Emacs with:

    $ emacs -Q

We expect that adding a box of width W greater than 0 around a string
yields a string that is 2*W pixels wider, because the box has a left
and a right edge, i.e., two edges.

For example, when we evaluate the following expression, which
subtracts, from a character whose face has a :box attribute with
line-width 1, the width of a plain character without boxes:

    (let (w)
      (font-lock-mode 0)
      (insert (propertize "b" 'face '(:box (:line-width 1))))
      (setq w (car (window-text-pixel-size nil (1- (point)) (point))))
      (delete-char -1)
      (insert "p")
      (prog1
          (- w (car (window-text-pixel-size nil (1- (point)) (point))))
        (delete-char -1)))

then we expect as result the value 2.

But unexpectedly, the value is instead 1.

We see that the *height* of the character is taken into account as
expected also when its face has a :box attribute with width 1:

    (pcase-let
        ((`((,w0 . ,h0) (,w1 . ,h1))
          (mapcar (lambda (str)
                    (font-lock-mode 0)
                    (insert str)
                    (prog1
                        (window-text-pixel-size nil (1- (point)) (point))
                      (delete-char -1)))
                  `("p"
                    ,(propertize "b" 'face '(:box (:line-width 1)))))))
      (cons (- w1 w0) (- h1 h0)))

This yields (1 . 2), i.e., the height difference is 2 as expected.

The expected overall value is (2 . 2), i.e., the same difference for
width and height.

Thank you and all the best,
Markus



In GNU Emacs 31.0.90 (build 2, x86_64-pc-linux-gnu, X toolkit, Xaw
 scroll bars) of 2026-07-19 built on beelink-ser8
Repository revision: 407de5142c2631d42d53c8da470188f61e46ab22
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Debian GNU/Linux 13 (trixie)

Configured using:
 'configure --without-cairo --with-x-toolkit=lucid
 --with-xpm=ifavailable --with-gif=ifavailable --with-tiff=ifavailable
 --with-gnutls=ifavailable --with-native-compilation=no'

Configured features:
DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBSYSTEMD
LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS
TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XFT XIM XINERAMA
XINPUT2 XPM XRANDR LUCID ZLIB