/* $Id: plotX.c,v 1.9 2002/06/09 18:49:11 karim Exp $ Copyright (C) 2000 The PARI group. This file is part of the PARI/GP package. PARI/GP is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY WHATSOEVER. Check the License for details. You should have received a copy of it, along with the package; see the file 'COPYING'. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************/ /* */ /* HIGH RESOLUTION PLOT */ /* */ /*******************************************************************/ #ifdef BOTH_GNUPLOT_AND_X11 /* The switch support in plotgnuplot */ # define rectdraw0 X11_rectdraw0 # define term_set X11_term_set # define PARI_get_plot X11_PARI_get_plot # define plot_outfile_set X11_plot_outfile_set # define set_pointsize X11_set_pointsize # define pari_plot pari_X11plot #endif #include "pari.h" #include "rect.h" #include "../language/anal.h" extern void free_graph(void); #ifdef HPPA # ifndef __GNUC__ typedef char *caddr_t; # endif #endif BEGINEXTERN #include #include #include ENDEXTERN static Colormap PARI_Colormap; static XColor *PARI_Colors; static XColor *PARI_ExactColors; static char *PARI_DefaultColors[MAX_COLORS] = { " ", "black", /* Default */ "blue", /* Axes */ "sienna", /* Odd numbered curves in ploth */ "red", /* Curves, or Even numbered curves in ploth */ "cornsilk", "grey", "gainsboro", }; static void PARI_ColorSetUp(Display *display, char **Colors, int n) { static int init_done = 0; int i; if (init_done) return; init_done=1; PARI_Colormap = DefaultColormap(display, 0); PARI_Colors = (XColor *) gpmalloc((n+1) * sizeof(XColor)); PARI_ExactColors = (XColor *) gpmalloc((n+1) * sizeof(XColor)); for (i=1; ierror_code,buf,MAX_BUF); exiterr(buf); return 0; } static int IOerror(Display *d) { char buf[MAX_BUF]; sprintf(buf, "lost display on %s", DisplayString(d)); exiterr(buf); return 0; } static char* zmalloc(size_t x) { return x? gpmalloc(x): NULL; } void rectdraw0(long *w, long *x, long *y, long lw, long do_free) { double *ptx,*pty; long *c, shift; long *numpoints[MAX_COLORS],*numtexts[MAX_COLORS]; long *xtexts[MAX_COLORS],*ytexts[MAX_COLORS]; long rcolcnt[MAX_COLORS][ROt_MAX]; long col,i,j,x0,y0,a,b,oldwidth,oldheight; long rcnt[ROt_MAX+1], hjust, vjust, hgap, vgap, hgapsize, vgapsize; char **texts[MAX_COLORS]; PariRect *e; RectObj *p1; double xs=1,ys=1; int screen; Display *display; GC gc; Window win; XEvent event; XSizeHints size_hints; XFontStruct *font_info; XSetWindowAttributes attrib; XPoint *points[MAX_COLORS],**lines[MAX_COLORS]; XSegment *seg[MAX_COLORS]; XRectangle *rec[MAX_COLORS]; Atom wm_delete_window, wm_protocols; if (fork()) return; /* parent process returns */ /* child process goes on */ freeall(); /* PARI stack isn't needed anymore, keep rectgraph */ /* if gnuplot X11 plotting is active, may get SIGPIPE... XXXX Better disable * some X callback? */ os_signal(SIGPIPE, SIG_IGN); PARI_get_plot(1); display = XOpenDisplay(NULL); font_info = XLoadQueryFont(display, "9x15"); if (!font_info) exiterr("cannot open 9x15 font"); hgapsize = h_unit; vgapsize = v_unit; XSetErrorHandler(Xerror); XSetIOErrorHandler(IOerror); PARI_ColorSetUp(display,PARI_DefaultColors,MAX_COLORS); for(col=1;colfid); XClearWindow(display, win); XMapWindow(display, win); oldwidth = w_width; oldheight = w_height; for(;;) { XNextEvent(display, &event); switch(event.type) { case ClientMessage: if (event.xclient.message_type != wm_protocols || (Atom)event.xclient.data.l[0] != wm_delete_window) break; case ButtonPress: case DestroyNotify: XUnloadFont(display,font_info->fid); XFreeGC(display,gc); #define myfree(x) if (x) free(x) for(col=1;col