Commit e43110f4 authored by Dom Lachowicz's avatar Dom Lachowicz

enable loading remote images

parent a1b3283e
2004-04-18 Dom Lachowicz <cinamod@hotmail.com>
* configure.in
* rsvg-shapes.c: Enable loading remote images
2004-04-18 Dodji Seketeli <dodji@gnome.org>
* configure.in: use libcroco 0.6.0
......
......@@ -57,6 +57,7 @@ librsvginc_HEADERS = \
librsvg-features.h
INCLUDES = \
$(LIBGNOME_VFS_CFLAGS) \
$(LIBGSF_CFLAGS) \
$(LIBCROCO_CFLAGS) \
-I$(top_srcdir) \
......@@ -69,6 +70,7 @@ INCLUDES = \
DEPS = $(top_builddir)/librsvg-2.la
LDADDS = \
$(LIBGNOME_VFS_LIBS) \
$(LIBGSF_LIBS) \
$(LIBCROCO_LIBS) \
$(top_builddir)/librsvg-2.la \
......
......@@ -126,6 +126,33 @@ AC_SUBST(LIBGSF_LIBS)
dnl ===========================================================================
LIBGNOME_VFS_CFLAGS=""
LIBGNOME_VFS_LIBS=""
LIBGNOME_VFS_PKG=""
test_gnome_vfs=true
AC_ARG_WITH(svgz,[ --with-gnome-vfs Use Gnome VFS for reading remote files],[
if test "x$withval" = "xno"; then
test_gnome_vfs=false
fi
])
if test "x$test_gnome_vfs" = "xtrue"; then
PKG_CHECK_MODULES(LIBGNOME_VFS,[gnome-vfs-2.0 >= 1.9.16], test_gnome_vfs=true, test_gnome_vfs=false)
fi
if test "x$test_gnome_vfs" = "xtrue"; then
LIBGNOME_VFS_CFLAGS="$LIBGNOME_VFS_CFLAGS -DHAVE_GNOME_VFS=1"
LIBGNOME_VFS_PKG="gnome-vfs-2.0"
else
AC_MSG_WARN([Gnome VFS support disabled, as request (Use --with-gnome-vfs to enable)])
fi
AM_CONDITIONAL(WITH_LIBGNOME_VFS,[test "$LIBGNOME_VFS_PKG" != ""])
AC_SUBST(LIBGNOME_VFSPKG)
AC_SUBST(LIBGNOME_VFS_CFLAGS)
AC_SUBST(LIBGNOME_VFS_LIBS)
dnl ===========================================================================
LIBCROCO_CFLAGS=""
......@@ -372,6 +399,7 @@ librsvg-$LIBRSVG_VERSION
Build theme engine: ${enable_gtk_theme}
Build Netscape plugin: ${build_mozilla_plugin}
Handle svgz files: ${test_gsf}
Use Gnome VFS: ${test_gnome_vfs}
Use libcroco for css parsing: ${test_croco}
Build documentation: ${enable_gtk_doc}
"
......
......@@ -3810,16 +3810,10 @@ rsvg_filter_primitive_image_render_ext (RsvgFilterPrimitive * self,
boundarys = rsvg_filter_primitive_get_bounds (self, ctx);
if(!strncmp(oself->href->str, "data:", 5))
return rsvg_pixbuf_new_from_data_at_size(oself->href->str,
boundarys.x2 - boundarys.x1,
boundarys.y2 - boundarys.y1,
FALSE, NULL);
else
return rsvg_pixbuf_new_from_file_at_size(oself->href->str,
boundarys.x2 - boundarys.x1,
boundarys.y2 - boundarys.y1,
FALSE, NULL);
return rsvg_pixbuf_new_from_href(oself->href->str,
boundarys.x2 - boundarys.x1,
boundarys.y2 - boundarys.y1,
FALSE, NULL);
}
static void
......
......@@ -46,7 +46,6 @@
/* 4/3 * (1-cos 45ƒ)/sin 45ƒ = 4/3 * sqrt(2) - 1 */
#define RSVG_ARC_MAGIC ((double) 0.5522847498)
/**
* rsvg_close_vpath: Close a vector path.
* @src: Source vector path.
......@@ -1242,7 +1241,7 @@ rsvg_pixbuf_ensure_alpha_channel(GdkPixbuf * pixbuf)
}
}
GdkPixbuf *
static GdkPixbuf *
rsvg_pixbuf_new_from_data_at_size (const char *data,
int width,
int height,
......@@ -1319,7 +1318,7 @@ rsvg_pixbuf_new_from_data_at_size (const char *data,
return rsvg_pixbuf_ensure_alpha_channel(pixbuf);
}
GdkPixbuf *
static GdkPixbuf *
rsvg_pixbuf_new_from_file_at_size (const char *filename,
int width,
int height,
......@@ -1396,6 +1395,117 @@ rsvg_pixbuf_new_from_file_at_size (const char *filename,
return rsvg_pixbuf_ensure_alpha_channel(pixbuf);
}
#ifdef HAVE_GNOME_VFS
#include <libgnomevfs/gnome-vfs.h>
static GdkPixbuf *
rsvg_pixbuf_new_from_vfs_at_size (const char *filename,
int width,
int height,
gboolean keep_aspect_ratio,
GError **error)
{
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf;
guchar buffer [4096];
GnomeVFSFileSize length;
GnomeVFSHandle *f = NULL;
GnomeVFSResult res;
struct {
gint width;
gint height;
gboolean keep_aspect_ratio;
} info;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
if (!gnome_vfs_initialized())
gnome_vfs_init();
res = gnome_vfs_open (&f, filename, GNOME_VFS_OPEN_READ);
if (res != GNOME_VFS_OK) {
g_set_error (error, rsvg_error_quark (), (gint) res,
gnome_vfs_result_to_string (res));
return NULL;
}
loader = gdk_pixbuf_loader_new ();
info.width = width;
info.height = height;
info.keep_aspect_ratio = keep_aspect_ratio;
g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
while (TRUE) {
res = gnome_vfs_read (f, buffer, sizeof (buffer), &length);
if (res == GNOME_VFS_OK && length > 0) {
if (!gdk_pixbuf_loader_write (loader, buffer, length, error)) {
gdk_pixbuf_loader_close (loader, NULL);
gnome_vfs_close (f);
g_object_unref (loader);
return NULL;
}
} else {
break;
}
}
gnome_vfs_close (f);
if (!gdk_pixbuf_loader_close (loader, error)) {
g_object_unref (loader);
return NULL;
}
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (!pixbuf) {
g_object_unref (loader);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
filename);
return NULL;
}
g_object_ref (pixbuf);
g_object_unref (loader);
return rsvg_pixbuf_ensure_alpha_channel(pixbuf);
}
#endif
GdkPixbuf *
rsvg_pixbuf_new_from_href (const char *href,
int w,
int h,
gboolean keep_aspect_ratio,
GError **err)
{
GdkPixbuf * img = NULL;
if(!strncmp(href, "data:", 5))
img = rsvg_pixbuf_new_from_data_at_size (href, w, h, keep_aspect_ratio, err);
if(!img)
img = rsvg_pixbuf_new_from_file_at_size (href, w, h, keep_aspect_ratio, err);
#ifdef HAVE_GNOME_VFS
if(!img)
img = rsvg_pixbuf_new_from_vfs_at_size (href, w, h, keep_aspect_ratio, err);
#endif
return img;
}
/* TODO 1: issue with affining alpha images - this is gdkpixbuf's fault...
* TODO 2: issue with rotating images - do we want to rotate the whole
* canvas 2x to get this right, only to have #1 bite us?
......@@ -1452,10 +1562,7 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
w *= state->affine[0];
h *= state->affine[3];
if(!strncmp(href, "data:", 5))
img = rsvg_pixbuf_new_from_data_at_size (href, w, h, FALSE, &err);
else
img = rsvg_pixbuf_new_from_file_at_size (href, w, h, FALSE, &err);
img = rsvg_pixbuf_new_from_href (href, w, h, FALSE, &err);
if (!img)
{
......
......@@ -74,17 +74,11 @@ struct _RsvgDefsDrawableUse {
};
GdkPixbuf *
rsvg_pixbuf_new_from_file_at_size (const char *filename,
int width,
int height,
gboolean keep_aspect_ratio,
GError **error);
GdkPixbuf *
rsvg_pixbuf_new_from_data_at_size (const char *data,
int width,
int height,
gboolean keep_aspect_ratio,
GError **error);
rsvg_pixbuf_new_from_href (const char *href,
int w,
int h,
gboolean keep_aspect_ratio,
GError **err);
void rsvg_defs_drawable_draw (RsvgDefsDrawable * self, RsvgHandle *ctx,
int dominate);
......
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