home *** CD-ROM | disk | FTP | other *** search
/ Frame 3.2 / Frame.iso / Application / FrameMaker.app / fminit2.0 / next / makerbegin.ps < prev    next >
Encoding:
Text File  |  1994-08-11  |  18.6 KB  |  860 lines

  1. %-
  2. %- FrameMaker display server prologue, for use with FrameMaker 3.0
  3. %- Copyright (c) 1986, 87, 88, 89, 90, 91, 94 by Frame Technology, Inc.
  4. %- All rights reserved.
  5. %-
  6. /FMdict 250 dict def
  7. FMdict begin
  8.  
  9. /myfonts 41 array def    % must match c code
  10. 3.86 setmiterlimit
  11. /windows 0 def
  12. /mymatrix matrix def
  13. /IPheight -1000 def
  14. /saveipgstate null def
  15. /textgstack null def
  16. /Textwidth 0 def
  17. /Textheight 0 def
  18. /mygstate gstate def
  19. %/CACHEX 128 def     % size of offscreen cached patterns. must be power of 2
  20. %/CACHEY 128 def
  21.  
  22. %
  23. % Color Handling
  24. %
  25. /PrintInColor true def
  26. PrintInColor {
  27.     /HUE 0 def
  28.     /SAT 0 def
  29.     /BRIGHT 0 def
  30.     % array of arrays Hue and Sat values for the separations [HUE BRIGHT]
  31.     /Colors [
  32.         [0    0  ]    % black
  33.         [0    0  ]    % white
  34.         [0.00 1.0]    % red
  35.         [0.37 1.0]    % green
  36.         [0.60 1.0]    % blue
  37.         [0.50 1.0]    % cyan
  38.         [0.83 1.0]    % magenta
  39.         [0.16 1.0]    % yellow
  40.     ] def
  41.  
  42.     /K {    % num K => - ; use separation NUM
  43.         Colors exch get dup
  44.         0 get /HUE exch store
  45.         1 get /BRIGHT exch store
  46.         HUE 0 eq BRIGHT 0 eq and {
  47.             1.0 SAT sub setgray
  48.         } {
  49.             HUE SAT BRIGHT sethsbcolor
  50.         } ifelse
  51.     } def
  52.     % special separation command for text.  If it's a 2-bit
  53.     % window (see <appkit/graphics.h> for definition of 258)
  54.     % don't change the color.
  55.     /KT
  56.         currentdefaultdepthlimit 258 eq {/pop} {/K} ifelse
  57.     load def
  58.     /G {    % num G => - ; set current gray to NUM
  59.         /SAT exch 1.0 exch sub store
  60.         HUE 0 eq BRIGHT 0 eq and {
  61.             1.0 SAT sub setgray
  62.         } {
  63.             HUE SAT BRIGHT sethsbcolor
  64.         } ifelse
  65.     } bind def
  66. } {
  67.     /K /pop load def
  68.     /KT /pop load def
  69.     /G /setgray load def
  70. } ifelse
  71.  
  72. /F /fill load def
  73. /S /stroke load def
  74. /rc /rectclip load def
  75. /GS /gsave load def
  76. /GR /grestore load def
  77. /SL /setlinewidth load def
  78. /SC /setlinecap load def
  79. /CS { closepath S } bind def
  80. /A /strokepath load def
  81. /TR /translate load def
  82. /L /lineto load def
  83. /M /moveto load def
  84. /D /curveto load def
  85. /C /closepath load def
  86. /xhow    /xshow load def
  87. /xyhow    /xyshow load def
  88. /smat { mymatrix currentmatrix pop } bind def
  89. /rmat { mymatrix setmatrix } bind def
  90. /sp { 0 G P exch get exec } bind def % wiml@omni #84261
  91. /T { moveto show } bind def
  92. /BitmapWidths false def
  93.  
  94. %
  95. % Array of procedures which set the current pattern when executed
  96. %
  97. /P 16 array def
  98.  
  99. /patoffsetx 0 def
  100. /patoffsety 0 def
  101. /currentpat null def
  102.  
  103. %
  104. % Find the display size XXXXX
  105. %
  106. /DisplayHeight 850 def
  107. /DisplayWidth  1200 def
  108.  
  109. % you must protect your current gstate before this call
  110. /createwindowg { % w h  ==> graphics stack
  111.     /h 1 index def
  112.     0 0 4 2 roll Retained window windowdeviceround
  113.     initmatrix 0 h TR 1 -1 scale
  114.     gstate
  115. } def
  116.  
  117.  
  118. %
  119. % Create 4 offscreen canvases for doing dotted lines fast
  120. %
  121. mygstate currentgstate
  122.     /HorThickCanvas DisplayWidth 1 createwindowg def
  123.     /HorThinCanvas DisplayWidth 1 createwindowg def
  124.     /VerThinCanvas 1 DisplayHeight createwindowg def
  125.     /VerThickCanvas 1 DisplayHeight createwindowg def
  126.  
  127.     HorThickCanvas setgstate
  128.     1 setlinewidth
  129.     0.0 setgray
  130.     [] 0 setdash
  131.     .5 .5 M DisplayWidth .5 lineto stroke
  132.     [.001 3] 0 setdash
  133.     1.0 setgray
  134.     .5 .5 M DisplayWidth .5 lineto stroke
  135.  
  136.     VerThickCanvas setgstate
  137.     1 setlinewidth
  138.     0.0 setgray
  139.     [] 0 setdash
  140.     .5 .5 M .5 DisplayHeight lineto stroke
  141.     [.001 3] 0 setdash
  142.     1.0 setgray
  143.     .5 .5 M .5 DisplayHeight lineto stroke
  144.  
  145.     HorThinCanvas setgstate
  146.     [.001 3] 0 setdash
  147.     0.0 setgray
  148.     1 setlinewidth
  149.     .5 .5 M DisplayWidth .5 lineto stroke
  150.  
  151.     VerThinCanvas setgstate
  152.     [.001 3] 0 setdash
  153.     0.0 setgray
  154.     1 setlinewidth
  155.     .5 .5 M .5 DisplayHeight lineto stroke
  156. setgstate
  157.  
  158.  
  159. /FmEncoding [
  160. /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  161. /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  162. /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  163. /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  164. /.notdef /.notdef /.notdef /.notdef /space /exclam /quotedbl
  165. /numbersign /dollar /percent /ampersand /quotesingle /parenleft
  166. /parenright /asterisk /plus /comma /hyphen /period /slash /zero /one
  167. /two /three /four /five /six /seven /eight /nine /colon /semicolon
  168. /less /equal /greater /question /at /A /B /C /D /E /F /G /H /I /J /K
  169. /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /bracketleft /backslash
  170. /bracketright /asciicircum /underscore /grave /a /b /c /d /e /f /g /h
  171. /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z /braceleft /bar
  172. /braceright /asciitilde /.notdef /Adieresis /Aring /Ccedilla /Eacute
  173. /Ntilde /Odieresis /Udieresis /aacute /agrave /acircumflex /adieresis
  174. /atilde /aring /ccedilla /eacute /egrave /ecircumflex /edieresis
  175. /iacute /igrave /icircumflex /idieresis /ntilde /oacute /ograve
  176. /ocircumflex /odieresis /otilde /uacute /ugrave /ucircumflex
  177. /udieresis /dagger /.notdef /cent /sterling /section /bullet
  178. /paragraph /germandbls /registered /copyright /trademark /acute
  179. /dieresis /.notdef /AE /Oslash /.notdef /.notdef /.notdef /.notdef
  180. /yen /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  181. /ordfeminine /ordmasculine /.notdef /ae /oslash /questiondown
  182. /exclamdown /logicalnot /.notdef /florin /.notdef /.notdef
  183. /guillemotleft /guillemotright /ellipsis /.notdef /Agrave /Atilde
  184. /Otilde /OE /oe /endash /emdash /quotedblleft /quotedblright
  185. /quoteleft /quoteright /.notdef /.notdef /ydieresis /Ydieresis
  186. /fraction /currency /guilsinglleft /guilsinglright /fi /fl /daggerdbl
  187. /periodcentered /quotesinglbase /quotedblbase /perthousand
  188. /Acircumflex /Ecircumflex /Aacute /Edieresis /Egrave /Iacute
  189. /Icircumflex /Idieresis /Igrave /Oacute /Ocircumflex /.notdef /Ograve
  190. /Uacute /Ucircumflex /Ugrave /dotlessi /circumflex /tilde /macron
  191. /breve /dotaccent /ring /cedilla /hungarumlaut /ogonek /caron
  192. ] def
  193.  
  194. /FmEncode {
  195.     /basefontdict exch def
  196.     /newfontdict basefontdict maxlength 3 add dict def
  197.     basefontdict {
  198.         exch dup
  199.         /FID ne {
  200.             dup /Encoding eq {
  201.                 exch pop FmEncoding
  202.             } {
  203.                 exch
  204.             } ifelse
  205.             newfontdict 3 1 roll put
  206.         } {
  207.             pop pop
  208.         } ifelse
  209.     } forall
  210.     newfontdict /BitmapWidths BitmapWidths put
  211.     newfontdict
  212. } def
  213.  
  214. % makecontextpattern --- make a pattern, and also store it in the array 
  215. % of patterns, P, for quick access.
  216. %
  217. % 7August1994 wiml@omnigroup.com #84261
  218. % Replaced makecontextpattern and Z with routines that use the PSL2 pattern
  219. % operators. This allows colored patterns and is probably also a bit faster.
  220. %
  221. /makecontextpattern % str-data name index ---
  222. {
  223.   3 -1 roll fmmakepatternproc
  224.   % name index patternproc
  225.   dup 4 -1 roll cvn exch def
  226.   % index patternproc
  227.   P 3 1 roll put
  228. } def
  229.  
  230. % 7August1994 wiml@omnigroup.com #84261
  231. % Utility routines. fmmakepatternproc takes bitmap data and returns a 
  232. % newly created procedure of the form { /currentpat pattern store }
  233. % where pattern is the result of running 'makepattern' (the PSL2 operator)
  234. % on a pattern dictionary set up to tile the bitmap across the pattern space.
  235. % fmpatternpainter and fmpatternbbox are defined ahead of time to reduce
  236. % silliness and VM usage.
  237. /fmpatternpainter
  238. {
  239.   begin
  240.     8 8 //true null patternImageData imagemask
  241.   end
  242. } dup 4 [1 0 0 1 0 0] put bind def
  243.  
  244. /fmpatternbbox [0 0 8 8] def
  245.  
  246. /fmmakepatternproc % <data> --- patternproc
  247. {
  248.   <<
  249.     /patternImageData 3 -1 roll
  250.     /PaintType 2
  251.     /TilingType 3
  252.     /PatternType 1
  253.     /BBox //fmpatternbbox
  254.     /XStep 8
  255.     /YStep 8
  256.     /PaintProc //fmpatternpainter
  257.   >> 
  258.   matrix makepattern
  259.   % pattern
  260.   
  261.   [ /currentpat
  262.   % pattern [ /currentpat
  263.   3 -1 roll /store load
  264.   % [ /currentpat pattern --store--
  265.   ] cvx
  266.   % { /currentpat pattern store } bind
  267. }
  268. def
  269.  
  270. % debug code
  271. /mypstack {
  272.     count /w exch def
  273.     w copy
  274.     w { errfile exch (%  ) fprintf } repeat
  275.     errfile (\n) writestring
  276. } def
  277.  
  278. % printout dictionary
  279. /pdict  {
  280.     dup
  281.     { errfile 3 1 roll (%  %\n) fprintf }
  282.     forall
  283. } def
  284.  
  285. % printout array
  286. /parray {
  287.     dup errfile exch (parray %\n) fprintf
  288.     dup { errfile exch (   %\n) fprintf } forall
  289. } def
  290.  
  291. % Z --- sets gstate to the current pattern, and does a fill.
  292. %7August1994 wiml@omnigroup.com #84261 --- changed to work with
  293. % new makecontextpattern, using the PSL2 pattern ops instead of
  294. % offscreen window pattern caches.
  295. /Z
  296. {
  297.   gsave
  298.     gsave
  299.       1 setgray fill % patterns are opaque with white background...
  300.     grestore
  301.     patoffsetx patoffsety sethalftonephase
  302.     currentcolor currentpat setpattern
  303.     fill
  304.   grestore
  305.   newpath
  306. } bind def
  307.  
  308. %
  309. % vertical dotted line
  310. %
  311. /vdottedthick { % int x, int y, int h
  312.     /vh exch def /vy exch def /vx exch def
  313.     0 vy 2 vh VerThickCanvas vx vy Copy composite
  314.     % Copy was Sover
  315. } bind def
  316.  
  317. /vdottedthin { % int x, int y, int h
  318.     /vh exch def /vy exch def /vx exch def
  319.     0 vy 2 vh VerThinCanvas vx vy Copy composite
  320.     % Copy was Sover
  321. } bind def
  322.  
  323. %
  324. %
  325. % horizontal dotted line
  326. %
  327. /hdottedthick { % int x, int y, int w
  328.     0 exch 1 HorThickCanvas        % x y 0 w 1 can
  329.     5 index 6 -1 roll            % x 0 w 1 can x y
  330.     Sover composite
  331. } bind def
  332.  
  333. /hdottedthin { % int x, int y, int w
  334.     0 exch 1 HorThinCanvas        % x y 0 w 1 can
  335.     5 index 6 -1 roll            % x 0 w 1 can x y
  336.     Sover composite
  337. } bind def
  338.  
  339. /line { % int x0, int y0, int x1, int y1
  340.     M lineto
  341.     stroke
  342. } bind def
  343.  
  344. /grid { % int x, int y, int w, int h, int gridw, int offx, int offy
  345.     GS
  346.     TR
  347.     /step exch def
  348.     /h exch def
  349.     /w exch def
  350.     /y exch def
  351.     /x exch def
  352.  
  353.     /w w x add store    % w has stop x
  354.     /h h y add store    % h has stop y
  355.     x step idiv step mul
  356.     step w
  357.         { y h vdottedline } for
  358.     y step idiv step mul
  359.     step h
  360.         { x exch w hdottedline } for
  361.     GR
  362. } def
  363.  
  364. /rrectpath { %    r x y w h  =>  -  (make a round rect path)
  365.     smat
  366.     4 2 roll TR            % r w h
  367.     /h exch def /w exch def /r exch def
  368.     mark
  369.         r 0 M
  370.         w 0 w h r arcto w h 0 h r arcto
  371.         0 h 0 0 r arcto 0 0 w 0 r arcto C
  372.     cleartomark
  373.     rmat
  374. } def
  375.  
  376. /RF { % r x y w h
  377.     rrectpath fill
  378. } bind def
  379.  
  380. /RP { % r x y w h
  381.     rrectpath Z
  382. } bind def
  383.  
  384. /RS { % r x y w h
  385.     rrectpath stroke
  386. } bind def
  387.  
  388. /RQ { % r x y w h
  389.     rrectpath A Z
  390. } bind def
  391.  
  392. /NF { % x y w h
  393.     rectfill
  394. } bind def
  395.  
  396. /NR { % w h x y
  397.     newpath M
  398.     dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  399.     Z
  400. } bind def
  401.  
  402. /W { % x y w h
  403.     currentgray 5 1 roll
  404.     1.0 setgray rectfill setgray
  405. } bind def
  406.  
  407. /invertbox { highbox } bind def
  408.  
  409. /highbox { % x y w h
  410.     currentgray 5 1 roll
  411.     0.0 setgray
  412.     Highlight compositerect
  413.     setgray
  414. } bind def
  415.  
  416. /PP { % int n
  417.     3 1 roll M 1 sub { lineto } repeat
  418. } bind def
  419.  
  420. /SP { % int n
  421.     3 1 roll M 3 div cvi { curveto } repeat
  422. } bind def
  423.  
  424. % note: this routine requires a GS,GR in the C codee
  425. /myimage { % int dx, int dy, int w, int h, int bytes
  426.     /picstr exch string def
  427.     /h exch def
  428.     /w exch def         % dx dy
  429.     h add TR
  430.     w h neg scale
  431.     w h 1
  432.     [w 0 0 h neg 0 h]
  433.     {currentfile picstr readstring pop }
  434.     image
  435. } bind def
  436.  
  437. /rectpath  { % w h x y
  438.     M dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  439. } def
  440.  
  441. /N { %  x y w h
  442.     rectstroke
  443. } bind def
  444.  
  445. /NQ { % int w, int h, int x, int y
  446.     rectpath A Z
  447. } bind def
  448.  
  449. %
  450. %
  451. %         | y0
  452. %         |
  453. %       ----- x0,y1
  454. %
  455. %
  456.  
  457. % make sure our offscreen insert point window is big enough
  458. % variable h must be set
  459. /checkip {
  460.     h IPheight gt {
  461.         GS mygstate currentgstate saveipgstate null ne { } if
  462.             1 h createwindowg /saveipgstate exch def
  463.         saveipgstate setgstate
  464.         setgstate
  465.         GR
  466.         /IPheight h store
  467.     } if
  468. } def
  469.  
  470.  
  471. /drawip { % int y1, int x0, int y0
  472.     /y0 exch def
  473.     /x0 exch def
  474.     /y1 exch def
  475.     /h y1 y0 sub 4 add def
  476.     checkip
  477.     mygstate currentgstate saveipgstate setgstate
  478.     x0 y0 1 h 4 index 0 0 Copy composite  % saveunder
  479.     % Copy was Sover
  480.     setgstate
  481.     % now draw cursor
  482.     currentgray 0 setgray
  483.     x0 y0 1 h rectfill
  484.      fill
  485.     setgray
  486.     flushgraphics % XXX
  487. } bind def
  488.  
  489. /eraseip  { % int y1, int x0, int y0
  490.     /y0 exch def
  491.     /x0 exch def
  492.     /y1 exch def
  493.     /h y1 y0 sub 4 add def
  494.     0 0 1 h saveipgstate x0 y0 Copy composite  % restore bits
  495.     % Copy was Sover
  496.     flushgraphics % XXX
  497. } bind def
  498.  
  499. %
  500. %  Highlight underneath saved area
  501. /highip { % x y w h => -
  502.     mygstate currentgstate saveipgstate setgstate
  503.     5 1 roll
  504.     highbox
  505.     setgstate
  506. } bind def
  507.  
  508.  
  509. % make sure our offscreen text drawing window is big enough
  510. /checktextsize { %
  511.     ScratchHeight Textheight gt ScratchWidth Textwidth gt or {
  512.         mygstate currentgstate
  513.         initclip 1.0 setgray
  514.         ScratchWidth ScratchHeight createwindowg /Textgstate exch def
  515.         setgstate
  516.         /Textheight ScratchHeight def
  517.         /Textwidth ScratchWidth def
  518.     } if
  519. } def
  520.  
  521. % prepare offscreen text drawing for typing in retained windows
  522. /beginscratch { % x y w h => -
  523.     /ScratchHeight exch def
  524.     /ScratchWidth exch def
  525.     /ScratchY exch def
  526.     /ScratchX exch def
  527.     checktextsize
  528.     mygstate currentgstate pop
  529.     Textgstate setgstate     % Textgstate has white fill and no clip
  530.     ScratchX neg ScratchY neg translate
  531.     ScratchX ScratchY ScratchWidth ScratchHeight rectfill
  532.     0 setgray
  533. } bind def
  534.  
  535. % Blit textline onto the screen
  536. /endscratch { %
  537.     mygstate setgstate
  538.     0 0 ScratchWidth ScratchHeight Textgstate ScratchX ScratchY Copy composite
  539.     % Copy was Sover
  540. } bind def
  541.  
  542.  
  543. /insideedgebox { % w h x y t => -
  544.     /t exch def
  545.     GS
  546.     0 setgray
  547.     4 copy rectpath
  548.     t add exch t add exch
  549.     M                % w h
  550.     /t t dup add def
  551.     t sub exch t sub exch  % w h
  552.     dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  553.     eofill
  554.     GR
  555. } bind def
  556.  
  557. % fill a box with a pattern
  558. /replbox { % string datastring, string proc, int w, int h, int x, int y
  559.     M dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  560.     currentgray .5 setgray fill setgray pop pop
  561. } def
  562.  
  563.  
  564. /graybox { % x y w h => -
  565.     currentgray 5 1 roll
  566.     .6666666 setgray rectfill setgray
  567. } bind def
  568.  
  569. /darkgraybox { % x y w h => -
  570.     currentgray 5 1 roll
  571.     .333333 setgray rectfill setgray
  572. } bind def
  573.  
  574. /arcpath { % int th, int dth, int w, int h, int x, int y
  575.     newpath
  576.     TR
  577.     /h exch def
  578.     /w exch def
  579.     /dth exch def
  580.     /th exch def
  581.     90 th dth add sub 90 th sub       % theta1 theta2
  582.     dth 0 lt
  583.         { exch } if
  584.     1 h w div neg scale
  585.     0 0 w 2 div 5 -2 roll arc
  586. } def
  587.  
  588. /AS { % int th, int dth, int w, int h, int x, int y
  589.     smat
  590.     arcpath
  591.     rmat
  592.     stroke
  593. } bind def
  594.  
  595. /AP { % int th, int dth, int w, int h, int x, int y
  596.     smat
  597.     arcpath
  598.     rmat
  599.     A Z
  600. } bind def
  601.  
  602. /AF { % int th, int dth, int w, int h, int x, int y
  603.     smat
  604.     arcpath
  605.     0 0 lineto
  606.     rmat
  607.     fill
  608. } bind def
  609.  
  610. /AQ { % int th, int dth, int w, int h, int x, int y
  611.     smat
  612.     arcpath
  613.     0 0 lineto
  614.     rmat
  615.     Z
  616. } bind def
  617.  
  618. /mymakefont { % i name size => -
  619.     /size exch def
  620.     /name exch def
  621.     /i exch def
  622.     /myfontdict name cvn findfont def
  623.     myfontdict /Encoding get NextStepEncoding eq {
  624.         myfontdict FmEncode /gfontdict exch def
  625.         /gfontdict (F   ) dup 1 i (   ) cvs putinterval cvn
  626.             gfontdict definefont def
  627.     } {
  628.         /gfontdict myfontdict def
  629.     } ifelse
  630.  
  631.     /myfonts [ myfonts aload pop null ] def
  632.     myfonts i  gfontdict  [size 0 0 size neg 0 0 ] makefont put
  633. } def
  634.  
  635. /mymakefontmetric { % i name size printermetrics => -
  636.     /BitmapWidths exch 0 eq def   % the font reencoding will add this to font
  637.     mymakefont
  638. } def
  639.  
  640. /FF { % i => -
  641.     myfonts exch get setfont
  642. } bind def
  643.  
  644. % close clipping down to this rectangle
  645. /CR { % x y w h => -
  646.     initclip
  647.     rectclip
  648. } bind def
  649.  
  650. /CRnotrans { % x y w h => -
  651.     mymatrix currentmatrix pop
  652.     initmatrix 1 -1 scale
  653.     mymatrix setmatrix
  654. } bind def
  655.  
  656. /cliptowindow {
  657.     initclip
  658. } def
  659.  
  660. /beginprintcode { % -x -y w h scale dx dy => -
  661.     GS
  662.     newpath 1 setlinewidth 0 setlinecap 0 setlinejoin
  663.     [] 0 setdash 0 setgray 10 setmiterlimit
  664.     /FMdicttop countdictstack 1 add def % high-water mark of dict stack
  665.     /FMoptop count 7 sub def % tricky! 7 params on stack, plus "/FMoptop"
  666.     200 dict begin
  667.  
  668.     TR                        % translate to bottom left
  669.     dup neg scale            % convert to postscript coordinates
  670.     1.0 setgray 2 copy 0 0 4 -2 roll rectfill 0 setgray  % clear underneath
  671.     0.0 0.0 M
  672. } def
  673.  
  674. /endprintcode {
  675.     count -1 FMoptop {pop pop} for % clear user junk from operand stack
  676.     countdictstack -1 FMdicttop {pop end} for % ditto for dict stack
  677.     GR
  678. } def
  679.  
  680. /beginPSInsetprintcode {
  681.     /insetsave save def
  682.     newpath 1 setlinewidth 0 setlinecap 0 setlinejoin
  683.     [] 0 setdash 0 setgray 10 setmiterlimit
  684.     /FMdicttop countdictstack 1 add def % high-water mark of dict stack
  685.     /FMoptop count def % tricky!           +1 in both cases for the 'for' loop.
  686.     200 dict begin %
  687. } def
  688.  
  689. /endPSInsetprintcode {
  690.     count -1 FMoptop {pop pop} for % clear user junk from operand stack
  691.     countdictstack -1 FMdicttop {pop end} for % ditto for dict stack
  692.     insetsave restore
  693. } def
  694.  
  695.  
  696. /cacheimage { % destX destY destWidth destHeight w h bps theta flip => -
  697.     /flip exch def
  698.     /theta exch def
  699.     /bps exch def
  700.     /h exch def
  701.     /w exch def
  702.     /destHeight exch def
  703.     /destWidth exch def
  704.     /destY exch def
  705.     /destX exch def
  706.     /rowbytes w bps mul 7 add 8 idiv def
  707.     /buffer rowbytes string def
  708.  
  709.     GS
  710.     destX destY TR
  711.     theta rotate
  712.     destWidth flip {neg} if destHeight scale
  713.     w h bps
  714.     [w 0 0 h neg 0 h ]
  715.     { currentfile buffer readstring pop } bind
  716.     image
  717.     GR
  718. } def
  719.  
  720. % sbs 910917
  721. /FmHorrible{}def
  722. /FmEndHorrible{}def
  723.  
  724. /FMBEGINPAGE { } def
  725. /FMENDPAGE { } def
  726. %
  727. % screen capture code
  728. %
  729. /grabdict 50 dict def
  730. grabdict begin
  731.  
  732. /winx 0 def /winy 0 def
  733. /winw 0 def /winh 0 def
  734. /lastwin null def /mywin null def
  735. /catcherradius 20 def
  736.  
  737. /mousedownx 0 def /mousedowny 0 def
  738. /curmousex 0 def /curmousey 0 def
  739.  
  740. /min    % a b => min(a, b)
  741. {
  742.     2 copy gt {exch} if pop
  743. } bind def
  744.  
  745. /max    % a b => max(a, b)
  746. {
  747.     2 copy lt {exch} if pop
  748. } bind def
  749.  
  750. /abs    %    a => abs(a)
  751. {
  752.     dup 0 lt {neg} if
  753. } bind def
  754.  
  755.  
  756. /updatewin % - => didchange
  757. {
  758.     /winw winw 1 max def        % Warning: no zero-height windows!
  759.     /winh winh 1 max def
  760.  
  761.     mywin currentwindowbounds
  762.     winh ne exch winw ne or exch winy ne or exch winx ne or dup {
  763.         % Warning: keep a window under mouse so we get all clicks!
  764.         /lastwin mywin def
  765.  
  766.         /mywin winx winy winw winh Buffered window def
  767.         mywin windowdeviceround
  768.         100 mywin setwindowlevel
  769.         Below lastwin mywin fillwindow
  770.         Above 0 mywin orderwindow
  771.  
  772.         lastwin termwindow
  773.     } if
  774. } def
  775.  
  776.  
  777. /framewin
  778. {
  779.     0 1 winw 1 sub winh 1 sub rectstroke
  780.     flushgraphics
  781. } def
  782.  
  783. /getcurmouse
  784. {
  785.     mywin currentmouse
  786.     /curmousey exch winy add def
  787.     /curmousex exch winx add def
  788. } def
  789.  
  790. /captureloops
  791. {
  792.     {
  793.         getcurmouse
  794.         /winx curmousex catcherradius sub def
  795.         /winy curmousey catcherradius sub def
  796.         /winw catcherradius catcherradius add def
  797.         /winh catcherradius catcherradius add def
  798.         updatewin {} if
  799.         buttondown {exit} if
  800.     } loop
  801.     
  802.     /mousedownx curmousex 1 sub def        % Offset mousedown point over our
  803.     /mousedowny curmousey 1 sub def        %  window so we get the click.
  804.     
  805.     {
  806.         getcurmouse
  807.         /winx mousedownx curmousex min def
  808.         /winy mousedowny curmousey min def
  809.         /winw mousedownx curmousex sub abs def
  810.         /winh mousedowny curmousey sub abs def
  811.         mousedownx curmousex gt            % Adjust coordinates to
  812.             {                %  capture pixels under
  813.             /winx winx 1 sub def        %  the current frame.
  814.             /winw winw 2 add def
  815.             } if
  816.         mousedowny curmousey gt            % Adjust coordinates to
  817.             {                %  capture pixels under
  818.             /winy winy 1 sub def        %  the current frame.
  819.             /winh winh 2 add def
  820.             } if
  821.         updatewin {framewin} if
  822.         buttondown not {exit} if
  823.     } loop
  824. } def
  825.  
  826. /setcrosshaircursor
  827. {
  828.     0 0 16 16 Retained window
  829.     windowdeviceround
  830.     0 0 16 16 Clear compositerect
  831.     7 1 moveto 0 16 rlineto stroke
  832.     0 8 moveto 16 0 rlineto stroke
  833.     0 16 8 -8 setcursor
  834.     currentwindow termwindow
  835. } def
  836.  
  837. end % grabdict
  838.  
  839. /docapture % - => w h bps
  840. {
  841.     grabdict begin
  842.         
  843.     {
  844.         setcrosshaircursor
  845.         /mywin 0 0 0 0 Buffered window def
  846.         captureloops
  847.         Below mywin mywin fillwindow
  848.         0 0 winw winh matrix currentmatrix sizeimage pop pop pop
  849.     } stopped pop
  850. } def
  851.  
  852. /cleanupcapture % - => -
  853. {
  854.     {
  855.         mywin termwindow
  856.     } stopped pop
  857.     
  858.     end
  859. } def
  860.