16

The gtk-vector-screenshot program can be used to take vector screenshots of Gtk-3 applications. It seems to work by asking the application to redraw itself onto an SVG canvas.

Emacs on GNU/Linux can be built with Gtk+, but trying to use the aforementioned application on an Emacs window results in a screenshot that only contains GUI elements such as the menu bar; buffers are not rendered (I tried with and without Cairo). This is not too surprising, given that Emacs' buffer rendering happens at a pretty low level.

Still, is there a way to take scalable vector screenshots of Emacs?

Clément
  • 3,924
  • 1
  • 22
  • 37

2 Answers2

4

It's possible in Cairo builds, which are now the default on GNU/Linux!

(x-export-frames FRAMES TYPE)

Return image data of FRAMES in TYPE format.
FRAMES should be nil (the selected frame), a frame, or a list of
frames (each of which corresponds to one page).  Each frame should be
visible.  Optional arg TYPE should be either `pdf' (default), `png',
`postscript', or `svg'.  Supported types are determined by the
compile-time configuration of cairo.
Clément
  • 3,924
  • 1
  • 22
  • 37
2

According to the documentation Gtk+ widgets in Emacs are:

  • menus,
  • dialogs,
  • tool bars and
  • scroll bars

Buffers are rendered by Emacs itself. Neither the buffer nor the lines in a buffer are Gtk+ widgets. This means they do not know anything about the export functionality of Gtk+ widgets.

The best thing you can do is to use htmlfontify-buffer in order to embed the generated HTML into your SVG containing the widgets. But this will require some additional work to merge the HTML and SVG. But be aware that htmlfontify-buffer has also some limitations and does not work with every buffer.

ceving
  • 1,308
  • 1
  • 14
  • 28
  • I'm not sure this answers the question. I did mention `take-vector-screenshot` as an example, but I also mentioned that it wasn't surprising that it didn't work. `htmlfontify-buffer` has too many limitations to really qualify (it won't render overlays, display-string, line wraps, font fallback, etc.) – Clément Feb 16 '16 at 14:41
  • 1
    @Clément The short answer is: no way. – ceving Feb 16 '16 at 14:42
  • Is this personal opinion, or do you have evidence to back that claim? Given the number of rendering backends (Cairo, directly through X, Gtk, etc.) that Emacs has, one could imagine that a slight tweak to one of them might be enough. – Clément Feb 16 '16 at 15:18
  • 2
    @Clément Gtk+ can render to SVG, because Gtk+ uses Cairo, which has a [backend](https://en.wikipedia.org/wiki/Cairo_%28graphics%29#Available_back-ends) for SVG. Emacs does not use Cairo for the buffer rendering. But there is a experimental [branch](http://emacs.1067599.n5.nabble.com/Cairo-branch-td349305.html) for Cairo. Maybe in the near future it might be possible. – ceving Feb 17 '16 at 08:46
  • Cairo builds are now the default. – Clément Jul 04 '20 at 05:26