]> granicus.if.org Git - graphviz/commitdiff
some clean up
authorellson <devnull@localhost>
Tue, 21 Aug 2007 21:13:28 +0000 (21:13 +0000)
committerellson <devnull@localhost>
Tue, 21 Aug 2007 21:13:28 +0000 (21:13 +0000)
plugin/gd/Makefile.am
plugin/gd/gvformatter_gd.c
plugin/gdk_pixbuf/gvformatter_gdk_pixbuf.c

index a68074129b15e5ec07c50dd4be67fd475b4443ae..aa11d58679f50ba89de499fcb508894a31c81c1e 100644 (file)
@@ -8,7 +8,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/gvc \
        -I$(top_srcdir)/lib/graph \
        -I$(top_srcdir)/lib/cdt \
-       $(GD_INCLUDES) $(LIBGVC_CFLAGS)
+       $(GD_INCLUDES) $(PANGOCAIRO_CFLAGS) $(LIBGVC_CFLAGS)
 
 noinst_LTLIBRARIES = libgvplugin_gd_C.la
 
index 3440dfd10b888325d1f34256d4ae8d6bd0586de6..cfbdf7e3b4794c0c29406bba8255140d3ce5b646 100644 (file)
@@ -21,6 +21,8 @@
 #include "gvplugin_formatter.h"
 
 #ifdef HAVE_LIBGD
+#ifdef HAVE_PANGOCAIRO
+#include <pango/pangocairo.h>
 #include "gd.h"
 
 typedef enum {
@@ -33,77 +35,100 @@ 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 = {
@@ -114,12 +139,14 @@ static gvformatter_features_t gd_features = {
     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
@@ -131,9 +158,10 @@ gvplugin_installed_t gvformatter_gd_types[] = {
 #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}
index 858f98e4830aff48b6ef8897ebb0a0267a083729..bade8476afac77e7a078a8ef171e868e4683566d 100644 (file)
@@ -78,17 +78,17 @@ writer ( const gchar *buf, gsize count, GError **error, gpointer data)
 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
@@ -100,9 +100,9 @@ cairo_surface_write_to_gdk_pixbuf(cairo_surface_t *surface, const char *format,
                 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)