Commit 8531bcae authored by Jonathan Blandford's avatar Jonathan Blandford

Clean up API substantially. Support GError in API. Remove FILE based API,



	* librsvg-features.c:
	* rsvg.c: (rsvg_start_svg), (rsvg_parse_style_arg),
	(rsvg_parse_style), (rsvg_parse_transform_attr),
	(rsvg_parse_style_attrs), (rsvg_push_opacity_group),
	(rsvg_pop_opacity_group), (rsvg_start_g), (rsvg_end_g),
	(rsvg_render_svp), (rsvg_render_bpath), (rsvg_start_path),
	(rsvg_text_handler_characters), (rsvg_start_text),
	(rsvg_start_defs), (rsvg_gradient_stop_handler_new),
	(rsvg_start_linear_gradient), (rsvg_start_radial_gradient),
	(rsvg_start_element), (rsvg_end_element), (rsvg_characters),
	(rsvg_get_entity), (rsvg_entity_decl), (rsvg_error_quark),
	(rsvg_handle_new), (rsvg_handle_set_fonts_dir),
	(rsvg_handle_set_size_callback), (rsvg_handle_write),
	(rsvg_handle_close), (rsvg_handle_get_pixbuf), (rsvg_handle_free),
	(rsvg_size_callback), (rsvg_pixbuf_from_file),
	(rsvg_pixbuf_from_file_at_zoom), (rsvg_pixbuf_from_file_at_size):
	* rsvg.h:
	* TODO:
	* test-rsvg.c: (main): Clean up API substantially.  Support
	GError in API.  Remove FILE based API, and support pushing of data
	similar to GdkPixbufLoader.  Support loading to a file size, and
	to independent x/y zoom factors.  Robustify a little.  Add a
	TODO.  Probably break eel a little.
parent 8f225cda
2001-09-10 Jonathan Blandford <jrb@redhat.com>
* librsvg-features.c:
* rsvg.c: (rsvg_start_svg), (rsvg_parse_style_arg),
(rsvg_parse_style), (rsvg_parse_transform_attr),
(rsvg_parse_style_attrs), (rsvg_push_opacity_group),
(rsvg_pop_opacity_group), (rsvg_start_g), (rsvg_end_g),
(rsvg_render_svp), (rsvg_render_bpath), (rsvg_start_path),
(rsvg_text_handler_characters), (rsvg_start_text),
(rsvg_start_defs), (rsvg_gradient_stop_handler_new),
(rsvg_start_linear_gradient), (rsvg_start_radial_gradient),
(rsvg_start_element), (rsvg_end_element), (rsvg_characters),
(rsvg_get_entity), (rsvg_entity_decl), (rsvg_error_quark),
(rsvg_handle_new), (rsvg_handle_set_fonts_dir),
(rsvg_handle_set_size_callback), (rsvg_handle_write),
(rsvg_handle_close), (rsvg_handle_get_pixbuf), (rsvg_handle_free),
(rsvg_size_callback), (rsvg_pixbuf_from_file),
(rsvg_pixbuf_from_file_at_zoom), (rsvg_pixbuf_from_file_at_size):
* rsvg.h:
* TODO:
* test-rsvg.c: (main): Clean up API substantially. Support
GError in API. Remove FILE based API, and support pushing of data
similar to GdkPixbufLoader. Support loading to a file size, and
to independent x/y zoom factors. Robustify a little. Add a
TODO. Probably break eel a little.
2001-08-31 Darin Adler <darin@bentspoon.com>
* rsvg-paint-server.c: (rsvg_paint_server_parse):
......
* Add actual GError support in the loader, rather then the g_warnings
now.
* Clean up test-rsvg
Post 2.0
* Consider storing the paths so that the file can be rerendered
multiple times without reparsing
* Allow affine's other than scaling
......@@ -6,13 +6,3 @@ const unsigned int librsvg_major_version=LIBRSVG_MAJOR_VERSION,
librsvg_micro_version=LIBRSVG_MICRO_VERSION;
const char *librsvg_version = LIBRSVG_VERSION;
void
librsvg_preinit(void *app, void *modinfo)
{
}
void
librsvg_postinit(void *app, void *modinfo)
{
}
This diff is collapsed.
......@@ -24,19 +24,53 @@
#ifndef RSVG_H
#define RSVG_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
#include <stdio.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
void rsvg_set_fonts_dir (const char *fonts_dir);
GdkPixbuf *rsvg_render_file (FILE *f,
double zoom);
typedef enum {
RSVG_ERROR_FAILED
} RsvgError;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#define RSVG_ERROR (rsvg_error_quark ())
GQuark rsvg_error_quark (void) G_GNUC_CONST;
typedef struct RsvgHandle RsvgHandle;
typedef void (* RsvgSizeFunc) (gint *width,
gint *height,
gpointer user_data);
RsvgHandle *rsvg_handle_new (void);
void rsvg_handle_set_fonts_dir (RsvgHandle *handle,
const char *fonts_dir);
void rsvg_handle_set_size_callback (RsvgHandle *handle,
RsvgSizeFunc size_func,
gpointer user_data,
GDestroyNotify user_data_destroy);
gboolean rsvg_handle_write (RsvgHandle *handle,
const guchar *buf,
gsize count,
GError **error);
gboolean rsvg_handle_close (RsvgHandle *handle,
GError **error);
GdkPixbuf *rsvg_handle_get_pixbuf (RsvgHandle *handle);
void rsvg_handle_free (RsvgHandle *handle);
/* convenience API */
GdkPixbuf *rsvg_pixbuf_from_file (gchar *file_name,
GError **error);
GdkPixbuf *rsvg_pixbuf_from_file_at_zoom (gchar *file_name,
double x_zoom,
double y_zoom,
GError **error);
GdkPixbuf *rsvg_pixbuf_from_file_at_size (gchar *file_name,
gint width,
gint height,
GError **error);
G_END_DECLS
#endif
......@@ -32,155 +32,21 @@
#include "rsvg.h"
/* The following routine is lifted wholesale from nautilus-icon-factory.c.
It should find a permanent home somewhere else, at which point it should
be deleted here and simply linked. -RLL
*/
/* utility routine for saving a pixbuf to a png file.
* This was adapted from Iain Holmes' code in gnome-iconedit, and probably
* should be in a utility library, possibly in gdk-pixbuf itself.
*
* It is split up into save_pixbuf_to_file and save_pixbuf_to_file_internal
* to work around a gcc warning about handle possibly getting clobbered by
* longjmp. Declaring handle 'volatile FILE *' didn't work as it should have.
*/
static gboolean
save_pixbuf_to_file_internal (GdkPixbuf *pixbuf, char *filename, FILE *handle)
{
char *buffer;
gboolean has_alpha;
int width, height, depth, rowstride;
guchar *pixels;
png_structp png_ptr;
png_infop info_ptr;
png_text text[2];
int i;
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
return FALSE;
}
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL) {
png_destroy_write_struct (&png_ptr, (png_infopp)NULL);
return FALSE;
}
if (setjmp (png_ptr->jmpbuf)) {
png_destroy_write_struct (&png_ptr, &info_ptr);
return FALSE;
}
png_init_io (png_ptr, (FILE *)handle);
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
depth = gdk_pixbuf_get_bits_per_sample (pixbuf);
pixels = gdk_pixbuf_get_pixels (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
png_set_IHDR (png_ptr, info_ptr, width, height,
depth, PNG_COLOR_TYPE_RGB_ALPHA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
/* Some text to go with the png image */
text[0].key = "Title";
text[0].text = filename;
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
text[1].key = "Software";
text[1].text = "Test-Rsvg";
text[1].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text (png_ptr, info_ptr, text, 2);
/* Write header data */
png_write_info (png_ptr, info_ptr);
/* if there is no alpha in the data, allocate buffer to expand into */
if (has_alpha) {
buffer = NULL;
} else {
buffer = g_malloc(4 * width);
}
/* pump the raster data into libpng, one scan line at a time */
for (i = 0; i < height; i++) {
if (has_alpha) {
png_bytep row_pointer = pixels;
png_write_row (png_ptr, row_pointer);
} else {
/* expand RGB to RGBA using an opaque alpha value */
int x;
char *buffer_ptr = buffer;
char *source_ptr = pixels;
for (x = 0; x < width; x++) {
*buffer_ptr++ = *source_ptr++;
*buffer_ptr++ = *source_ptr++;
*buffer_ptr++ = *source_ptr++;
*buffer_ptr++ = 255;
}
png_write_row (png_ptr, (png_bytep) buffer);
}
pixels += rowstride;
}
png_write_end (png_ptr, info_ptr);
png_destroy_write_struct (&png_ptr, &info_ptr);
g_free (buffer);
return TRUE;
}
static gboolean
save_pixbuf_to_file (GdkPixbuf *pixbuf, char *filename)
{
FILE *handle;
gboolean result;
g_return_val_if_fail (pixbuf != NULL, FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (filename[0] != '\0', FALSE);
if (!strcmp (filename, "-")) {
handle = stdout;
} else {
handle = fopen (filename, "wb");
}
if (handle == NULL) {
return FALSE;
}
result = save_pixbuf_to_file_internal (pixbuf, filename, handle);
if (!result || handle != stdout)
fclose (handle);
return result;
}
int
main (int argc, char **argv)
{
FILE *f;
char *out_fn;
GdkPixbuf *pixbuf;
char *zoom_str = "1.0";
int n_iter = 1;
char *x_zoom_str = "1.0";
char *y_zoom_str = "1.0";
poptContext optCtx;
struct poptOption optionsTable[] = {
{ "zoom", 'z', POPT_ARG_STRING, &zoom_str, 0, NULL, "zoom factor" },
{ "num-iter", 'n', POPT_ARG_INT, &n_iter, 0, NULL, "number of iterations" },
{ "x-zoom", 'x', POPT_ARG_STRING, &x_zoom_str, 0, NULL, "zoom factor" },
{ "y-zoom", 'y', POPT_ARG_STRING, &y_zoom_str, 0, NULL, "zoom factor" },
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 }
};
char c;
const char * const *args;
int i;
g_type_init ();
......@@ -189,41 +55,10 @@ main (int argc, char **argv)
c = poptGetNextOpt (optCtx);
args = poptGetArgs (optCtx);
for (i = 0; i < n_iter; i++) {
if (args == NULL || args[0] == NULL) {
if (n_iter > 1) {
fprintf (stderr, "Can't do multiple iterations on stdin\n");
exit (1);
}
f = stdin;
out_fn = "-";
} else {
f = fopen(args[0], "r");
if (f == NULL) {
fprintf(stderr, "Error opening source file %s\n", argv[0]);
}
if (args[1] == NULL)
out_fn = "-";
else
out_fn = (char *)args[1];
}
pixbuf = rsvg_render_file (f, atof (zoom_str));
if (f != stdin)
fclose(f);
if (pixbuf != NULL) {
if (n_iter > 1)
gdk_pixbuf_unref (pixbuf);
else
save_pixbuf_to_file (pixbuf, out_fn);
} else {
fprintf (stderr, "Error loading SVG file.\n");
return 1;
}
}
pixbuf = rsvg_pixbuf_from_file_at_zoom ((char *)args[0],
atof (x_zoom_str),
atof (y_zoom_str),
NULL);
gdk_pixbuf_save (pixbuf, args[1], "png", NULL, NULL);
return 0;
}
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