Commit 1929dc10 authored by Dom Lachowicz's avatar Dom Lachowicz

rsvg's convenience API should now be able to transparently handle remote files...

rsvg's convenience API should now be able to transparently handle remote files via Gnome VFS, if available
parent 62df0562
2004-11-17 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-file-util.c: RSVG's convenience API should now be able to transparently handle remote files via gnome-vfs, if available.
* rsvg.c: Some Win32/Unix path portability changes
2004-11-17 Caleb Moore <c.moore@student.unsw.edu.au> 2004-11-17 Caleb Moore <c.moore@student.unsw.edu.au>
* rsvg-defs.c: Interfile vfs linking now implemented. Utility api automatically gives contextual information. * rsvg-defs.c: Interfile vfs linking now implemented. Utility api automatically gives contextual information.
......
...@@ -120,33 +120,33 @@ rsvg_pixbuf_from_file_with_size_data_ex (RsvgHandle * handle, ...@@ -120,33 +120,33 @@ rsvg_pixbuf_from_file_with_size_data_ex (RsvgHandle * handle,
struct RsvgSizeCallbackData * data, struct RsvgSizeCallbackData * data,
GError ** error) GError ** error)
{ {
guchar chars[SVG_BUFFER_SIZE];
GdkPixbuf *retval; GdkPixbuf *retval;
gint result;
FILE *f = fopen (file_name, "rb");
gchar *base_uri; gchar *base_uri;
GByteArray *f;
if (!f) base_uri = rsvg_get_base_uri_from_filename(file_name);
f = _rsvg_acquire_xlink_href_resource (file_name, base_uri, error);
if (f)
{ {
g_set_error (error, G_FILE_ERROR, rsvg_handle_set_base_uri (handle, base_uri);
g_file_error_from_errno (errno),
g_strerror (errno)); rsvg_handle_set_size_callback (handle, rsvg_size_callback, data, NULL);
return NULL;
rsvg_handle_write (handle, f->data, f->len, error);
rsvg_handle_close (handle, error);
retval = rsvg_handle_get_pixbuf (handle);
g_byte_array_free (f, TRUE);
}
else
{
retval = NULL;
} }
base_uri = rsvg_get_base_uri_from_filename(file_name);
rsvg_handle_set_base_uri (handle, base_uri);
g_free(base_uri); g_free(base_uri);
rsvg_handle_set_size_callback (handle, rsvg_size_callback, data, NULL);
while (!feof(f) && !ferror(f) && ((result = fread (chars, 1, SVG_BUFFER_SIZE, f)) > 0))
rsvg_handle_write (handle, chars, result, error);
rsvg_handle_close (handle, error);
retval = rsvg_handle_get_pixbuf (handle);
fclose (f);
return retval; return retval;
} }
...@@ -187,27 +187,17 @@ rsvg_pixbuf_from_data_with_size_data (const guchar * buff, ...@@ -187,27 +187,17 @@ rsvg_pixbuf_from_data_with_size_data (const guchar * buff,
} }
static GdkPixbuf * static GdkPixbuf *
rsvg_pixbuf_from_stdio_file_with_size_data(FILE * f, rsvg_pixbuf_from_stdio_file_with_size_data(GByteArray *f,
struct RsvgSizeCallbackData * data, struct RsvgSizeCallbackData * data,
gchar *base_uri, gchar *base_uri,
GError ** error) GError ** error)
{ {
RsvgHandle * handle; RsvgHandle * handle;
GdkPixbuf * retval; GdkPixbuf * retval;
guchar chars[SVG_BUFFER_SIZE]; const guchar * chars = f->data;
int result;
result = fread (chars, 1, SVG_BUFFER_SIZE, f);
if (result == 0) {
g_set_error (error, G_FILE_ERROR,
g_file_error_from_errno (errno),
g_strerror (errno));
return NULL;
}
/* test for GZ marker */ /* test for GZ marker */
if ((result >= 2) && (chars[0] == (guchar)0x1f) && (chars[1] == (guchar)0x8b)) if ((f->len >= 2) && (chars[0] == (guchar)0x1f) && (chars[1] == (guchar)0x8b))
handle = rsvg_handle_new_gz (); handle = rsvg_handle_new_gz ();
else else
handle = rsvg_handle_new (); handle = rsvg_handle_new ();
...@@ -222,11 +212,8 @@ rsvg_pixbuf_from_stdio_file_with_size_data(FILE * f, ...@@ -222,11 +212,8 @@ rsvg_pixbuf_from_stdio_file_with_size_data(FILE * f,
rsvg_handle_set_base_uri(handle, base_uri); rsvg_handle_set_base_uri(handle, base_uri);
rsvg_handle_write (handle, chars, result, error); rsvg_handle_write (handle, f->data, f->len, error);
while (!feof(f) && !ferror(f) && ((result = fread (chars, 1, SVG_BUFFER_SIZE, f)) > 0))
rsvg_handle_write (handle, chars, result, error);
rsvg_handle_close (handle, error); rsvg_handle_close (handle, error);
retval = rsvg_handle_get_pixbuf (handle); retval = rsvg_handle_get_pixbuf (handle);
rsvg_handle_free (handle); rsvg_handle_free (handle);
...@@ -240,24 +227,24 @@ rsvg_pixbuf_from_file_with_size_data (const gchar * file_name, ...@@ -240,24 +227,24 @@ rsvg_pixbuf_from_file_with_size_data (const gchar * file_name,
GError ** error) GError ** error)
{ {
GdkPixbuf * pixbuf; GdkPixbuf * pixbuf;
FILE *f = fopen (file_name, "rb");
gchar * base_uri; gchar * base_uri;
GByteArray *f;
if (!f)
{
g_set_error (error, G_FILE_ERROR,
g_file_error_from_errno (errno),
g_strerror (errno));
return NULL;
}
base_uri = rsvg_get_base_uri_from_filename(file_name); base_uri = rsvg_get_base_uri_from_filename(file_name);
f = _rsvg_acquire_xlink_href_resource (file_name, base_uri, error);
pixbuf = rsvg_pixbuf_from_stdio_file_with_size_data(f, data, if (f)
base_uri, error); {
pixbuf = rsvg_pixbuf_from_stdio_file_with_size_data(f, data,
base_uri, error);
g_byte_array_free (f, TRUE);
}
else
{
pixbuf = NULL;
}
g_free(base_uri); g_free(base_uri);
fclose(f);
return pixbuf; return pixbuf;
} }
......
...@@ -1436,7 +1436,7 @@ rsvg_get_base_uri_from_filename(const gchar * file_name) ...@@ -1436,7 +1436,7 @@ rsvg_get_base_uri_from_filename(const gchar * file_name)
last = 0; last = 0;
for (i = 0; file_name[i] != '\0'; i++) for (i = 0; file_name[i] != '\0'; i++)
if (file_name[i] == '/') if (file_name[i] == G_DIR_SEPARATOR)
last = i; last = i;
base_uri = g_new(gchar, i + 2); base_uri = g_new(gchar, i + 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment