Commit 459c450e authored by Dom Lachowicz's avatar Dom Lachowicz

deprecate rsvg-gz. move its functionality into rsvghandle itself.

parent 260d03cd
2005-02-23 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-image.c: Fix bug 168182
* rsvg-image.c: Fix bug #168182
* test-display.c: rsvg-view now can view images on any medium that
gnome-vfs can see.
* *: Deprecate rsvg-gz. Move its functionality directly into RsvgHandle instead.
Greatly simplifies much code.
2005-02-23 Caleb Moore <c.moore@student.unsw.edu.au>
......@@ -12,7 +14,7 @@
2005-02-18 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-structure.c: bug 167813
* rsvg-structure.c: bug #167813
2005-2-17 Caleb Moore <c.moore@student.unsw.edu.au>
......
......@@ -18,7 +18,7 @@ libm = -lm
endif
headers = \
rsvg-gz.h \
rsvg-gz.h \
rsvg.h
enum_sources = \
......
......@@ -25,7 +25,6 @@
#include <stdlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gdk-pixbuf-io.h>
#include <rsvg-gz.h>
#include "rsvg-private.h"
typedef struct {
......@@ -112,11 +111,7 @@ gdk_pixbuf__svg_image_load_increment (gpointer data,
if (context->first_write == TRUE) {
context->first_write = FALSE;
/* lazy create a SVGZ or SVG loader */
if ((size >= 2) && (buf[0] == (guchar)0x1f) && (buf[1] == (guchar)0x8b))
context->handle = rsvg_handle_new_gz ();
else
context->handle = rsvg_handle_new ();
context->handle = rsvg_handle_new ();
if (!context->handle) {
rsvg_propegate_error (error, _("Error displaying image"), ERROR_DISPLAYING_IMAGE);
......
......@@ -27,7 +27,6 @@
#include "svg.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <rsvg.h>
#include <rsvg-gz.h>
GCache *pixbuf_cache = NULL;
......@@ -698,10 +697,7 @@ get_pixbuf(GByteArray * arr, gint width, gint height)
if(!arr || !arr->len)
return NULL;
if((arr->len >= 2) && (arr->data[0] == (guchar)0x1f) && (arr->data[1] == (guchar)0x8b))
handle = rsvg_handle_new_gz();
else
handle = rsvg_handle_new();
handle = rsvg_handle_new();
if (!handle)
return NULL;
......
......@@ -25,7 +25,6 @@
#include "config.h"
#include "rsvg-private.h"
#include "rsvg-defs.h"
#include "rsvg-gz.h"
#include "rsvg-styles.h"
#include "rsvg-image.h"
......
......@@ -26,7 +26,6 @@
#include "config.h"
#include "rsvg.h"
#include "rsvg-private.h"
#include "rsvg-gz.h"
#include <errno.h>
#include <stdio.h>
......@@ -161,15 +160,11 @@ rsvg_pixbuf_from_data_with_size_data (const guchar * buff,
RsvgHandle * handle;
GdkPixbuf * retval;
/* test for GZ marker */
if ((len >= 2) && (buff[0] == (guchar)0x1f) && (buff[1] == (guchar)0x8b))
handle = rsvg_handle_new_gz ();
else
handle = rsvg_handle_new ();
handle = rsvg_handle_new ();
if (!handle) {
g_set_error (error, rsvg_error_quark (), 0,
_("Error creating SVG reader (probably a gzipped SVG)"));
_("Error creating SVG reader"));
return NULL;
}
......@@ -194,17 +189,12 @@ rsvg_pixbuf_from_stdio_file_with_size_data(GByteArray *f,
{
RsvgHandle * handle;
GdkPixbuf * retval;
const guchar * chars = f->data;
/* test for GZ marker */
if ((f->len >= 2) && (chars[0] == (guchar)0x1f) && (chars[1] == (guchar)0x8b))
handle = rsvg_handle_new_gz ();
else
handle = rsvg_handle_new ();
handle = rsvg_handle_new ();
if (!handle) {
g_set_error (error, rsvg_error_quark (), 0,
_("Error creating SVG reader (probably a gzipped SVG)"));
_("Error creating SVG reader"));
return NULL;
}
......
......@@ -24,126 +24,15 @@
#include "rsvg-gz.h"
#include "rsvg-private.h"
#ifdef HAVE_SVGZ
#include <gsf/gsf-input-gzip.h>
#include <gsf/gsf-input-memory.h>
#include <gsf/gsf-output-memory.h>
/* TODO: this could probably be done about a billion times better */
struct RsvgHandleGz
{
RsvgHandle super;
GsfOutput * mem;
};
typedef struct RsvgHandleGz RsvgHandleGz;
static gboolean
rsvg_handle_gz_write_impl (RsvgHandle *handle,
const guchar *buf,
gsize num_bytes,
GError **error)
{
RsvgHandleGz * me = (RsvgHandleGz*)handle;
return gsf_output_write (me->mem, num_bytes, buf);
}
static gboolean
rsvg_handle_gz_close_impl (RsvgHandle *handle,
GError **error)
{
RsvgHandleGz * me = (RsvgHandleGz*)handle;
GsfInput * gzip;
const guchar * bytes;
gsize size;
gsize remaining;
bytes = gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (me->mem));
size = gsf_output_size (me->mem);
gzip = GSF_INPUT (gsf_input_gzip_new (GSF_INPUT (gsf_input_memory_new (bytes, size, FALSE)), error));
remaining = gsf_input_remaining (gzip);
while ((size = MIN (remaining, 1024)) > 0) {
guint8 const *buf;
/* write to parent */
buf = gsf_input_read (gzip, size, NULL);
if (!buf)
{
/* an error occured, so bail */
g_warning ("rsvg_gz_handle_close_impl: gsf_input_read returned NULL");
break;
}
rsvg_handle_write_impl (&(me->super),
buf,
size, error);
/* if we didn't manage to lower remaining number of bytes,
* something is wrong, and we should avoid an endless loop */
if (remaining == ((gsize) gsf_input_remaining (gzip)))
{
g_warning ("rsvg_gz_handle_close_impl: write_impl didn't lower the input_remaining count");
break;
}
remaining = gsf_input_remaining (gzip);
}
g_object_unref (G_OBJECT (gzip));
/* close parent */
gsf_output_close (me->mem);
return rsvg_handle_close_impl (handle, error);
}
static void
rsvg_handle_gz_free_impl (RsvgHandle *handle)
{
RsvgHandleGz * me = (RsvgHandleGz*)handle;
g_object_unref (G_OBJECT (me->mem));
/* free parent */
rsvg_handle_free_impl (handle);
}
static RsvgHandle *
rsvg_handle_new_gz_impl (void)
{
RsvgHandleGz * me = g_new0 (RsvgHandleGz, 1);
/* init parent */
rsvg_handle_init (&me->super);
me->mem = GSF_OUTPUT (gsf_output_memory_new ());
me->super.write = rsvg_handle_gz_write_impl;
me->super.close = rsvg_handle_gz_close_impl;
me->super.free = rsvg_handle_gz_free_impl;
return (RsvgHandle*)me;
}
#else
static RsvgHandle *
rsvg_handle_new_gz_impl (void)
{
g_warning ("Doesn't support GZipped SVG files");
return NULL;
}
#endif
/**
* rsvg_handle_new_gz
*
* See rsvg_handle_new, except that this will handle GZipped SVGs (svgz)
* Use the returned handle identically to how you use a handle returned
* from rsvg_handle_new()
* DEPRECATED. Please use rsvg_handle_new () instead.
*
* Returns: a new SVGZ handle or null if it isn't supported
* Returns: a new SVGZ handle
*/
RsvgHandle *
rsvg_handle_new_gz (void)
{
return rsvg_handle_new_gz_impl ();
return rsvg_handle_new ();
}
......@@ -27,7 +27,9 @@
G_BEGIN_DECLS
#ifndef RSVG_DISABLE_DEPRECATED
RsvgHandle * rsvg_handle_new_gz (void);
#endif
G_END_DECLS
......
......@@ -111,16 +111,9 @@ struct RsvgHandle {
void * currentfilter;
void * currentsubfilter;
/* virtual fns */
gboolean (* write) (RsvgHandle *handle,
const guchar *buf,
gsize count,
GError **error);
gboolean (* close) (RsvgHandle *handle,
GError **error);
void (* free) (RsvgHandle * handle);
gboolean first_write;
gboolean is_gzipped;
void * gzipped_data; /* really a GsfOutput */
};
/*Contextual information for the drawing phase*/
......@@ -159,16 +152,6 @@ void rsvg_linear_gradient_free (RsvgDefVal *self);
void rsvg_radial_gradient_free (RsvgDefVal *self);
void rsvg_pattern_free (RsvgDefVal *self);
/* "super"/parent calls */
void rsvg_handle_init (RsvgHandle * handle);
gboolean rsvg_handle_write_impl (RsvgHandle *handle,
const guchar *buf,
gsize count,
GError **error);
gboolean rsvg_handle_close_impl (RsvgHandle *handle,
GError **error);
void rsvg_handle_free_impl (RsvgHandle *handle);
typedef enum {
RSVG_SIZE_ZOOM,
RSVG_SIZE_WH,
......
......@@ -25,6 +25,13 @@
#include "config.h"
#ifdef HAVE_SVGZ
#include <gsf/gsf-input-gzip.h>
#include <gsf/gsf-input-memory.h>
#include <gsf/gsf-output-memory.h>
#include <gsf/gsf-utils.h>
#endif
#include "rsvg.h"
#include "rsvg-private.h"
#include "rsvg-css.h"
......@@ -49,10 +56,6 @@
#include "rsvg-art-render.h"
#include "rsvg-art-draw.h"
#ifdef HAVE_SVGZ
#include <gsf/gsf-utils.h>
#endif
/*
* This is configurable at runtime
*/
......@@ -1450,7 +1453,7 @@ rsvg_error_quark (void)
return q;
}
gboolean
static gboolean
rsvg_handle_write_impl (RsvgHandle *handle,
const guchar *buf,
gsize count,
......@@ -1478,7 +1481,7 @@ rsvg_handle_write_impl (RsvgHandle *handle,
return TRUE;
}
gboolean
static gboolean
rsvg_handle_close_impl (RsvgHandle *handle,
GError **error)
{
......@@ -1538,7 +1541,7 @@ rsvg_drawing_ctx_free (RsvgDrawingCtx *handle)
g_free (handle);
}
void
static void
rsvg_handle_free_impl (RsvgHandle *handle)
{
g_hash_table_foreach (handle->entities, rsvg_ctx_free_helper, NULL);
......@@ -1634,13 +1637,24 @@ rsvg_handle_new (void)
RsvgHandle *handle;
handle = g_new0 (RsvgHandle, 1);
rsvg_handle_init (handle);
handle->write = rsvg_handle_write_impl;
handle->close = rsvg_handle_close_impl;
handle->free = rsvg_handle_free_impl;
handle->defs = rsvg_defs_new ();
handle->handler_nest = 0;
handle->entities = g_hash_table_new (g_str_hash, g_str_equal);
handle->dpi_x = internal_dpi_x;
handle->dpi_y = internal_dpi_y;
handle->css_props = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
rsvg_SAX_handler_struct_init();
handle->ctxt = NULL;
handle->current_defs_group = NULL;
handle->treebase = NULL;
handle->dimensions = NULL;
handle->finished = 0;
handle->first_write = TRUE;
return handle;
}
......@@ -1693,28 +1707,7 @@ rsvg_new_drawing_ctx(RsvgHandle * handle)
return draw;
}
void
rsvg_handle_init (RsvgHandle * handle)
{
handle->defs = rsvg_defs_new ();
handle->handler_nest = 0;
handle->entities = g_hash_table_new (g_str_hash, g_str_equal);
handle->dpi_x = internal_dpi_x;
handle->dpi_y = internal_dpi_y;
handle->css_props = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
rsvg_SAX_handler_struct_init();
handle->ctxt = NULL;
handle->current_defs_group = NULL;
handle->treebase = NULL;
handle->dimensions = NULL;
}
/**
* rsvg_set_default_dpi_x_y
/** rsvg_set_default_dpi_x_y
* @dpi_x: Dots Per Inch (aka Pixels Per Inch)
* @dpi_y: Dots Per Inch (aka Pixels Per Inch)
*
......@@ -1851,10 +1844,29 @@ rsvg_handle_write (RsvgHandle *handle,
gsize count,
GError **error)
{
if (handle->write)
return (*handle->write) (handle, buf, count, error);
if (handle->first_write) {
handle->first_write = FALSE;
/* test for GZ marker. todo: store the first 2 bytes in the odd circumstance that someone calls
* write() in 1 byte increments */
if ((count >= 2) && (buf[0] == (guchar)0x1f) && (buf[1] == (guchar)0x8b)) {
handle->is_gzipped = TRUE;
return FALSE;
#ifdef HAVE_SVGZ
handle->gzipped_data = GSF_OUTPUT (gsf_output_memory_new ());
#endif
}
}
if (handle->is_gzipped) {
#ifdef HAVE_SVGZ
return gsf_output_write (handle->gzipped_data, count, buf);
#else
return FALSE;
#endif
}
return rsvg_handle_write_impl (handle, buf, count, error);
}
/**
......@@ -1873,10 +1885,50 @@ gboolean
rsvg_handle_close (RsvgHandle *handle,
GError **error)
{
if (handle->close)
return (*handle->close) (handle, error);
#if HAVE_SVGZ
if (handle->is_gzipped) {
GsfInput * gzip;
const guchar * bytes;
gsize size;
gsize remaining;
bytes = gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (handle->gzipped_data));
size = gsf_output_size (handle->gzipped_data);
return FALSE;
gzip = GSF_INPUT (gsf_input_gzip_new (GSF_INPUT (gsf_input_memory_new (bytes, size, FALSE)), error));
remaining = gsf_input_remaining (gzip);
while ((size = MIN (remaining, 1024)) > 0) {
guint8 const *buf;
/* write to parent */
buf = gsf_input_read (gzip, size, NULL);
if (!buf)
{
/* an error occured, so bail */
g_warning (_("rsvg_gz_handle_close_impl: gsf_input_read returned NULL"));
break;
}
rsvg_handle_write_impl (handle,
buf,
size, error);
/* if we didn't manage to lower remaining number of bytes,
* something is wrong, and we should avoid an endless loop */
if (remaining == ((gsize) gsf_input_remaining (gzip)))
{
g_warning (_("rsvg_gz_handle_close_impl: write_impl didn't lower the input_remaining count"));
break;
}
remaining = gsf_input_remaining (gzip);
}
g_object_unref (G_OBJECT (gzip));
/* close parent */
gsf_output_close (handle->gzipped_data);
}
#endif
return rsvg_handle_close_impl (handle, error);
}
/**
......@@ -1921,8 +1973,12 @@ rsvg_handle_get_pixbuf (RsvgHandle *handle)
void
rsvg_handle_free (RsvgHandle *handle)
{
if (handle->free)
(*handle->free) (handle);
#if HAVE_SVGZ
if (handle->is_gzipped)
g_object_unref (G_OBJECT (handle->gzipped_data));
#endif
rsvg_handle_free_impl (handle);
}
#ifdef HAVE_GNOME_VFS
......
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