(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10)
(FILECREATED " 8-Dec-87 17:13:07" |{MCS:MCS:STANFORD}<LANE>HPGL.;21| 41881  

      changes to%:  (FNS \COLOR.HPGL \FILL.HPGL)
                    (VARS HPGLCOMS)
                    (RECORDS RGB)

      previous date%: "10-Nov-87 15:37:41" |{MCS:MCS:STANFORD}<LANE>HPGL.;17|)


(* "
Copyright (c) 1985, 1986, 1987 by Stanford University.  All rights reserved.
")

(PRETTYCOMPRINT HPGLCOMS)

(RPAQQ HPGLCOMS 
       ((* * User Functions)
        (FNS MAKEHPGL OPENHPGLSTREAM HARDCOPYW.HPGL)
        (* * ImageOp Functions)
        (FNS \BITBLT.HPGL \BLTSHADE.HPGL \CLOSEFN.HPGL \COLOR.HPGL \DRAWARC.HPGL \DRAWCIRCLE.HPGL 
             \DRAWCURVE.HPGL \DRAWLINE.HPGL \DRAWPOLYGON.HPGL \FILLCIRCLE.HPGL \FONT.HPGL 
             \LEFTMARGIN.HPGL \LINEFEED.HPGL \MOVETO.HPGL \RESET.HPGL \RIGHTMARGIN.HPGL \ROTATE.HPGL 
             \SCALEDBITBLT.HPGL \STRINGWIDTH.HPGL \CLIPPINGREGION.HPGL \TERPRI.HPGL \XPOSITION.HPGL 
             \YPOSITION.HPGL)
        (* * Internal Functions)
        (FNS \DUMPSTRING.HPGL \FONTCREATE.HPGL \INIT.HPGL \OUTCHAR.HPGL \SEARCH.HPGL.FONTS \FILL.HPGL 
             \DASHING.HPGL)
        (* * etc.)
        (VARS HPGL.FONTS HPGL.OPTIONS HPGL.FONT.EXPANSIONS HPGL.DASHING (SKETCHINCOLORFLG T))
        (INITVARS (HPGL.TERMINATOR (CHARACTER (CHARCODE ;)))
               (HPGL.SEPARATOR (CHARACTER (CHARCODE %,)))
               (HPGL.TEXT.TERMINATOR (CHARACTER (CHARCODE ↑A)))
               HPGL.CHORD.ANGLE HPGL.PATTERN.LENGTH \HPGLIMAGEOPS \NULLFDEV SK.DASHING.PATTERNS)
        (GLOBALVARS HPGL.FONTS HPGL.OPTIONS HPGL.FONT.EXPANSIONS HPGL.DASHING HPGL.TERMINATOR 
               HPGL.SEPARATOR HPGL.TEXT.TERMINATOR HPGL.CHORD.ANGLE HPGL.PATTERN.LENGTH \HPGLIMAGEOPS 
               \NULLFDEV)
        (DECLARE%: DOEVAL@COMPILE DONTCOPY (FILES UTILISOPRS)
               (ALISTS (PRINTOUTMACROS !, !; !!;))
               (RECORDS PLOTTERDATA))
        [ADDVARS (PRINTERTYPES ((PLOTTER HPGL)
                                (CANPRINT (HPGL))
                                (STATUS TRUE)
                                (BITMAPFILE (HARDCOPYW.HPGL FILE BITMAP SCALEFACTOR REGION ROTATION 
                                                   TITLE))
                                (PROPERTIES NILL)))
               [PRINTFILETYPES (HPGL (EXTENSION (HPGL PLOT))
                                     (CONVERSION (TEXT MAKEHPGL TEDIT
                                                       (LAMBDA (FILE PFILE)
                                                              (SETQ FILE (OPENTEXTSTREAM FILE))
                                                              (TEDIT.FORMAT.HARDCOPY FILE PFILE T NIL 
                                                                     NIL NIL 'HPGL)
                                                              (CLOSEF? FILE)
                                                              PFILE]
               (IMAGESTREAMTYPES (HPGL (OPENSTREAM OPENHPGLSTREAM)
                                       (FONTCREATE \FONTCREATE.HPGL)
                                       (FONTSAVAILABLE \SEARCH.HPGL.FONTS)
                                       (CREATECHARSET NILL]
        (P [if (FGETD (FUNCTION SK.DASHING.LABEL))
               then
               (for ENTRY in HPGL.DASHING do (push SK.DASHING.PATTERNS (LIST (SK.DASHING.LABEL
                                                                              (CDR ENTRY))
                                                                             (CDR ENTRY]
           (\INIT.HPGL))))
(* * User Functions)

(DEFINEQ

(MAKEHPGL
  [LAMBDA (FILE PFILE FONTS HEADING TABS)                    (* cdl "12-Jun-85 11:22")
    (TEXTTOIMAGEFILE FILE PFILE 'HPGL FONTS HEADING TABS])

(OPENHPGLSTREAM
  [LAMBDA (FILE OPTIONS)                                     (* ; "Edited  8-Sep-87 08:50 by cdl")
                                                             (* DECLARATIONS%: (RECORD PAIR
                                                             (KEY VALUE)))
    (LET (HPGLSTREAM POSITION (STREAM (OPENSTREAM FILE 'OUTPUT))
                (SCALE (create POSITION
                              XCOORD ← SCREENWIDTH
                              YCOORD ← SCREENHEIGHT)))
         (if (AND (SETQ POSITION (LISTGET OPTIONS 'SCALE))
                  (POSITIONP POSITION))
             then (SETQ SCALE POSITION))
         (SETQ HPGLSTREAM (create STREAM
                                 IMAGEOPS ← \HPGLIMAGEOPS
                                 IMAGEDATA ← (create PLOTTERDATA
                                                    PD.STREAM ← STREAM
                                                    PD.SCALE ← SCALE
                                                    PD.RIGHTMARGIN ← (with POSITION SCALE XCOORD))
                                 OUTCHARFN ← (FUNCTION \OUTCHAR.HPGL)
                                 CBUFPTR ← NIL
                                 CBUFSIZE ← 0
                                 DEVICE ← \NULLFDEV using STREAM))
         (with STREAM STREAM (SETQ LINELENGTH MAX.SMALLP))
         (with POSITION SCALE
               (printout STREAM "DF" !; "SC" "0" !, XCOORD !, "0" !, YCOORD !; "DT" !!; !;))
         [bind ENTRY for PAIR on OPTIONS by (CDDR PAIR)
            do (with PAIR PAIR (if (SETQ ENTRY (ASSOC KEY HPGL.OPTIONS))
                                   then (printout STREAM (CDR ENTRY)
                                               VALUE !;]
         (DSPFONT DEFAULTFONT HPGLSTREAM)
         (DSPRESET HPGLSTREAM)
         HPGLSTREAM])

(HARDCOPYW.HPGL
  [LAMBDA (FILE BITMAP SCALEFACTOR REGION ROTATION TITLE)    (* cdl " 1-May-85 09:21")
    (PROG ((PFILE (OPENHPGLSTREAM FILE)))
          (with REGION REGION (BITBLT BITMAP LEFT BOTTOM PFILE NIL NIL WIDTH HEIGHT))
          (RETURN (CLOSEF PFILE])
)
(* * ImageOp Functions)

(DEFINEQ

(\BITBLT.HPGL
  [LAMBDA (BITMAP SOURCELEFT SOURCEBOTTOM STREAM DESTINATIONLEFT DESTINATIONBOTTOM WIDTH HEIGHT 
                 SOURCETYPE OPERATION TEXTURE CLIPPINGREGION CLIPPEDSOURCELEFT CLIPPEDSOURCEBOTTOM)
                                                             (* ; "Edited  8-Sep-87 08:41 by cdl")

    (\DUMPSTRING.HPGL STREAM)
    (bind (FILESTREAM ← (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
                              PD.STREAM)) for Y from SOURCEBOTTOM
       to (SUB1 (PLUS SOURCEBOTTOM HEIGHT)) as J from DESTINATIONBOTTOM
       do (bind PI (STATE ← 0) for X from SOURCELEFT to (SUB1 (PLUS SOURCELEFT WIDTH)) as I
             from DESTINATIONLEFT
             do (if (NEQ STATE (BITMAPBIT BITMAP X Y))
                    then (if (ZEROP (SETQ STATE (IDIFFERENCE 1 STATE)))
                             then (printout FILESTREAM "PD")
                                  (if (NEQ PI (SUB1 I))
                                      then (printout FILESTREAM (SUB1 I)
                                                  !, J))
                                  (printout FILESTREAM !;)
                           else (printout FILESTREAM "PU" I !, J !;))
                         (SETQ PI I)) finally (if (NOT (ZEROP STATE))
                                                  then (printout FILESTREAM "PD")
                                                       (if (NEQ PI (SUB1 I))
                                                           then (printout FILESTREAM (SUB1 I)
                                                                       !, J))
                                                       (printout FILESTREAM !;)))
       finally (printout FILESTREAM "PU" !;))
    T])

(\BLTSHADE.HPGL
  [LAMBDA (TEXTURE STREAM DESTINATIONLEFT DESTINATIONBOTTOM WIDTH HEIGHT OPERATION CLIPPINGREGION)
                                                             (* ; "Edited 10-Nov-87 15:37 by cdl")

    (SUB1VAR WIDTH)
    (SUB1VAR HEIGHT)
    (if (AND (OR (ZEROP WIDTH)
                 (ZEROP HEIGHT))
             (EQ TEXTURE BLACKSHADE))
        then 
          
          (* Get around bug in plotter hardware triggered by SKETCH boxes)

             (DRAWLINE DESTINATIONLEFT DESTINATIONBOTTOM (PLUS DESTINATIONLEFT WIDTH)
                    (PLUS DESTINATIONBOTTOM HEIGHT)
                    NIL OPERATION STREAM)
      else (IMAGEOP 'IMMOVETO STREAM STREAM DESTINATIONLEFT DESTINATIONBOTTOM)
           (\FILL.HPGL STREAM TEXTURE)
           (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
                 (printout PD.STREAM "RA" (PLUS DESTINATIONLEFT WIDTH)
                        !,
                        (PLUS DESTINATIONBOTTOM HEIGHT)
                        !;)))
    T])

(\CLOSEFN.HPGL
  [LAMBDA (STREAM)                                           (* ; "Edited  8-Sep-87 08:34 by cdl")

    (\DUMPSTRING.HPGL STREAM)
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (printout PD.STREAM "PU" !;)
          (CLOSEF? PD.STREAM)
          (SETQ PD.STREAM NIL))
    T])

(\COLOR.HPGL
  [LAMBDA (STREAM COLOR)                                     (* ; "Edited  8-Dec-87 17:10 by cdl")
                                                             (* DECLARATIONS%: (RECORD ENTRY
                                                             (NAME . VALUES)))
    (DECLARE (GLOBALVARS COLORNAMES))
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (PROG1 PD.COLOR (if COLOR
                              then [if (LITATOM COLOR)
                                       then (SETQ COLOR
                                             (for ENTRY in COLORNAMES as I from 1
                                                thereis (with ENTRY ENTRY (EQ COLOR NAME))
                                                yield (DIFFERENCE (LENGTH COLORNAMES)
                                                             I)))
                                     elseif (RGBP COLOR)
                                       then (SETQ COLOR
                                             (for ENTRY in COLORNAMES as I from 1
                                                thereis (with ENTRY ENTRY (EQUAL COLOR VALUES))
                                                yield (DIFFERENCE (LENGTH COLORNAMES)
                                                             I]
                                   (if (AND (FIXP COLOR)
                                            (NEQ COLOR PD.COLOR))
                                       then (\DUMPSTRING.HPGL STREAM)
                                            (printout PD.STREAM "SP" (ADD1 (SETQ PD.COLOR COLOR))
                                                   !;])

(\DRAWARC.HPGL
  [LAMBDA (STREAM CENTERX CENTERY RADIUS STARTANGLE NDEGREES BRUSH DASHING)
                                                             (* ; "Edited 14-Sep-87 10:57 by cdl")

    (DECLARE (SPECVARS . T))
    (\DUMPSTRING.HPGL STREAM)
    [if (LISTP BRUSH)
        then (with BRUSH BRUSH (if BRUSHCOLOR
                                   then (IMAGEOP 'IMCOLOR STREAM STREAM BRUSHCOLOR]
    [RESETLST [RESETSAVE NIL `(\DASHING.HPGL ,STREAM ,(\DASHING.HPGL STREAM DASHING]
           [RESETSAVE NIL `(DSPCOLOR ,(IMAGEOP 'IMCOLOR STREAM STREAM
                                             (if (LISTP BRUSH)
                                                 then (with BRUSH BRUSH BRUSHCOLOR))) ,STREAM]
           (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
                 (with POSITION PD.POSITION (printout PD.STREAM "PU" (SETQ XCOORD CENTERX)
                                                   !,
                                                   (SETQ YCOORD CENTERY)
                                                   !; "EW" RADIUS !, (PLUS STARTANGLE 90)
                                                   !, NDEGREES)
                       (if HPGL.CHORD.ANGLE
                           then (printout PD.STREAM !, HPGL.CHORD.ANGLE))
                       (printout PD.STREAM !;]
    T])

(\DRAWCIRCLE.HPGL
  [LAMBDA (STREAM CENTERX CENTERY RADIUS BRUSH DASHING)      (* ; "Edited 14-Sep-87 10:54 by cdl")

    (DECLARE (SPECVARS . T))
    (\DUMPSTRING.HPGL STREAM)
    [if (LISTP BRUSH)
        then (with BRUSH BRUSH (if BRUSHCOLOR
                                   then (IMAGEOP 'IMCOLOR STREAM STREAM BRUSHCOLOR]
    [RESETLST [RESETSAVE NIL `(\DASHING.HPGL ,STREAM ,(\DASHING.HPGL STREAM DASHING]
           [RESETSAVE NIL `(DSPCOLOR ,(IMAGEOP 'IMCOLOR STREAM STREAM
                                             (if (LISTP BRUSH)
                                                 then (with BRUSH BRUSH BRUSHCOLOR))) ,STREAM]
           (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
                 (with POSITION PD.POSITION (printout PD.STREAM "PU" (SETQ XCOORD CENTERX)
                                                   !,
                                                   (SETQ YCOORD CENTERY)
                                                   !; "CI" RADIUS)
                       (if HPGL.CHORD.ANGLE
                           then (printout PD.STREAM !, HPGL.CHORD.ANGLE))
                       (printout PD.STREAM !;]
    T])

(\DRAWCURVE.HPGL
  [LAMBDA (STREAM KNOTS CLOSED BRUSH DASHING)                (* ; "Edited  8-Sep-87 11:25 by cdl")

    (DECLARE (SPECVARS . T))
    (\DUMPSTRING.HPGL STREAM)
    (if (FGETD 'DRAWCURVE.STREAM)
        then (RESETLST [RESETSAVE NIL `(DSPCOLOR ,(IMAGEOP 'IMCOLOR STREAM STREAM
                                                         (if (LISTP BRUSH)
                                                             then (with BRUSH BRUSH BRUSHCOLOR)))
                                              ,STREAM]
                    (DRAWCURVE.STREAM STREAM KNOTS CLOSED BRUSH DASHING))
      else (IMAGEOP 'IMDRAWPOLYGON STREAM STREAM KNOTS CLOSED BRUSH DASHING])

(\DRAWLINE.HPGL
  [LAMBDA (STREAM X1 Y1 X2 Y2 WIDTH OPERATION COLOR DASHING) (* ; "Edited  8-Sep-87 09:29 by cdl")

    (DECLARE (SPECVARS . T))
    [if [AND DASHING (NOT (bind (DASHING ← (MKLIST DASHING)) for ENTRY in HPGL.DASHING
                             thereis (EQUAL DASHING (CDR ENTRY]
        then                                                 (* Not a hardware dashing pattern)
             (DRAWDASHEDLINE X1 Y1 X2 Y2 WIDTH OPERATION STREAM COLOR DASHING)
      else (\DUMPSTRING.HPGL STREAM)
           (RESETLST [RESETSAVE NIL `(\DASHING.HPGL ,STREAM ,(\DASHING.HPGL STREAM DASHING]
                  [RESETSAVE NIL `(DSPCOLOR ,(IMAGEOP 'IMCOLOR STREAM STREAM COLOR) ,STREAM]
                  (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
                        (with POSITION PD.POSITION (if [NOT (AND (OR (EQ X1 T)
                                                                     (EQ X1 XCOORD))
                                                                 (OR (EQ Y1 T)
                                                                     (EQ Y1 YCOORD]
                                                       then (printout PD.STREAM "PU"
                                                                   (if (EQ X1 T)
                                                                       then XCOORD
                                                                     else X1)
                                                                   !,
                                                                   (if (EQ Y1 T)
                                                                       then YCOORD
                                                                     else Y1)
                                                                   !;))
                              (printout PD.STREAM "PD" (SETQ XCOORD X2)
                                     !,
                                     (SETQ YCOORD Y2)
                                     !;]
    T])

(\DRAWPOLYGON.HPGL
  [LAMBDA (STREAM POINTS CLOSED BRUSH DASHING)               (* ; "Edited  8-Sep-87 08:22 by cdl")

    (DECLARE (SPECVARS . T))
    (\DUMPSTRING.HPGL STREAM)
    [RESETLST [RESETSAVE NIL `(\DASHING.HPGL ,STREAM ,(\DASHING.HPGL STREAM DASHING]
           [RESETSAVE NIL `(DSPCOLOR ,(IMAGEOP 'IMCOLOR STREAM STREAM
                                             (if (LISTP BRUSH)
                                                 then (with BRUSH BRUSH BRUSHCOLOR))) ,STREAM]
           (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
                 (with POSITION (CAR POINTS)
                       (printout PD.STREAM "PU" XCOORD !, YCOORD !; "PD"))
                 (for POINT on (CDR POINTS) do (with POSITION (CAR POINT)
                                                     (printout PD.STREAM XCOORD !, YCOORD))
                                               (if (CDR POINT)
                                                   then (printout PD.STREAM !,)))
                 (if CLOSED
                     then (with POSITION (CAR POINTS)
                                (printout PD.STREAM XCOORD !, YCOORD)))
                 (PRINTOUT PD.STREAM !;)
                 (with POSITION (CAR (LAST POINTS))
                       (create POSITION
                              XCOORD ← XCOORD
                              YCOORD ← YCOORD smashing PD.POSITION]
    T])

(\FILLCIRCLE.HPGL
  [LAMBDA (STREAM CENTERX CENTERY RADIUS TEXTURE)            (* ; "Edited 14-Sep-87 11:25 by cdl")

    (\DUMPSTRING.HPGL STREAM)
    (\FILL.HPGL STREAM TEXTURE)
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (with POSITION PD.POSITION (printout PD.STREAM "PU" (SETQ XCOORD CENTERX)
                                            !,
                                            (SETQ YCOORD CENTERY)
                                            !; "WG" RADIUS !, "0" !, "360")
                (if HPGL.CHORD.ANGLE
                    then (printout PD.STREAM !, HPGL.CHORD.ANGLE))
                (printout PD.STREAM !;)))
    T])

(\FONT.HPGL
  [LAMBDA (STREAM FONT)                                      (* ; "Edited  8-Sep-87 08:25 by cdl")
                                                             (* DECLARATIONS%: (RECORD FACE
                                                             (WEIGHT SLOPE EXPANSION)))
    [if (type? FONTCLASS FONT)
        then (SETQ FONT (FONTCLASSCOMPONENT FONT (IMAGESTREAMTYPE STREAM]
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (if (AND FONT (NEQ FONT PD.FONT))
              then (\DUMPSTRING.HPGL STREAM)
                   [with FONTDESCRIPTOR FONT (if (NEQ FONTFAMILY (fetch FONTFAMILY of PD.FONT))
                                                 then (printout PD.STREAM "CS"
                                                             (OR (CDR (FASSOC FONTFAMILY HPGL.FONTS))
                                                                 (CONSTANT null))
                                                             !;))
                         (if (NEQ ROTATION (fetch ROTATION of PD.FONT))
                             then (printout PD.STREAM "DI")
                                  (if (AND ROTATION (NOT (ZEROP ROTATION)))
                                      then (printout PD.STREAM (COS ROTATION)
                                                  !,
                                                  (SIN ROTATION)))
                                  (printout PD.STREAM !;))
                         (with POSITION PD.SCALE (printout PD.STREAM "SR")
                               (PRINTNUM '(FLOAT NIL 3)
                                      (QUOTIENT (QUOTIENT [TIMES FONTAVGCHARWIDTH
                                                                 (with FACE FONTFACE
                                                                       (CDR (ASSOC EXPANSION 
                                                                                 HPGL.FONT.EXPANSIONS
                                                                                   ]
                                                       3)
                                             XCOORD)
                                      PD.STREAM)
                               (printout PD.STREAM !,)
                               (PRINTNUM '(FLOAT NIL 3) (QUOTIENT (TIMES \SFHeight 100.0)
                                                               YCOORD)
                                      PD.STREAM)
                               (printout PD.STREAM !;))
                         (with FACE FONTFACE (if (NEQ SLOPE (fetch (FACE SLOPE)
                                                               of (fetch FONTFACE of PD.FONT)))
                                                 then (printout PD.STREAM "SL"
                                                             (SELECTQ SLOPE
                                                                 (REGULAR (CONSTANT null))
                                                                 (ITALIC 1)
                                                                 (SHOULDNT))
                                                             !;]
                   (PROG1 PD.FONT (SETQ PD.FONT FONT))
            else PD.FONT])

(\LEFTMARGIN.HPGL
  [LAMBDA (STREAM XPOSITION)                                 (* cdl "25-Jun-85 15:33")
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (PROG1 PD.LEFTMARGIN (if XPOSITION
                                   then (SETQ PD.LEFTMARGIN XPOSITION])

(\LINEFEED.HPGL
  [LAMBDA (STREAM DELTAY)                                    (* cdl "24-Jul-85 08:01")
    (MINUS (TIMES 2 (FONTPROP (with STREAM STREAM (with PLOTTERDATA IMAGEDATA PD.FONT))
                           'HEIGHT])

(\MOVETO.HPGL
  [LAMBDA (STREAM X Y)                                       (* ; "Edited  8-Sep-87 10:39 by cdl")

    (\DUMPSTRING.HPGL STREAM)
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (with POSITION PD.POSITION (printout PD.STREAM "PU" (SETQ XCOORD X)
                                            !,
                                            (SETQ YCOORD Y)
                                            !;)))
    T])

(\RESET.HPGL
  [LAMBDA (STREAM)                                           (* cdl "19-Jul-85 16:30")
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (IMAGEOP 'IMMOVETO STREAM STREAM PD.LEFTMARGIN (PLUS (with POSITION PD.SCALE YCOORD)
                                                               (IMAGEOP 'IMLINEFEED STREAM STREAM])

(\RIGHTMARGIN.HPGL
  [LAMBDA (STREAM XPOSITION)                                 (* cdl "25-Jun-85 15:34")
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (PROG1 PD.RIGHTMARGIN (if XPOSITION
                                    then (SETQ PD.RIGHTMARGIN XPOSITION])

(\ROTATE.HPGL
  [LAMBDA (STREAM ROTATION)                                  (* ; "Edited  8-Sep-87 08:37 by cdl")

    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (PROG1 PD.ROTATION (if PD.ROTATION
                                 then (\DUMPSTRING.HPGL STREAM)
                                      (printout PD.STREAM "RO" PD.ROTATION !;])

(\SCALEDBITBLT.HPGL
  [LAMBDA (BITMAP SOURCELEFT SOURCEBOTTOM STREAM DESTINATIONLEFT DESTINATIONBOTTOM WIDTH HEIGHT 
                 SOURCETYPE OPERATION TEXTURE CLIPPINGREGION CLIPPEDSOURCELEFT CLIPPEDSOURCEBOTTOM 
                 SCALE)                                      (* ; "Edited  8-Sep-87 08:43 by cdl")

    (\DUMPSTRING.HPGL STREAM)
    (bind (FILESTREAM ← (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
                              PD.STREAM))
          (SOURCEWIDTH ← (SUB1 (PLUS SOURCELEFT WIDTH))) for Y from SOURCEBOTTOM
       to (SUB1 (PLUS SOURCEBOTTOM HEIGHT)) as J from DESTINATIONBOTTOM by SCALE
       do [for Z from J to (PLUS J (SUB1 SCALE))
             do (bind PI LASTPOSITION (STATE ← 0) for X from SOURCELEFT to SOURCEWIDTH as I
                   from DESTINATIONLEFT by SCALE
                   do (if (NEQ STATE (BITMAPBIT BITMAP X Y))
                          then (if (ZEROP (SETQ STATE (DIFFERENCE 1 STATE)))
                                   then (printout FILESTREAM "PD")
                                        (if (NOT (IEQP PI (SUB1 I)))
                                            then (printout FILESTREAM (SUB1 I)
                                                        !, Z))
                                        (printout FILESTREAM !;)
                                 else (printout FILESTREAM "PU" I !, Z !;))
                               (SETQ PI I))
                   finally (if (NOT (ZEROP STATE))
                               then (printout FILESTREAM "PD")
                                    (if (NOT (IEQP PI (SUB1 I)))
                                        then (printout FILESTREAM (SUB1 I)
                                                    !, Z))
                                    (printout FILESTREAM !;] finally (printout FILESTREAM "PU" !;))
    T])

(\STRINGWIDTH.HPGL
  [LAMBDA (STREAM STRING RDTBL)                              (* cdl "29-Apr-85 14:31")
    (STRINGWIDTH STRING (DSPFONT NIL STREAM)
           RDTBL RDTBL])

(\CLIPPINGREGION.HPGL
  [LAMBDA (STREAM REGION)                                    (* cdl "16-Oct-85 10:57")
    (with STREAM STREAM (with PLOTTERDATA IMAGEDATA (with POSITION PD.SCALE
                                                          (CREATEREGION 0 0 XCOORD YCOORD])

(\TERPRI.HPGL
  [LAMBDA (STREAM)                                           (* cdl "24-Jul-85 09:26")
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (with POSITION PD.POSITION (IMAGEOP 'IMMOVETO STREAM STREAM PD.LEFTMARGIN
                                            (PLUS YCOORD (IMAGEOP 'IMLINEFEED STREAM STREAM])

(\XPOSITION.HPGL
  [LAMBDA (STREAM XPOSITION)                                 (* ; "Edited  8-Sep-87 08:32 by cdl")

    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (with POSITION PD.POSITION (PROG1 XCOORD (if XPOSITION
                                                       then (\DUMPSTRING.HPGL STREAM)
                                                            (printout PD.STREAM "PU" (SETQ XCOORD 
                                                                                      XPOSITION)
                                                                   !, YCOORD !;])

(\YPOSITION.HPGL
  [LAMBDA (STREAM YPOSITION)                                 (* ; "Edited  8-Sep-87 08:31 by cdl")

    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (with POSITION PD.POSITION (PROG1 YCOORD (if YPOSITION
                                                       then (\DUMPSTRING.HPGL STREAM)
                                                            (printout PD.STREAM "PU" XCOORD !,
                                                                   (SETQ YCOORD YPOSITION)
                                                                   !;])
)
(* * Internal Functions)

(DEFINEQ

(\DUMPSTRING.HPGL
  [LAMBDA (STREAM)                                           (* ; "Edited  8-Sep-87 08:51 by cdl")

    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (if PD.TEXT
              then (printout PD.STREAM "LB")
                   (for CHARCODE in (DREVERSE PD.TEXT) do (BOUT PD.STREAM CHARCODE))
                   (printout PD.STREAM !!;)
                   (SETQ PD.TEXT NIL)
                   T])

(\FONTCREATE.HPGL
  [LAMBDA (FAMILY SIZE FACE ROTATION)                        (* ; "Edited  4-Sep-87 15:13 by cdl")

    (if (ASSOC FAMILY HPGL.FONTS)
        then (LET ((WIDTHSBLOCK (\CREATECSINFOELEMENT))
                   (FONTDESCRIPTOR (create FONTDESCRIPTOR
                                          FONTDEVICE ← 'HPGL
                                          FONTFAMILY ← FAMILY
                                          FONTSIZE ← SIZE
                                          FONTFACE ← FACE
                                          ROTATION ← ROTATION
                                          \SFHeight ← SIZE
                                          \SFAscent ← SIZE
                                          \SFDescent ← 0)))
                  (bind (WIDTH ← (FIX (QUOTIENT (TIMES 3 SIZE)
                                             4))) for N from 0 to 254
                     do (\FSETWIDTH WIDTHSBLOCK N WIDTH))
                  (with FONTDESCRIPTOR FONTDESCRIPTOR
                        (\SETCHARSETINFO FONTCHARSETVECTOR 0
                               (create CHARSETINFO
                                      WIDTHS ← WIDTHSBLOCK
                                      IMAGEWIDTHS ← WIDTHSBLOCK
                                      CHARSETASCENT ← SIZE
                                      CHARSETDESCENT ← 0)))
                  FONTDESCRIPTOR)
      else (FONTCREATE (CAAR HPGL.FONTS)
                  SIZE FACE ROTATION 'HPGL])

(\INIT.HPGL
  [LAMBDA NIL                                                (* ; "Edited  8-Sep-87 07:40 by cdl")

    (DECLARE (GLOBALVARS DEFAULTFONT LITTLEFONT BIGFONT BOLDFONT))
    (SETQ \NULLFDEV (create FDEV
                           CLOSEFILE ← (FUNCTION NILL)))
    (SETQ \HPGLIMAGEOPS (create IMAGEOPS
                               IMAGETYPE ← 'HPGL
                               IMCLOSEFN ← (FUNCTION \CLOSEFN.HPGL)
                               IMXPOSITION ← (FUNCTION \XPOSITION.HPGL)
                               IMYPOSITION ← (FUNCTION \YPOSITION.HPGL)
                               IMFONT ← (FUNCTION \FONT.HPGL)
                               IMLEFTMARGIN ← (FUNCTION \LEFTMARGIN.HPGL)
                               IMRIGHTMARGIN ← (FUNCTION \RIGHTMARGIN.HPGL)
                               IMLINEFEED ← (FUNCTION \LINEFEED.HPGL)
                               IMDRAWLINE ← (FUNCTION \DRAWLINE.HPGL)
                               IMDRAWCURVE ← (FUNCTION \DRAWCURVE.HPGL)
                               IMDRAWCIRCLE ← (FUNCTION \DRAWCIRCLE.HPGL)
                               IMDRAWELLIPSE ← (FUNCTION DRAWELLIPSEWITHDRAWCURVE)
                               IMFILLCIRCLE ← (FUNCTION \FILLCIRCLE.HPGL)
                               IMBITBLT ← (FUNCTION \BITBLT.HPGL)
                               IMBLTSHADE ← (FUNCTION \BLTSHADE.HPGL)
                               IMMOVETO ← (FUNCTION \MOVETO.HPGL)
                               IMSCALE ← [FUNCTION (LAMBDA (STREAM SCALE)
                                                     1]
                               IMTERPRI ← (FUNCTION \TERPRI.HPGL)
                               IMFONTCREATE ← 'HPGL
                               IMCOLOR ← (FUNCTION \COLOR.HPGL)
                               IMSTRINGWIDTH ← (FUNCTION \STRINGWIDTH.HPGL)
                               IMCHARWIDTH ← (FUNCTION \STRINGWIDTH.HPGL)
                               IMRESET ← (FUNCTION \RESET.HPGL)
                               IMCLIPPINGREGION ← (FUNCTION \CLIPPINGREGION.HPGL)
                               IMDRAWPOLYGON ← (FUNCTION \DRAWPOLYGON.HPGL)
                               IMSCALEDBITBLT ← (FUNCTION \SCALEDBITBLT.HPGL)
                               IMDRAWARC ← (FUNCTION \DRAWARC.HPGL)
                               IMROTATE ← (FUNCTION \ROTATE.HPGL)))
    (SETFONTCLASSCOMPONENT DEFAULTFONT 'HPGL (FONTCREATE 'STANDARD 10 NIL NIL 'HPGL))
    (SETFONTCLASSCOMPONENT LITTLEFONT 'HPGL (FONTCREATE 'STANDARD 8 NIL NIL 'HPGL))
    (SETFONTCLASSCOMPONENT BIGFONT 'HPGL (FONTCREATE 'STANDARD 12 NIL NIL 'HPGL))
    (SETFONTCLASSCOMPONENT BOLDFONT 'HPGL (FONTCREATE 'STANDARD 10 'BOLD NIL 'HPGL])

(\OUTCHAR.HPGL
  [LAMBDA (STREAM CHARCODE)                                  (* cdl " 3-Oct-85 13:20")
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (SELCHARQ CHARCODE
               (EOL (\TERPRI.HPGL STREAM))
               (if (AND (GEQ CHARCODE (CHARCODE SPACE))
                        (LEQ CHARCODE (CHARCODE ~)))
                   then (with POSITION PD.POSITION (add XCOORD (CHARWIDTH CHARCODE PD.FONT)))
                        (push PD.TEXT CHARCODE])

(\SEARCH.HPGL.FONTS
  [LAMBDA (FAMILY SIZE FACE ROTATION DEVICE)                 (* cdl " 1-May-85 09:34")
    (if (EQ DEVICE 'HPGL)
        then (if (FASSOC FAMILY HPGL.FONTS)
                 then (LIST (LIST FAMILY SIZE FACE ROTATION DEVICE])

(\FILL.HPGL
  [LAMBDA (STREAM TEXTURE)                                   (* ; "Edited  8-Dec-87 16:56 by cdl")
                                                             (* DECLARATIONS%: (RECORD TEXTURE
                                                             (TYPE SPACING ANGLE))
                                                             (RECORD TEXTURECOLORPAIR
                                                             (TEXURE COLOR)))
    (\DUMPSTRING.HPGL STREAM)
    (if (LISTP TEXTURE)
        then (SETQ TEXTURE (with TEXTURECOLORPAIR TEXTURE (if (RGBP COLOR)
                                                              then (IMAGEOP 'IMCOLOR STREAM STREAM 
                                                                          COLOR))
                                 TEXTURE)))
    [if (FIXP TEXTURE)
        then (SETQ TEXTURE (create TEXTURE
                                  TYPE ← (if (IEQP TEXTURE BLACKSHADE)
                                             then 1
                                           elseif (IEQP TEXTURE WHITESHADE)
                                             then 3
                                           else 4)
                                  SPACING ← 0
                                  ANGLE ← (TIMES (LOGAND TEXTURE 3)
                                                 45]
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (with TEXTURE TEXTURE (printout PD.STREAM "FT" (if (AND (FIXP TYPE)
                                                                  (GEQ TYPE 1)
                                                                  (LEQ TYPE 4))
                                                             then TYPE
                                                           else 1)
                                       !,
                                       (if (FIXP SPACING)
                                           then SPACING
                                         else 0)
                                       !,
                                       (if (AND (FIXP ANGLE)
                                                (ZEROP (IMOD ANGLE 45)))
                                           then ANGLE
                                         else 0)
                                       !;)))
    T])

(\DASHING.HPGL
  [LAMBDA (STREAM DASHING)                                   (* ; "Edited 14-Sep-87 11:28 by cdl")
                                                             (* DECLARATIONS%: (RECORD ENTRY
                                                             (INDEX . LENGTHS)))
    (with PLOTTERDATA (with STREAM STREAM IMAGEDATA)
          (PROG1 (if PD.DASHING
                     then (CDR (ASSOC PD.DASHING HPGL.DASHING)))
                 (if DASHING
                     then (LET (INDEX)
                               [if (SETQ DASHING (MKLIST DASHING))
                                   then (SETQ INDEX (for ENTRY in HPGL.DASHING
                                                       thereis (with ENTRY ENTRY (EQUAL DASHING 
                                                                                        LENGTHS))
                                                       yield (with ENTRY ENTRY INDEX]
                               (if (AND (FIXP INDEX)
                                        (NEQ INDEX PD.DASHING))
                                   then (\DUMPSTRING.HPGL STREAM)
                                        (printout PD.STREAM "LT" (SETQ PD.DASHING INDEX))
                                        (if HPGL.PATTERN.LENGTH
                                            then (printout PD.STREAM !, HPGL.PATTERN.LENGTH))
                                        (printout PD.STREAM !;)))
                   elseif PD.DASHING
                     then (\DUMPSTRING.HPGL STREAM)
                          (printout PD.STREAM "LT" !;)
                          (SETQ PD.DASHING NIL])
)
(* * etc.)


(RPAQQ HPGL.FONTS ((STANDARD . 0)
                   (9825 . 1)
                   (FRENCH . 2)
                   (SCANDINAVIAN . 3)
                   (SPANISH . 4)
                   (JISASCII . 6)
                   (ROMAN . 7)
                   (KATAKANA . 8)
                   (IRV . 9)
                   (SWEDISH . 30)
                   (SWEDISH2 . 31)
                   (NORWAY . 32)
                   (GERMAN . 33)
                   (FRENCH2 . 34)
                   (BRITISH . 35)
                   (ITALIAN . 36)
                   (SPANISH2 . 37)
                   (PORTUGUESE . 38)
                   (NORWAY2 . 39)))

(RPAQQ HPGL.OPTIONS ((ROTATE . "RO")
                     (VELOCITY . "VS")
                     (PAPER . "PS")
                     (TERMINATOR . "DT")))

(RPAQQ HPGL.FONT.EXPANSIONS ((REGULAR . 200.0)
                             (COMPRESSED . 100.0)
                             (EXPANDED . 400.0)))

(RPAQQ HPGL.DASHING ((1 1 49)
                     (2 25)
                     (3 35 15)
                     (4 39 5 1 5)
                     (5 35 5 5 5)
                     (6 25 5 5 5 5 5)))

(RPAQQ SKETCHINCOLORFLG T)

(RPAQ? HPGL.TERMINATOR (CHARACTER (CHARCODE ;)))

(RPAQ? HPGL.SEPARATOR (CHARACTER (CHARCODE %,)))

(RPAQ? HPGL.TEXT.TERMINATOR (CHARACTER (CHARCODE ↑A)))

(RPAQ? HPGL.CHORD.ANGLE NIL)

(RPAQ? HPGL.PATTERN.LENGTH NIL)

(RPAQ? \HPGLIMAGEOPS NIL)

(RPAQ? \NULLFDEV NIL)

(RPAQ? SK.DASHING.PATTERNS NIL)
(DECLARE%: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS HPGL.FONTS HPGL.OPTIONS HPGL.FONT.EXPANSIONS HPGL.DASHING HPGL.TERMINATOR HPGL.SEPARATOR 
       HPGL.TEXT.TERMINATOR HPGL.CHORD.ANGLE HPGL.PATTERN.LENGTH \HPGLIMAGEOPS \NULLFDEV)
)
(DECLARE%: DOEVAL@COMPILE DONTCOPY 
(FILESLOAD UTILISOPRS)


(ADDTOVAR PRINTOUTMACROS [!, (LAMBDA (COMS)
                                    (CONS '(PRIN1 HPGL.SEPARATOR NIL) (CDR COMS]
                         [!; (LAMBDA (COMS)
                                    (CONS '(PRIN1 HPGL.TERMINATOR NIL) (CDR COMS]
                         [!!; (LAMBDA (COMS)
                                     (CONS '(PRIN1 HPGL.TEXT.TERMINATOR NIL) (CDR COMS])

(DECLARE%: EVAL@COMPILE

(RECORD PLOTTERDATA (PD.STREAM PD.POSITION PD.FONT PD.TEXT PD.COLOR PD.SCALE PD.LEFTMARGIN 
                           PD.RIGHTMARGIN PD.DASHING PD.ROTATION)
                    PD.POSITION ← (create POSITION)
                    PD.COLOR ← 0 PD.LEFTMARGIN ← 0 PD.ROTATION ← 0)
)
)

(ADDTOVAR PRINTERTYPES ((PLOTTER HPGL)
                        (CANPRINT (HPGL))
                        (STATUS TRUE)
                        (BITMAPFILE (HARDCOPYW.HPGL FILE BITMAP SCALEFACTOR REGION ROTATION TITLE))
                        (PROPERTIES NILL)))

(ADDTOVAR PRINTFILETYPES [HPGL (EXTENSION (HPGL PLOT))
                               (CONVERSION (TEXT MAKEHPGL TEDIT
                                                 (LAMBDA (FILE PFILE)
                                                        (SETQ FILE (OPENTEXTSTREAM FILE))
                                                        (TEDIT.FORMAT.HARDCOPY FILE PFILE T NIL NIL 
                                                               NIL 'HPGL)
                                                        (CLOSEF? FILE)
                                                        PFILE])

(ADDTOVAR IMAGESTREAMTYPES (HPGL (OPENSTREAM OPENHPGLSTREAM)
                                 (FONTCREATE \FONTCREATE.HPGL)
                                 (FONTSAVAILABLE \SEARCH.HPGL.FONTS)
                                 (CREATECHARSET NILL)))
[if (FGETD (FUNCTION SK.DASHING.LABEL))
    then
    (for ENTRY in HPGL.DASHING do (push SK.DASHING.PATTERNS (LIST (SK.DASHING.LABEL (CDR ENTRY))
                                                                  (CDR ENTRY]
(\INIT.HPGL)
(PUTPROPS HPGL COPYRIGHT ("Stanford University" 1985 1986 1987))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (3622 5974 (MAKEHPGL 3632 . 3799) (OPENHPGLSTREAM 3801 . 5686) (HARDCOPYW.HPGL 5688 . 
5972)) (6005 28210 (\BITBLT.HPGL 6015 . 7864) (\BLTSHADE.HPGL 7866 . 8914) (\CLOSEFN.HPGL 8916 . 9246)
 (\COLOR.HPGL 9248 . 11006) (\DRAWARC.HPGL 11008 . 12407) (\DRAWCIRCLE.HPGL 12409 . 13648) (
\DRAWCURVE.HPGL 13650 . 14365) (\DRAWLINE.HPGL 14367 . 16483) (\DRAWPOLYGON.HPGL 16485 . 17975) (
\FILLCIRCLE.HPGL 17977 . 18676) (\FONT.HPGL 18678 . 22023) (\LEFTMARGIN.HPGL 22025 . 22327) (
\LINEFEED.HPGL 22329 . 22576) (\MOVETO.HPGL 22578 . 23045) (\RESET.HPGL 23047 . 23418) (
\RIGHTMARGIN.HPGL 23420 . 23726) (\ROTATE.HPGL 23728 . 24115) (\SCALEDBITBLT.HPGL 24117 . 26108) (
\STRINGWIDTH.HPGL 26110 . 26297) (\CLIPPINGREGION.HPGL 26299 . 26599) (\TERPRI.HPGL 26601 . 26956) (
\XPOSITION.HPGL 26958 . 27592) (\YPOSITION.HPGL 27594 . 28208)) (28242 37902 (\DUMPSTRING.HPGL 28252
 . 28719) (\FONTCREATE.HPGL 28721 . 30240) (\INIT.HPGL 30242 . 32928) (\OUTCHAR.HPGL 32930 . 33452) (
\SEARCH.HPGL.FONTS 33454 . 33727) (\FILL.HPGL 33729 . 36168) (\DASHING.HPGL 36170 . 37900)))))
STOP