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 16660c5928
)
This commit is contained in:

committed by
Michael Natterer

parent
38e87c2d16
commit
b7f22216e9
@ -413,62 +413,22 @@ load_rsvg_pixbuf (const gchar *filename,
|
|||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf = NULL;
|
GdkPixbuf *pixbuf = NULL;
|
||||||
RsvgHandle *handle;
|
RsvgHandle *handle;
|
||||||
GIOChannel *io;
|
GFile *file;
|
||||||
gchar *uri;
|
|
||||||
GIOStatus status = G_IO_STATUS_NORMAL;
|
|
||||||
gboolean success = TRUE;
|
|
||||||
|
|
||||||
io = g_io_channel_new_file (filename, "r", error);
|
file = g_file_new_for_path (filename);
|
||||||
if (!io)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
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 ();
|
g_object_unref (file);
|
||||||
rsvg_handle_set_dpi (handle, vals->resolution);
|
|
||||||
|
|
||||||
/* set the base URI so that librsvg can resolve relative paths */
|
if (!handle)
|
||||||
uri = g_filename_to_uri (filename, NULL, NULL);
|
|
||||||
if (uri)
|
|
||||||
{
|
{
|
||||||
gchar *p = strrchr (uri, '/');
|
return NULL;
|
||||||
|
|
||||||
if (p)
|
|
||||||
*p = '\0';
|
|
||||||
|
|
||||||
rsvg_handle_set_base_uri (handle, uri);
|
|
||||||
g_free (uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rsvg_handle_set_dpi (handle, vals->resolution);
|
||||||
rsvg_handle_set_size_callback (handle, load_set_size_callback, vals, NULL);
|
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);
|
g_object_unref (handle);
|
||||||
@ -478,76 +438,48 @@ load_rsvg_pixbuf (const gchar *filename,
|
|||||||
|
|
||||||
static GtkWidget *size_label = NULL;
|
static GtkWidget *size_label = NULL;
|
||||||
|
|
||||||
/* This function retrieves the pixel size from an SVG file. Parsing
|
/* This function retrieves the pixel size from an SVG file. */
|
||||||
* 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).
|
|
||||||
*/
|
|
||||||
static gboolean
|
static gboolean
|
||||||
load_rsvg_size (const gchar *filename,
|
load_rsvg_size (const gchar *filename,
|
||||||
SvgLoadVals *vals,
|
SvgLoadVals *vals,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
RsvgHandle *handle;
|
RsvgHandle *handle;
|
||||||
GIOChannel *io;
|
GFile *file;
|
||||||
GIOStatus status = G_IO_STATUS_NORMAL;
|
RsvgDimensionData dim;
|
||||||
gboolean success = TRUE;
|
gboolean has_size;
|
||||||
gboolean done = FALSE;
|
|
||||||
|
|
||||||
io = g_io_channel_new_file (filename, "r", error);
|
file = g_file_new_for_path (filename);
|
||||||
if (!io)
|
|
||||||
|
handle = rsvg_handle_new_from_gfile_sync (file, RSVG_HANDLE_FLAGS_NONE, NULL, error);
|
||||||
|
|
||||||
|
g_object_unref (file);
|
||||||
|
|
||||||
|
if (!handle)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
g_io_channel_set_encoding (io, NULL, NULL);
|
|
||||||
|
|
||||||
handle = rsvg_handle_new ();
|
|
||||||
rsvg_handle_set_dpi (handle, vals->resolution);
|
rsvg_handle_set_dpi (handle, vals->resolution);
|
||||||
|
|
||||||
vals->width = SVG_DEFAULT_SIZE;
|
|
||||||
vals->height = SVG_DEFAULT_SIZE;
|
|
||||||
|
|
||||||
while (success && status != G_IO_STATUS_EOF && (! done))
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
rsvg_handle_get_dimensions (handle, &dim);
|
rsvg_handle_get_dimensions (handle, &dim);
|
||||||
|
|
||||||
if (dim.width > 0 && dim.height > 0)
|
if (dim.width > 0 && dim.height > 0)
|
||||||
{
|
{
|
||||||
vals->width = dim.width;
|
vals->width = dim.width;
|
||||||
vals->height = dim.height;
|
vals->height = dim.height;
|
||||||
|
has_size = TRUE;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vals->width = SVG_DEFAULT_SIZE;
|
||||||
|
vals->height = SVG_DEFAULT_SIZE;
|
||||||
|
has_size = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size_label)
|
if (size_label)
|
||||||
{
|
{
|
||||||
if (done)
|
if (has_size)
|
||||||
{
|
{
|
||||||
gchar *text = g_strdup_printf (_("%d × %d"),
|
gchar *text = g_strdup_printf (_("%d × %d"),
|
||||||
vals->width, vals->height);
|
vals->width, vals->height);
|
||||||
@ -561,13 +493,12 @@ load_rsvg_size (const gchar *filename,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_io_channel_unref (io);
|
|
||||||
g_object_unref (handle);
|
g_object_unref (handle);
|
||||||
|
|
||||||
if (vals->width < 1) vals->width = 1;
|
if (vals->width < 1) vals->width = 1;
|
||||||
if (vals->height < 1) vals->height = 1;
|
if (vals->height < 1) vals->height = 1;
|
||||||
|
|
||||||
return success;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user