>From db9af103944959be640a53fcf0f0b696f25d553f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 18 May 2019 10:00:26 -0700 Subject: [PATCH] For SVG, 8192 is the new 256 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefer librsvg for display of splash.svg When both librsvg and Imagemagick are available, Emacs should prefer librsvg to render SVG images. However, Emacs was using Imagemagick to render its own splash.svg file because image-type-from-file-header returned nil for that file. * lisp/image.el (image-type-from-buffer) (image-type-from-file-header): Look at the first 8192 bytes of the image, not just the first 256. For Emacs’s own splash.svg file, image-type-header-regexps needs to look at 939 bytes. 8192 bytes is a reasonable number nowadays given typical file system design. * test/lisp/image-tests.el (image-tests--emacs-images-directory): New contant. (image-type-from-file-header-test): New test. --- lisp/image.el | 4 ++-- test/lisp/image-tests.el | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lisp/image.el b/lisp/image.el index ba87d7f785..db11302086 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -315,7 +315,7 @@ image-type-from-buffer (buffer-substring (point-min) (min (point-max) - (+ (point-min) 256)))))) + (+ (point-min) 8192)))))) (setq image-type (cdr image-type)))) (setq type image-type types nil) @@ -339,7 +339,7 @@ image-type-from-file-header (file-readable-p file) (with-temp-buffer (set-buffer-multibyte nil) - (insert-file-contents-literally file nil 0 256) + (insert-file-contents-literally file nil 0 8192) (image-type-from-buffer)))) diff --git a/test/lisp/image-tests.el b/test/lisp/image-tests.el index 89b926e629..621646e575 100644 --- a/test/lisp/image-tests.el +++ b/test/lisp/image-tests.el @@ -22,6 +22,10 @@ (require 'ert) (require 'image) +(defconst image-tests--emacs-images-directory + (expand-file-name "../etc/images" (getenv "EMACS_TEST_DIRECTORY")) + "Directory containing Emacs images.") + (ert-deftest image--set-property () "Test `image--set-property' behavior." (let ((image (list 'image))) @@ -42,4 +46,11 @@ (setf (image-property image :width) nil) (should (equal image '(image))))) +(ert-deftest image-type-from-file-header-test () + "Test image-type-from-file-header." + (should (eq 'svg + (image-type-from-file-header + (expand-file-name "splash.svg" + image-tests--emacs-images-directory))))) + ;;; image-tests.el ends here -- 2.17.1