Subject: bug#67533: SVG images confound position pixel measurements

From: Manuel Giraud <[email-masked]>
Date: Fri, 01 Dec 2023 15:40:59 +0100

Eli Zaretskii <[email-masked]> writes:

>> From: JD Smith <[email-masked]>
>> Date: Wed, 29 Nov 2023 15:31:43 -0500
>> 
>> ;;; test-svg-pixel-position --- test pixel position for SVG images
>> 
>> ;;; This small code creates a buffer with two lines, the first of
>> ;;; which is long, and the second of which has an SVG image at start.
>> ;;; Line truncation is turned on.  `window-text-pixel-size` returns
>> ;;; differing results depending on whether truncation is actually in
>> ;;; effect (alter the frame width to see this).
>> 
>> ;;; Code:
>> (require 'svg)
>> (let ((buf "svg-pixel-demo")
>>      (svg (svg-create 50 25)))
>>  (svg-circle svg 25 25 25 :stroke-color "green")
>>  (with-current-buffer (get-buffer-create buf)
>>    (erase-buffer)
>>    (insert "Pellentesque condimentum, magna ut suscipit hendrerit, ipsum augue ornare nulla, non luctus diam neque sit amet urna.\n")
>>    (insert (propertize "THISISACIRCLE" 'display (svg-image svg)))
>>    (insert " Aliquam posuere.\n")
>>    (pop-to-buffer buf)
>>    (goto-char (point-max))
>>    (forward-line -1)
>>    (toggle-truncate-lines 1)
>>    (message "PIXEL SIZE OF LINE ABOVE IMAGE: %S"
>> 	     (window-text-pixel-size nil (cons (point) -1) (point) nil nil nil t))))
>
> Does the patch below fix the issue?  (It should fix the recipe you
> posted, but you hinted that this is just the simplest way of seeing a
> more general problem, so I wonder whether that more general problem is
> also fixed.)

Hi,

I have applied your patch to master and here are the results I get with
the recipe at the end of this message:

With a not large enough window:
  FIRST LINE: (925 24 1); ABOVE IMAGE: (925 24 119)

With a large enough window (i.e., that can display the whole first
line):
  FIRST LINE: (1053 24 1); ABOVE IMAGE: (1062 24 119)

--8<---------------cut here---------------start------------->8---
;;; test-svg-pixel-position --- test pixel position for SVG images

;;; This small code creates a buffer with two lines, the first of
;;; which is long, and the second of which has an SVG image at start.
;;; Line truncation is turned on.  `window-text-pixel-size` returns
;;; differing results depending on whether truncation is actually in
;;; effect (alter the frame width to see this).

;;; Code:
(require 'svg)
(let ((buf "svg-pixel-demo")
      (svg (svg-create 50 25)))
  (svg-circle svg 25 25 25 :stroke-color "green")
  (with-current-buffer (get-buffer-create buf)
    (erase-buffer)
    (insert "Pellentesque condimentum, magna ut suscipit hendrerit, ipsum augue ornare nulla, non luctus diam neque sit amet urna.\n")
    (insert "Pellentesque condimentum, magna ut suscipit hendrerit, ipsum augue ornare nulla, non luctus diam neque sit amet urna.\n")
    (insert (propertize "THISISACIRCLE" 'display (svg-image svg)))
    (insert " Aliquam posuere.\n")
    (pop-to-buffer buf)
    (goto-char (point-max))
    (forward-line -1)
    (toggle-truncate-lines 1)
    (let ((above-image (window-text-pixel-size nil (cons (point) -1) (point) nil nil nil t)))
      (forward-line -1)
      (message "FIRST LINE: %S; ABOVE IMAGE: %S"
	       (window-text-pixel-size nil (cons (point) -1) (point) nil nil nil t)
	       above-image))))
--8<---------------cut here---------------end--------------->8---
-- 
Manuel Giraud