/*
 * $RCSfile: ControlWraps.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:    PSWDefineControlPoints
**
** DESCRIPTION: Defines control point procedures
**
** PARAMETERS:  None
**
** RETURN:      None
**
***************************************************************/
defineps PSWDefineControlPoints(float size)
    /HALF size 2 div def

    % Bound rectangle fill
    /BRF{ 			% x y BRF -
        moveto HALF neg HALF neg rmoveto  0 size rlineto
        size 0 rlineto 0 size neg rlineto size neg 0 rlineto
        closepath fill
    } bind def

    % Bound rectangle stroked
    /BRS{ 			% x y BRS -
        moveto HALF neg HALF neg rmoveto  0 size rlineto
        size 0 rlineto 0 size neg rlineto size neg 0 rlineto
        closepath stroke
    } bind def
    
    % Bound X
    /BX { 			% x y BX -
        moveto HALF neg HALF neg rmoveto size size rlineto
        0 size neg rmoveto size neg size rlineto stroke
    } bind def
    
    % Bound cross
    /BC{ 			% x y BC -
        moveto
        0 HALF rmoveto  0 size neg rlineto
        HALF neg HALF rmoveto size 0 rlineto stroke
    }  bind def
	    
    % Stroke adjustment
    /A  { 			% x y  A  x' y'
	transform
	floor 0.5 add exch
	floor 0.5 add exch
	itransform
    } bind def
endps

/***************************************************************
**
** FUNCTION:    PSWDefineFont
**
** DESCRIPTION: Define the font being used for some of the methods.
**
** PARAMETERS:  fontname    the name of the font
**
** RETURN:      None
**
***************************************************************/
defineps PSWDefineFont(char *fontname)
  8 dict dup begin
    /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
        dup (b) 0 get /Rectstroke put
        dup (c) 0 get /Xstroke put
        (d) 0 get /Crossstroke put
    
    /CharProcs 5 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
        /Xstroke
        {
	    0 0 A moveto -500 -500 rmoveto 1000 1000 rlineto
	    -1000 0 rmoveto 1000 -1000 rlineto
	    250 setlinewidth
	    stroke
        } def
        /Crossstroke
        {
            0 0 A moveto 0 500 rmoveto 0 -1000 rlineto
            -500 500 rmoveto 1000 0 rlineto
	    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:    PSWBasic
**
** DESCRIPTION: Draws the control point using the basic wrap
**              defined above and specified in Figure.
**
** PARAMETERS:  X, Y        coordinates of control point
**              Figure      wrap name of figure to draw
**
** RETURN:      None
**
***************************************************************/
defineps PSWBasic(float X, Y; char *Figure)
    X Y Figure
endps

/***************************************************************
**
** FUNCTION:    PSWRectDraw
**
** DESCRIPTION: Draw a rectangular control point.
**
** PARAMETERS:  XYCoords    array of X,Y Coordinate pairs
**              j           number of pairs in array
**              rectOp      DPS rectangular operator
**
** RETURN:      None
**
***************************************************************/
defineps PSWRectDraw (float numstring XYCoords[j]; int j; char *rectOp)
    XYCoords rectOp
endps

/***************************************************************
**
** FUNCTION:    PSWShow
**
** DESCRIPTION: Draw a control point using the show operator.
**
** PARAMETERS:  X, Y        coordinates of control point
**              Char        font character to draw
**
** RETURN:      None
**
***************************************************************/
defineps PSWShow (float X, Y; char *Char)
     X Y moveto (Char) show
endps

/***************************************************************
**
** FUNCTION:    PSWXYShow
**
** DESCRIPTION: Draw a control point using the xyshow operator.
**
** PARAMETERS:  X, Y        coordinates of initial control point
**              CharString  array of font character to draw
**              XYCoords    array of X,Y difference pairs
**              j           number of pairs in array
**
** RETURN:      None
**
***************************************************************/
defineps PSWXYShow (float X, Y; char *CharString;
		    float numstring XYCoords[j]; int j)
    X Y moveto
    (CharString) XYCoords xyshow
endps

/***************************************************************
**
** FUNCTION:    PSWGetTransform
**
** DESCRIPTION: Gets the current transform matrices and offset
**              coordinates.
**
** PARAMETERS:	Ctm         array returning current transform matrix
**              Invctm      array returning 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
