[gimp/gimp-2-10] file-svg: Use rsvg_handle_new_from_gfile_sync() instead of GIOChannel
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] file-svg: Use rsvg_handle_new_from_gfile_sync() instead of GIOChannel
- Date: Mon, 22 Jul 2019 23:07:37 +0000 (UTC)
commit b7f22216e9eb2ae2d9483c45d471a5807d0e97f4
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Jul 22 17:06:04 2019 -0500
file-svg: Use rsvg_handle_new_from_gfile_sync() instead of GIOChannel
The latter is obsolete, and rsvg_handle_write()/close() are deprecated
anyway.
(cherry picked from commit 16660c5928db9a826e19eb5f32afa2d0c632c919)
plug-ins/common/file-svg.c | 137 +++++++++++----------------------------------
1 file changed, 34 insertions(+), 103 deletions(-)
---
diff --git a/plug-ins/common/file-svg.c b/plug-ins/common/file-svg.c
index 9f3de881d1..6786bee2cb 100644
--- a/plug-ins/common/file-svg.c
+++ b/plug-ins/common/file-svg.c
@@ -413,63 +413,23 @@ load_rsvg_pixbuf (const gchar *filename,
{
GdkPixbuf *pixbuf = NULL;
RsvgHandle *handle;
- GIOChannel *io;
- gchar *uri;
- GIOStatus status = G_IO_STATUS_NORMAL;
- gboolean success = TRUE;
+ GFile *file;
- io = g_io_channel_new_file (filename, "r", error);
- if (!io)
- return NULL;
+ file = g_file_new_for_path (filename);
- g_io_channel_set_encoding (io, NULL, NULL);
+ handle = rsvg_handle_new_from_gfile_sync (file, RSVG_HANDLE_FLAGS_NONE, NULL, error);
- handle = rsvg_handle_new ();
- rsvg_handle_set_dpi (handle, vals->resolution);
+ g_object_unref (file);
- /* set the base URI so that librsvg can resolve relative paths */
- uri = g_filename_to_uri (filename, NULL, NULL);
- if (uri)
+ if (!handle)
{
- gchar *p = strrchr (uri, '/');
-
- if (p)
- *p = '\0';
-
- rsvg_handle_set_base_uri (handle, uri);
- g_free (uri);
+ return NULL;
}
+ rsvg_handle_set_dpi (handle, vals->resolution);
rsvg_handle_set_size_callback (handle, load_set_size_callback, vals, NULL);
- while (success && status != G_IO_STATUS_EOF)
- {
- gchar buf[8192];
- gsize len;
-
- status = g_io_channel_read_chars (io, buf, sizeof (buf), &len, error);
-
- switch (status)
- {
- case G_IO_STATUS_ERROR:
- success = FALSE;
- break;
- case G_IO_STATUS_EOF:
- success = rsvg_handle_close (handle, error);
- break;
- case G_IO_STATUS_NORMAL:
- success = rsvg_handle_write (handle,
- (const guchar *) buf, len, error);
- break;
- case G_IO_STATUS_AGAIN:
- break;
- }
- }
-
- g_io_channel_unref (io);
-
- if (success)
- pixbuf = rsvg_handle_get_pixbuf (handle);
+ pixbuf = rsvg_handle_get_pixbuf (handle);
g_object_unref (handle);
@@ -478,76 +438,48 @@ load_rsvg_pixbuf (const gchar *filename,
static GtkWidget *size_label = NULL;
-/* This function retrieves the pixel size from an SVG file. Parsing
- * stops after the first chunk that provided the parser with enough
- * information to determine the size. This is usually the opening
- * <svg> element and should thus be in the first chunk (1024 bytes).
- */
+/* This function retrieves the pixel size from an SVG file. */
static gboolean
load_rsvg_size (const gchar *filename,
SvgLoadVals *vals,
GError **error)
{
- RsvgHandle *handle;
- GIOChannel *io;
- GIOStatus status = G_IO_STATUS_NORMAL;
- gboolean success = TRUE;
- gboolean done = FALSE;
+ RsvgHandle *handle;
+ GFile *file;
+ RsvgDimensionData dim;
+ gboolean has_size;
- io = g_io_channel_new_file (filename, "r", error);
- if (!io)
- return FALSE;
+ file = g_file_new_for_path (filename);
- g_io_channel_set_encoding (io, NULL, NULL);
-
- handle = rsvg_handle_new ();
- rsvg_handle_set_dpi (handle, vals->resolution);
+ handle = rsvg_handle_new_from_gfile_sync (file, RSVG_HANDLE_FLAGS_NONE, NULL, error);
- vals->width = SVG_DEFAULT_SIZE;
- vals->height = SVG_DEFAULT_SIZE;
+ g_object_unref (file);
- while (success && status != G_IO_STATUS_EOF && (! done))
+ if (!handle)
{
- gchar buf[1024];
- gsize len;
- RsvgDimensionData dim = { 0, 0, 0.0, 0.0 };
-
- status = g_io_channel_read_chars (io, buf, sizeof (buf), &len, error);
-
- switch (status)
- {
- case G_IO_STATUS_ERROR:
- success = FALSE;
- break;
- case G_IO_STATUS_EOF:
- success = rsvg_handle_close (handle, error);
+ return FALSE;
+ }
- if (success)
- {
- rsvg_handle_get_dimensions (handle, &dim);
+ rsvg_handle_set_dpi (handle, vals->resolution);
- if (dim.width > 0 && dim.height > 0)
- {
- vals->width = dim.width;
- vals->height = dim.height;
+ rsvg_handle_get_dimensions (handle, &dim);
- done = TRUE;
- }
- }
-
- break;
- case G_IO_STATUS_NORMAL:
- success = rsvg_handle_write (handle,
- (const guchar *) buf, len, error);
- break;
- case G_IO_STATUS_AGAIN:
- break;
- }
+ if (dim.width > 0 && dim.height > 0)
+ {
+ vals->width = dim.width;
+ vals->height = dim.height;
+ has_size = TRUE;
+ }
+ else
+ {
+ vals->width = SVG_DEFAULT_SIZE;
+ vals->height = SVG_DEFAULT_SIZE;
+ has_size = FALSE;
}
if (size_label)
{
- if (done)
+ if (has_size)
{
gchar *text = g_strdup_printf (_("%d × %d"),
vals->width, vals->height);
@@ -561,13 +493,12 @@ load_rsvg_size (const gchar *filename,
}
}
- g_io_channel_unref (io);
g_object_unref (handle);
if (vals->width < 1) vals->width = 1;
if (vals->height < 1) vals->height = 1;
- return success;
+ return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]