diff --git a/graphics/grTCairo1.c b/graphics/grTCairo1.c index ff9a50c8..7e293d2f 100644 --- a/graphics/grTCairo1.c +++ b/graphics/grTCairo1.c @@ -22,6 +22,7 @@ #include #include +#include #include "tcltk/tclmagic.h" #include "utils/main.h" @@ -342,9 +343,47 @@ GrTCairoFlush () } /* + *--------------------------------------------------------- + * Generate SVG graphics output *--------------------------------------------------------- */ +void +GrTCairoPlotSVG (char *filename, MagWindow *mw) +{ + int screenw, screenh; + cairo_surface_t *wind_surface; + cairo_t *wind_context; + + TCairoData *tcairodata = (TCairoData *)mw->w_grdata2; + + if (tcairodata == NULL) + { + TxError("Must be running in mode \"-d XR\" (CAIRO) to get SVG output.\n"); + return; + } + + screenw = mw->w_screenArea.r_xtop - mw->w_screenArea.r_xbot; + screenh = mw->w_screenArea.r_ytop - mw->w_screenArea.r_ybot; + + wind_surface = tcairodata->surface; + wind_context = tcairodata->context; + tcairodata->surface = (cairo_surface_t *)cairo_svg_surface_create(filename, + (double)screenw, (double)screenh); + tcairodata->context = cairo_create(tcairodata->surface); + WindRedisplay(mw); + WindUpdate(); + + cairo_surface_destroy(tcairodata->surface); + cairo_destroy(tcairodata->context); + tcairodata->surface = wind_surface; + tcairodata->context = wind_context; + WindRedisplay(mw); + WindUpdate(); + + return; +} + /* *--------------------------------------------------------- * Set the Cairo projection matrix for a window diff --git a/plot/plotCmd.c b/plot/plotCmd.c index 15706de6..4baa8cb9 100644 --- a/plot/plotCmd.c +++ b/plot/plotCmd.c @@ -67,6 +67,9 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/ typedef enum { POSTSCRIPT=0, PLOTPNM, +#ifdef HAVE_LIBCAIRO + PLOTSVG, +#endif #ifdef GREMLIN STYLE_GREMLIN, #endif @@ -94,12 +97,19 @@ CmdPlot(w, cmd) float width; int iwidth, scale; +#ifdef HAVE_LIBCAIRO + extern void GrTCairoPlotSVG(); +#endif + static char *cmdPlotOption[] = { "postscript file [layers] generate PostScript file for what's\n\ underneath the box", "pnm file [width [layers]] generate PNM file for what's\n\ underneath the box", +#ifdef HAVE_LIBCAIRO + "svg file generate SVG file for the whole window", +#endif #ifdef GREMLIN "gremlin file [layers] generate gremlin file for what's\n\ underneath the box", @@ -138,6 +148,9 @@ CmdPlot(w, cmd) #ifdef GREMLIN || (option == STYLE_GREMLIN) #endif +#ifdef HAVE_LIBCAIRO + || (option == PLOTSVG) +#endif #ifdef VERSATEC || (option == STYLE_VERSATEC) #endif @@ -192,7 +205,7 @@ CmdPlot(w, cmd) } PlotPS(cmd->tx_argv[2], &scx, &mask, crec->dbw_bitmask); return; - + #ifdef GREMLIN case STYLE_GREMLIN: if ((cmd->tx_argc != 3) && (cmd->tx_argc != 4)) @@ -250,6 +263,18 @@ CmdPlot(w, cmd) return; #endif +#ifdef HAVE_LIBCAIRO + case PLOTSVG: + if (cmd->tx_argc > 3) + { + TxError("Too many arguments:\n plot %s\n", + cmdPlotOption[PLOTSVG]); + return; + } + GrTCairoPlotSVG(cmd->tx_argv[2], window); + return; +#endif + case PLOTPNM: if (cmd->tx_argc > 5) {