summaryrefslogtreecommitdiff
path: root/src/image.c
diff options
context:
space:
mode:
authorZajcev Evgeny <zevlg@yandex.ru>2020-12-03 18:37:18 +0300
committerAlan Third <alan@idiocy.org>2020-12-12 12:48:32 +0000
commitf45ce78c40e37bf2aab83d2d1183ed896c5c1c4c (patch)
tree489dd8e710e0e5a6eec73b95ace3ad47987c7688 /src/image.c
parent8ff70045c371253b3c2c22c4f62bd9f911bccd51 (diff)
downloademacs-f45ce78c40e37bf2aab83d2d1183ed896c5c1c4c.tar.gz
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 (enum svg_keyword_index): (svg_format): Add :base-uri. * lisp/svg.el (svg-embed-base-uri-image): New function to embed images located relative to images `:base-uri'
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/image.c b/src/image.c
index 54380d1cdfa..6b85ab78f61 100644
--- a/src/image.c
+++ b/src/image.c
@@ -9492,6 +9492,7 @@ enum svg_keyword_index
SVG_TYPE,
SVG_DATA,
SVG_FILE,
+ SVG_BASE_URI,
SVG_ASCENT,
SVG_MARGIN,
SVG_RELIEF,
@@ -9511,6 +9512,7 @@ static const struct image_keyword svg_format[SVG_LAST] =
{":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},
@@ -9743,10 +9745,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;
@@ -9766,15 +9769,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))
@@ -9782,10 +9786,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;
@@ -9886,6 +9890,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
FRAME_DISPLAY_INFO (f)->resy);
/* 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"
<https://gitlab.gnome.org/GNOME/librsvg/issues/33>. */
if (filename)
@@ -10058,6 +10063,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
FRAME_DISPLAY_INFO (f)->resy);
/* 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"
<https://gitlab.gnome.org/GNOME/librsvg/issues/33>. */
if (filename)
@@ -10740,6 +10746,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. */