/*
 * $RCSfile: HitWraps.psw,v $
 *
 * (c) Copyright 1992-1994 Adobe Systems Incorporated.
 * All rights reserved.
 * 
 * Permission to use, copy, modify, distribute, and sublicense this software
 * and its documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notices appear in all copies and that
 * both those copyright notices and this permission notice appear in
 * supporting documentation and that the name of Adobe Systems Incorporated
 * not be used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  No trademark license
 * to use the Adobe trademarks is hereby granted.  If the Adobe trademark
 * "Display PostScript"(tm) is used to describe this software, its
 * functionality or for any other purpose, such use shall be limited to a
 * statement that this software works in conjunction with the Display
 * PostScript system.  Proper trademark attribution to reflect Adobe's
 * ownership of the trademark shall be given whenever any such reference to
 * the Display PostScript system is made.
 * 
 * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
 * ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
 * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NON- INFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO EVENT SHALL ADOBE BE LIABLE
 * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  ADOBE WILL NOT
 * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
 * 
 * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
 * Incorporated which may be registered in certain jurisdictions
 * 
 * Author:  Adobe Systems Incorporated
 */

/***************************************************************
**
** FUNCTION:    PSWDrawControlPoints
**
** DESCRIPTION: Draws control points from the current font with xyshow
**
** PARAMETERS:  X, Y		initial position
**		Pts		list of displacements
**		NumPts		size of Pts array
**		String		characters to show
**
** RETURN:      None
**
***************************************************************/

defineps PSWDrawControlPoints (float X, Y; float numstring Pts[NumPts];
			       int NumPts; char *String)
	X Y moveto (String) Pts xyshow
endps

/***************************************************************
**
** FUNCTION:    PSWSetRectViewClip
**
** DESCRIPTION: Sets the view clip to the rectangles
**
** PARAMETERS:  Rect		List of rectangles
**		NumRect		Number of points in Rect
**
** RETURN:      None
**
***************************************************************/

defineps PSWSetRectViewClip(float numstring Rect[NumRect]; int NumRect)
    Rect rectviewclip
endps

/***************************************************************
**
** FUNCTION:    PSWClearWindow
**
** DESCRIPTION: Fills window with white
**
** PARAMETERS:  Width, Height	window dimensions
**
** RETURN:      None
**
***************************************************************/

defineps PSWClearWindow(float Width, Height)
    currentgray 1 setgray 0 0 Width Height rectfill setgray
endps

/***************************************************************
**
** FUNCTION:    PSWDrawGrid
**
** DESCRIPTION: Draws the grid
**
** PARAMETERS:  gray	grayscale for grid
**		width	line width for grid
**		grid	user object for grid
**
** RETURN:      None
**
***************************************************************/

defineps PSWDrawGrid(float gray, width; userobject grid)
    gsave
    gray setgray
    width setlinewidth
    grid ustroke
    grestore
endps

/***************************************************************
**
** FUNCTION:    PSWDefineFont
**
** DESCRIPTION: Define the control point font 
**
** PARAMETERS:  fontname    the name of the font
**
** RETURN:      None
**
***************************************************************/

defineps PSWDefineFont(char *fontname)
  9 dict dup begin
    /A  { 			% x y  A  x' y'
	transform
	floor 0.5 add exch
	floor 0.5 add exch
	itransform
    } bind def
    /FontName /fontname def
    /FontType 3 def
    /FontMatrix [.001 0 0 .001 0 0] def
    /FontBBox [-625 -625 625 625] def 

    /Encoding 256 array def
        0 1 255 {Encoding exch /.notdef put} for
    
    Encoding
        dup (a) 0 get /Rectfill put
        (b) 0 get /Rectstroke put
    
    /CharProcs 3 dict def
    CharProcs begin
        /.notdef { } def
        /Rectfill
        {
            0 0 A moveto -500 -500 rmoveto 0 1000 rlineto
            1000 0 rlineto 0 -1000 rlineto closepath
            fill
        } def
        /Rectstroke
        {
            0 0 A moveto -500 -500 rmoveto 0 1000 rlineto
            1000 0 rlineto 0 -1000 rlineto closepath
	    250 setlinewidth
            stroke
        } def
    end
    
    /BuildChar
    {
        1000 0 -625 -625 625 625 setcachedevice
        exch begin
            true setstrokeadjust
            Encoding exch get
            CharProcs exch get
            exec
        end
    } def
  end
  
  /fontname exch definefont pop
endps

/***************************************************************
**
** FUNCTION:    PSWGetTransform
**
** DESCRIPTION: Gets the current transform matrices and offset
**              coordinates.
**
** PARAMETERS:  None
**
** RETURN:      Ctm         array containing current transform matrix
**              Invctm      array containing inverted matrix
**              XOffset     X offset value
**              YOffset     Y offset value
**
***************************************************************/

defineps PSWGetTransform (| float ctm[6], invctm[6]; 
			  int *xOffset, *yOffset)
	matrix currentmatrix dup ctm
	matrix invertmatrix invctm
	currentXoffset yOffset xOffset
endps

/***************************************************************
**
** FUNCTION:	PSWSetMatrixAndGetTransform
**
** DESCRIPTION:	Sets the current matrix to have the specified
**		translation, scale, and halftone phase, and returns
**		the matrices
**
** PARAMETERS:	tx, ty		translation
**		s		scale
**		hx, hy		halftonephase
**
** RETURN:	Ctm		array of current transform matrix
**		Invctm		array of inverted matrix
**		XOffset		X offset value
**		YOffset		Y offset value
**
***************************************************************/
defineps PSWSetMatrixAndGetTransform (float tx, ty, s; int hx, hy
		| float Ctm[6], Invctm[6]; int *XOffset, *YOffset)
        initmatrix
	tx ty translate
	s s scale
	hx hy sethalftonephase
	matrix currentmatrix dup Ctm
	matrix invertmatrix Invctm
	currentXoffset YOffset XOffset
endps

/***************************************************************
**
** FUNCTION:    PSWDeskTop
**
** DESCRIPTION: Draw gray background, page, and drop shadow
**
** PARAMETERS:  X, Y, W, H	Dimensions of page
**
** RETURN:      None
**
***************************************************************/

defineps PSWDesktop (float X, Y, W, H)
	%
	% draw a background 80% gray "desktop" behind the page
	%
	gsave
		/desk 1024 16 mul def
		/edge 10 def
		newpath
		%
		% draw a hole for the display page at X, Y 
		%
		X Y moveto
		0 H rlineto
		W 0 rlineto
		0 H neg rlineto
		closepath
		%
		% draw the outside, huge, desktop rectangle 
		%
		desk neg desk neg moveto
		desk desk neg lineto
		desk desk lineto
		desk neg desk lineto
		closepath
		%
		% fill the area between the two rectangles 
		%
		0.8 setgray fill
		%
		% add a black drop shadow under the display page
		%
		newpath
		edge edge neg translate
		X Y moveto
		W 0 rlineto
		0 H rlineto
		edge neg 0 rlineto
		0 H neg edge add rlineto
		W neg edge add 0 rlineto
		closepath
		0 setgray fill
	grestore
	%
	% draw a border around the outside of the display page
	%
	gsave
		%
		% draw a black border around the display page edge 
		%
		newpath
		X Y moveto
		W 0 rlineto
		0 H rlineto
		W neg 0 rlineto
		closepath
		4 setlinewidth
		0 setgray
		stroke
	grestore
endps
