]> granicus.if.org Git - graphviz/commitdiff
add GVDEVICE_BINARY_FORMAT feature flag
authorellson <devnull@localhost>
Thu, 6 Sep 2007 19:04:17 +0000 (19:04 +0000)
committerellson <devnull@localhost>
Thu, 6 Sep 2007 19:04:17 +0000 (19:04 +0000)
consolidate O_BINARY treatment for windows into emit.c

12 files changed:
lib/common/diagen.c
lib/common/emit.c
lib/gvc/gvcjob.h
plugin/core/gvrender_core.c
plugin/core/gvrender_core_svg.c
plugin/devil/gvdevice_devil.c
plugin/gd/gvdevice_gd.c
plugin/gd/gvrender_gd.c
plugin/gd/gvrender_gd_vrml.c
plugin/gdk_pixbuf/gvdevice_gdk_pixbuf.c
plugin/ming/gvrender_ming.c
plugin/pango/gvrender_pango.c

index 1b9d54302970b42dda980f4c186f97bc0e55c6c1..03a270120e70466394cb4d88048928955ddc166a 100644 (file)
 #endif
 #ifdef HAVE_LIBZ
 #include <zlib.h>
-#ifdef WIN32
-#include <fcntl.h>
-#include <io.h>
-#endif
 #endif
 
 /* DIA font modifiers */
@@ -302,17 +298,6 @@ dia_begin_job(FILE * ofp, graph_t * g, char **lib, char *user,
 
     fd = dup(fileno(Output_file));     /* open dup so can gzclose 
                                           independent of FILE close */
-#ifdef HAVE_SETMODE
-#ifdef O_BINARY
-    /*
-     * Windows will do \n -> \r\n  translations on
-     * stdout unless told otherwise.
-     */
-    setmode(fd, O_BINARY);
-#endif
-#endif
-
-
     Zfile = gzdopen(fd, "wb");
     if (!Zfile) {
        agerr(AGERR, "Error opening compressed output file\n");
index 689b04a45c62c6f91543b87072db15d51e9bfd09..71e6db278d91e5c8a5963787b71f4c89f99e3b08 100644 (file)
 #include "config.h"
 #endif
 
+#ifdef WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include "render.h"
@@ -541,8 +546,8 @@ static void init_job_flags(GVJ_t * job, graph_t * g)
     switch (job->output_lang) {
     case GVRENDER_PLUGIN:
        job->flags |= chkOrder(g)
-               | job->render.features->flags
-               | job->device.features->flags;
+                  | job->render.features->flags
+                  | job->device.features->flags;
        break;
     case VTX:
         /* output sorted, i.e. all nodes then all edges */
@@ -550,7 +555,8 @@ static void init_job_flags(GVJ_t * job, graph_t * g)
         break;
     case DIA:
         /* output in preorder traversal of the graph */
-        job->flags |= EMIT_PREORDER;
+        job->flags |= EMIT_PREORDER
+                  | GVDEVICE_BINARY_FORMAT;
         break;
     default:
         job->flags |= chkOrder(g);
@@ -2599,17 +2605,6 @@ char **parse_style(char *s)
     return parse;
 }
 
-static FILE *file_select(char *str)
-{
-    FILE *rv;
-    rv = fopen(str, "w");  /* binary formats add O_BINARY later */
-    if (rv == NULL) {
-        perror(str);
-        exit(1);
-    }
-    return rv;
-}
-
 static boxf bezier_bb(bezier bz)
 {
     int i;
@@ -2818,14 +2813,26 @@ int gvRenderJobs (GVC_t * gvc, graph_t * g)
         if (!job->output_file) {        /* if not yet opened */
            if (gvc->common.auto_outfile_names)
                auto_output_filename(job);
-            if (job->output_filename)
-                job->output_file = file_select(job->output_filename);
+            if (job->output_filename) {
+               job->output_file = fopen(job->output_filename, "w");
+               if (job->output_file == NULL) {
+                   perror(job->output_filename);
+                   exit(1);
+               }
+           }
             else
                 job->output_file = stdout;
 #ifdef WITH_CODEGENS
            Output_file = job->output_file;
 #endif
-           gvrender_begin_job(job); /* FIXME? - semantics are unclear */
+
+#ifdef HAVE_SETMODE
+#ifdef O_BINARY
+           if (job->flags & GVDEVICE_BINARY_FORMAT)
+               setmode(fileno(job->output_file), O_BINARY);
+#endif
+#endif
+           gvrender_begin_job(job);
         }
 
        if (! (job->flags & GVDEVICE_EVENTS)) {
index dd6144e0d0a0e8a2e170fbf7d5703ae1e1d5a22b..c5c294222d58116fa370387bb9d212a283745c1f 100644 (file)
@@ -51,22 +51,23 @@ extern "C" {
 #define GVDEVICE_DOES_LAYERS (1<<6)
 #define GVDEVICE_EVENTS (1<<7)
 #define GVDEVICE_DOES_TRUECOLOR (1<<8)
-#define GVRENDER_Y_GOES_DOWN (1<<9)
-#define GVRENDER_DOES_TRANSFORM (1<<10)
-#define GVRENDER_DOES_ARROWS (1<<11)
-#define GVRENDER_DOES_LABELS (1<<12)
-#define GVRENDER_DOES_MAPS (1<<13)
-#define GVRENDER_DOES_MAP_RECTANGLE (1<<14)
-#define GVRENDER_DOES_MAP_CIRCLE (1<<15)
-#define GVRENDER_DOES_MAP_POLYGON (1<<16)
-#define GVRENDER_DOES_MAP_ELLIPSE (1<<17)
-#define GVRENDER_DOES_MAP_BSPLINE (1<<18)
-#define GVRENDER_DOES_TOOLTIPS (1<<19)
-#define GVRENDER_DOES_TARGETS (1<<20)
-#define GVRENDER_DOES_Z (1<<21)
-#define GVRENDER_NO_BG (1<<22)
-#define LAYOUT_NOT_REQUIRED (1<<23)
-#define OUTPUT_NOT_REQUIRED (1<<24)
+#define GVDEVICE_BINARY_FORMAT (1<<9)
+#define GVRENDER_Y_GOES_DOWN (1<<10)
+#define GVRENDER_DOES_TRANSFORM (1<<11)
+#define GVRENDER_DOES_ARROWS (1<<12)
+#define GVRENDER_DOES_LABELS (1<<13)
+#define GVRENDER_DOES_MAPS (1<<14)
+#define GVRENDER_DOES_MAP_RECTANGLE (1<<15)
+#define GVRENDER_DOES_MAP_CIRCLE (1<<16)
+#define GVRENDER_DOES_MAP_POLYGON (1<<17)
+#define GVRENDER_DOES_MAP_ELLIPSE (1<<18)
+#define GVRENDER_DOES_MAP_BSPLINE (1<<19)
+#define GVRENDER_DOES_TOOLTIPS (1<<20)
+#define GVRENDER_DOES_TARGETS (1<<21)
+#define GVRENDER_DOES_Z (1<<22)
+#define GVRENDER_NO_BG (1<<23)
+#define LAYOUT_NOT_REQUIRED (1<<24)
+#define OUTPUT_NOT_REQUIRED (1<<25)
 
     typedef struct {
        int flags;
index 5a7ee512b88bab124f4c925c10edff3320f14d7e..df44212504b58835a60044b74de24bad8eb2f183 100644 (file)
@@ -31,8 +31,6 @@
 #endif
 
 #ifdef WIN32
-#include <io.h>
-#include <fcntl.h>
 #include "compat.h"
 #endif
 
@@ -49,16 +47,6 @@ void core_init_compression(GVJ_t *job, compression_t compression)
 #if HAVE_LIBZ
         /* open dup so can gzclose independent of FILE close */
         fd = dup(fileno(job->output_file));
-#ifdef HAVE_SETMODE
-#ifdef O_BINARY
-        /*
-        * Windows will do \n -> \r\n  translations on
-        * stdout unless told otherwise.
-        */
-        setmode(fd, O_BINARY);
-#endif
-#endif
-
         job->output_file = (FILE *) (gzdopen(fd, "wb"));
         if (!job->output_file) {
             (job->common->errorfn) ("Error initializing compression on output file\n");
index e67874bdfa7ba38e0405e917745536f4136902eb..221ad62d123e8196514f648509f0e456dca40018 100644 (file)
@@ -496,6 +496,14 @@ gvdevice_features_t device_features_svg = {
     {72.,72.},                 /* default dpi */
 };
 
+gvdevice_features_t device_features_svgz = {
+    GVDEVICE_BINARY_FORMAT
+      | GVDEVICE_DOES_TRUECOLOR,/* flags */
+    {0.,0.},                   /* default margin - points */
+    {0.,0.},                    /* default page width, height - points */
+    {72.,72.},                 /* default dpi */
+};
+
 gvplugin_installed_t gvrender_svg_types[] = {
     {FORMAT_SVG, "svg", 1, &svg_engine, &render_features_svg},
     {0, NULL, 0, NULL, NULL}
@@ -504,7 +512,7 @@ gvplugin_installed_t gvrender_svg_types[] = {
 gvplugin_installed_t gvdevice_svg_types[] = {
     {FORMAT_SVG, "svg:svg", 1, NULL, &device_features_svg},
 #if HAVE_LIBZ
-    {FORMAT_SVGZ, "svgz:svg", 1, NULL, &device_features_svg},
+    {FORMAT_SVGZ, "svgz:svg", 1, NULL, &device_features_svgz},
 #endif
     {0, NULL, 0, NULL, NULL}
 };
index c05b51bb3df0ebaa2a5d14ca6aade1b928315548..e8707dd228b920f18eb003f1f17690cb1071a70a 100644 (file)
 #include "config.h"
 #endif
 
-#ifdef WIN32
-#include <io.h>
-#include <fcntl.h>
-#endif
 #include "gvplugin_device.h"
 #include <IL/il.h>
 #include <IL/ilu.h>
@@ -54,16 +50,6 @@ static void devil_format(GVJ_t * job)
     ILenum     Error;
     ILboolean rc;
 
-#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
-
     // Check if the shared lib's version matches the executable's version.
     if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
        iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
@@ -114,7 +100,8 @@ static gvdevice_engine_t devil_engine = {
 };
 
 static gvdevice_features_t device_features_devil = {
-        GVDEVICE_DOES_TRUECOLOR,    /* flags */
+       GVDEVICE_BINARY_FORMAT        
+          | GVDEVICE_DOES_TRUECOLOR,/* flags */
        {0.,0.},                    /* default margin - points */
        {0.,0.},                    /* default page width, height - points */
        {96.,96.},                  /* svg 72 dpi */
index bfdc4a632f54dfa0da03d43b4cda98d710ee5c59..f822894f44a1a47e60ce7a18e237b8db61049c61 100644 (file)
 #include "config.h"
 #endif
 
-#ifdef WIN32
-#include <fcntl.h>
-#include <io.h>
-#endif
-#include <stdlib.h>
 #include "gvplugin_device.h"
 
 #ifdef HAVE_LIBGD
@@ -46,16 +41,6 @@ static void gd_format(GVJ_t * job)
     unsigned int width = job->width;
     unsigned int height = job->height;
 
-#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);
     for (y = 0; y < height; y++) {
         for (x = 0; x < width; x++) {
@@ -144,7 +129,8 @@ static gvdevice_engine_t gd_engine = {
 };
 
 static gvdevice_features_t device_features_gd = {
-    GVDEVICE_DOES_TRUECOLOR,    /* flags */
+    GVDEVICE_BINARY_FORMAT
+      | GVDEVICE_DOES_TRUECOLOR,/* flags */
     {0.,0.},                    /* default margin - points */
     {0.,0.},                    /* default page width, height - points */
     {96.,96.},                  /* dpi */
index 684eb959ece90e5a50ad104c13d006b7b39d14f7..a726e574d99aa667a05e807d96d8bdd8c24e29f3 100644 (file)
@@ -157,15 +157,6 @@ static void gdgen_end_page(GVJ_t * job)
        fprintf(stderr, "gdgen_end_graph (to memory)\n");
 #endif
     } else {
-#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
-
        /* 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 */
@@ -197,11 +188,16 @@ static void gdgen_end_page(GVJ_t * job)
 #endif
            break;
 
-#if 0
+#ifdef HAVE_GD_GIF
        case FORMAT_WBMP:
-           /* Use black for the foreground color for the B&W wbmp image. */
-           gdImageWBMP(im, black, job->output_file);
+           {
+               /* Use black for the foreground color for the B&W wbmp image. */
+               int black = gdImageColorResolveAlpha(im, 0, 0, 0, gdAlphaOpaque);
+               gdImageWBMP(im, black, job->output_file);
+           }
            break;
+#endif
+
        case FORMAT_GD:
            gdImageGd(im, job->output_file);
            break;
@@ -213,11 +209,13 @@ static void gdgen_end_page(GVJ_t * job)
                       GD2_COMPRESSED);
            break;
        case FORMAT_XBM:
+#if 0
+/* libgd support only reading .xpm files */
 #ifdef HAVE_GD_XPM
            gdImageXbm(im, job->output_file);
 #endif
-           break;
 #endif
+           break;
        }
        gdImageDestroy(im);
 #ifdef MYTRACE
@@ -619,22 +617,24 @@ gvplugin_installed_t gvdevice_gd_types2[] = {
 #ifdef HAVE_LIBGD
 #ifdef HAVE_GD_GIF
     {FORMAT_GIF, "gif:gd", 1, NULL, &device_features_gd},
+    {FORMAT_WBMP, "wbmp:gd", 1, NULL, &device_features_gd},
 #endif
+
 #ifdef HAVE_GD_JPEG
     {FORMAT_JPEG, "jpe:gd", 1, NULL, &device_features_gd_tc},
     {FORMAT_JPEG, "jpeg:gd", 1, NULL, &device_features_gd_tc},
     {FORMAT_JPEG, "jpg:gd", 1, NULL, &device_features_gd_tc},
 #endif
+
 #ifdef HAVE_GD_PNG
     {FORMAT_PNG, "png:gd", 1, NULL, &device_features_gd_tc},
 #endif
 
-#if 0
     {FORMAT_GD, "gd:gd", 1, NULL, &device_features_gd_tc},
     {FORMAT_GD2, "gd2:gd", 1, NULL, &device_features_gd_tc},
-#ifdef HAVE_GD_GIF
-    {FORMAT_WBMP, "wbmp:gd", 1, NULL, &device_features_gd},
-#endif
+
+#if 0
+/* libgd has no support for xbm as output */
 #ifdef HAVE_GD_XPM
     {FORMAT_XBM, "xbm:gd", 1, NULL, &device_features_gd},
 #endif
index 61c87576120e758d0c50c1139c89f82c12413152..38de9d52cfab92e41b958b11481c3b629e5ed218 100644 (file)
@@ -845,7 +845,7 @@ static gvrender_features_t render_features_vrml = {
 };
 
 static gvdevice_features_t device_features_vrml = {
-    0,                         /* flags */
+    GVDEVICE_BINARY_FORMAT,    /* flags */
     {0.,0.},                   /* default margin - points */
     {0.,0.},                    /* default page width, height - points */
     {72.,72.},                  /* default dpi */
index ef9443790a488e264026d3d8abe5efe9ec42930f..376d77c1c952d7264eb54c238ab53c10f74938c9 100644 (file)
 #include "config.h"
 #endif
 
-#ifdef WIN32
-#include <io.h>
-#include <fcntl.h>
-#endif
 #include "gvplugin_device.h"
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
@@ -111,15 +107,6 @@ static void gdk_pixbuf_format(GVJ_t * job)
     char *format_str = "";
     GdkPixbuf *pixbuf;
 
-#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
     switch (job->device.id) {
     case FORMAT_BMP:
        format_str = "bmp";
@@ -165,7 +152,8 @@ static gvdevice_engine_t gdk_pixbuf_engine = {
 };
 
 static gvdevice_features_t device_features_gdk_pixbuf = {
-    GVDEVICE_DOES_TRUECOLOR,    /* flags */
+    GVDEVICE_BINARY_FORMAT
+      | GVDEVICE_DOES_TRUECOLOR,/* flags */
     {0.,0.},                    /* default margin - points */
     {0.,0.},                    /* default page width, height - points */
     {96.,96.},                  /* dpi */
index 8cd9323cbebfbf83f2f580682085129153b1ea79..8ce54867e1c888da9d592be80e0301872a1e5360 100644 (file)
@@ -48,16 +48,6 @@ static void ming_end_job(GVJ_t * job)
 {
     SWFMovie movie = (SWFMovie)(job->context);
 
-#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
-
     SWFMovie_output_to_stream(movie, job->output_file);
     destroySWFMovie(movie);
     job->context = NULL;
index ec094069dfa7b47c1863ee73d3af692dce130c0c..b114ebee01738518de3885144ffe3415d541f3e3 100644 (file)
@@ -25,9 +25,6 @@
 #include <string.h>
 #endif
 #include <fcntl.h>
-#ifdef WIN32
-#include <io.h>
-#endif
 
 #if defined(HAVE_FENV_H) && defined(HAVE_FESETENV) && defined(HAVE_FEGETENV) && defined(HAVE_FEENABLEEXCEPT)
 
@@ -176,14 +173,6 @@ static void cairogen_end_page(GVJ_t * job)
 
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
     case FORMAT_PNG:
-#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
         surface = cairo_get_target(cr);
        cairo_surface_write_to_png_stream(surface, writer, job->output_file);
        break;
@@ -382,8 +371,9 @@ static gvrender_features_t render_features_cairo = {
     "cairo",                   /* imageloader for usershapes */
 };
 
-static gvdevice_features_t device_features_bitmaps = {
-    GVDEVICE_DOES_TRUECOLOR,    /* flags */
+static gvdevice_features_t device_features_png = {
+    GVDEVICE_BINARY_FORMAT
+      | GVDEVICE_DOES_TRUECOLOR,/* flags */
     {0.,0.},                   /* default margin - points */
     {0.,0.},                    /* default page width, height - points */
     {96.,96.},                 /* typical monitor dpi */
@@ -414,7 +404,7 @@ gvplugin_installed_t gvrender_pango_types[] = {
 gvplugin_installed_t gvdevice_pango_types[] = {
 #ifdef HAVE_PANGOCAIRO
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
-    {FORMAT_PNG, "png:cairo", 10, NULL, &device_features_bitmaps},
+    {FORMAT_PNG, "png:cairo", 10, NULL, &device_features_png},
 #endif
 #ifdef CAIRO_HAS_PS_SURFACE
     {FORMAT_PS, "ps:cairo", -10, NULL, &device_features_ps},
@@ -426,19 +416,19 @@ gvplugin_installed_t gvdevice_pango_types[] = {
     {FORMAT_SVG, "svg:cairo", -10, NULL, &device_features_svg},
 #endif
 //#ifdef CAIRO_HAS_XCB_SURFACE
-//    {FORMAT_XCB, "xcb:cairo", 0, NULL, &device_features_bitmaps},
+//    {FORMAT_XCB, "xcb:cairo", 0, NULL, &device_features_xcb},
 //#endif
 //#ifdef CAIRO_HAS_SDL_SURFACE
-//    {FORMAT_SDL, "sdl:cairo", 0, NULL, &device_features_bitmaps},
+//    {FORMAT_SDL, "sdl:cairo", 0, NULL, &device_features_sdl},
 //#endif
 //#ifdef CAIRO_HAS_GLITZ_SURFACE
-//    {FORMAT_GLITZ, "glitz:cairo", 0, NULL, &device_features_bitmaps},
+//    {FORMAT_GLITZ, "glitz:cairo", 0, NULL, &device_features_glitz},
 //#endif
 //#ifdef CAIRO_HAS_QUARTZ_SURFACE
-//    {FORMAT_QUARTZ, "quartz:cairo", 0, NULL, &device_features_bitmaps},
+//    {FORMAT_QUARTZ, "quartz:cairo", 0, NULL, &device_features_quartz},
 //#endif
 //#ifdef CAIRO_HAS_WIN32_SURFACE
-//    {FORMAT_WIN32, "win32:cairo", 0, NULL, &device_features_bitmaps},
+//    {FORMAT_WIN32, "win32:cairo", 0, NULL, &device_features_win32},
 //#endif
 #endif
     {0, NULL, 0, NULL, NULL}