Subject: bug#60575: 28.2; string-pixel-width always returns zero

From: Sean Devlin <[email-masked]>
Date: Thu, 5 Jan 2023 10:51:25 -0500

Hi folks,

The compat package recently added a function string-pixel-width. On my
macOS GUI build of Emacs 28.2, this function always returns zero.

I'm using commit 46d97649897e91a4086b9812346eed168a8c9cc9 of the compat
package.

To reproduce this result, install compat with the given commit hash and
evaluate the following forms:

(require 'compat)
(string-pixel-width "a string of some width")

The second form returns zero regardless of the input string.

I see that string-pixel-width inserts the string in a buffer and then
calls (buffer-text-pixel-size nil nil t). This function is also defined
in compat and calls window-text-pixel-size to do its work.

It looks like the handling of the x-limit parameter in
window-text-pixel-size may have changed in the Emacs 29 branch. In
particular, it seems to set the max_x variable to INT_MAX if x-limit is
t (or any non-nil value that is not a fixnum in the expected range).

The string-pixel-width function does pass t as the x-limit argument, so
I think the behavior will differ between Emacs 29 and earlier versions.

Maybe the string-pixel-width function in compat should just pass
most-positive-fixnum for x-limit.

Thanks!

In GNU Emacs 28.2
System Description:  macOS 13

Configured using:
'configure --with-ns '--enable-locallisppath=/Library/Application
Support/Emacs/${version}/site-lisp:/Library/Application
Support/Emacs/site-lisp' --with-modules'

Configured features:
ACL GMP GNUTLS JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER THREADS
TOOLKIT_SCROLL_BARS ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: IELM

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny rfc822 mml mml-sec epa
derived epg rfc6068 epg-config gnus-util rmail rmail-loaddefs
auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json map text-property-search mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils pulse color
help-fns radix-tree help-mode xref project time-date subr-x thingatpt
find-func compat compat-29 compat-28 compat-27 compat-26 compat-25
compat-24 vc-git diff-mode easy-mmode vc-dispatcher seq byte-opt gv
bytecomp byte-compile cconv cl-print ielm pp comint ansi-color ring
misearch multi-isearch dired-aux cl-loaddefs cl-lib dired dired-loaddefs
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/ns-win ns-win ucs-normalize
mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 73699 8408)
(symbols 48 8298 1)
(strings 32 24928 1639)
(string-bytes 1 835607)
(vectors 16 17852)
(vector-slots 8 238271 15106)
(floats 8 118 69)
(intervals 56 1264 0)
(buffers 992 18))