Commit 3697a8a8 authored by Dom Lachowicz's avatar Dom Lachowicz

create new fns for the convenience API, but don't export them yet. will be...

create new fns for the convenience API, but don't export them yet. will be capable of handling gzipped files
parent c4803cdb
2003-01-30 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-file-util.c (*): Made '_ex' versions of all "convenience"
functions that take a RsvgHandle as an argument. This will allow the
caller to pass in a handle with DPI specified, or a handle capable of
handling gzipped files. Made all existing convenience functions call
their _ex cousins. TODO: make the _ex functions part of the public API.
2003-01-30 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-paint-server.c (radial, linear): Handle objBbox coordinate space properly. Thanks Lauris for the tip!
......
......@@ -108,13 +108,13 @@ rsvg_size_callback (int *width,
}
static GdkPixbuf *
rsvg_pixbuf_from_file_with_size_data (const gchar * file_name,
rsvg_pixbuf_from_file_with_size_data (RsvgHandle * handle,
const gchar * file_name,
struct RsvgSizeCallbackData * data,
GError ** error)
{
char chars[SVG_BUFFER_SIZE];
GdkPixbuf *retval;
RsvgHandle *handle;
gint result;
FILE *f = fopen (file_name, "r");
......@@ -124,8 +124,6 @@ rsvg_pixbuf_from_file_with_size_data (const gchar * file_name,
return NULL;
}
handle = rsvg_handle_new ();
rsvg_handle_set_size_callback (handle, rsvg_size_callback, data, NULL);
while ((result = fread (chars, 1, SVG_BUFFER_SIZE, f)) > 0)
......@@ -134,32 +132,67 @@ rsvg_pixbuf_from_file_with_size_data (const gchar * file_name,
rsvg_handle_close (handle, error);
retval = rsvg_handle_get_pixbuf (handle);
fclose (f);
rsvg_handle_free (handle);
fclose (f);
return retval;
}
/**
* rsvg_pixbuf_from_file:
* rsvg_pixbuf_from_file_at_size_ex:
* @handle: The RSVG handle you wish to render with (either normal or gzipped)
* @file_name: A file name
* @width: The new width, or -1
* @height: The new height, or -1
* @error: return location for errors
*
* Loads a new #GdkPixbuf from @file_name and returns it. This pixbuf is scaled
* from the size indicated to the new size indicated by @width and @height. If
* either of these are -1, then the default size of the image being loaded is
* used. The caller must assume the reference to the returned pixbuf. If an
* error occurred, @error is set and %NULL is returned. Returned handle is closed
* by this call and must be freed by the caller.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
static GdkPixbuf *
rsvg_pixbuf_from_file_at_size_ex (RsvgHandle * handle,
const gchar *file_name,
gint width,
gint height,
GError **error)
{
struct RsvgSizeCallbackData data;
data.type = RSVG_SIZE_WH;
data.width = width;
data.height = height;
return rsvg_pixbuf_from_file_with_size_data (handle, file_name, &data, error);
}
/**
* rsvg_pixbuf_from_file_ex:
* @handle: The RSVG handle you wish to render with (either normal or gzipped)
* @file_name: A file name
* @error: return location for errors
*
* Loads a new #GdkPixbuf from @file_name and returns it. The caller must
* assume the reference to the reurned pixbuf. If an error occurred, @error is
* set and %NULL is returned.
* set and %NULL is returned. Returned handle is closed by this call and must be
* freed by the caller.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
GdkPixbuf *
rsvg_pixbuf_from_file (const gchar *file_name,
GError **error)
static GdkPixbuf *
rsvg_pixbuf_from_file_ex (RsvgHandle * handle,
const gchar *file_name,
GError **error)
{
return rsvg_pixbuf_from_file_at_size (file_name, -1, -1, error);
return rsvg_pixbuf_from_file_at_size_ex (handle, file_name, -1, -1, error);
}
/**
* rsvg_pixbuf_from_file_at_zoom:
* rsvg_pixbuf_from_file_at_zoom_ex:
* @handle: The RSVG handle you wish to render with (either normal or gzipped)
* @file_name: A file name
* @x_zoom: The horizontal zoom factor
* @y_zoom: The vertical zoom factor
......@@ -168,15 +201,17 @@ rsvg_pixbuf_from_file (const gchar *file_name,
* Loads a new #GdkPixbuf from @file_name and returns it. This pixbuf is scaled
* from the size indicated by the file by a factor of @x_zoom and @y_zoom. The
* caller must assume the reference to the returned pixbuf. If an error
* occurred, @error is set and %NULL is returned.
* occurred, @error is set and %NULL is returned. Returned handle is closed by this
* call and must be freed by the caller.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
GdkPixbuf *
rsvg_pixbuf_from_file_at_zoom (const gchar *file_name,
double x_zoom,
double y_zoom,
GError **error)
static GdkPixbuf *
rsvg_pixbuf_from_file_at_zoom_ex (RsvgHandle * handle,
const gchar *file_name,
double x_zoom,
double y_zoom,
GError **error)
{
struct RsvgSizeCallbackData data;
......@@ -187,11 +222,44 @@ rsvg_pixbuf_from_file_at_zoom (const gchar *file_name,
data.x_zoom = x_zoom;
data.y_zoom = y_zoom;
return rsvg_pixbuf_from_file_with_size_data (file_name, &data, error);
return rsvg_pixbuf_from_file_with_size_data (handle, file_name, &data, error);
}
/**
* rsvg_pixbuf_from_file_at_zoom_with_max:
* rsvg_pixbuf_from_file_at_max_size_ex:
* @handle: The RSVG handle you wish to render with (either normal or gzipped)
* @file_name: A file name
* @max_width: The requested max width
* @max_height: The requested max heigh
* @error: return location for errors
*
* Loads a new #GdkPixbuf from @file_name and returns it. This pixbuf is uniformly
* scaled so that the it fits into a rectangle of size max_width * max_height. The
* caller must assume the reference to the returned pixbuf. If an error occurred,
* @error is set and %NULL is returned. Returned handle is closed by this call and
* must be freed by the caller.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
static GdkPixbuf *
rsvg_pixbuf_from_file_at_max_size_ex (RsvgHandle * handle,
const gchar *file_name,
gint max_width,
gint max_height,
GError **error)
{
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 (handle, file_name, &data, error);
}
/**
* rsvg_pixbuf_from_file_at_zoom_with_max_ex:
* @handle: The RSVG handle you wish to render with (either normal or gzipped)
* @file_name: A file name
* @x_zoom: The horizontal zoom factor
* @y_zoom: The vertical zoom factor
......@@ -204,16 +272,18 @@ rsvg_pixbuf_from_file_at_zoom (const gchar *file_name,
* resulting pixbuf would be larger than max_width/max_heigh it is uniformly scaled
* down to fit in that rectangle. The caller must assume the reference to the
* returned pixbuf. If an error occurred, @error is set and %NULL is returned.
* Returned handle is closed by this call and must be freed by the caller.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
GdkPixbuf *
rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
double x_zoom,
double y_zoom,
gint max_width,
gint max_height,
GError **error)
static GdkPixbuf *
rsvg_pixbuf_from_file_at_zoom_with_max_ex (RsvgHandle * handle,
const gchar *file_name,
double x_zoom,
double y_zoom,
gint max_width,
gint max_height,
GError **error)
{
struct RsvgSizeCallbackData data;
......@@ -226,7 +296,85 @@ rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
data.width = max_width;
data.height = max_height;
return rsvg_pixbuf_from_file_with_size_data (file_name, &data, error);
return rsvg_pixbuf_from_file_with_size_data (handle, file_name, &data, error);
}
/**
* rsvg_pixbuf_from_file:
* @file_name: A file name
* @error: return location for errors
*
* Loads a new #GdkPixbuf from @file_name and returns it. The caller must
* assume the reference to the reurned pixbuf. If an error occurred, @error is
* set and %NULL is returned.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
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;
}
/**
* rsvg_pixbuf_from_file_at_zoom:
* @file_name: A file name
* @x_zoom: The horizontal zoom factor
* @y_zoom: The vertical zoom factor
* @error: return location for errors
*
* Loads a new #GdkPixbuf from @file_name and returns it. This pixbuf is scaled
* from the size indicated by the file by a factor of @x_zoom and @y_zoom. The
* caller must assume the reference to the returned pixbuf. If an error
* occurred, @error is set and %NULL is returned.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
GdkPixbuf *
rsvg_pixbuf_from_file_at_zoom (const gchar *file_name,
double x_zoom,
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;
}
/**
* rsvg_pixbuf_from_file_at_zoom_with_max:
* @file_name: A file name
* @x_zoom: The horizontal zoom factor
* @y_zoom: The vertical zoom factor
* @max_width: The requested max width
* @max_height: The requested max heigh
* @error: return location for errors
*
* Loads a new #GdkPixbuf from @file_name and returns it. This pixbuf is scaled
* from the size indicated by the file by a factor of @x_zoom and @y_zoom. If the
* resulting pixbuf would be larger than max_width/max_heigh it is uniformly scaled
* down to fit in that rectangle. The caller must assume the reference to the
* returned pixbuf. If an error occurred, @error is set and %NULL is returned.
*
* Return value: A newly allocated #GdkPixbuf, or %NULL
**/
GdkPixbuf *
rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
double x_zoom,
double y_zoom,
gint max_width,
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;
}
/**
......@@ -250,13 +398,10 @@ rsvg_pixbuf_from_file_at_size (const gchar *file_name,
gint height,
GError **error)
{
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);
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;
}
/**
......@@ -279,11 +424,8 @@ rsvg_pixbuf_from_file_at_max_size (const gchar *file_name,
gint max_height,
GError **error)
{
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);
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;
}
......@@ -39,8 +39,8 @@ GQuark rsvg_error_quark (void) G_GNUC_CONST;
typedef struct RsvgHandle RsvgHandle;
typedef void (* RsvgSizeFunc) (gint *width,
gint *height,
gpointer user_data);
gint *height,
gpointer user_data);
void rsvg_set_default_dpi (double dpi);
......@@ -48,39 +48,40 @@ void rsvg_set_default_dpi (double dpi);
RsvgHandle *rsvg_handle_new (void);
void rsvg_handle_set_dpi (RsvgHandle * handle, double dpi);
void rsvg_handle_set_size_callback (RsvgHandle *handle,
RsvgSizeFunc size_func,
gpointer user_data,
GDestroyNotify user_data_destroy);
RsvgSizeFunc size_func,
gpointer user_data,
GDestroyNotify user_data_destroy);
gboolean rsvg_handle_write (RsvgHandle *handle,
const guchar *buf,
gsize count,
GError **error);
const guchar *buf,
gsize count,
GError **error);
gboolean rsvg_handle_close (RsvgHandle *handle,
GError **error);
GError **error);
GdkPixbuf *rsvg_handle_get_pixbuf (RsvgHandle *handle);
void rsvg_handle_free (RsvgHandle *handle);
/* convenience API */
GdkPixbuf *rsvg_pixbuf_from_file (const gchar *file_name,
GError **error);
GError **error);
GdkPixbuf *rsvg_pixbuf_from_file_at_zoom (const gchar *file_name,
double x_zoom,
double y_zoom,
GError **error);
double x_zoom,
double y_zoom,
GError **error);
GdkPixbuf *rsvg_pixbuf_from_file_at_size (const gchar *file_name,
gint width,
gint height,
GError **error);
gint width,
gint height,
GError **error);
GdkPixbuf *rsvg_pixbuf_from_file_at_max_size (const gchar *file_name,
gint max_width,
gint max_height,
GError **error);
gint max_width,
gint max_height,
GError **error);
GdkPixbuf *rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
double x_zoom,
double y_zoom,
gint max_width,
gint max_height,
GError **error);
double x_zoom,
double y_zoom,
gint max_width,
gint max_height,
GError **error);
G_END_DECLS
......
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