emacs-framebuffer

Emacs library to show images and documents in console using Linux framebuffer
Log | Files | Refs

commit 6906f41ae3517e79e611a4f917d79c93c24886a3
parent 6c7cede532498801ab552e6f99e415ef38029f6b
Author: Tomas Hlavaty <tom@logand.com>
Date:   Wed,  2 Sep 2020 22:36:17 +0200

add svg support

Diffstat:
Memacs-framebuffer.el | 27+++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -17,7 +17,7 @@ ;;; - sha256sum from coreutils ;;; - pdftocairo and pdfinfo from poppler-utils to display pdf ;;; - abiword to display abw, doc, docx, odt, rtf -;;; - imagemagick to modify images +;;; - imagemagick to modify images and svg support ;;; ;;; Example configuration: ;;; @@ -79,6 +79,7 @@ ((string-match "\\.\\(pnm\\|PNM\\)\\'" name) 'pnm) ((string-match "\\.\\(ppm\\|PPM\\)\\'" name) 'ppm) ((string-match "\\.\\(rtf\\|RTF\\)\\'" name) 'rtf) + ((string-match "\\.\\(svg\\|SVG\\)\\'" name) 'svg) ((string-match "\\.\\(tiff?\\|TIFF?\\)\\'" name) 'tiff) ((string-match "\\.\\(xbm\\|XBM\\)\\'" name) 'xbm) ((string-match "\\.\\(xpm\\|XPM\\)\\'" name) 'xpm) @@ -143,9 +144,20 @@ (call-process "pdftocairo" nil nil nil "-singlefile" "-f" page "-l" page "-png" (expand-file-name file) output)) ofile)) +(defun framebuffer-cache-svg-to-png (file) + (let ((ofile (concat (or framebuffer-cache-directory (temporary-file-directory)) + "/" + (framebuffer-file-hash file) + ".png"))) + (unless (file-readable-p ofile) + (call-process "convert" nil nil nil (expand-file-name file) ofile)) + ofile)) + (defun framebuffer-draw (x y w h sx sy sw sh file) (let ((format (framebuffer-file-format file))) (case format + (svg + (setq file (framebuffer-cache-svg-to-png file))) ((abw odt rtf doc docx) (setq file (framebuffer-cache-to-pdf format file))))) (case (framebuffer-file-format file) @@ -292,8 +304,15 @@ ((?1 ?2 ?3 ?4 ?5 ?6) (search-forward-regexp "^\\([0-9]+\\) \\([0-9]+\\)$") (cons (read (match-string 1)) (read (match-string 2)))))) - (?< ;; abw + (?< ;; abw svg (case (framebuffer-next-u8 brook) + (?s + (case (framebuffer-next-u8 brook) + (?v + (case (framebuffer-next-u8 brook) + (?g + (framebuffer-image-size + (framebuffer-cache-svg-to-png file))))))) (?? (case (framebuffer-next-u8 brook) (?x @@ -305,6 +324,9 @@ ((? ) (let ((xml (xml-parse-file file))) (ecase (caar xml) + (svg + (framebuffer-image-size + (framebuffer-cache-svg-to-png file))) (abiword (framebuffer-pdf-page-size (framebuffer-cache-to-pdf 'abw file)))))))))))))))) @@ -598,6 +620,7 @@ (add-to-list 'auto-mode-alist '("\\.\\(pdf\\|PDF\\)\\'" . framebuffer-image-mode)) (add-to-list 'auto-mode-alist '("\\.\\(png\\|PNG\\)\\'" . framebuffer-image-mode)) (add-to-list 'auto-mode-alist '("\\.\\(rtf\\|RTF\\)\\'" . framebuffer-image-mode)) + (add-to-list 'auto-mode-alist '("\\.\\(svg\\|SVG\\)\\'" . framebuffer-image-mode)) (add-to-list 'auto-mode-alist '("\\.\\(tiff?\\|TIFF?\\)\\'" . framebuffer-image-mode)) (add-to-list 'auto-mode-alist '("\\.\\(x[bp]m\\|X[BP]M\\)\\'" . framebuffer-image-mode)) (with-eval-after-load 'dired