/* Defines the internal format of a psplot object. */ /* Last edited on 2002-03-15 09:35:33 by stolfi */ #ifndef psplot_def_H #define psplot_def_H #include /* ** WORK NOTES ** One design goal is to provide a more friendly interface to certain ** functions (dots, separate draw/fill/text colors, lunes, ellipses, ** multiline and aligned text, grids, etc.) Part of that goal is to ** filter out redundant Postscript commands, e.g. repeated "setrgbcolor"s ** and "setfont"s. To accomplish that goal, the PSPLOT object contains ** its own graphics state (as assumed by clients), and also maintains a ** projection of the Postscript intepreter's state. ** TO DO ** We must revise carefully which Postscript state variables are ** mirrored in the PSPLOT object (e.g. line_width) and which ones ** exist only in the interpreter (e.g. the transformation matrix). ** I suppose that the deciding factors are whether a client "set" ** command is likely to be a no-op, and whether the parameter's ** value affects what gets written to the Postscript file. ** We must decide whether the Postscript state must track the ** PSPLOT state closely or lazily. E.g., should the Postscript ** "fillcolor" variable always be set whenever the client changes ** the PSPLOT "fill_color" field? Or should we keep two separate ** fields in the PSPLOT state, "client_fill_color" and ** "ps_fill_color", which are synchronized only before an ** area-filling operator? The latter is more efficient but also ** more dangerous, since we must know for sure which parameters are ** used by each Postscript operator (including those that we ** defined in the prolog). It also seems to require more code. */ typedef enum { psplot_Axis_X, psplot_Axis_Y} psplot_Axis; typedef struct { double min; double max; } psplot_Range; typedef struct { float c[3]; } psplot_Color; /* RGB in the range [0__1]. If any components are negative, the color is interpreted as "invisible" (wholly transparent). */ typedef struct psplot_State { /* Emulated graphics state parameters */ int do_line; /* 1 = draw figure outlines. [in] */ int do_area; /* 1 = fill figure interiors. [in] */ int do_text; /* 1 = display labels and captions. [in] */ double x_min, x_max; /* Nominal range of user's X coords. [ex][vr] */ double y_min, y_max; /* Nominal range of user's Y coords. [ex][vr] */ int n_x, n_y; /* Number of grid cells on each axis. [ex][vr] */ int clip; /* 1 = the plotting region is clipping. [ex][gb] */ double y_caption; /* Ordinate for next "caption" command. [ex][vr] */ psplot_Color area_color; /* Current visible color for area filling. [ex][vr] */ psplot_Color text_color; /* Current visible color for text. [ex][vr] */ psplot_Color line_color; /* Current visible color for line drawing. [ex][ps] */ char *font_name; /* Current font name. [ex][ps] */ float font_size; /* Current font size (points). [ex][ps] */ float line_width; /* Current line width (mm). [ex][ps] */ float *dash_pattern; /* Dash-space pattern lengths (mm). [ex][ps] */ float *dash_pattern_n; /* Number of entries in dash pattern (mm). [ex][ps] */ float dash_skip; /* Initial phase into dash pattern (mm). [ex][ps] */ double x_scale_mm; /* Actual size (mm) of current X unit. [ex][ps] */ double y_scale_mm; /* Actual size (mm) of current Y unit. [ex][ps] */ /* AUXILIARY (DERIVED) VARIABLES */ int line_solid; /* TRUE for non-dashed lines. [dv] */ double x_scale; /* Current combined X scale factor (mm/user). [dv] */ double y_scale; /* Current combined Y scale factor (mm/user). [dv] */ struct psplot_State *next; /* Link to previous state on stack. */ } psplot_State; /* The current graphics state of a PSPLOT object. A psplot_State is analogous to the Postscript graphics state in concept, but differs from it in some details. The fields marked [ex] track certain components of the Postscript interpreter' state. Those marked [ex][ps] correspond to parameters of the Postscript graphics state. Those marked [ex][vr] correspond to Postscript variables kept in the "psplot$dict" dictionary. Those marked [ex][gb] correspond to other global components of the Poststcript state (e.g. the current clipping path). Fields marked [in] are internal to this library, and do not correspond to any persistent components of the Postscript interpreter's state. Finally, fields marked [dv] are convenience variables derived from other fields. Note that some components of the PSPLOT state are not represented in the computer, but are kept entirely in the Postscript state. These include the current coordinate transformation matrix, the current path, and the current path cursor (Postscript's "current point"). The PSPLOT state is pushed by "begin_context" and popped by "end_context". The former call also issues a "gsave" operator to be inserted in the Postscript file. The latter issues a "grestore" operator, possibly followed by "def" commands that explicitly reset any [ex][vr] parameters that were changed between the two calls. */ typedef struct psplot_Descriptor { /* PSPLOT object */ FILE *file; /* The underlying postscript file. [f][ro] */ int epsformat; /* 0 = document, 1 = EPS figure. [f][ro] */ double x_full_mm; /* Page/figure width in millimeters. [f][ro] */ double y_full_mm; /* Page/figure height in millimeters. [f][ro] */ char *title; /* User-given title, for page headline. [f][ro] */ char *date; /* Date file was opened, for 1st page footline. [f][ro] */ int n_pages; /* Number of pages started so far. [f][PS] */ int page_started; /* 1 = $do_begin_page$ was started. [f] */ int page_state_defined; /* 1 = $do_begin_page$ was completed. [f] */ psplot_State *g; /* Emulated graphics state stack. */ } psplot_Descriptor; /* A PSPLOT object is a virtual graphics device that uses a graphics model similar to Postscript. Fields marked [f] are valid throughout the life of the file. Fields marked [p] and [p] can be set or used only within the scope of an unclosed $psplot_begin_page$ or $psplot_begin_drawing$, respectively. */ #endif