unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: Re: SVG/PNG images in toolbars?
Date: Sat, 14 Oct 2017 04:15:15 +0200	[thread overview]
Message-ID: <5b6aaac8-6e10-4458-7947-3ac4bd40b47c@gmail.com> (raw)
In-Reply-To: <f7393660-4ca7-67c3-6f88-ec9741b109af@gmail.com>

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)))




  parent reply	other threads:[~2017-10-14  2:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13 15:07 SVG/PNG images in toolbars? Clément Pit-Claudel
2017-10-13 16:11 ` Eli Zaretskii
2017-10-13 22:49   ` Clément Pit-Claudel
2017-10-14  6:51     ` Eli Zaretskii
2017-10-14  2:15 ` Clément Pit-Claudel [this message]
2017-10-14  7:13   ` Eli Zaretskii
2017-11-19  2:31     ` Clément Pit-Claudel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b6aaac8-6e10-4458-7947-3ac4bd40b47c@gmail.com \
    --to=cpitclaudel@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).