X11: Add a button for writing an SVG file to the plot window.

Update button texts.
Add a function hardcopySVG to write the SVG file, called by
clicking the SVG button.
This commit is contained in:
Holger Vogt 2021-03-02 18:11:07 +01:00
parent 43c44a8ca9
commit 1607b3a21f
1 changed files with 36 additions and 4 deletions

View File

@ -65,7 +65,7 @@ Author: 1988 Jeffrey M. Hsu
typedef struct x11info { typedef struct x11info {
Window window; Window window;
int isopen; int isopen;
Widget shell, form, view, buttonbox, buttons[2]; Widget shell, form, view, buttonbox, buttons[3];
XFontStruct *font; XFontStruct *font;
GC gc; /* graphics context for graphs */ GC gc; /* graphics context for graphs */
GC gridgc; /* graphics context for grid, linewidth may differ */ GC gridgc; /* graphics context for grid, linewidth may differ */
@ -131,6 +131,7 @@ static void resize(Widget w, XtPointer client_data, XEvent *ev, Boolean *continu
//XtCallbackProc //XtCallbackProc
static void hardcopy(Widget w, XtPointer client_data, XtPointer call_data); static void hardcopy(Widget w, XtPointer client_data, XtPointer call_data);
static void hardcopySVG(Widget w, XtPointer client_data, XtPointer call_data);
static void killwin(Widget w, XtPointer client_data, XtPointer call_data); static void killwin(Widget w, XtPointer client_data, XtPointer call_data);
int X11_GetLenStr(GRAPH* gr, char* instring); int X11_GetLenStr(GRAPH* gr, char* instring);
@ -505,18 +506,23 @@ X11_NewViewport(GRAPH *graph)
("buttonbox", boxWidgetClass, DEVDEP(graph).form, bboxargs, XtNumber(bboxargs)); ("buttonbox", boxWidgetClass, DEVDEP(graph).form, bboxargs, XtNumber(bboxargs));
/* set up buttons */ /* set up buttons */
XtSetArg(buttonargs[0], XtNlabel, "quit"); XtSetArg(buttonargs[0], XtNlabel, "Quit");
XtSetArg(bboxargs[1], XtNfromVert, NULL); XtSetArg(bboxargs[1], XtNfromVert, NULL);
DEVDEP(graph).buttons[0] = XtCreateManagedWidget DEVDEP(graph).buttons[0] = XtCreateManagedWidget
("quit", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1); ("quit", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1);
XtAddCallback(DEVDEP(graph).buttons[0], XtNcallback, killwin, graph); XtAddCallback(DEVDEP(graph).buttons[0], XtNcallback, killwin, graph);
XtSetArg(buttonargs[0], XtNlabel, "hardcopy"); XtSetArg(buttonargs[0], XtNlabel, "PostScript");
XtSetArg(bboxargs[1], XtNfromVert, DEVDEP(graph).buttons[0]); XtSetArg(bboxargs[1], XtNfromVert, DEVDEP(graph).buttons[0]);
DEVDEP(graph).buttons[1] = XtCreateManagedWidget DEVDEP(graph).buttons[1] = XtCreateManagedWidget
("hardcopy", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1); ("hardcopy", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1);
XtAddCallback(DEVDEP(graph).buttons[1], XtNcallback, hardcopy, graph); XtAddCallback(DEVDEP(graph).buttons[1], XtNcallback, hardcopy, graph);
XtSetArg(buttonargs[0], XtNlabel, "SVG");
DEVDEP(graph).buttons[2] = XtCreateManagedWidget(
"SVG", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1);
XtAddCallback(DEVDEP(graph).buttons[2], XtNcallback, hardcopySVG, graph);
/* set up fonts */ /* set up fonts */
if (!cp_getvar("xfont", CP_STRING, fontname, sizeof(fontname))) if (!cp_getvar("xfont", CP_STRING, fontname, sizeof(fontname)))
(void) strcpy(fontname, DEF_FONT); (void) strcpy(fontname, DEF_FONT);
@ -726,7 +732,7 @@ X11_Text(const char *text, int x, int y, int angle)
#ifndef HAVE_LIBXFT #ifndef HAVE_LIBXFT
if (DEVDEP(currentgraph).isopen) { if (DEVDEP(currentgraph).isopen) {
if (angle != 0) { if (angle != 0) {
fprintf(stderr, " Xft: angles other than 0 are not supported\n"); fprintf(stderr, " No Xft: angles other than 0 are not supported\n");
} }
XDrawString(display, DEVDEP(currentgraph).window, XDrawString(display, DEVDEP(currentgraph).window,
DEVDEP(currentgraph).gc, x, DEVDEP(currentgraph).gc, x,
@ -1066,6 +1072,7 @@ zoomin(GRAPH *graph)
} }
strncpy(buf2, graph->plotname, sizeof(buf2) - 1); strncpy(buf2, graph->plotname, sizeof(buf2) - 1);
buf2[sizeof buf2 - 1] = '\0';
if ((t = strchr(buf2, ':')) != NULL) if ((t = strchr(buf2, ':')) != NULL)
*t = '\0'; *t = '\0';
@ -1103,6 +1110,11 @@ hardcopy(Widget w, XtPointer client_data, XtPointer call_data)
NG_IGNORE(call_data); NG_IGNORE(call_data);
NG_IGNORE(w); NG_IGNORE(w);
int i = 1;
cp_vset("hcopydevtype", CP_STRING, "postscript");
/* If not set, the color will be b&w, i = 1 is white background */
cp_vset("hcopypscolor", CP_NUM, &i);
/* com_hardcopy() -> gr_resize() -> setcolor() during postscript /* com_hardcopy() -> gr_resize() -> setcolor() during postscript
printing will act on currentgraph with a DEVDEP inherited from PSdevdep. printing will act on currentgraph with a DEVDEP inherited from PSdevdep.
But currentgraph had not changed its devdep, which was derived from But currentgraph had not changed its devdep, which was derived from
@ -1128,6 +1140,26 @@ hardcopy(Widget w, XtPointer client_data, XtPointer call_data)
} }
} }
static void
hardcopySVG(Widget w, XtPointer client_data, XtPointer call_data)
{
NG_IGNORE(call_data);
NG_IGNORE(w);
lasthardcopy = (GRAPH*)client_data;
cp_vset("hcopydevtype", CP_STRING, "svg");
if (currentgraph) {
void* devdep = currentgraph->devdep;
com_hardcopy(NULL);
currentgraph->devdep = devdep;
}
else {
com_hardcopy(NULL);
}
}
static void static void
killwin(Widget w, XtPointer client_data, XtPointer call_data) killwin(Widget w, XtPointer client_data, XtPointer call_data)