diff options
| author | Chong Yidong | 2008-07-25 17:06:23 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-07-25 17:06:23 +0000 |
| commit | e025c9c2fd7016ab3c1e3e968e975780fceb616b (patch) | |
| tree | 6cd8bd09bee7659b8450b5b451f8aa4c7d84b0c7 | |
| parent | c01c4e35bfbf09cb08c4c5f277c441123da65267 (diff) | |
| download | emacs-e025c9c2fd7016ab3c1e3e968e975780fceb616b.tar.gz emacs-e025c9c2fd7016ab3c1e3e968e975780fceb616b.zip | |
(svg_load_image): Use rsvg_handle_get_dimensions to check that image
size is valid. Use g_object_unref instead of deprecated
rsvg_handle_free to free rsvg handle.
| -rw-r--r-- | src/image.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/image.c b/src/image.c index ffc075332f9..5c9f5d5bdd1 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -8841,7 +8841,7 @@ svg_image_p (object) | |||
| 8841 | 8841 | ||
| 8842 | /* SVG library functions. */ | 8842 | /* SVG library functions. */ |
| 8843 | DEF_IMGLIB_FN (rsvg_handle_new); | 8843 | DEF_IMGLIB_FN (rsvg_handle_new); |
| 8844 | DEF_IMGLIB_FN (rsvg_handle_set_size_callback); | 8844 | DEF_IMGLIB_FN (rsvg_handle_get_dimensions); |
| 8845 | DEF_IMGLIB_FN (rsvg_handle_write); | 8845 | DEF_IMGLIB_FN (rsvg_handle_write); |
| 8846 | DEF_IMGLIB_FN (rsvg_handle_close); | 8846 | DEF_IMGLIB_FN (rsvg_handle_close); |
| 8847 | DEF_IMGLIB_FN (rsvg_handle_get_pixbuf); | 8847 | DEF_IMGLIB_FN (rsvg_handle_get_pixbuf); |
| @@ -8873,7 +8873,7 @@ init_svg_functions (Lisp_Object libraries) | |||
| 8873 | return 0; | 8873 | return 0; |
| 8874 | 8874 | ||
| 8875 | LOAD_IMGLIB_FN (library, rsvg_handle_new); | 8875 | LOAD_IMGLIB_FN (library, rsvg_handle_new); |
| 8876 | LOAD_IMGLIB_FN (library, rsvg_handle_set_size_callback); | 8876 | LOAD_IMGLIB_FN (library, rsvg_handle_get_dimensions); |
| 8877 | LOAD_IMGLIB_FN (library, rsvg_handle_write); | 8877 | LOAD_IMGLIB_FN (library, rsvg_handle_write); |
| 8878 | LOAD_IMGLIB_FN (library, rsvg_handle_close); | 8878 | LOAD_IMGLIB_FN (library, rsvg_handle_close); |
| 8879 | LOAD_IMGLIB_FN (library, rsvg_handle_get_pixbuf); | 8879 | LOAD_IMGLIB_FN (library, rsvg_handle_get_pixbuf); |
| @@ -8898,7 +8898,7 @@ init_svg_functions (Lisp_Object libraries) | |||
| 8898 | /* The following aliases for library functions allow dynamic loading | 8898 | /* The following aliases for library functions allow dynamic loading |
| 8899 | to be used on some platforms. */ | 8899 | to be used on some platforms. */ |
| 8900 | #define fn_rsvg_handle_new rsvg_handle_new | 8900 | #define fn_rsvg_handle_new rsvg_handle_new |
| 8901 | #define fn_rsvg_handle_set_size_callback rsvg_handle_set_size_callback | 8901 | #define fn_rsvg_handle_get_dimensions rsvg_handle_get_dimensions |
| 8902 | #define fn_rsvg_handle_write rsvg_handle_write | 8902 | #define fn_rsvg_handle_write rsvg_handle_write |
| 8903 | #define fn_rsvg_handle_close rsvg_handle_close | 8903 | #define fn_rsvg_handle_close rsvg_handle_close |
| 8904 | #define fn_rsvg_handle_get_pixbuf rsvg_handle_get_pixbuf | 8904 | #define fn_rsvg_handle_get_pixbuf rsvg_handle_get_pixbuf |
| @@ -8993,6 +8993,7 @@ svg_load_image (f, img, contents, size) | |||
| 8993 | unsigned int size; | 8993 | unsigned int size; |
| 8994 | { | 8994 | { |
| 8995 | RsvgHandle *rsvg_handle; | 8995 | RsvgHandle *rsvg_handle; |
| 8996 | RsvgDimensionData dimension_data; | ||
| 8996 | GError *error = NULL; | 8997 | GError *error = NULL; |
| 8997 | GdkPixbuf *pixbuf; | 8998 | GdkPixbuf *pixbuf; |
| 8998 | int width; | 8999 | int width; |
| @@ -9013,21 +9014,22 @@ svg_load_image (f, img, contents, size) | |||
| 9013 | 9014 | ||
| 9014 | /* Parse the contents argument and fill in the rsvg_handle. */ | 9015 | /* Parse the contents argument and fill in the rsvg_handle. */ |
| 9015 | fn_rsvg_handle_write (rsvg_handle, contents, size, &error); | 9016 | fn_rsvg_handle_write (rsvg_handle, contents, size, &error); |
| 9016 | if (error) | 9017 | if (error) goto rsvg_error; |
| 9017 | goto rsvg_error; | ||
| 9018 | 9018 | ||
| 9019 | /* The parsing is complete, rsvg_handle is ready to used, close it | 9019 | /* The parsing is complete, rsvg_handle is ready to used, close it |
| 9020 | for further writes. */ | 9020 | for further writes. */ |
| 9021 | fn_rsvg_handle_close (rsvg_handle, &error); | 9021 | fn_rsvg_handle_close (rsvg_handle, &error); |
| 9022 | if (error) | 9022 | if (error) goto rsvg_error; |
| 9023 | |||
| 9024 | fn_rsvg_handle_get_dimensions (rsvg_handle, &dimension_data); | ||
| 9025 | if (! check_image_size (f, dimension_data.width, dimension_data.height)) | ||
| 9023 | goto rsvg_error; | 9026 | goto rsvg_error; |
| 9024 | 9027 | ||
| 9025 | /* We can now get a valid pixel buffer from the svg file, if all | 9028 | /* We can now get a valid pixel buffer from the svg file, if all |
| 9026 | went ok. */ | 9029 | went ok. */ |
| 9027 | pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle); | 9030 | pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle); |
| 9028 | fn_rsvg_handle_free (rsvg_handle); | 9031 | if (!pixbuf) goto rsvg_error; |
| 9029 | if (!pixbuf) | 9032 | fn_g_object_unref (rsvg_handle); |
| 9030 | goto rsvg_error; | ||
| 9031 | 9033 | ||
| 9032 | /* Extract some meta data from the svg handle. */ | 9034 | /* Extract some meta data from the svg handle. */ |
| 9033 | width = fn_gdk_pixbuf_get_width (pixbuf); | 9035 | width = fn_gdk_pixbuf_get_width (pixbuf); |
| @@ -9148,6 +9150,7 @@ svg_load_image (f, img, contents, size) | |||
| 9148 | return 1; | 9150 | return 1; |
| 9149 | 9151 | ||
| 9150 | rsvg_error: | 9152 | rsvg_error: |
| 9153 | fn_g_object_unref (rsvg_handle); | ||
| 9151 | /* FIXME: Use error->message so the user knows what is the actual | 9154 | /* FIXME: Use error->message so the user knows what is the actual |
| 9152 | problem with the image. */ | 9155 | problem with the image. */ |
| 9153 | image_error ("Error parsing SVG image `%s'", img->spec, Qnil); | 9156 | image_error ("Error parsing SVG image `%s'", img->spec, Qnil); |