Subject: bug#77429: 31.0.50; Image map and display slice on mode/header/tab line

From: David Ponce <[email-masked]>
Date: Tue, 1 Apr 2025 19:57:14 +0200

On 2025-04-01 17:43, Eli Zaretskii wrote:
>> Date: Tue, 1 Apr 2025 15:06:49 +0200
>> From:  David Ponce via "Bug reports for GNU Emacs,
>>   the Swiss army knife of text editors" <[email-masked]>
>>
>> (require 'svg)
>> (let* ((w 304)
>>          (h (frame-char-height))
>>          (svg (svg-create w h)))
>>     (svg-rectangle svg 0   0 100 h :fill "red")
>>     (svg-rectangle svg 102 0 100 h :fill "green")
>>     (svg-rectangle svg 204 0 100 h :fill "blue")
>>     (let* ((img (svg-image svg :scale 1
>>                            :map
>>                            `(
>>                              ((rect . ((0   . 0) . (100 . ,h)))
>>                               r (help-echo "RED"   pointer hand))
>>                              ((rect . ((102 . 0) . (202 . ,h)))
>>                               g (help-echo "GREEN" pointer hand))
>>                              ((rect . ((204 . 0) . (304 . ,h)))
>>                               b (help-echo "BLUE"  pointer hand))
>>                              )))
>>            (full (propertize " " 'display img))
>>            (cut  (propertize " " 'display `((slice 102 0 202 1.0) ,img)))
>>            (both (concat cut " " full)))
>>       (setq header-line-format both)
>>       (insert both "\n")))
>>
>> I'm reporting this inconsistency, at least to find out if it's a real
>> bug or a limitation that needs to be addressed by the programmer.
> 
> Bug.  And a very old one.  Should be fixed now on the master branch;
> please test.

It seems the bug is only partially fixed.  The image map behaves as
expected for the help-echo and pointer properties, but doesn't report
the correct hot spot ID.  The updated recipe below illustrates this:

(require 'svg)
(let* ((w 304)
        (h (frame-char-height))
        (svg (svg-create w h))
        (km (define-keymap
              "<r> <mouse-1>"
              (lambda () (interactive) (message "Red"))
              "<g> <mouse-1>"
              (lambda () (interactive) (message "Green"))
              "<b> <mouse-1>"
              (lambda () (interactive) (message "Blue")))))
   (svg-rectangle svg 0   0 100 h :fill "red")
   (svg-rectangle svg 102 0 100 h :fill "green")
   (svg-rectangle svg 204 0 100 h :fill "blue")
   (let* ((img (svg-image svg :scale 1
                          :map
                          `(
                            ((rect . ((0   . 0) . (100 . ,h)))
                             r (help-echo "RED"   pointer hand))
                            ((rect . ((102 . 0) . (202 . ,h)))
                             g (help-echo "GREEN" pointer hand))
                            ((rect . ((204 . 0) . (304 . ,h)))
                             b (help-echo "BLUE"  pointer hand))
                            )))
          (full (propertize " " 'display img
                            'keymap km))
          (cut  (propertize " " 'display `((slice 102 0 202 1.0) ,img)
                            'keymap km))
          (both (concat cut " " full)))
     (setq header-line-format both)
     (insert both "\n")))

Thanks!