emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SVG/PNG images in toolbars?


From: Clément Pit-Claudel
Subject: Re: SVG/PNG images in toolbars?
Date: Sat, 14 Oct 2017 04:15:15 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

On 2017-10-13 17:07, Clément Pit-Claudel wrote:
> Do we support any form of scalable graphics for toolbar icons, or at least 
> any format that supports anti-aliasing? All I can seem to get working is 
> XPM/XBM/PBM, but I can't find a statement that we don't support anything 
> better.

Answering my own question: although the convenience functions in tool-bar.el 
produce find-image specs refering only to XPM/XBM/PBM images, other images do 
seem to work.  I used the code below to post-process my tool-bar keymap, 
replacing XMP images with PNGs and SVGs.

Question: could we extend tool-bar--image-expression to return a form including 
references to SVGs and PNGs? I'd be happy to provide a patch.

Clément.

(defun cpc--tool-bar-add-item (command icon map)
  "Add an ICON running COMMAND to MAP."
  (tool-bar-local-item-from-menu
   command nil map cpc--mode-map
   :vert-only t :cpc--icon icon))

(defun cpc--tool-bar-cleanup-binding (binding)
  "Recompute :image spec in toolbar entry BINDING."
  (pcase binding
    (`(,key menu-item ,doc ,cmd . ,props)
     (-when-let* ((img (plist-get props :cpc--icon)))
       (let ((specs nil))
         (dolist (type '(xpm png svg))
           (push `(:type ,type :file ,(format "%s.%S" img type)) specs))
         (setq props (plist-put props :image `(find-image '(,@specs))))))
     `(,key menu-item ,doc ,cmd . ,props))
    (_ binding)))

(defun cpc--tool-bar-cleanup-map (map)
  "Replace image paths in MAP.
This is a hacky way to work around the fact that
`tool-bar-local-item-from-menu' doesn't include `png' files in
its `find-image' forms."
  (pcase map
    (`(keymap . ,bindings)
     `(keymap . ,(mapcar #'cpc--tool-bar-cleanup-binding bindings)))
    (_ map)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]