From: Zajcev Evgeny Date: Thu, 3 Dec 2020 15:37:18 +0000 (+0300) Subject: Explicitly specify svg base_uri using `:base-uri' image property X-Git-Tag: emacs-28.0.90~4771 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a8e2143a5c03785742464406306fda7fce6caf04;p=emacs.git 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 --- diff --git a/src/image.c b/src/image.c index 0dd108a96b5..7012003ea13 100644 --- a/src/image.c +++ b/src/image.c @@ -9724,10 +9724,11 @@ static bool 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; @@ -9747,15 +9748,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)) @@ -9763,10 +9765,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; @@ -9864,6 +9866,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) @@ -10028,6 +10031,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) @@ -10710,6 +10714,7 @@ non-numeric, there is no explicit limit on the size of images. */); #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. */