Added a "plot svg" command that, when used in conjuction with the
Cairo graphics package (magic -d XR), will map the display onto an SVG surface and save it to a file using the Cairo SVG backend. Due to the simplicity of the mapping, there are no options to this plot command; it just creates a file that is a (scalable!) replica of the layout window.
This commit is contained in:
parent
c08ddd355f
commit
1f3a512909
|
|
@ -22,6 +22,7 @@
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
#include <cairo/cairo-xlib.h>
|
#include <cairo/cairo-xlib.h>
|
||||||
|
#include <cairo/cairo-svg.h>
|
||||||
|
|
||||||
#include "tcltk/tclmagic.h"
|
#include "tcltk/tclmagic.h"
|
||||||
#include "utils/main.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
|
* Set the Cairo projection matrix for a window
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,9 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
POSTSCRIPT=0,
|
POSTSCRIPT=0,
|
||||||
PLOTPNM,
|
PLOTPNM,
|
||||||
|
#ifdef HAVE_LIBCAIRO
|
||||||
|
PLOTSVG,
|
||||||
|
#endif
|
||||||
#ifdef GREMLIN
|
#ifdef GREMLIN
|
||||||
STYLE_GREMLIN,
|
STYLE_GREMLIN,
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -94,12 +97,19 @@ CmdPlot(w, cmd)
|
||||||
float width;
|
float width;
|
||||||
int iwidth, scale;
|
int iwidth, scale;
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBCAIRO
|
||||||
|
extern void GrTCairoPlotSVG();
|
||||||
|
#endif
|
||||||
|
|
||||||
static char *cmdPlotOption[] =
|
static char *cmdPlotOption[] =
|
||||||
{
|
{
|
||||||
"postscript file [layers] generate PostScript file for what's\n\
|
"postscript file [layers] generate PostScript file for what's\n\
|
||||||
underneath the box",
|
underneath the box",
|
||||||
"pnm file [width [layers]] generate PNM file for what's\n\
|
"pnm file [width [layers]] generate PNM file for what's\n\
|
||||||
underneath the box",
|
underneath the box",
|
||||||
|
#ifdef HAVE_LIBCAIRO
|
||||||
|
"svg file generate SVG file for the whole window",
|
||||||
|
#endif
|
||||||
#ifdef GREMLIN
|
#ifdef GREMLIN
|
||||||
"gremlin file [layers] generate gremlin file for what's\n\
|
"gremlin file [layers] generate gremlin file for what's\n\
|
||||||
underneath the box",
|
underneath the box",
|
||||||
|
|
@ -138,6 +148,9 @@ CmdPlot(w, cmd)
|
||||||
#ifdef GREMLIN
|
#ifdef GREMLIN
|
||||||
|| (option == STYLE_GREMLIN)
|
|| (option == STYLE_GREMLIN)
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_LIBCAIRO
|
||||||
|
|| (option == PLOTSVG)
|
||||||
|
#endif
|
||||||
#ifdef VERSATEC
|
#ifdef VERSATEC
|
||||||
|| (option == STYLE_VERSATEC)
|
|| (option == STYLE_VERSATEC)
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -192,7 +205,7 @@ CmdPlot(w, cmd)
|
||||||
}
|
}
|
||||||
PlotPS(cmd->tx_argv[2], &scx, &mask, crec->dbw_bitmask);
|
PlotPS(cmd->tx_argv[2], &scx, &mask, crec->dbw_bitmask);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef GREMLIN
|
#ifdef GREMLIN
|
||||||
case STYLE_GREMLIN:
|
case STYLE_GREMLIN:
|
||||||
if ((cmd->tx_argc != 3) && (cmd->tx_argc != 4))
|
if ((cmd->tx_argc != 3) && (cmd->tx_argc != 4))
|
||||||
|
|
@ -250,6 +263,18 @@ CmdPlot(w, cmd)
|
||||||
return;
|
return;
|
||||||
#endif
|
#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:
|
case PLOTPNM:
|
||||||
if (cmd->tx_argc > 5)
|
if (cmd->tx_argc > 5)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue