help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: make a drawing with Emacs


From: Tomas Hlavaty
Subject: Re: make a drawing with Emacs
Date: Wed, 02 Sep 2020 23:10:29 +0200

>> That might be an emacs-nox thing, perhaps?
>
> Your Emacs has to be able to display svg images.

It is a shame that image code in emacs is completely dependent on unsafe
foreign libraries and tightly coupled with graphics toolkits.

> Your easiest bet is that you are just missing librsvg (package
> librsvg2-2 or thereabouts, if you are on Debian) -- but of course,
> your Emacs has to be compiled with SVG support built in (no idea
> whether emacs-nox does).

Here is an alternative which works even on console without any graphics
toolkit compiled in:

(require 'xml)
(with-temp-buffer
  (xml-print
   '((svg
      ((xmlns . "http://www.w3.org/2000/svg";)
       (viewBox . "0 0 100 100"))
      (circle
       ((cx . "50") (cy . "50") (r . "20"))))))
  (write-file "/tmp/a.svg"))

The /tmp/a.svg file will contain the SVG image.

Now the nice part of doing it in pure Elisp is that you can refactor the
code into useful functions as you need.  For example:

(defun svg (x y w h &rest body)
  `((svg
     ((xmlns . "http://www.w3.org/2000/svg";)
      (viewBox . ,(format "%s %s %s %s" x y w h)))
     ,@body)))

(defun svg-circle (cx cy r)
  `(circle
    ((cx . ,(format "%s" cx)
     (cy . ,(format "%s" cy))
     (r . ,(format "%s" r))))))

(with-temp-buffer
  (xml-print
   (svg 0 0 100 100 (svg-circle 50 50 20)))
  (write-file "/tmp/a.svg"))

You can then display the generated image in the console using
https://logand.com/sw/emacs-framebuffer/file/emacs-framebuffer.el.html



reply via email to

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