From 230359a4bd7ca75a28441f7e5fae6ef1440a8c1b Mon Sep 17 00:00:00 2001 From: Zajcev Evgeny Date: Thu, 3 Dec 2020 18:37:18 +0300 Subject: [PATCH] Explicitly specify svg base_uri using `:base-uri' image property * src/image.c (svg_load): Check `:base-uri' image property to explicitly set base_uri for images embedded into SVG --- etc/NEWS | 6 ++++++ src/image.c | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 2fb33e342e..493e456c6c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -24,6 +24,12 @@ applies, and please also update docstrings as needed. * Installation Changes in Emacs 28.1 +--- +** Can explicitly specify base_uri for svg images. +':base-uri' image property can be used to explicitly specify base_uri +for embedded images into svg. ':base-uri' is supported for both file +and data svg images. + ** Cairo graphics library is now used by default if found. '--with-cairo' is now the default, if the appropriate development files are found by 'configure'. Note that building with Cairo means using diff --git a/src/image.c b/src/image.c index 5eb4132295..89ebc60c6c 100644 --- a/src/image.c +++ b/src/image.c @@ -9472,6 +9472,7 @@ DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0, {":type", IMAGE_SYMBOL_VALUE, 1}, {":data", IMAGE_STRING_VALUE, 0}, {":file", IMAGE_STRING_VALUE, 0}, + {":base-uri", IMAGE_STRING_VALUE, 0}, {":ascent", IMAGE_ASCENT_VALUE, 0}, {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0}, {":relief", IMAGE_INTEGER_VALUE, 0}, @@ -9698,10 +9699,11 @@ init_svg_functions (void) svg_load (struct frame *f, struct image *img) { bool success_p = 0; - Lisp_Object file_name; + Lisp_Object file_name, base_uri; /* If IMG->spec specifies a file name, create a non-file spec from it. */ file_name = image_spec_value (img->spec, QCfile, NULL); + base_uri = image_spec_value (img->spec, QCbase_uri, NULL); if (STRINGP (file_name)) { int fd; @@ -9721,15 +9723,16 @@ svg_load (struct frame *f, struct image *img) return 0; } /* If the file was slurped into memory properly, parse it. */ - success_p = svg_load_image (f, img, contents, size, - SSDATA (ENCODE_FILE (file))); + if (!STRINGP (base_uri)) + base_uri = ENCODE_FILE (file); + success_p = svg_load_image (f, img, contents, size, SSDATA (base_uri)); xfree (contents); } /* Else it's not a file, it's a Lisp object. Load the image from a Lisp object rather than a file. */ else { - Lisp_Object data, original_filename; + Lisp_Object data; data = image_spec_value (img->spec, QCdata, NULL); if (!STRINGP (data)) @@ -9737,10 +9740,10 @@ svg_load (struct frame *f, struct image *img) image_error ("Invalid image data `%s'", data); return 0; } - original_filename = BVAR (current_buffer, filename); + if (!STRINGP (base_uri)) + base_uri = BVAR (current_buffer, filename); success_p = svg_load_image (f, img, SSDATA (data), SBYTES (data), - (NILP (original_filename) ? NULL - : SSDATA (original_filename))); + (NILP (base_uri) ? NULL : SSDATA (base_uri))); } return success_p; @@ -9838,6 +9841,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, eassume (rsvg_handle); /* Set base_uri for properly handling referenced images (via 'href'). + Can be explicitly specified using `:base_uri' image property. See rsvg bug 596114 - "image refs are relative to curdir, not .svg file" . */ if (filename) @@ -10002,6 +10006,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, eassume (rsvg_handle); /* Set base_uri for properly handling referenced images (via 'href'). + Can be explicitly specified using `:base_uri' image property. See rsvg bug 596114 - "image refs are relative to curdir, not .svg file" . */ if (filename) @@ -10684,6 +10689,7 @@ syms_of_image (void) #if defined (HAVE_RSVG) DEFSYM (Qsvg, "svg"); + DEFSYM (QCbase_uri, ":base-uri"); add_image_type (Qsvg); #ifdef HAVE_NTGUI /* Other libraries used directly by svg code. */ -- 2.25.1