Commit 073f6804 authored by Dom Lachowicz's avatar Dom Lachowicz

better SVGZ support through the old API

parent 3957dd02
2003-01-30 Dom Lachowicz <cinamod@hotmail.com>
* gdk-pixbuf-loader: Conditionally support SVGZ files
* rsvg-file-util.c: Support SVGZ through the OLD API as well
2003-01-30 Dom Lachowicz <cinamod@hotmail.com>
* gdk-pixbuf-loader/io-svg.c: Conditionally support SVGZ files
* TODO: Remove SVGZ in pixbuf loader TODO-item
* tests/104201.svg, tests/folder_home-2.2.svg, tests/stock_home.svg,
tests/stock_paste.svg, tests/undo-128-d-sodipodi.svg.gz: New testcases
......
......@@ -87,6 +87,7 @@ dnl ===========================================================================
LIBGSF_CFLAGS=""
LIBGSF_LIBS=""
LIBGSFPKG=""
test_gsf=true
AC_ARG_WITH(svgz,[ --with-svgz Use libgsf for run-time decompression],[
if test "x$withval" = "xno"; then
......@@ -96,6 +97,7 @@ AC_ARG_WITH(svgz,[ --with-svgz Use libgsf for run-time decompression],[
if test "x$test_gsf" = "xtrue"; then
PKG_CHECK_MODULES(LIBGSF,[libgsf-1 >= 0.5])
LIBGSF_CFLAGS="$LIBGSF_CFLAGS -DHAVE_SVGZ=1"
LIBGSFPKG="libgsf-1"
fi
AM_CONDITIONAL(WITH_LIBGSF,[test "$LIBGSFPKG" != ""])
......
......@@ -26,6 +26,10 @@
#include "config.h"
#include "rsvg.h"
#if HAVE_SVGZ
#include "rsvg-gz.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
......@@ -108,15 +112,45 @@ rsvg_size_callback (int *width,
}
static GdkPixbuf *
rsvg_pixbuf_from_file_with_size_data (RsvgHandle * handle,
const gchar * file_name,
rsvg_pixbuf_from_file_with_size_data_ex (RsvgHandle * handle,
const gchar * file_name,
struct RsvgSizeCallbackData * data,
GError ** error)
{
guchar chars[SVG_BUFFER_SIZE];
GdkPixbuf *retval;
gint result;
FILE *f = fopen (file_name, "rb");
if (!f)
{
/* FIXME: Set up error. */
return NULL;
}
rsvg_handle_set_size_callback (handle, rsvg_size_callback, data, NULL);
while ((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;
}
static GdkPixbuf *
rsvg_pixbuf_from_file_with_size_data (const gchar * file_name,
struct RsvgSizeCallbackData * data,
GError ** error)
{
char chars[SVG_BUFFER_SIZE];
#if HAVE_SVGZ
RsvgHandle * handle;
guchar chars[SVG_BUFFER_SIZE];
GdkPixbuf *retval;
gint result;
FILE *f = fopen (file_name, "r");
FILE *f = fopen (file_name, "rb");
if (!f)
{
......@@ -124,7 +158,21 @@ rsvg_pixbuf_from_file_with_size_data (RsvgHandle * handle,
return NULL;
}
result = fread (chars, 1, SVG_BUFFER_SIZE, f);
if (result == 0) {
fclose (f);
return NULL;
}
/* test for GZ marker */
if ((result >= 2) && (chars[0] == (guchar)0x1f) && (chars[1] == (guchar)0x8b))
handle = rsvg_handle_new_gz ();
else
handle = rsvg_handle_new ();
rsvg_handle_set_size_callback (handle, rsvg_size_callback, data, NULL);
rsvg_handle_write (handle, chars, result, error);
while ((result = fread (chars, 1, SVG_BUFFER_SIZE, f)) > 0)
rsvg_handle_write (handle, chars, result, error);
......@@ -133,9 +181,17 @@ rsvg_pixbuf_from_file_with_size_data (RsvgHandle * handle,
retval = rsvg_handle_get_pixbuf (handle);
fclose (f);
rsvg_handle_free (handle);
return retval;
#else
RsvgHandle * handle = rsvg_handle_new ();
GdkPixbuf * retval = rsvg_pixbuf_from_file_with_size_data_ex (handle, file_name, data, error);
rsvg_handle_free (handle);
return retval;
#endif
}
/**
* rsvg_pixbuf_from_file_at_size_ex:
* @handle: The RSVG handle you wish to render with (either normal or gzipped)
......@@ -166,7 +222,7 @@ rsvg_pixbuf_from_file_at_size_ex (RsvgHandle * handle,
data.width = width;
data.height = height;
return rsvg_pixbuf_from_file_with_size_data (handle, file_name, &data, error);
return rsvg_pixbuf_from_file_with_size_data_ex (handle, file_name, &data, error);
}
/**
......@@ -222,7 +278,7 @@ rsvg_pixbuf_from_file_at_zoom_ex (RsvgHandle * handle,
data.x_zoom = x_zoom;
data.y_zoom = y_zoom;
return rsvg_pixbuf_from_file_with_size_data (handle, file_name, &data, error);
return rsvg_pixbuf_from_file_with_size_data_ex (handle, file_name, &data, error);
}
/**
......@@ -254,7 +310,7 @@ rsvg_pixbuf_from_file_at_max_size_ex (RsvgHandle * handle,
data.width = max_width;
data.height = max_height;
return rsvg_pixbuf_from_file_with_size_data (handle, file_name, &data, error);
return rsvg_pixbuf_from_file_with_size_data_ex (handle, file_name, &data, error);
}
/**
......@@ -296,7 +352,7 @@ rsvg_pixbuf_from_file_at_zoom_with_max_ex (RsvgHandle * handle,
data.width = max_width;
data.height = max_height;
return rsvg_pixbuf_from_file_with_size_data (handle, file_name, &data, error);
return rsvg_pixbuf_from_file_with_size_data_ex (handle, file_name, &data, error);
}
/**
......@@ -314,10 +370,7 @@ GdkPixbuf *
rsvg_pixbuf_from_file (const gchar *file_name,
GError **error)
{
RsvgHandle * handle = rsvg_handle_new ();
GdkPixbuf * pixbuf = rsvg_pixbuf_from_file_ex (handle, file_name, error);
rsvg_handle_free (handle);
return pixbuf;
return rsvg_pixbuf_from_file_at_size (file_name, -1, -1, error);
}
/**
......@@ -340,10 +393,16 @@ rsvg_pixbuf_from_file_at_zoom (const gchar *file_name,
double y_zoom,
GError **error)
{
RsvgHandle * handle = rsvg_handle_new ();
GdkPixbuf * pixbuf = rsvg_pixbuf_from_file_at_zoom_ex (handle, file_name, x_zoom, y_zoom, error);
rsvg_handle_free (handle);
return pixbuf;
struct RsvgSizeCallbackData data;
g_return_val_if_fail (file_name != NULL, NULL);
g_return_val_if_fail (x_zoom > 0.0 && y_zoom > 0.0, NULL);
data.type = RSVG_SIZE_ZOOM;
data.x_zoom = x_zoom;
data.y_zoom = y_zoom;
return rsvg_pixbuf_from_file_with_size_data (file_name, &data, error);
}
/**
......@@ -371,10 +430,18 @@ rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
gint max_height,
GError **error)
{
RsvgHandle * handle = rsvg_handle_new ();
GdkPixbuf * pixbuf = rsvg_pixbuf_from_file_at_zoom_with_max_ex (handle, file_name, x_zoom, y_zoom, max_width, max_height, error);
rsvg_handle_free (handle);
return pixbuf;
struct RsvgSizeCallbackData data;
g_return_val_if_fail (file_name != NULL, NULL);
g_return_val_if_fail (x_zoom > 0.0 && y_zoom > 0.0, NULL);
data.type = RSVG_SIZE_ZOOM_MAX;
data.x_zoom = x_zoom;
data.y_zoom = y_zoom;
data.width = max_width;
data.height = max_height;
return rsvg_pixbuf_from_file_with_size_data (file_name, &data, error);
}
/**
......@@ -398,10 +465,13 @@ rsvg_pixbuf_from_file_at_size (const gchar *file_name,
gint height,
GError **error)
{
RsvgHandle * handle = rsvg_handle_new ();
GdkPixbuf * pixbuf = rsvg_pixbuf_from_file_at_size_ex (handle, file_name, width, height, error);
rsvg_handle_free (handle);
return pixbuf;
struct RsvgSizeCallbackData data;
data.type = RSVG_SIZE_WH;
data.width = width;
data.height = height;
return rsvg_pixbuf_from_file_with_size_data (file_name, &data, error);
}
/**
......@@ -424,8 +494,11 @@ rsvg_pixbuf_from_file_at_max_size (const gchar *file_name,
gint max_height,
GError **error)
{
RsvgHandle * handle = rsvg_handle_new ();
GdkPixbuf * pixbuf = rsvg_pixbuf_from_file_at_max_size_ex (handle, file_name, max_width, max_height, error);
rsvg_handle_free (handle);
return pixbuf;
struct RsvgSizeCallbackData data;
data.type = RSVG_SIZE_WH_MAX;
data.width = max_width;
data.height = max_height;
return rsvg_pixbuf_from_file_with_size_data (file_name, &data, error);
}
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