void psplot_begin_context( PSPLOT *p, double x_min, double y_min, double x_max, double y_max, int clip ) { if (! p->page_started) { psplot_error("must call begin_page first"); } { double x_min_PS = x_center - x_size/2.0; double x_max_PS = x_min_PS + x_size; double y_min_PS = y_center - y_size/2.0; double y_max_PS = y_min_PS + y_size; psplot_do_begin_context(p, x_min_PS, x_max_PS, y_min_PS, y_max_PS); } } void psplot_end_context(PSPLOT *p) { if (p->epsformat) { psplot_error("illegal in eps file"); } if (! p->page_started) { psplot_error("must call begin_page first"); } if (! p->context_started) { return; } psplot_do_end_context(p); } void psplot_setup_page_state(FILE *psfile, int xn, int yn) { double fxn = xn; double fyn = yn; fprintf(psfile, "%% Round joints and caps:\n"); fprintf(psfile, "1 setlinecap 1 setlinejoin\n"); fprintf(psfile, "\n"); fprintf(psfile, "%% Black thin lines:\n"); fprintf(psfile, "0 setlinewidth 0 setgray [ ] 0 setdash\n"); fprintf(psfile, "\n"); fprintf(psfile, "/xmin %f def %% min plottable x\n", x_min_PS); fprintf(psfile, "/xmax %f def %% max plottable x\n", x_max_PS); fprintf(psfile, "/xn %d def %% grid cells along x axis\n", xn); fprintf(psfile, "/xstep %f def %% x-size of grid cell\n", (x_max_PS-x_min_PS)/fxn); fprintf(psfile, "/ymin %f def %% min plottable y\n", y_min_PS); fprintf(psfile, "/ymax %f def %% max plottable y\n", y_max_PS); fprintf(psfile, "/yn %d def %% grid cells along y axis\n", yn); fprintf(psfile, "/ystep %f def %% y-size of grid cell\n", (y_max_PS-y_min_PS)/fyn); fprintf(psfile, "%% Units of measure:\n"); fprintf(psfile, "/pt 1.0 def\n"); fprintf(psfile, "/in pt 72.0 mul def \n"); fprintf(psfile, "/mm pt 72.0 25.4 div mul def\n"); fprintf(psfile, "\n"); psplot_set_label_font (psfile, "Courier", 8.0); fprintf(psfile, "%% Set clipping path to boundary of plot area:\n"); fprintf(psfile, "newpath\n"); fprintf(psfile, " xmin ymin moveto\n"); fprintf(psfile, " xmax ymin lineto\n"); fprintf(psfile, " xmax ymax lineto\n"); fprintf(psfile, " xmin ymax lineto\n"); fprintf(psfile, " xmin ymin lineto\n"); fprintf(psfile, "clip\n"); fprintf(psfile, "\n"); fflush(psfile); } void psplot_setup_caption_data(FILE *psfile) { fprintf(psfile, "%% Caption text cursor:\n"); fprintf(psfile, "/xtext xmin def\n"); fprintf(psfile, "/ytext ymin def\n"); fprintf(psfile, "/dytext 10 pt mul def\n"); fprintf(psfile, "\n"); fprintf(psfile, "%% Caption font setup:\n"); fprintf(psfile, "/captionfont\n"); fprintf(psfile, " /Courier findfont\n"); fprintf(psfile, " dytext scalefont\n"); fprintf(psfile, "def\n"); fprintf(psfile, "\n"); } ====================================================================== void psplot_end_figure(FILE *psfile) { psplot_aux_end_page(psfile); fprintf(psfile, "%%%%Trailer\n"); fflush(psfile); } void psplot_save_scales( double xmin, double xmax, double ymin, double ymax, double hmin, double hmax, double vmin, double vmax ) { x_min_PS = hmin; x_max_PS = hmax; ps_xmin = xmin; ps_xmax = xmax; ps_xscale = (hmax - hmin)/(xmax - xmin); y_min_PS = vmin; y_max_PS = vmax; ps_ymin = ymin; ps_ymax = ymax; ps_yscale = (vmax - vmin)/(ymax - ymin); assert ( (fabs(ps_xscale - ps_yscale)/fabs(ps_xscale + ps_yscale) < 0.0001), "psplot_begin_figure: unequal Postscript scales" ); } ====================================================================== /*** PROTOTYPES FOR INTERNAL FUNCTIONS ***/ void ps_aux_polygon( FILE *psfile, double x[], double y[], int npoints, double r, double g, double b, char *operator ); void psplot_aux_rectangle( FILE *psfile, double xlo, double xhi, double ylo, double yhi, double gray, char *operator ); void psplot_aux_polygon( FILE *psfile, double x[], double y[], int npoints, double gray, char *operator ); void psplot_aux_circle( FILE *psfile, double xc, double yc, double radius, double gray, char *operator ); void psplot_aux_lune( FILE *psfile, double xc, double yc, double radius, double tilt, double gray, char *operator ); void ps_aux_slice( FILE *psfile, double xc, double yc, double radius, double start, double stop, double r, double g, double b, char *operator ); void psplot_define_procs(FILE *psfile); void psplot_define_caption_procs(FILE *psfile); void psplot_save_scales( double xmin, double xmax, double ymin, double ymax, double hmin, double hmax, double vmin, double vmax ); void psplot_setup_page_state(FILE *psfile, int xn, int yn); void psplot_setup_caption_data(FILE *psfile); void psplot_aux_end_page(FILE *psfile); void psplot_put_text(FILE *psfile, char *text, char *newline); ====================================================================== int drawing_started; /* 1 = $do_begin_drawing$ was started. [f] */ int drawing_state_defined; /* 1 = $do_begin_drawing$ was completed. [f] */ double y_caption_PS; /* Y of next caption of current drawing. [d][PS][ex] */ Some $psplot$ procedures change only certain descriptor fields these fields (marked [in] above) comprise the `internal state' of the psplot $object$. Other procedures may write Postscript commands to the associated $file$, which may change certain variables of the Postscript interpreter. Some of those variables are mirrored by descriptor fields, marked by [ex], which comprise the `external state' of the object. The remaining fields, marked [tv], are derived from the internal and/or external states, and explicitly provided for convenience. The internal state consists of the nominal ranges for user coordinate and the booleans `do_draw', `do_fill', `do_text'. p->drawing_started = 0; p->drawing_state_defined = 0;