/***********************************************************************
 *
 * TITLE:
 *	gr_plot.h
 *
 * AUTHOR:
 *	Kevin J. Miller, Ana Maria Guerrero, Chester Joe
 *
 * DESCRIPTION:
 *	This module is the header file for the gr_ graphics ploting
 *	routines.
 *
 *				CHANGE HISTORY
 *
 * $Log: gr_plot.h,v $
 * Revision 1.19  1994/11/30  02:17:23  kevin
 * added gr_circle_fill
 *
 * Revision 1.18  1994/06/17  03:48:03  kevin
 * make option for AppleSingle or PICT
 *
 * Revision 1.17  1994/06/15  00:05:26  kevin
 * updated constants
 *
 * Revision 1.16  1994/06/06  03:15:13  kevin
 * added gr_point function
 *
 * Revision 1.15  1994/05/16  21:11:03  kevin
 * standardized RCS id
 *
 * Revision 1.14  1994/05/16  18:47:46  kevin
 * added partial WMF & univeral header
 *
 * Revision 1.13  1994/04/29  00:19:02  kevin
 * ANSI port - first stage
 *
 * Revision 1.12  1992/12/31  02:55:01  chester
 * add gr_rotate_text function for rotated text.
 * add gr_set_clip and gr_reset_clip.
 *
 * Revision 1.11  1992/12/30  23:10:12  chester
 * add gr_current_state function to get current graphics state.
 * add gr_masked_line function for lines with a white background.
 * add gr_poly_clear for whiting out a polygon.
 *
 * Revision 1.10  1991/10/04  16:53:49  chester
 * remove gr_curve and math library from gr routines
 *
 * Revision 1.9  1991/09/16  17:07:24  chester
 * added gr_rect_shade to header.
 *
 * Revision 1.8  1991/08/27  21:06:05  chester
 * added gr_init_colors and gr_hilight functions.
 *
 * Revision 1.7  1991/08/27  20:40:19  chester
 * added functions gr_poly_fill, gr_rect_fill, and gr_set_line.
 * added line type enumerated type.
 * added bold italic to fonts and rearrange font constant values.
 *
 * Revision 1.6  1991/04/30  00:06:45  kevin
 * added man page (exman style)
 *
 * Revision 1.5  1990/12/28  13:03:17  kevin
 * changed name to gr_ and fixed so there is only one include
 *
 * Revision 1.4  90/12/20  17:15:46  kevin
 * added bitmap definition
 * 
 * Revision 1.3  90/12/19  14:28:33  kevin
 * removed memory functions, and added a screen font routine
 * 
 * Revision 1.2  90/11/29  15:34:25  ana
 * New version.
 * 
 ***********************************************************************
 *
 * WARNINGS:
 *
 * EXTERNAL CALLABLE COMPONENTS (PUBLIC):
 *
 * GLOBALS:
 *
 * WAIVERS:
 *
 * NOTES:
 *
 ***********************************************************************/

#ifdef Header
**
** MANUAL
**	GR_PLOT 3 "December 30, 1992"
** NAME
**	gr_init, gr_init_colors, gr_screen_on, gr_screen_off, gr_laser_on,
**	gr_laser_off, gr_move, gr_draw, gr_line, gr_masked_line, gr_arc,
**	gr_circle, gr_circle_fill, gr_poly, gr_rectangle, gr_clear, gr_page,
**	gr_poly_clear, gr_rect_clear, gr_poly_fill, gr_rect_fill, gr_hilight,
**	gr_text, gr_rotate_text, gr_vert_text, gr_strwidth, gr_txwidth,
**	gr_txheight, gr_txdescent, gr_txascent, gr_free_fonts, gr_set_color,
**	gr_image, gr_set_clip, gr_reset_clip
**	-- common graphics interface to Xlib and PostScript
** SYNOPSIS
**	#include <stdio.h>
**	#include <X11/Xlib>
**	#include <X11/Intrinsic>
**	#include "gr_plot.h"
**
**	int gr_init(tp_width, tp_height, tp_mode)
**	int tp_width, tp_height, tp_mode;
**
**	int gr_init_colors(p_background, p_foreground, p_highlight)
**	int p_background, p_foreground, p_highlight;
**
**	int gr_current_state()
**
**	int gr_screen_on(disp)
**	GRDisplay *disp;
**
**	int gr_screen_off()
**
**	int gr_laser_on(ulp)
**	FILE *ulp;
**
**	int gr_laser_off()
**
**	int gr_point(x, y)
**	int x, y;
**
**	int gr_move(x, y)
**	int x, y;
**
**	int gr_draw(x, y)
**	int x, y;
**
**	int gr_set_color(color, grayscale)
**	char *cname;
**	float grayscale;
**
**	int gr_set_line(line)
**	int line;
**
**	int gr_line(x1, y1, x2, y2)
**	int x1, y1, x2, y2;
**
**	int gr_masked_line(x1, y1, x2, y2)
**	int x1, y1, x2, y2;
**
**	int gr_arc(x, y, dx, dy, ang1, ang2)
**	int x, y, dx, dy, ang1, ang2;
**
**	int gr_circle(x, y, r)
**	int x, y, r;
**
**	int gr_circle_fill(x, y, r)
**	int x, y, r;
**
**	int gr_poly(points, npoints)
**	XPoint *points;
**	int npoints;
**
**	int gr_rectangle(x, y, dx, dy)
**	int x, y, dx, dy;
**
**	int gr_clear()
**
**	int gr_page()
**
**	int gr_poly_clear(points, npoints)
**	XPoint *points;
**	int npoints;
**
**	int gr_rect_clear(x, y, dx, dy)
**	int x, y, dx, dy;
**
**	int gr_poly_fill(points, npoints, color, gs)
**	XPoint *points;
**	int npoints;
**	char *color;
**	int gs;
**
**	int gr_rect_fill(x, y, dx, dy, color, gs)
**	int x, y, dx, dy;
**	char *color;
**	int gs;
**
**      int gr_rect_shade(x, y, dx, dy, gs)
**      int x, y, dx, dy;
**      int gs;
**
**      int gr_hilight(x, y, width, height)
**      int x, y, width, height;
**
**	int gr_image(x, y, fsimage, rdimage, scale)
**	int x, y;
**	GRBitmap *fsimage, *rdimage;
**	int scale;
**
**	int gr_set_clip(x, y, dx, dy, orig_clip_region)
**	int x, y, dx, dy;
**	Region orig_clip_region;
**
**	int gr_reset_clip()
**
**	int gr_free_fonts()
**
**	int gr_text(x, y, str, just, font)
**	int x, y;
**	char *str;
**	int just, font;
**
**	int gr_rotate_text(x, y, str, font, rotate)
**	int x, y;
**	char *str;
**	int rotate;
**
**	int gr_vert_text(x, y, str, just, font, delta)
**	int x, y;
**	char *str;
**	int just, font, delta;
**
**	int gr_strwidth(str, font)
**	char *str;
**	int font;
**
**	int gr_txwidth(font)
**	int font;
**
**	int gr_txheight(font)
**	int font;
**
**	int gr_txdescent(font)
**	int font;
**
**	int gr_txascent(font)
**	int font;
**
**	int gr_free_fonts()
**
** DESCRIPTION
**	The _ gr_plot routines are a set of functions that sit on top
**	of the _ Xlib and _ PostScript funtions in order to generate
**	hardcopy of screen drawings without resorting to screendumps.
**	The same sequence of drawing routines used to draw to the screen
**	are used produce hardcopy on a _ PostScript laser printer.
**
**	_ gr_init() must be called once and only once before any other
**	_ gr_plot routines.  The values _ tp_width and _ tp_height
**	specify the width and height of the screen drawing area in
**	pixels.  _ tp_mode determines how the screen is mapped onto
**	8 1/2 by 11 inch paper.  It is the bitwise or of the paper
**	orientation: __ GR_PORTRAIT or __ GR_LANDSCAPE, and mapping
**	of screen pixels to the paper inch. __ GR_STANDARD is 75 pixels
**	to the paper inch, and __ GR_EXPAND is 100 pixels to the paper
**	inch.
**
**	_ gr_init_color() set the foreground, background, and highlight
**	colors from the resource file.
**	
**	_ gr_screen_on() and _ gr_screen_off() are used to delimit
**	any graphics commands to the screen.  The argument _ disp
**	is a _ GRDisplay structure which contains all information
**	needed to specify the drawing window.  The _ GRDisplay structure
**	is given by:
**
** NROFF .RS
** NROFF .nf
** NROFF .ft B
** NROFF typedef struct {
** NROFF 	Display *display;
** NROFF 	int screen;
** NROFF 	int iscolor;
** NROFF 	Window win;
** NROFF 	GC gc;
** NROFF } GRDisplay;
** NROFF .fi
** NROFF .ft R
** NROFF .RE
**
**	The _ display, _ screen, _ win elements uniquely define the
**	drawing window.  _ iscolor is _ TRUE if the screen supports
**	color graphics.  _ gc is the graphics context for the drawing
**	window.  It must be created prior to calling _ gr_screen_on(),
**	and must be editable.
**
**	A program may have more than one drawing window, and these are
**	selected by _ gr_screen_on().
**
**	_ gr_laser_on() and _ gr_laser_off() are used to delimit
**	any graphics commands to the laser printer.  _ gr_laser_on()
**	takes an open file pointer as its argument.  This is typically
**	created with a _ popen() call, however since the laser printer
**	commands are a text stream this may be a file if desired.  The
**	file pointer should be closed after _ gr_laser_off() is called.
**
**	_ gr_point() draws a single point (pixel) at the specified
**	coordinates.
**
**	_ gr_move() sets the current location (or pen position) to
**	the specified coordinates.
**
**	_ gr_draw() draws a line from the current location to the
**	the specified coordinates.  The current location is then set
**	to the specified coordinates: _ (x, _ y).
**
**	_ gr_line() combines _ gr_move() and _ gr_draw() by drawing a
**	line from _ (x1, _ y1) to _ (x2, _ y2).  The current location is
**	set to: _ (x2, _ y2).
**
**	_ gr_masked_line() combines works just like gr_line except it
**	draws a line with the background whited out.
**
**	_ gr_arc() should probably be removed.
**
**	_ gr_circle() draws a circle of radius _ r centered at _ (x, _ y).
**
**	_ gr_circle_fill() draws a filled circle of radius _ r centered
**	at _ (x, _ y).
**
**	_ gr_poly() draws a polygon of _ npoints.  The vertices of the
**	polygon are defined by the array _ points.  _ XPoint is an _ Xlib
**	structure.
**
**	_ gr_rectangle() draws a retangle of width and height _ (dx, _ dy),
**	whose upper left hand corner is at _ (x, _ y).
**
**	_ gr_clear() should probably be removed.
**
**	_ gr_page() should probably be removed.
**
**	_ gr_rect_clear() erases the area specified by the rectangle as
**	in _ gr_rectangle().
**
**	_ gr_poly_fill() fills the area with the foreground color specified
**	by the polygon as in _ gr_poly().  The _ color specifies a color
**	that will fill the polygon.  _ gs is the gray scale of shading for
**	the laser printer.
**
**	_ gr_rect_fill() fills the area with the foreground color specified
**	by the rectangle as in _ gr_rectangle().  The _ color specifies the
**	color that will fill the rectangle.  _ gs is the gray scale of
**	shading for the laser printer.
**
**	- gr_rect_shade shades an area on the laser printer.  These is no
**	shading done to the screen.  The parameters are the save as
**	_ gr_rect_fill.
**
**	_ gr_highlight() highlights the area specified by the rectangle as
**      in _ gr_rectangle().
**
**	_ gr_text() draws the text string _ str at the location _ (x, _ y).
**	The justification _ just may be __ GR_LEFT, __ GR_CENTER, or
**	__ GR_RIGHT.  The font is specified by bitwise ORing the font name
**	with the point size.  Currently, the following font names are
**	defined: __ GR_COURIER, __ GR_COURIER_BOLD, __ GR_COURIER_ITALIC,
**	__ GR_COURIER_BOLD_ITALIC, __ GR_HELVETICA, __ GR_HELVETICA_BOLD,
**	__ GR_HELVETICA_ITALIC, __ GR_HELVETICA_BOLD_ITALIC, __ GR_TIMES,
** 	__ GR_TIMES_BOLD, __ GR_TIMES_ITALIC, __ GR_TIMES_BOLD_ITALIC, and
**	__ GR_SYMBOL.
**
**	The point sizes generally available on X servers are: __ 8, __ 10,
**	__ 12, __ 14, __ 18, and __ 24, but _ gr_text() is not limited to
**	these values if more fonts exist on the server.  The specified font
**	will be loaded automatically if necessary.  The _ mask variable is
**	available to white out the background of the text.
**
**	_ gr_rotate_text() draws the text string _ str with a DEGREE90 or
**	a DEGREE270 rotation at the location _ (x, _ y). The font is
**	specified as in _ gr_text().
**
**	_ gr_vert_text() draws the text string _ str vertically at the
**	location _ (x, _ y).  The justification _ just may be __ GR_TOP,
**	__ GR_CENTER, or __ GR_BOTTOM.  The font is specified as in
**	_ gr_text().  If the height of the font is used to specify the
**	vertical spacing between characters, the resulting text will
**	generally look too spread out.  The parameter _ delta is used
**	to adjust the character spacing.
**
**	_ gr_strwidth() returns the length of the string _ str in pixels
**	for the specified font.
**
**	_ gr_txwidth() returns the maximum character width in pixels
**	for the specified font.
**
**	_ gr_txheight() returns the maximum character height in pixels
**	for the specified font.
**
**	_ gr_txdescent() returns the maximum descent (the distance
**	below the baseline) in pixels for the specified font.
**
**	_ gr_txascent() returns the maximum ascent (the distance
**	above the baseline) in pixels for the specified font.
**
**	_ gr_free_fonts() frees memory used in the server for fonts.
**	It should be called at the end of the program.
**
**	_ gr_set_color() sets the color for future text and graphics.
**	_ cname is a text string naming a color in the X11 color database.
**	_ grayscale is a number from __ 0 (white) to __ 100 (black) used
**	to map the color to the laser printer.
**
**	_ gr_image() copies a bitmap image to the drawing at the
**	location _ (x, _ y).  Since the screen is always 75 pixels
**	per inch,  whereas hardcopy may be done at sizes typically
**	divisible into 300 pixels per inch, a _ scale factor is
**	provided.  _ fsimage is the full size image sent to the laser
**	printer, and _ rdimage is a reduced image sent to the screen.
**	the width and height of _ rdimage should be the width and height
**	of _ fsimage divided by _ scale.
**
**	_ gr_set_clip() sets the X11 clip region to the rectangle denoted
**	by x, y, dx, dy.  Saves the original clip_region for restoration
**	with the next gr_reset_clip() call.
**
**	_ gr_reset_clip() resets the X11 clip region to the clip
**	region before the last gr_set_clip() call.
**
** NOTES
**	These routines are based only on the Xlib functions, and therefore
**	will work with both Motif and XView programs.  The header files
**	__ <Xm/Xm.h> and __ <xview/xview.h> include the Xlib header file
**	__ <X11/Xlib.h> automatically.
** BUGS
**	Functions should be properly typed and not all be int.
**
**	_ gr_free_fonts() should also free local memory used for font
**	information.
**
#endif

#ifndef gr_plot_h
#define gr_plot_h

#ifndef lint
static char rcsid_gr_plot[] =
    "$Id: gr_plot.h,v 1.19 1994/11/30 02:17:23 kevin OEL $";
#endif

/*
 * structure definitions
 */
typedef struct {
    Display *display;           /* pointer to display structure */
    int screen;                 /* screen number for display (typically 0) */
    int iscolor;                /* TRUE if color screen */
    Window win;                 /* drawing window for X */
    GC gc;                      /* graphics context for window */
} GRDisplay;

typedef struct {
    unsigned int width;		/* width of bitmap in pixels */
    unsigned int height;	/* height of bitmap in pixels */
    char *bits;			/* array of data bits in bitmap */
} GRBitmap;

/*
 * constant definitions
 */
#define GR_PORTRAIT	0
#define GR_LANDSCAPE	1
#define GR_STANDARD	0
#define GR_EXPAND	2

#define GR_LEFT		0
#define GR_CENTER	1
#define GR_RIGHT	2
#define GR_TOP		GR_LEFT
#define GR_BOTTOM	GR_RIGHT

#define GR_SOLID_LINE	0
#define GR_DOT_LINE	1
#define GR_SHORT_DASH	2
#define GR_LONG_DASH	3

/*
 * fonts
 */
#define GR_COURIER			0x0000
#define GR_COURIER_BOLD			0x0100
#define GR_COURIER_ITALIC		0x0200
#define GR_COURIER_BOLD_ITALIC		0x0300
#define GR_HELVETICA			0x0400
#define GR_HELVETICA_BOLD		0x0500
#define GR_HELVETICA_ITALIC		0x0600
#define GR_HELVETICA_BOLD_ITALIC	0x0700
#define GR_TIMES			0x0800
#define GR_TIMES_BOLD			0x0900
#define GR_TIMES_ITALIC			0x0A00
#define GR_TIMES_BOLD_ITALIC		0x0B00
#define GR_SYMBOL			0x1200

#define GR_BOLD				0x0100
#define GR_ITALIC			0x0200
#define GR_FONT_NAME			0xff00
#define GR_FONT_FAMILY			0xfc00
#define GR_FONT_OPTIONS			0x0300
#define GR_FONT_SIZE			0x00ff

/*
 * text rotation
 */
#define GR_DEGREE90  90
#define GR_DEGREE270 270

#ifdef _NO_PROTO
#define P_(x) ()
#else
#define P_(x) x
#endif

/*
 * global function prototypes
 */
extern void gr_init P_((int, int, int));
extern void gr_init_colors P_((unsigned long, unsigned long, unsigned long));
extern int gr_current_state P_((void));
extern void gr_screen_on P_((GRDisplay *));
extern void gr_screen_off P_((void));
extern void gr_laser_on P_((FILE *));
extern void gr_laser_off P_((void));
extern int gr_pict_on P_((char *, int));
extern void gr_pict_off P_((void));
extern int gr_wmf_on P_((char *));
extern void gr_wmf_off P_((void));
extern int gr_debug_on P_((char *));
extern void gr_debug_off P_((void));
extern void gr_point P_((int, int));
extern void gr_move P_((int, int));
extern void gr_set_line P_((int));
extern void gr_draw P_((int, int));
extern void gr_line P_((int, int, int, int));
extern void gr_masked_line P_((int, int, int, int));
extern void gr_arc P_((int, int, int, int, int, int));
extern void gr_circle P_((int, int, int));
extern void gr_circle_fill P_((int, int, int));
extern void gr_poly P_((XPoint *, int));
extern void gr_rectangle P_((int, int, int, int));
extern void gr_clear P_((void));
extern void gr_page P_((void));
extern void gr_poly_clear P_((XPoint *, int));
extern void gr_rect_clear P_((int, int, int, int));
extern void gr_poly_fill P_((XPoint *, int, char *, int));
extern void gr_rect_fill P_((int, int, int, int, char *, int));
extern void gr_rect_shade P_((int, int, int, int, int));
extern void gr_hilight P_((int, int, int, int));
extern void gr_free_fonts P_((void));
extern void gr_text P_((int, int, char *, int, int, int));
extern void gr_rotate_text P_((int, int, char *, int, int));
extern void gr_vert_text P_((int, int, char *, int, int, int));
extern int gr_strwidth P_((char *, int));
extern int gr_txwidth P_((int));
extern int gr_txheight P_((int));
extern int gr_txdescent P_((int));
extern int gr_txascent P_((int));
extern void gr_set_color P_((char *, int));
extern void gr_image P_((int, int, GRBitmap *, GRBitmap *, int));
extern void gr_set_clip P_((int, int, int, int, Region));
extern void gr_reset_clip P_((void));

#endif
