From: Alan Third Date: Sat, 24 May 2025 20:12:22 +0000 (+0100) Subject: Move CSS into the SVG wrapper X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=bfd8e77f2669413a8ad3555300a1f3cd2717f5e4;p=emacs.git Move CSS into the SVG wrapper This allows CSS to be used with librsvg < 2.48. * src/image.c (svg_load_image): Move CSS construction and include "color". Also append the CSS passed in by the user rather than replacing it. (cherry picked from commit 9f5d17cd7219f72066488c6c57f77e4db9ca2563) --- diff --git a/src/image.c b/src/image.c index 745668d4cd1..c5caaf739e7 100644 --- a/src/image.c +++ b/src/image.c @@ -12078,26 +12078,6 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, FRAME_DISPLAY_INFO (f)->resy); - -#if LIBRSVG_CHECK_VERSION (2, 48, 0) - Lisp_Object lcss = image_spec_value (img->spec, QCcss, NULL); - if (!STRINGP (lcss)) - { - /* Generate the CSS for the SVG image. - - We use this to set the font (font-family in CSS lingo) and - the font size. We can extend this to handle any CSS values - SVG supports, however it's only available in librsvg 2.48 and - above so some things we could set here are handled in the - wrapper below. */ - lcss = make_formatted_string ("svg{font-family:\"%s\";font-size:%dpx}", - img->face_font_family, - img->face_font_size); - rsvg_handle_set_stylesheet (rsvg_handle, (guint8 *) SDATA (lcss), - SBYTES (lcss), NULL); - } -#endif - #else /* Make a handle to a new rsvg object. */ rsvg_handle = rsvg_handle_new (); @@ -12265,9 +12245,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents, static char const wrapper[] = "" + "" "" "" ""; @@ -12296,10 +12276,33 @@ svg_load_image (struct frame *f, struct image *img, char *contents, #endif unsigned int color = foreground & 0xFFFFFF, fill = background & 0xFFFFFF; + + Lisp_Object user_css = image_spec_value (img->spec, QCcss, NULL); + if (!STRINGP (user_css)) + user_css = make_string("", 0); + + /* Generate the CSS for the SVG image. + + We use this to set the "current color", font (font-family in CSS + lingo) and the font size. We can extend this to handle any CSS + values SVG supports. We append the user CSS, which should allow + the user to over-ride anything we set in our defaults. This gets + inserted in the SVG's style element. */ + Lisp_Object css = make_formatted_string ("svg{" + " font-family: \"%s\";" + " font-size: %dpx;" + " color: #%06X;" + "}" + "%s", + img->face_font_family, + img->face_font_size, + color, SDATA(user_css)); + wrapped_contents - = make_formatted_string (wrapper, color, width, height, + = make_formatted_string (wrapper, width, height, viewbox_width, viewbox_height, - fill, SSDATA (encoded_contents)); + SDATA(css), fill, + SSDATA (encoded_contents)); } /* Now we parse the wrapped version. */ @@ -12321,13 +12324,6 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, FRAME_DISPLAY_INFO (f)->resy); - -#if LIBRSVG_CHECK_VERSION (2, 48, 0) - /* Set the CSS for the wrapped SVG. See the comment above the - previous use of 'css'. */ - rsvg_handle_set_stylesheet (rsvg_handle, (guint8 *) SDATA (lcss), - SBYTES (lcss), NULL); -#endif #else /* Make a handle to a new rsvg object. */ rsvg_handle = rsvg_handle_new ();