100 dict dup begin

% Author: Charles Loomis

% Redefinitions which save some space in the output file.  These are also
% the same as the PDF operators.
/q {gsave} def
/Q {grestore} def

/n {newpath} def
/m {moveto} def
/l {lineto} def
/c {curveto} def
/h {closepath} def

/re {4 -2 roll moveto
     dup 0 exch rlineto exch 0 rlineto
     neg 0 exch rlineto closepath} def

/f {fill} def
/f* {eofill} def
/F {gsave vg&FC fill grestore} def
/F* {gsave vg&FC eofill grestore} def

/s {closepath stroke} def
/S {stroke} def

/b {closepath gsave vg&FC fill grestore
    gsave stroke grestore newpath} def
/B {gsave vg&FC fill grestore gsave stroke grestore newpath} def
/b* {closepath gsave vg&FC eofill grestore
    gsave stroke grestore newpath} def
/B* {gsave vg&FC eofill grestore gsave stroke grestore newpath} def

/g {1 array astore /vg&fcolor exch def} def
/G {setgray} def
/k {4 array astore /vg&fcolor exch def} def
/K {setcmykcolor} def
/rg {3 array astore /vg&fcolor exch def} def
/RG {setrgbcolor} def

% Initialize the fill color.
0 0 0 rg

/vg&FC {mark vg&fcolor aload pop
        counttomark 1 eq {G} if
        counttomark 3 eq {RG} if
        counttomark 4 eq {K} if
        cleartomark } def

/vg&DFC {/vg&fcolor exch def} def

/vg&C {mark exch aload pop
       counttomark 1 eq {G} if
       counttomark 3 eq {RG} if
       counttomark 4 eq {K} if
       cleartomark } def

/w {setlinewidth} def
/j {setlinejoin} def
/J {setlinecap} def
/M {setmiterlimit} def
/d {setdash} def
/i {setflat} def

/W {clip} def
/W* {eoclip} def

% Setup the default graphics state.
% (black; 1 pt. linewidth; miter join; butt-ends; solid)
/defaultGraphicsState {0 g 1 w 0 j 0 J [] 0 d} def

% Emulation of the rectangle operators for PostScript implementations
% which do not implement all Level 2 features.  This is an INCOMPLETE
% emulation; only the "x y width height rect..." form is emulated.
/*rf {gsave newpath re fill grestore} def
/*rs {gsave newpath re stroke grestore} def
/*rc {newpath re clip} def
/rf  /rectfill where {pop /rectfill}{/*rf} ifelse load def
/rs  /rectstroke where {pop /rectstroke}{/*rs} ifelse load def
/rc  /rectclip where {pop /rectclip}{/*rc} ifelse load def

% Emulation of the selectfont operator.  This includes a 20% increase in
% the fontsize which is necessary to get sizes similar to the Java fonts.
/*sf {exch findfont exch
      dup type /arraytype eq {makefont}{scalefont} ifelse setfont} bind def
/sf /selectfont where {pop {1.2 mul selectfont}}{{1.2 mul *sf}} ifelse def

% Initialize variables for safety.
/delta 0 def
/xv 0 def  /yv 0 def  /width 0 def  /height 0 def

% Initialize to portrait A4 page.
/pw 595 def  /ph 842  def  /po true def /ftp false def

% Initialize margins to 20 points.
/ml 20 def  /mr 20 def  /mt 20 def  /mb 20 def

% set page size (usage: <page width><page height> setpagesize)
/setpagesize {/ph exch def /pw exch def} def

% set page orientation (usage: portrait or landscape)
/portrait {/po true def} def
/landscape {/po false def} def

% force natural size for image (usage: naturalsize)
/naturalsize {/ftp false def} def

% resize image to fill page (usage: fittopage)
/fittopage {/ftp true def} def

% set margins of the page (usage: <left><bottom><top><right> setmargins)
/setmargins {/mr exch def /mt exch def /mb exch def /ml exch def} def

% set the graphic's size (usage: <width><height> setsize)
/setsize {/gh exch def /gw exch def} def

% set the graphic's origin (usage: <x0><y0> setorigin)
/setorigin {/gy exch def /gx exch def} def

% calculate image center
/imagecenter {pw ml sub mr sub 2 div ml add
              ph mt sub mb sub 2 div mb add} def

% calculate the necessary scaling
/imagescale {po {gw}{gh} ifelse pw ml sub mr sub div
             po {gh}{gw} ifelse ph mt sub mb sub div
             2 copy lt {exch} if pop
             ftp not {1 2 copy lt {exch} if pop} if
             1 exch div /sfactor exch def
             /gw gw sfactor mul def /gh gh sfactor mul def} def

% calculate image origin
/imageorigin {pw ml sub mr sub 2 div ml add
              po {gw}{gh} ifelse 2 div sub
              ph mt sub mb sub 2 div mb add
              po {gh}{gw} ifelse 2 div po {add}{sub} ifelse} def

% calculate the clipping origin
/cliporigin  {pw ml sub mr sub 2 div ml add
              po {gw}{gh} ifelse 2 div sub floor
              ph mt sub mb sub 2 div mb add
              po {gh}{gw} ifelse 2 div sub floor} def

% Set the clipping region to the bounding box.
/cliptobounds {cliporigin po {gw}{gh} ifelse 1 add
                          po {gh}{gw} ifelse 1 add rc} def

% set the base transformation matrix (usage: setbasematrix)
/setbasematrix {imageorigin translate
                po {0}{90} ifelse rotate
                sfactor sfactor neg scale
                /defaultmatrix matrix currentmatrix def} def



