From: ellson Date: Tue, 18 Oct 2005 20:58:07 +0000 (+0000) Subject: Allow bitmap images in postscript output; X-Git-Tag: LAST_LIBGRAPH~32^2~7121 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6989f4e978d8ab48754dadda3f4e27fe80f6521f;p=graphviz Allow bitmap images in postscript output; update Windows build script --- diff --git a/lib/common/psgen.c b/lib/common/psgen.c index 614318407..c09905c65 100644 --- a/lib/common/psgen.c +++ b/lib/common/psgen.c @@ -24,6 +24,7 @@ #include "render.h" #include "ps.h" #include "agxbuf.h" +#include "gd.h" #ifndef MSWIN32 #include @@ -36,6 +37,8 @@ void epsf_emit_body(ps_image_t *img, FILE *of); extern void ps_freeusershapes(void); extern ps_image_t *ps_usershape(char *shapeimagefile); +extern gdImagePtr gd_getshapeimage(char *name); + static int N_pages, Cur_page; /* static point Pages; */ static box PB; @@ -471,6 +474,50 @@ static void ps_polyline(point * A, int n) fprintf(Output_file, Stroke); } +static void writePSBitmap (gdImagePtr im, point p, point sz) +{ + int x, y, px; + + fprintf(Output_file, "gsave\n"); + + /* this sets the position of the image */ + fprintf(Output_file, "%d %d translate %% lower-left coordinate\n", p.x, p.y); + + /* this sets the rendered size, from 'pixels' to points (1/72 inch) */ + fprintf(Output_file,"%d %d scale\n", sz.x, sz.y); + + /* xsize ysize bits-per-sample [matrix] */ + fprintf(Output_file, "%d %d 8 [%d 0 0 %d 0 %d]\n", im->sx, im->sy, + im->sx, -(im->sy), im->sy); + + fprintf(Output_file, "{<\n"); + for (y = 0; y < im->sy; y++) { + for (x = 0; x < im->sx; x++) { + if (im->trueColor) { + px = gdImageTrueColorPixel(im, x, y); + fprintf(Output_file, "%02x%02x%02x", + gdTrueColorGetRed(px), + gdTrueColorGetGreen(px), + gdTrueColorGetBlue(px)); + } + else { + px = gdImagePalettePixel(im, x, y); + fprintf(Output_file, "%02x%02x%02x", + im->red[px], + im->green[px], + im->blue[px]); + } + } + fprintf(Output_file, "\n"); + } + + fprintf(Output_file, ">}\n"); + fprintf(Output_file, "false 3 colorimage\n"); + + fprintf(Output_file, "grestore\n"); + +} + /* ps_user_shape: * Images for postscript are complicated by the old epsf shape, as * well as user-defined shapes using postscript code. @@ -483,7 +530,7 @@ static void ps_polyline(point * A, int n) static void ps_user_shape(char *name, point * A, int sides, int filled) { int j; - ps_image_t *img = 0; + gdImagePtr bmimg; point offset; char *shapeimagefile = NULL; char *suffix; @@ -492,7 +539,6 @@ static void ps_user_shape(char *name, point * A, int sides, int filled) return; if (streq(name, "custom")) { shapeimagefile = agget(Curnode, "shapefile"); - img = ps_usershape(shapeimagefile); } else if (find_user_shape(name)) { fprintf(Output_file, "[ "); @@ -504,36 +550,39 @@ static void ps_user_shape(char *name, point * A, int sides, int filled) return; } else - img = ps_usershape(name); - if (img) { - ps_begin_context(); - offset.x = -img->origin.x - (img->size.x) / 2; - offset.y = -img->origin.y - (img->size.y) / 2; - fprintf(Output_file, "%d %d translate newpath\n", + shapeimagefile = name; + + assert (shapeimagefile); + suffix = strrchr(shapeimagefile, '.'); + if (suffix) { + suffix++; + if (streq(suffix, "ps")) { + ps_image_t *img = 0; + img = ps_usershape(shapeimagefile); + if (!img) /* problems would have been reported by image_size */ + return; + ps_begin_context(); + offset.x = -img->origin.x - (img->size.x) / 2; + offset.y = -img->origin.y - (img->size.y) / 2; + fprintf(Output_file, "%d %d translate newpath\n", ND_coord_i(Curnode).x + offset.x, ND_coord_i(Curnode).y + offset.y); - if (img->must_inline) epsf_emit_body(img,Output_file); - else fprintf(Output_file,"user_shape_%d\n",img->macro_id); - ps_end_context(); - } - else if (shapeimagefile) { - suffix = strrchr(shapeimagefile, '.'); - if (suffix) { - suffix++; - if (strcmp(suffix, "ps")) { - agerr(AGERR, - "image type \"%s\" not supported in PostScript output\n", - suffix); - } else { - agerr(AGERR, "Could not find image file \"%s\"\n", - shapeimagefile); - } - } else { - agerr(AGERR, - "image file %s not supported in PostScript output\n", - shapeimagefile); + if (img->must_inline) epsf_emit_body(img,Output_file); + else fprintf(Output_file,"user_shape_%d\n",img->macro_id); + ps_end_context(); + } + else if ((bmimg = gd_getshapeimage(shapeimagefile))) { + point sz; + sz.x = A[0].x - A[2].x; + sz.y = A[0].y - A[2].y; + writePSBitmap (bmimg, A[2], sz); } - } + else { /* some other type of image */ + agerr(AGERR, "image type \"%s\" of file %s unsupported in PostScript output\n", + suffix, shapeimagefile); + } + } + /* if !suffix, already reported by image_size */ } codegen_t PS_CodeGen = { diff --git a/windows/bin/win.sh b/windows/bin/win.sh index 9558e2d13..00d7e964f 100755 --- a/windows/bin/win.sh +++ b/windows/bin/win.sh @@ -8,12 +8,13 @@ TCLSH=/C/tcl/bin/tclsh.exe # tcl INPKG=graphviz-win.tgz # input CVS package #WISE=/C/wisein~1/wise32.exe # = /Wise InstallMaker WISE=/C/progra~1/wisein~2/wise32.exe # = Wise InstallMaker -SOURCE=ellson@www.graphviz.org:www.graphviz.org/pub/graphviz -NSOURCE=www.graphviz.org:/home/ellson/www.graphviz.org/pub/graphviz +SOURCEID=ellson@www.graphviz.org +SOURCE=/home/ellson/www.graphviz.org/pub/graphviz +#NSOURCE=www.graphviz.org:/home/ellson/www.graphviz.org/pub/graphviz SOURCEFILE=$SOURCE/CURRENT/$INPKG -NSOURCEFILE=$NSOURCE/CURRENT/$INPKG +#NSOURCEFILE=$NSOURCE/CURRENT/$INPKG DESTDIR=$SOURCE/CURRENT -NDESTDIR=$NSOURCE/CURRENT +#NDESTDIR=$NSOURCE/CURRENT OPTION=Release WISEFLAG=0 @@ -45,10 +46,12 @@ function getFile { # $TCLSH get.tcl $INPKG # scp -q $SOURCEFILE . >> $LFILE 2>&1 - echo ssh soohan scp -q $NSOURCEFILE . >> $LFILE 2>&1 - ssh soohan scp -q $NSOURCEFILE . - echo rcp raptor:graphviz-win.tgz . >> $LFILE 2>&1 - rcp raptor:graphviz-win.tgz . >> $LFILE 2>&1 +# echo ssh graphviz. scp -q $NSOURCEFILE . >> $LFILE 2>&1 +# ssh soohan scp -q $NSOURCEFILE . +# echo rcp raptor:graphviz-win.tgz . >> $LFILE 2>&1 +# rcp raptor:graphviz-win.tgz . >> $LFILE 2>&1 + echo ssh $SOURCEID "cat $SOURCEFILE" >> $LFILE + ssh $SOURCEID "cat $SOURCEFILE" > $INPKG 2>> $LFILE if [[ $? != 0 ]] then ErrorEx "failure to get source" @@ -64,9 +67,11 @@ function putFile # sleep 10 # kill $PID BASE=$(basename $1) - rcp $1 raptor:. >> $LFILE 2>&1 - ssh raptor scp -q $BASE $NDESTDIR >> $LFILE 2>&1 - ssh raptor rm $BASE >> $LFILE 2>&1 +# rcp $1 raptor:. >> $LFILE 2>&1 +# ssh raptor scp -q $BASE $NDESTDIR >> $LFILE 2>&1 +# ssh raptor rm $BASE >> $LFILE 2>&1 + echo "cat $1 | ssh $SOURCEID cat - $DESTDIR" >> $LFILE + cat $1 | ssh $SOURCEID "cat - $DESTDIR" if [[ $? != 0 ]] then ErrorEx "failure to put $1"