From: Evgeny Zajcev <lg.zevlg@gmail.com>
To: Alan Third <alan@idiocy.org>, Evgeny Zajcev <lg.zevlg@gmail.com>,
Eli Zaretskii <eliz@gnu.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: Loading svg from memory using custom filename for base_uri
Date: Fri, 4 Dec 2020 02:02:52 +0300 [thread overview]
Message-ID: <CAO=W_Zp+9b7=B9ONaYL0ppjZ6od_C3FbS4Txrh_k01GpVRu2hA@mail.gmail.com> (raw)
In-Reply-To: <CAO=W_Zqt4drzBMaMODJpvb6jomm0LBvP=Wu0wvscDZ28g9PL4w@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 737 bytes --]
пт, 4 дек. 2020 г. в 01:11, Evgeny Zajcev <lg.zevlg@gmail.com>:
>
>
> чт, 3 дек. 2020 г. в 22:57, Alan Third <alan@idiocy.org>:
>
>> On Thu, Dec 03, 2020 at 08:50:15PM +0300, Evgeny Zajcev wrote:
>> >
>> > Here is updated patch, with support for `:base-uri` for :file image
>> spec as
>> > well
>>
>> It looks good to me. There are two things I think we need. One is to
>> add an entry for :base-uri to the svg_format array in image.c,
>
> done!
>
> and
>> some documentation, if you fancy writing it?
>>
>> Documentation better to write when `svg-embed` will support this feature.
>
I wrote a new function `svg-embed-base-uri-image' to do the job, and wrote
documentation for it.
--
lg
[-- Attachment #1.2: Type: text/html, Size: 1599 bytes --]
[-- Attachment #2: 0001-Explicitly-specify-svg-base_uri-using-base-uri-image.patch --]
[-- Type: text/x-patch, Size: 6913 bytes --]
From ac2f4fe1ec8b2d848d815322ba683f99c7db2e36 Mon Sep 17 00:00:00 2001
From: Zajcev Evgeny <zevlg@yandex.ru>
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
* lisp/svg.el (svg-embed-base-uri-image): New function to embed images
located relative to images `:base-uri'
---
doc/lispref/display.texi | 20 ++++++++++++++++++++
etc/NEWS | 11 +++++++++++
lisp/svg.el | 13 +++++++++++++
src/image.c | 20 +++++++++++++-------
4 files changed, 57 insertions(+), 7 deletions(-)
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index f86baf5936..0038a5c58d 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -5898,6 +5898,26 @@ SVG Images
@end lisp
@end defun
+@defun svg-embed-base-uri-image svg relative-filename &rest args
+To @var{svg} add an embedded (raster) image placed at
+@var{relative-filename}. @var{relative-filename} is searched inside
+@code{file-name-directory} of the @code{:base-uri} svg image property.
+This makes embedding large images work very fast.
+
+@lisp
+;; Embeding /tmp/subdir/rms.jpg and /tmp/another/rms.jpg
+(svg-embed-base-uri-image svg "subdir/rms.jpg"
+ :width "100px" :height "100px"
+ :x "50px" :y "75px")
+(svg-embed-base-uri-image svg "another/rms.jpg"
+ :width "100px" :height "100px"
+ :x "75px" :y "50px")
+(svg-image svg :scale 1.0
+ :base-uri "/tmp/dummy"
+ :width 175 :height 175)
+@end lisp
+@end defun
+
@defun svg-clip-path svg &rest args
Add a clipping path to @var{svg}. If applied to a shape via the
@var{:clip-path} property, parts of that shape which lie outside of
diff --git a/etc/NEWS b/etc/NEWS
index 2fb33e342e..392b81f03c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -24,6 +24,17 @@ applies, and please also update docstrings as needed.
\f
* 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.
+
++++
+** 'svg-embed-base-uri-image' added to embed images
+'svg-embed-base-uri-image' can be used to embed images located
+relatively to 'file-name-directory' of the ':base-uri' svg image property.
+This works much faster then 'svg-embed'.
+
** 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/lisp/svg.el b/lisp/svg.el
index eeb945f53b..6896e0088b 100644
--- a/lisp/svg.el
+++ b/lisp/svg.el
@@ -184,6 +184,19 @@ svg-embed
`((xlink:href . ,(svg--image-data image image-type datap))
,@(svg--arguments svg args)))))
+(defun svg-embed-base-uri-image (svg relative-filename &rest args)
+ "Insert image placed at RELATIVE-FILENAME into the SVG structure.
+RELATIVE-FILENAME will be searched in `file-name-directory' of the
+image's `:base-uri' property. If `:base-uri' is not specified for the
+image, then embedding won't work. Embedding large images using this
+function is much faster, then `svg-embed'."
+ (svg--append
+ svg
+ (dom-node
+ 'image
+ `((xlink:href . ,relative-filename)
+ ,@(svg--arguments svg args)))))
+
(defun svg-text (svg text &rest args)
"Add TEXT to SVG."
(svg--append
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"
<https://gitlab.gnome.org/GNOME/librsvg/issues/33>. */
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"
<https://gitlab.gnome.org/GNOME/librsvg/issues/33>. */
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
next prev parent reply other threads:[~2020-12-03 23:02 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 22:01 Loading svg from memory using custom filename for base_uri Evgeny Zajcev
2019-02-23 7:45 ` Eli Zaretskii
2019-02-25 10:23 ` Evgeny Zajcev
2020-12-03 15:47 ` Evgeny Zajcev
2020-12-03 16:16 ` Alan Third
2020-12-03 16:25 ` lg.zevlg
2020-12-03 16:30 ` Alan Third
2020-12-03 16:54 ` Evgeny Zajcev
2020-12-03 17:50 ` Evgeny Zajcev
2020-12-03 19:57 ` Alan Third
2020-12-03 22:11 ` Evgeny Zajcev
2020-12-03 23:02 ` Evgeny Zajcev [this message]
2020-12-12 5:46 ` lg.zevlg
2020-12-12 10:45 ` Alan Third
2020-12-12 11:52 ` Evgeny Zajcev
2020-12-12 12:50 ` Alan Third
2020-12-03 16:56 ` Vasilij Schneidermann
2020-12-03 16:50 ` Vasilij Schneidermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAO=W_Zp+9b7=B9ONaYL0ppjZ6od_C3FbS4Txrh_k01GpVRu2hA@mail.gmail.com' \
--to=lg.zevlg@gmail.com \
--cc=alan@idiocy.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).