TransWikia.com

Can I take vector (SVG) screenshots of Emacs?

Emacs Asked by Clément on September 2, 2021

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?

2 Answers

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.

Correct answer by Clément on September 2, 2021

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.

Answered by ceving on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP