aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2026-02-21 19:34:59 +0200
committerEli Zaretskii2026-02-21 19:34:59 +0200
commitc6cedfbb2f29992c911a9a730d1567bf6a9adbad (patch)
treeb61db6c3eca4603cfc4640b493b7995d375c82fb /src
parent9d98450f3636fb36c609bfa0708892f179d19075 (diff)
parent7478e6ae7d047abd19263578605e64df714f5a43 (diff)
downloademacs-c6cedfbb2f29992c911a9a730d1567bf6a9adbad.tar.gz
emacs-c6cedfbb2f29992c911a9a730d1567bf6a9adbad.zip
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs
Diffstat (limited to 'src')
-rw-r--r--src/image.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/image.c b/src/image.c
index c81da7e7b25..8dfab77ce43 100644
--- a/src/image.c
+++ b/src/image.c
@@ -12156,6 +12156,31 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
12156 12156
12157 rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, 12157 rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx,
12158 FRAME_DISPLAY_INFO (f)->resy); 12158 FRAME_DISPLAY_INFO (f)->resy);
12159
12160#if LIBRSVG_CHECK_VERSION (2, 48, 0)
12161 Lisp_Object user_css = image_spec_value (img->spec, QCcss, NULL);
12162 if (!STRINGP (user_css))
12163 user_css = make_string("", 0);
12164
12165 /* Generate the CSS for the SVG image.
12166
12167 We use this to set the font (font-family in CSS lingo) and the font
12168 size. We can extend this to handle any CSS values SVG supports,
12169 however it's only available in librsvg 2.48 and above so some
12170 things we could set here are handled in the wrapper below. */
12171 Lisp_Object css = make_formatted_string ("svg{"
12172 " font-family: \"%s\";"
12173 " font-size:%dpx;"
12174 "}"
12175 "%s",
12176 img->face_font_family,
12177 img->face_font_size,
12178 SDATA(user_css));
12179
12180 rsvg_handle_set_stylesheet (rsvg_handle, (guint8 *) SDATA (css),
12181 SBYTES (css), NULL);
12182#endif
12183
12159#else 12184#else
12160 /* Make a handle to a new rsvg object. */ 12185 /* Make a handle to a new rsvg object. */
12161 rsvg_handle = rsvg_handle_new (); 12186 rsvg_handle = rsvg_handle_new ();
@@ -12323,9 +12348,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
12323 static char const wrapper[] = 12348 static char const wrapper[] =
12324 "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" " 12349 "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
12325 "xmlns:xi=\"http://www.w3.org/2001/XInclude\" " 12350 "xmlns:xi=\"http://www.w3.org/2001/XInclude\" "
12351 "style=\"color: #%06X;\" "
12326 "width=\"%d\" height=\"%d\" preserveAspectRatio=\"none\" " 12352 "width=\"%d\" height=\"%d\" preserveAspectRatio=\"none\" "
12327 "viewBox=\"0 0 %f %f\">" 12353 "viewBox=\"0 0 %f %f\">"
12328 "<style>%s</style>"
12329 "<rect width=\"100%%\" height=\"100%%\" fill=\"#%06X\"/>" 12354 "<rect width=\"100%%\" height=\"100%%\" fill=\"#%06X\"/>"
12330 "<xi:include href=\"data:image/svg+xml;base64,%s\"></xi:include>" 12355 "<xi:include href=\"data:image/svg+xml;base64,%s\"></xi:include>"
12331 "</svg>"; 12356 "</svg>";
@@ -12354,33 +12379,10 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
12354#endif 12379#endif
12355 12380
12356 unsigned int color = foreground & 0xFFFFFF, fill = background & 0xFFFFFF; 12381 unsigned int color = foreground & 0xFFFFFF, fill = background & 0xFFFFFF;
12357
12358 Lisp_Object user_css = image_spec_value (img->spec, QCcss, NULL);
12359 if (!STRINGP (user_css))
12360 user_css = make_string("", 0);
12361
12362 /* Generate the CSS for the SVG image.
12363
12364 We use this to set the "current color", font (font-family in CSS
12365 lingo) and the font size. We can extend this to handle any CSS
12366 values SVG supports. We append the user CSS, which should allow
12367 the user to over-ride anything we set in our defaults. This gets
12368 inserted in the SVG's style element. */
12369 Lisp_Object css = make_formatted_string ("svg{"
12370 " font-family: \"%s\";"
12371 " font-size: %dpx;"
12372 " color: #%06X;"
12373 "}"
12374 "%s",
12375 img->face_font_family,
12376 img->face_font_size,
12377 color, SDATA(user_css));
12378
12379 wrapped_contents 12382 wrapped_contents
12380 = make_formatted_string (wrapper, width, height, 12383 = make_formatted_string (wrapper, color, width, height,
12381 viewbox_width, viewbox_height, 12384 viewbox_width, viewbox_height,
12382 SDATA(css), fill, 12385 fill, SSDATA (encoded_contents));
12383 SSDATA (encoded_contents));
12384 } 12386 }
12385 12387
12386 /* Now we parse the wrapped version. */ 12388 /* Now we parse the wrapped version. */
@@ -12402,6 +12404,13 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
12402 12404
12403 rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, 12405 rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx,
12404 FRAME_DISPLAY_INFO (f)->resy); 12406 FRAME_DISPLAY_INFO (f)->resy);
12407
12408#if LIBRSVG_CHECK_VERSION (2, 48, 0)
12409 /* Set the CSS for the wrapped SVG. See the comment above the
12410 previous use of 'css'. */
12411 rsvg_handle_set_stylesheet (rsvg_handle, (guint8 *) SDATA (css),
12412 SBYTES (css), NULL);
12413#endif
12405#else 12414#else
12406 /* Make a handle to a new rsvg object. */ 12415 /* Make a handle to a new rsvg object. */
12407 rsvg_handle = rsvg_handle_new (); 12416 rsvg_handle = rsvg_handle_new ();