GNU bug report logs - #76008
31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Kévin Le Gouguec <kevin.legouguec@HIDDEN>; Keywords: patch; dated Sun, 2 Feb 2025 12:04:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) patch. Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 2 Feb 2025 12:03:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 02 07:03:33 2025
Received: from localhost ([127.0.0.1]:33412 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1teYhJ-0007b9-Eu
	for submit <at> debbugs.gnu.org; Sun, 02 Feb 2025 07:03:33 -0500
Received: from lists.gnu.org ([2001:470:142::17]:57104)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <kevin.legouguec@HIDDEN>)
 id 1teYhG-0007aJ-JY
 for submit <at> debbugs.gnu.org; Sun, 02 Feb 2025 07:03:31 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <kevin.legouguec@HIDDEN>)
 id 1teYh7-0003k2-Ea
 for bug-gnu-emacs@HIDDEN; Sun, 02 Feb 2025 07:03:22 -0500
Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <kevin.legouguec@HIDDEN>)
 id 1teYh5-0001VG-Qu
 for bug-gnu-emacs@HIDDEN; Sun, 02 Feb 2025 07:03:21 -0500
Received: by mail-wr1-x42c.google.com with SMTP id
 ffacd0b85a97d-38c5ba0be37so156464f8f.2
 for <bug-gnu-emacs@HIDDEN>; Sun, 02 Feb 2025 04:03:19 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1738497798; x=1739102598; darn=gnu.org;
 h=mime-version:message-id:date:subject:to:from:from:to:cc:subject
 :date:message-id:reply-to;
 bh=lLiicG7x9auAn0Iqe51Rw3QnrgS5XU6PWEGErCN5JxI=;
 b=QvAVlX8sUq4cEN29VR+T9kMXbkfp+Ijy4I+1bfo4bdrGgFarrdq9exFZSKf7FMzf+W
 pwh3WyPJHIx/ejKp8GQEC7laEtjuWjNrguSqN+Kg/bXflnwTSSAyWpS1xMaFp1TMaOAH
 E2Plv5MXgDLohOdNJBK5T1rpCcFnDvG73TVpPoqtYDHx8ybzl1SYTM+TpINjCLWCeAFY
 SP6TtoWu1j7xU2HqOjIzh4Bt2tSuny3B9PvFG60VqEuDIyg6/hBpWt64R+l5FQQ9iYds
 0zhhXJHviXUPsKWsTvqi9errctv5UITcj8Ge4+JAuozcXtVQ+fVNBUnzpqZU5/eQ8qo6
 yJTA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1738497798; x=1739102598;
 h=mime-version:message-id:date:subject:to:from:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=lLiicG7x9auAn0Iqe51Rw3QnrgS5XU6PWEGErCN5JxI=;
 b=UDnRVvaUYwvaKI+GoTP8P+H3df51nQP90Y2Ht1I5XstAGloVJtAFuGqr7LisvOAT14
 wOEdNrAMYNxFSLTK3owLVcf/DllG28xyyhqBV+NV6aK1qWLm4GcHr6mys35dV4RUJ06g
 rvqVxyPKWYndI7wbAgWB5HujUjFu6ED51Ddr2/4Jt4Fzq03nVFJp7xcwOeY/JuoRZtPC
 1BCVTvL4DdfmOnQuU6dDln0+YDUVbp4sXlU/4y4uFLsaHM/Gl5DcbggI41D9F0JRMDqc
 ZJtMI+0Tyrrw6CycBFCVhdGq5RjH7LW8zsNmLOytxm8A2YuQmae5QDA+vpABLSaFmo1C
 0A2Q==
X-Gm-Message-State: AOJu0YzTqEoDjFfbC/TKkbH2pAnX5k1phFTNeHW3sCBvwuKN0ZMjhpAz
 6LHJa624eEapXvvdRAB02FQ13k9NCKADayAHz0JEr7iFSl3ZW/9/4p/alA==
X-Gm-Gg: ASbGncsy+tnTo7VeU0532atzCefre/Z2gYSzUlSdWCsxvM5kQjpUi52hpxHmMGqrakD
 LMatNo0jVZn4LBOp8JnwG7epCEdwtk4Sw3Yz1vSxHPfC/RrBsr/ZxHBbE+NH/9WmTP3En7UGdAY
 KbC6JBgbnZW/YDBK0cf9SjjlsX7QKDLm+H9qewledfG+a/hO07TZ5XWNVo33hpI/KRMDbMALYIH
 clrKGWxaAi6pJbOgJn2UozXQOPpB3DSNnzfANUEi7n/Xb/v9cUDLKHGANbeCKqsI19r0jgwoSRp
 Oz3WC3HBQ8ETJoFqT5U=
X-Google-Smtp-Source: AGHT+IFqGLbAyJDJ0Mv6aeVHJpO/Z/e8uFG8Z5faCOMDeP+zwuQDiSw3G+bTFg6Id6pJB5FXAOOy+Q==
X-Received: by 2002:a05:6000:1544:b0:38d:9e86:2b24 with SMTP id
 ffacd0b85a97d-38d9e862bb7mr134687f8f.8.1738497797998; 
 Sun, 02 Feb 2025 04:03:17 -0800 (PST)
Received: from amdahl30 ([2a01:e0a:253:fe0:2ef0:5dff:fed2:7b49])
 by smtp.gmail.com with ESMTPSA id
 5b1f17b1804b1-438d7558ba2sm141240265e9.0.2025.02.02.04.03.17
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 02 Feb 2025 04:03:17 -0800 (PST)
From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= <kevin.legouguec@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when
 scaling text
X-Debbugs-Cc: Jim Porter <jporterbugs@HIDDEN>
Date: Sun, 02 Feb 2025 13:03:16 +0100
Message-ID: <877c681rln.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=2a00:1450:4864:20::42c;
 envelope-from=kevin.legouguec@HIDDEN; helo=mail-wr1-x42c.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Heya!

Steps to reproduce from emacs -Q:

    C-x C-f repro.rst
    C-x C-+ + [+=E2=80=A6]                  ; until e.g. "+6"
    - words
    M-x visual-wrap-prefix-mode

Expectation: no visual change.
Observation: the "- " prefix is propertized with=E2=80=A6

    There are text properties here:
      display              (min-width ((6 . width)))
      face                 rst-block
      fontified            t
      wrap-prefix          (space :align-to (6 . width))

=E2=80=A6 which makes the text look like this:

    -     words

I believe the cause lies in visual-wrap--content-prefix; empirically the
attached patch shows good results on this reproducer, but I landed on it
more by trial-and-error than by rational analysis, so it may be
incorrect or suboptimal (e.g. there may be better text-scale or
string-width APIs to use).

Thanks for your time (& for the love & care visual-wrap has been
receiving lately).



--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment

diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
index 1691ba9c500..12404127190 100644
--- a/lisp/visual-wrap.el
+++ b/lisp/visual-wrap.el
@@ -33,6 +33,8 @@
 
 ;;; Code:
 
+(require 'face-remap)
+
 (defcustom visual-wrap-extra-indent 0
   "Number of extra spaces to indent in `visual-wrap-prefix-mode'.
 
@@ -164,12 +166,16 @@ visual-wrap--content-prefix
     ;; units of the font's average-width) large enough to fit the
     ;; first-line prefix.
     (let ((avg-space (propertize (buffer-substring position (1+ position))
-                                 'display '(space :width 1))))
+                                 'display '(space :width 1)))
+          (scale (if text-scale-mode
+                     (expt text-scale-mode-step text-scale-mode-amount)
+                   1)))
       ;; Remove any `min-width' display specs since we'll replace with
       ;; our own later in `visual-wrap--apply-to-line' (bug#73882).
       (add-display-text-property 0 (length prefix) 'min-width nil prefix)
       (max (string-width prefix)
-           (ceiling (string-pixel-width prefix (current-buffer))
+           (ceiling (/ (string-pixel-width prefix (current-buffer))
+                       scale)
                     (string-pixel-width avg-space (current-buffer))))))))
 
 (defun visual-wrap-fill-context-prefix (beg end)

--=-=-=
Content-Type: text/plain


Configured using:
 'configure --prefix=/home/peniblec/apps/.emacs.2025-01-18 --with-cairo
 --with-native-compilation=no --with-sqlite3 --with-xinput2'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

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

--=-=-=--




Acknowledgement sent to Kévin Le Gouguec <kevin.legouguec@HIDDEN>:
New bug report received and forwarded. Copy sent to jporterbugs@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to jporterbugs@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#76008; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 2 Feb 2025 14:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.