Browse Source

postscript to file

pre-master-46
h_vogt 17 years ago
parent
commit
486ff89800
  1. 5
      ChangeLog
  2. 172
      src/frontend/com_hardcopy.c
  3. 89
      src/frontend/postsc.c
  4. 79
      src/frontend/wdisp/windisp.c

5
ChangeLog

@ -1,3 +1,8 @@
2009-11-29 Holger Vogt
* com_hardcopy.c, postsc.c, windisp.c: plotting with black or white background,
postscript to file with hardcopy command or menue entry from plot window
(still buggy with X11)
2009-11-27 Dietmar Warning
* a bunch of files, most in device library: changed the declarator to new format to
allow safe prototype check (but stay in the original line order)

172
src/frontend/com_hardcopy.c

@ -43,21 +43,17 @@ com_hardcopy(wordlist *wl)
*device = '\0';
if (wl) {
hc_button = 0;
hc_button = 0;
fname = wl->wl_word;
wl = wl->wl_next;
} else {
hc_button = 1;
hc_button = 1;
fname = smktemp("hc");
tempf = TRUE;
}
if (!cp_getvar("hcopydevtype", VT_STRING, buf)) {
#if defined (HAS_WINDOWS) || defined (__MINGW32__) || defined (_MSC_VER)
devtype = "postscript";
#else
devtype = "plot5";
#endif
devtype = "postscript";
} else {
devtype = buf;
}
@ -65,111 +61,132 @@ com_hardcopy(wordlist *wl)
/* enable screen plot selection for these display types */
foundit = 0;
/* save current graphics context, because plotit() will create a new
currentgraph */
PushGraphContext(currentgraph);
#ifndef X_DISPLAY_MISSING
if (!wl && hc_button) {
REQUEST request;
RESPONSE response;
GRAPH *tempgraph;
request.option = click_option;
Input(&request, &response);
if (response.option == error_option) return;
if (response.reply.graph) {
// PushGraphContext(currentgraph);
#ifdef HAS_WINDOWS
if (!wl && hc_button) {
char* psfname;
GRAPH *tempgraph;
if (DevSwitch(devtype)) return;
tempgraph = CopyGraph(response.reply.graph);
tempgraph = CopyGraph(currentgraph);
/* change .tmp to .ps */
psfname = strchr(fname, '.');
*(psfname + 1) = 'p';
*(psfname + 2) = 's';
*(psfname + 3) = '\0';
tempgraph->devdep = fname;
if (NewViewport(tempgraph)) {
DevSwitch(NULL);
return;
DevSwitch(NULL);
return;
}
gr_resize(tempgraph);
gr_redraw(tempgraph);
DestroyGraph(tempgraph->graphid);
DevSwitch(NULL);
foundit = 1;
}
}
#endif
if (!foundit) {
if (!wl) {
outmenuprompt("which variable ? ");
if ((buf2 = prompt(cp_in)) == (char *) -1) /* XXXX Sick */
return;
wl = (struct wordlist *) tmalloc(sizeof(struct wordlist));
wl->wl_word = buf2;
wl->wl_next = NULL;
wl = process(wl);
}
#ifndef X_DISPLAY_MISSING
if (!wl && hc_button) {
REQUEST request;
RESPONSE response;
GRAPH *tempgraph;
request.option = click_option;
Input(&request, &response);
if (response.option == error_option) return;
if (response.reply.graph) {
if (DevSwitch(devtype)) return;
tempgraph = CopyGraph(response.reply.graph);
tempgraph->devdep = fname;
if (NewViewport(tempgraph)) {
DevSwitch(NULL);
return;
}
gr_resize(tempgraph);
gr_redraw(tempgraph);
DestroyGraph(tempgraph->graphid);
DevSwitch(NULL);
foundit = 1;
}
}
if (DevSwitch(devtype)) return;
#endif
if (!wl || !plotit(wl, fname, (char *) NULL)) {
printf("com_hardcopy: graph not defined\n");
DevSwitch(NULL); /* remember to switch back */
return;
}
/* save current graphics context, because plotit() will create a new
currentgraph */
PushGraphContext(currentgraph);
DevSwitch(NULL);
if (!foundit) {
if (!wl) {
outmenuprompt("which variable ? ");
if ((buf2 = prompt(cp_in)) == (char *) -1) /* XXXX Sick */
return;
wl = (struct wordlist *) tmalloc(sizeof(struct wordlist));
wl->wl_word = buf2;
wl->wl_next = NULL;
wl = process(wl);
}
if (DevSwitch(devtype)) return;
if (!wl || !plotit(wl, fname, (char *) NULL)) {
printf("com_hardcopy: graph not defined\n");
DevSwitch(NULL); /* remember to switch back */
return;
}
DevSwitch(NULL);
}
printed = 0;
if (*device) {
#ifdef SYSTEM_PLOT5LPR
if (!strcmp(devtype, "plot5") || !strcmp(devtype, "MFB")) {
if (!cp_getvar("lprplot5", VT_STRING, format))
strcpy(format, SYSTEM_PLOT5LPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
}
if (!strcmp(devtype, "plot5") || !strcmp(devtype, "MFB")) {
if (!cp_getvar("lprplot5", VT_STRING, format))
strcpy(format, SYSTEM_PLOT5LPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
}
#endif
#ifdef SYSTEM_PSLPR
if (!printed && !strcmp(devtype, "postscript")) {
if (!printed && !strcmp(devtype, "postscript")) {
/* note: check if that was a postscript printer XXX */
if (!cp_getvar("lprps", VT_STRING, format))
strcpy(format, SYSTEM_PSLPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
}
if (!cp_getvar("lprps", VT_STRING, format))
strcpy(format, SYSTEM_PSLPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
}
#endif
}
if (!printed) {
if (!strcmp(devtype, "plot5")) {
fprintf(cp_out,
"The file \"%s\" may be printed with the Unix \"plot\" command,\n",
if (!strcmp(devtype, "plot5")) {
fprintf(cp_out,
"The file \"%s\" may be printed with the Unix \"plot\" command,\n",
fname);
fprintf(cp_out,
"\tor by using the '-g' flag to the Unix lpr command.\n");
} else if (!strcmp(devtype, "postscript")) {
fprintf(cp_out,
"The file \"%s\" may be printed on a postscript printer.\n",
fname);
} else if (!strcmp(devtype, "MFB")) {
fprintf(cp_out,
"The file \"%s\" may be printed on a MFB device.\n",
fname);
}
fprintf(cp_out,
"\tor by using the '-g' flag to the Unix lpr command.\n");
} else if (!strcmp(devtype, "postscript")) {
fprintf(cp_out,
"\nThe file \"%s\" may be printed on a postscript printer.\n",
fname);
} else if (!strcmp(devtype, "MFB")) {
fprintf(cp_out,
"The file \"%s\" may be printed on a MFB device.\n",
fname);
}
}
if (tempf && *device)
@ -177,6 +194,5 @@ com_hardcopy(wordlist *wl)
/* restore previous graphics context by retrieving the previous currentgraph */
PopGraphContext();
return;
}

89
src/frontend/postsc.c

@ -47,16 +47,16 @@ typedef struct {
} PSdevdep;
static char *linestyle[] = {
"[]", /* solid */
"[1 2]", /* dotted */
"[7 7]", /* longdashed */
"[3 3]", /* shortdashed */
"[7 2 2 2]", /* longdotdashed */
"[3 2 1 2]", /* shortdotdashed */
"[8 3 2 3]",
"[14 2]",
"[3 5 1 5]" /* dotdashed */
};
"[]", /* solid */
"[1 2]", /* dotted */
"[7 7]", /* longdashed */
"[3 3]", /* shortdashed */
"[7 2 2 2]", /* longdotdashed */
"[3 2 1 2]", /* shortdotdashed */
"[8 3 2 3]",
"[14 2]",
"[3 5 1 5]" /* dotdashed */
};
static FILE *plotfile;
char psfont[128], psfontsize[32], psscale[32], pscolor[32];
@ -81,7 +81,7 @@ void PS_Stroke(void);
int
PS_Init(void)
{
char pswidth[30], psheight[30];
char pswidth[30], psheight[30];
if (!cp_getvar("hcopyscale", VT_STRING, psscale)) {
scale = 1.0;
@ -90,39 +90,39 @@ PS_Init(void)
if ((scale <= 0) || (scale > 10))
scale = 1.0;
}
/* plot color */
if (!cp_getvar("hcopypscolor", VT_NUM, &setbgcolor)) {
/* if not set, set plot to b&w and use line styles */
colorflag = 0;
dispdev->numcolors = 2;
dispdev->numlinestyles = NUMELEMS(linestyle);
} else {
/* get backgroung color and set plot to color */
colorflag = 1;
dispdev->numcolors = 18; /* don't know what the maximum should be */
dispdev->numlinestyles = 1;
cp_getvar("hcopypstxcolor", VT_NUM, &settxcolor);
}
dispdev->numlinestyles = NUMELEMS(linestyle);
/* plot color */
if (!cp_getvar("hcopypscolor", VT_NUM, &setbgcolor)) {
/* if not set, set plot to b&w and use line styles */
colorflag = 0;
dispdev->numcolors = 2;
/* plot size */
if (!cp_getvar("hcopywidth", VT_STRING, pswidth)) {
dispdev->width = 7.75 * 72.0 * scale; /* (8 1/2 - 3/4) * 72 */
} else {
sscanf(pswidth, "%d", &(dispdev->width));
if (dispdev->width <= 100)
dispdev->width = 100;
if (dispdev->width >= 10000)
dispdev->width = 10000;
}
if (!cp_getvar("hcopyheight", VT_STRING, psheight)) {
dispdev->height = dispdev->width;
} else {
sscanf(psheight, "%d", &(dispdev->height));
if (dispdev->height <= 100)
dispdev->height = 100;
if (dispdev->height >= 10000)
dispdev->height = 10000;
}
} else {
/* get backgroung color and set plot to color */
colorflag = 1;
dispdev->numcolors = 21; /* don't know what the maximum should be */
cp_getvar("hcopypstxcolor", VT_NUM, &settxcolor);
}
/* plot size */
if (!cp_getvar("hcopywidth", VT_STRING, pswidth)) {
dispdev->width = 7.75 * 72.0 * scale; /* (8 1/2 - 3/4) * 72 */
} else {
sscanf(pswidth, "%d", &(dispdev->width));
if (dispdev->width <= 100)
dispdev->width = 100;
if (dispdev->width >= 10000)
dispdev->width = 10000;
}
if (!cp_getvar("hcopyheight", VT_STRING, psheight)) {
dispdev->height = dispdev->width;
} else {
sscanf(psheight, "%d", &(dispdev->height));
if (dispdev->height <= 100)
dispdev->height = 100;
if (dispdev->height >= 10000)
dispdev->height = 10000;
}
/* The following side effects have to be considered
* when the printer is called by com_hardcopy !
@ -357,6 +357,7 @@ PS_SetLinestyle(int linestyleid)
}
if (linestyleid < 0 || linestyleid > dispdev->numlinestyles) {
internalerror("bad linestyleid inside PS_SetLinestyle");
fprintf(cp_err, "linestyleid is: %d\n", linestyleid);
return 0;
}
PS_LinestyleColor(linestyleid, currentgraph->currentcolor);
@ -463,6 +464,8 @@ PS_LinestyleColor(int linestyleid, int colorid)
} else { /* colorflag == 0 -> mono*/
if ((colorid == 18) || (colorid == 19))
genstyle=DOTTED;
else if (linestyleid == -1)
genstyle=0;
else
genstyle=linestyleid;
}

79
src/frontend/wdisp/windisp.c

@ -39,7 +39,7 @@
typedef struct { /* Extra window data */
HWND wnd; /* window */
HDC hDC; /* Device context of window */
RECT Area; /* plot area */
RECT Area; /* plot area */
int ColorIndex; /* Index of actual color */
int PaintFlag; /* 1 with WM_PAINT */
int FirstFlag; /* 1 before first update */
@ -54,8 +54,7 @@ void WPRINT_PrintInit( HWND hwnd); /* Windows printer init */
void WaitForIdle(void); /* wait until no more events */
void RemoveWindow(GRAPH *pgraph);
static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy);
/* get new plot size coordinates */
static void RealClose(void);
/* externals */
extern HINSTANCE hInst; /* application instance */
extern int WinLineWidth; /* width of text window */
@ -79,10 +78,16 @@ static WNDCLASS TheWndClass; /* Plot-window class */
static HFONT PlotFont; /* which font */
#define ID_DRUCKEN 0xEFF0 /* System Menue: print */
#define ID_DRUCKEINR 0xEFE0 /* System Menue: printer setup */
#define ID_HARDCOPY 0xEFD0 /* System Menue: hardcopy color*/
#define ID_HARDCOPY_BW 0xEFB0 /* System Menue: hardcopy b&w*/
static const int ID_MASK = 0xFFF0; /* System-Menue: mask */
static char * STR_DRUCKEN = "Printer..."; /* System menue strings */
static char * STR_DRUCKEINR = "Printer setup...";
static char * STR_HARDCOPY = "Postscript file, color";
static char * STR_HARDCOPY_BW = "Postscript file, b&w";
static bool isblack = TRUE; /* background color of plot is black */
static bool isblackold = TRUE;
static int linewidth = 0; /* linewidth of grid and plot */
/******************************************************************************
@ -108,12 +113,18 @@ int WIN_Init( )
dispdev->numlinestyles = 5; /* see implications in WinPrint! */
dispdev->numcolors = NumWinColors;
/* always, user may have set color0 to white */
/* get background color information from spinit, only "white"
is recognized as a suitable option! */
if (cp_getvar("color0", VT_STRING, colorstring)) {
if (cieq(colorstring, "white")) isblack = FALSE;
else isblack = TRUE;
}
/* only for the first time: */
if (!IsRegistered) {
/* get background color information from spinit, only "white"
is recognized as a suitable option! */
if (cp_getvar("color0", VT_STRING, colorstring))
if (cieq(colorstring, "white")) isblack = FALSE;
isblackold = isblack;
/* get linewidth information from spinit */
if (!cp_getvar("xbrushwidth", VT_NUM, &linewidth))
linewidth = 0;
@ -128,6 +139,7 @@ int WIN_Init( )
ColorTable[0] = RGB(255,255,255); /* white = background */
ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */
}
ColorTable[2] = RGB( 0,255, 0); /* green = first line */
ColorTable[3] = RGB(255, 0, 0); /* red */
ColorTable[4] = RGB( 0, 0,255); /* blue */
@ -173,6 +185,23 @@ int WIN_Init( )
TheWndClass.cbWndExtra = sizeof(GRAPH *);
if (!RegisterClass(&TheWndClass)) return 1;
}
/* not first time */
else if (isblackold != isblack) {
if (isblack) {
ColorTable[0] = RGB( 0, 0, 0); /* black = background */
ColorTable[1] = RGB(255,255,255); /* white = text and grid */
}
else {
ColorTable[0] = RGB(255,255,255); /* white = background */
ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */
}
if (isblack)
ColorTable[12]= RGB(255,255,255); /* white */
else
ColorTable[12]= RGB( 0, 0, 0); /* black */
isblackold=isblack;
}
IsRegistered = 1;
/* ready */
@ -195,6 +224,26 @@ static int LType( int ColorIndex)
return PS_SOLID;
}
/* postscript hardcopy from a plot window */
/* called by SystemMenue / Postscript hardcopy */
LRESULT HcpyPlot( HWND hwnd)
{
int colorval = isblack? 0 : 1;
cp_vset("hcopypscolor", VT_NUM, (char*)(&colorval));
com_hardcopy(NULL);
return 0;
}
LRESULT HcpyPlotBW( HWND hwnd)
{
int bgcolor;
if (cp_getvar("hcopypscolor", VT_NUM, &bgcolor))
cp_remvar("hcopypscolor");
com_hardcopy(NULL);
return 0;
}
/* print a plot window */
/* called by SystemMenue / Print */
LRESULT PrintPlot( HWND hwnd)
@ -273,6 +322,8 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
switch(cmd) {
case ID_DRUCKEN: return PrintPlot( hwnd);
case ID_DRUCKEINR: return PrintInit( hwnd);
case ID_HARDCOPY: return HcpyPlot( hwnd);
case ID_HARDCOPY_BW: return HcpyPlotBW( hwnd);
}
}
goto WIN_DEFAULT;
@ -292,7 +343,6 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
if (wParam & MK_LBUTTON)
{
hdc = GetDC (hwnd) ;
if (isblack)
prevmix = SetROP2(hdc, R2_XORPEN);
else
@ -536,6 +586,15 @@ int WIN_NewViewport( GRAPH * graph)
window = CreateWindow( WindowName, graph->plotname, WS_OVERLAPPEDWINDOW,
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
if (!window) return 1;
/* change the background color of all windows (both new and already plotted)
by assessing the registered window class */
if (isblack)
SetClassLong(window, GCLP_HBRBACKGROUND, (int)GetStockObject( BLACK_BRUSH));
else
SetClassLong(window, GCLP_HBRBACKGROUND, (int)GetStockObject( WHITE_BRUSH));
wd->wnd = window;
SetWindowLong( window, 0, (long)graph);
@ -561,6 +620,8 @@ int WIN_NewViewport( GRAPH * graph)
AppendMenu( sysmenu, MF_SEPARATOR, 0, NULL);
AppendMenu( sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN);
AppendMenu( sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR);
AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY, STR_HARDCOPY);
AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY_BW, STR_HARDCOPY_BW);
/* set default parameters of DC */
SetBkColor( dc, ColorTable[0]);
@ -604,7 +665,7 @@ int WIN_Close()
return (0);
}
void RealClose(void)
static void RealClose(void)
{
/* delete window class */
if (IsRegistered) {

Loading…
Cancel
Save