#include "gvplugin_formatter.h"
#ifdef HAVE_LIBGD
+#ifdef HAVE_PANGOCAIRO
+#include <pango/pangocairo.h>
#include "gd.h"
typedef enum {
FORMAT_XBM,
} format_type;
-static void gd_formatter(GVJ_t * job)
+static void
+cairo_surface_write_to_gdk_pixbuf(cairo_surface_t *surface, format_type format, FILE *f)
{
- gdImagePtr im = (gdImagePtr) job->surface;
+ gdImagePtr im;
+ unsigned int width, height;
+ unsigned char *data;
- if (!im)
- return;
+ width = cairo_image_surface_get_width(surface);
+ height = cairo_image_surface_get_height(surface);
+ data = cairo_image_surface_get_data(surface);
-#ifdef HAVE_SETMODE
-#ifdef O_BINARY
- /*
- * Windows will do \n -> \r\n translations on stdout
- * unless told otherwise. */
- setmode(fileno(job->output_file), O_BINARY);
-#endif
-#endif
+ im = gdImageCreateTrueColor(width, height);
- /* Only save the alpha channel in outputs that support it if
- the base color was transparent. Otherwise everything
- was blended so there is no useful alpha info */
+ /*
+ * Only save the alpha channel in outputs that support it if
+ * the base color was transparent. Otherwise everything
+ * was blended so there is no useful alpha info.
+ */
//FIXME gdImageSaveAlpha(im, (basecolor == transparent));
- switch (job->render.id) {
+ switch (format) {
#if 0
- case FORMAT_GD:
- gdImageGd(im, job->output_file);
- break;
- case FORMAT_GD2:
+ case FORMAT_GD:
+ gdImageGd(im, f);
+ break;
+ case FORMAT_GD2:
#define GD2_CHUNKSIZE 128
#define GD2_RAW 1
#define GD2_COMPRESSED 2
- gdImageGd2(im, job->output_file, GD2_CHUNKSIZE,
- GD2_COMPRESSED);
- break;
+ gdImageGd2(im, f, GD2_CHUNKSIZE, GD2_COMPRESSED);
+ break;
#endif
- case FORMAT_GIF:
#ifdef HAVE_GD_GIF
- gdImageTrueColorToPalette(im, 0, 256);
- gdImageGif(im, job->output_file);
+ case FORMAT_GIF:
+ gdImageTrueColorToPalette(im, 0, 256);
+ gdImageGif(im, f);
+ break;
#endif
- break;
- case FORMAT_JPEG:
#ifdef HAVE_GD_JPEG
- /*
- * Write IM to OUTFILE as a JFIF-formatted JPEG image, using
- * quality JPEG_QUALITY. If JPEG_QUALITY is in the range
- * 0-100, increasing values represent higher quality but also
- * larger image size. If JPEG_QUALITY is negative, the
- * IJG JPEG library's default quality is used (which should
- * be near optimal for many applications). See the IJG JPEG
- * library documentation for more details. */
+ case FORMAT_JPEG:
+ /*
+ * Write IM to OUTFILE as a JFIF-formatted JPEG image, using
+ * quality JPEG_QUALITY. If JPEG_QUALITY is in the range
+ * 0-100, increasing values represent higher quality but also
+ * larger image size. If JPEG_QUALITY is negative, the
+ * IJG JPEG library's default quality is used (which should
+ * be near optimal for many applications). See the IJG JPEG
+ * library documentation for more details.
+ */
#define JPEG_QUALITY -1
- gdImageJpeg(im, job->output_file, JPEG_QUALITY);
+ gdImageJpeg(im, f, JPEG_QUALITY);
+ break;
#endif
- break;
- case FORMAT_PNG:
#ifdef HAVE_GD_PNG
- gdImagePng(im, job->output_file);
-#endif
- break;
- case FORMAT_WBMP:
- /* Use black for the foreground color for the B&W wbmp image. */
-//FIXME gdImageWBMP(im, black, job->output_file);
- break;
- case FORMAT_XBM:
+ case FORMAT_PNG:
+ gdImagePng(im, f);
+ break;
+#endif
+#if 0
+ case FORMAT_WBMP:
+ /* Use black for the foreground color for the B&W wbmp image. */
+//FIXME - black not defined - is it really needed?
+ gdImageWBMP(im, black, f);
+ break;
+#endif
#if 0
#ifdef HAVE_GD_XPM
- gdImageXbm(im, job->output_file);
+ case FORMAT_XBM:
+ gdImageXbm(im, f);
+#endif
+#endif
+ break;
+ default:
+ break;
+ }
+ gdImageDestroy(im);
+}
+
+static void gd_formatter(GVJ_t * job)
+{
+ cairo_t *cr = (cairo_t *) job->surface;
+ cairo_surface_t *surface;
+
+ surface = cairo_get_target(cr);
+#ifdef HAVE_SETMODE
+#ifdef O_BINARY
+ /*
+ * Windows will do \n -> \r\n translations on stdout
+ * unless told otherwise.
+ */
+ setmode(fileno(job->output_file), O_BINARY);
#endif
#endif
- break;
- }
- gdImageDestroy(im);
+
+ cairo_surface_write_to_gdk_pixbuf(surface, job->formatter.id, job->output_file);
}
static gvformatter_engine_t gd_engine = {
0, /* flags */
};
+#endif
#endif
gvplugin_installed_t gvformatter_gd_types[] = {
+#ifdef HAVE_PANGOCAIRO
#ifdef HAVE_LIBGD
- {FORMAT_GD, "cairo2gd", -1, &gd_engine, &gd_features},
- {FORMAT_GD2, "cairo2gd2", -1, &gd_engine, &gd_features},
+// {FORMAT_GD, "cairo2gd", -1, &gd_engine, &gd_features},
+// {FORMAT_GD2, "cairo2gd2", -1, &gd_engine, &gd_features},
#ifdef HAVE_GD_GIF
{FORMAT_GIF, "cairo2gif", -1, &gd_engine, &gd_features},
#endif
#ifdef HAVE_GD_PNG
{FORMAT_PNG, "cairo2png", -1, &gd_engine, &gd_features},
#endif
- {FORMAT_WBMP, "cairo2wbmp", -1, &gd_engine, &gd_features},
+// {FORMAT_WBMP, "cairo2wbmp", -1, &gd_engine, &gd_features},
#ifdef HAVE_GD_XPM
- {FORMAT_XBM, "cairo2xbm", -1, &gd_engine, &gd_features},
+// {FORMAT_XBM, "cairo2xbm", -1, &gd_engine, &gd_features},
+#endif
#endif
#endif
{0, NULL, 0, NULL, NULL}
static void
cairo_surface_write_to_gdk_pixbuf(cairo_surface_t *surface, const char *format, FILE *f)
{
- GdkPixbuf *pixbuf;
- unsigned int width, height;
- unsigned char *data;
+ GdkPixbuf *pixbuf;
+ unsigned int width, height;
+ unsigned char *data;
- width = cairo_image_surface_get_width(surface);
- height = cairo_image_surface_get_height(surface);
- data = cairo_image_surface_get_data(surface);
+ width = cairo_image_surface_get_width(surface);
+ height = cairo_image_surface_get_height(surface);
+ data = cairo_image_surface_get_data(surface);
- argb2rgba(width, height, data);
+ argb2rgba(width, height, data);
- pixbuf = gdk_pixbuf_new_from_data(
+ pixbuf = gdk_pixbuf_new_from_data(
data, // data
GDK_COLORSPACE_RGB, // colorspace
TRUE, // has_alpha
NULL // destroy_fn_data
);
- gdk_pixbuf_save_to_callback(pixbuf, writer, f, format, NULL, NULL);
+ gdk_pixbuf_save_to_callback(pixbuf, writer, f, format, NULL, NULL);
- gdk_pixbuf_unref(pixbuf);
+ gdk_pixbuf_unref(pixbuf);
}
static void gdk_pixbuf_formatter(GVJ_t * job)