diff options
author | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2016-06-27 18:20:48 +0200 |
---|---|---|
committer | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2016-06-27 18:20:57 +0200 |
commit | 44caa96dc5c16cbc4ee1bb26ec880af2e2ecf9f8 (patch) | |
tree | 5b2f03fdd02d3ed687e9ffb9cba1f9516e883a10 /lisp/svg.el | |
parent | 058e8562775571790e48b1614e84a9617a9e1e17 (diff) | |
download | emacs-44caa96dc5c16cbc4ee1bb26ec880af2e2ecf9f8.tar.gz |
Add a new function `svg-embed'
* doc/lispref/display.texi (SVG Images): Document `svg-embed'.
* lisp/svg.el (svg-embed): New function.
(svg--image-data): Ditto.
Diffstat (limited to 'lisp/svg.el')
-rw-r--r-- | lisp/svg.el | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lisp/svg.el b/lisp/svg.el index c4f3270ea8a..c33b0923c26 100644 --- a/lisp/svg.el +++ b/lisp/svg.el @@ -137,6 +137,18 @@ POINTS is a list of x/y pairs." ", ")) ,@(svg--arguments svg args))))) +(defun svg-embed (svg image image-type datap &rest args) + "Insert IMAGE into the SVG structure. +IMAGE should be a file name if DATAP is nil, and a binary string +otherwise. IMAGE-TYPE should be a MIME image type, like +\"image/jpeg\" or the like." + (svg--append + svg + (dom-node + 'image + `((xlink:href . ,(svg--image-data image image-type datap)) + ,@(svg--arguments svg args))))) + (defun svg--append (svg node) (let ((old (and (dom-attr node 'id) (dom-by-id svg @@ -147,6 +159,17 @@ POINTS is a list of x/y pairs." (dom-append-child svg node))) (svg-possibly-update-image svg)) +(defun svg--image-data (image image-type datap) + (with-temp-buffer + (set-buffer-multibyte nil) + (if datap + (insert image) + (insert-file-contents image)) + (base64-encode-region (point-min) (point-max) t) + (goto-char (point-min)) + (insert "data:" image-type ";base64,") + (buffer-string))) + (defun svg--arguments (svg args) (let ((stroke-width (or (plist-get args :stroke-width) (dom-attr svg 'stroke-width))) |