home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Demos / DE_FrameMaker / FrameMaker.app / fminit2.0 / next / makerbegin.ps < prev    next >
Text File  |  1992-08-24  |  19KB  |  897 lines

  1. %-
  2. %- FrameMaker display server prologue, for use with FrameMaker 3.0
  3. %- Copyright (c) 1986, 87, 88, 89, 90, 91 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 { P exch get exec } bind def
  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. %
  215. % this is the template for a procedure which when execute will set the
  216. % current pattern.
  217. %
  218. /patterninktemplate { %
  219.     null           % this gets filled in later
  220.     /currentpat exch store
  221. } def
  222.  
  223. %
  224. % make a pattern, and also store it in the array of patterns P for quick
  225. % access.
  226. %
  227. /makecontextpattern  { % str inkproc index
  228.     1 index 4 -2 roll      % index inkproc str inkproc
  229.     makermakepattern
  230.     cvn load P             % index {} P
  231.     3 1 roll put
  232. } def
  233.  
  234. %
  235. % Create a procedure if it already hasn't been defined, which will set the
  236. % current pattern when it gets executed. The pattern is
  237. % created by filling on offscreen canvas.
  238. %
  239. % create offscreen canvas of pattern
  240. %
  241. /makermakepattern { %  patternstring inkproc
  242.     dup
  243.     cvn dup
  244.     currentdict exch known  { % patternstring inkproc inkprocname
  245.         pop pop pop
  246.     } {
  247.         3 1 roll 0 get (I) 0 get eq    % inkprocname patternstring bool
  248.         cachepattern                % inkprocname canvas
  249.         /patterninktemplate load
  250.         dup length array copy        % name canvas array
  251.         dup 3 -1 roll                % name array array canvas
  252.         0 exch put cvx def
  253.     } ifelse
  254. } def
  255.  
  256. % debug code
  257. /mypstack {
  258.     count /w exch def
  259.     w copy
  260.     w { errfile exch (%  ) fprintf } repeat
  261.     errfile (\n) writestring
  262. } def
  263.  
  264. % printout dictionary
  265. /pdict  {
  266.     dup
  267.     { errfile 3 1 roll (%  %\n) fprintf }
  268.     forall
  269. } def
  270.  
  271. % printout array
  272. /parray {
  273.     dup errfile exch (parray %\n) fprintf
  274.     dup { errfile exch (   %\n) fprintf } forall
  275. } def
  276.  
  277. % these 2 are used in cachepattern
  278. /copyright {
  279.     0 0 w h cgstate w 0 Sover composite
  280.     /w w dup add def
  281. } def
  282.  
  283. /copyup {
  284.     0 0 w h cgstate 0 h Sover composite
  285.     /h h dup add def
  286. } def
  287.  
  288. /cachepattern { % patternstring polarity ==> canvas
  289.     gstate 3 1 roll
  290.     /polarity exch def
  291.     /datastr exch def
  292.  
  293.     % create on offscreen graphics context with an offscreen window
  294.     CACHEX CACHEY createwindowg  /cgstate exch def
  295.     0 setgray
  296.  
  297.     % plop the pattern down once
  298.     GS
  299.     8 8 scale
  300.     % we flip the pattern over the x axis here
  301.     8 8 polarity [8 0 0 8 0 0] { datastr } imagemask
  302.     GR
  303.  
  304.     % spread the pattern around
  305.     /w 8 def
  306.     /h 8 def
  307.     {
  308.         h CACHEY eq { exit } if
  309.         copyright copyup
  310.     } loop
  311.  
  312.     setgstate
  313.     cgstate
  314. } def
  315.  
  316. %
  317. % Fill area with pattern
  318. %
  319. /Z {
  320.     GS
  321.     pathbbox  /uy exch cvi def /ux exch cvi def
  322.             /ly exch cvi def /lx exch cvi def
  323.     clip
  324.  
  325.     /w lx patoffsetx add cvi 8 mod def
  326.     /h uy patoffsety add cvi 8 mod def
  327.  
  328.     /lx lx w sub def
  329.     /uy uy h sub def
  330.  
  331.     /ly ly cvi -32 and def
  332.     /uy uy cvi -32 and def
  333.  
  334.     lx CACHEX ux {
  335.         ly CACHEY uy {
  336.             1 index exch  % CACHEY add
  337.             0 0 CACHEX CACHEY currentpat 7 -2 roll  Sover flush composite
  338.         } for
  339.         pop
  340.     } for
  341.     GR
  342.     newpath
  343. } def
  344.  
  345. %
  346. % vertical dotted line
  347. %
  348. /vdottedthick { % int x, int y, int h
  349.     /vh exch def /vy exch def /vx exch def
  350.     0 vy 2 vh VerThickCanvas vx vy Copy composite
  351.     % Copy was Sover
  352. } bind def
  353.  
  354. /vdottedthin { % int x, int y, int h
  355.     /vh exch def /vy exch def /vx exch def
  356.     0 vy 2 vh VerThinCanvas vx vy Copy composite
  357.     % Copy was Sover
  358. } bind def
  359.  
  360. %
  361. %
  362. % horizontal dotted line
  363. %
  364. /hdottedthick { % int x, int y, int w
  365.     0 exch 1 HorThickCanvas        % x y 0 w 1 can
  366.     5 index 6 -1 roll            % x 0 w 1 can x y
  367.     Sover composite
  368. } bind def
  369.  
  370. /hdottedthin { % int x, int y, int w
  371.     0 exch 1 HorThinCanvas        % x y 0 w 1 can
  372.     5 index 6 -1 roll            % x 0 w 1 can x y
  373.     Sover composite
  374. } bind def
  375.  
  376. /line { % int x0, int y0, int x1, int y1
  377.     M lineto
  378.     stroke
  379. } bind def
  380.  
  381. /grid { % int x, int y, int w, int h, int gridw, int offx, int offy
  382.     GS
  383.     TR
  384.     /step exch def
  385.     /h exch def
  386.     /w exch def
  387.     /y exch def
  388.     /x exch def
  389.  
  390.     /w w x add store    % w has stop x
  391.     /h h y add store    % h has stop y
  392.     x step idiv step mul
  393.     step w
  394.         { y h vdottedline } for
  395.     y step idiv step mul
  396.     step h
  397.         { x exch w hdottedline } for
  398.     GR
  399. } def
  400.  
  401. /rrectpath { %    r x y w h  =>  -  (make a round rect path)
  402.     smat
  403.     4 2 roll TR            % r w h
  404.     /h exch def /w exch def /r exch def
  405.     mark
  406.         r 0 M
  407.         w 0 w h r arcto w h 0 h r arcto
  408.         0 h 0 0 r arcto 0 0 w 0 r arcto C
  409.     cleartomark
  410.     rmat
  411. } def
  412.  
  413. /RF { % r x y w h
  414.     rrectpath fill
  415. } bind def
  416.  
  417. /RP { % r x y w h
  418.     rrectpath Z
  419. } bind def
  420.  
  421. /RS { % r x y w h
  422.     rrectpath stroke
  423. } bind def
  424.  
  425. /RQ { % r x y w h
  426.     rrectpath A Z
  427. } bind def
  428.  
  429. /NF { % x y w h
  430.     rectfill
  431. } bind def
  432.  
  433. /NR { % w h x y
  434.     newpath M
  435.     dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  436.     Z
  437. } bind def
  438.  
  439. /W { % x y w h
  440.     currentgray 5 1 roll
  441.     1.0 setgray rectfill setgray
  442. } bind def
  443.  
  444. /invertbox { highbox } bind def
  445.  
  446. /highbox { % x y w h
  447.     currentgray 5 1 roll
  448.     0.0 setgray
  449.     Highlight compositerect
  450.     setgray
  451. } bind def
  452.  
  453. /PP { % int n
  454.     3 1 roll M 1 sub { lineto } repeat
  455. } bind def
  456.  
  457. /SP { % int n
  458.     3 1 roll M 3 div cvi { curveto } repeat
  459. } bind def
  460.  
  461. % note: this routine requires a GS,GR in the C codee
  462. /myimage { % int dx, int dy, int w, int h, int bytes
  463.     /picstr exch string def
  464.     /h exch def
  465.     /w exch def         % dx dy
  466.     h add TR
  467.     w h neg scale
  468.     w h 1
  469.     [w 0 0 h neg 0 h]
  470.     {currentfile picstr readstring pop }
  471.     image
  472. } bind def
  473.  
  474. /rectpath  { % w h x y
  475.     M dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  476. } def
  477.  
  478. /N { %  x y w h
  479.     rectstroke
  480. } bind def
  481.  
  482. /NQ { % int w, int h, int x, int y
  483.     rectpath A Z
  484. } bind def
  485.  
  486. %
  487. %
  488. %         | y0
  489. %         |
  490. %       ----- x0,y1
  491. %
  492. %
  493.  
  494. % make sure our offscreen insert point window is big enough
  495. % variable h must be set
  496. /checkip {
  497.     h IPheight gt {
  498.         GS mygstate currentgstate saveipgstate null ne { } if
  499.             1 h createwindowg /saveipgstate exch def
  500.         saveipgstate setgstate
  501.         setgstate
  502.         GR
  503.         /IPheight h store
  504.     } if
  505. } def
  506.  
  507.  
  508. /drawip { % int y1, int x0, int y0
  509.     /y0 exch def
  510.     /x0 exch def
  511.     /y1 exch def
  512.     /h y1 y0 sub 4 add def
  513.     checkip
  514.     mygstate currentgstate saveipgstate setgstate
  515.     x0 y0 1 h 4 index 0 0 Copy composite  % saveunder
  516.     % Copy was Sover
  517.     setgstate
  518.     % now draw cursor
  519.     currentgray 0 setgray
  520.     x0 y0 1 h rectfill
  521.      fill
  522.     setgray
  523.     flushgraphics % XXX
  524. } bind def
  525.  
  526. /eraseip  { % int y1, int x0, int y0
  527.     /y0 exch def
  528.     /x0 exch def
  529.     /y1 exch def
  530.     /h y1 y0 sub 4 add def
  531.     0 0 1 h saveipgstate x0 y0 Copy composite  % restore bits
  532.     % Copy was Sover
  533.     flushgraphics % XXX
  534. } bind def
  535.  
  536. %
  537. %  Highlight underneath saved area
  538. /highip { % x y w h => -
  539.     mygstate currentgstate saveipgstate setgstate
  540.     5 1 roll
  541.     highbox
  542.     setgstate
  543. } bind def
  544.  
  545.  
  546. % make sure our offscreen text drawing window is big enough
  547. /checktextsize { %
  548.     ScratchHeight Textheight gt ScratchWidth Textwidth gt or {
  549.         mygstate currentgstate
  550.         initclip 1.0 setgray
  551.         ScratchWidth ScratchHeight createwindowg /Textgstate exch def
  552.         setgstate
  553.         /Textheight ScratchHeight def
  554.         /Textwidth ScratchWidth def
  555.     } if
  556. } def
  557.  
  558. % prepare offscreen text drawing for typing in retained windows
  559. /beginscratch { % x y w h => -
  560.     /ScratchHeight exch def
  561.     /ScratchWidth exch def
  562.     /ScratchY exch def
  563.     /ScratchX exch def
  564.     checktextsize
  565.     mygstate currentgstate pop
  566.     Textgstate setgstate     % Textgstate has white fill and no clip
  567.     ScratchX neg ScratchY neg translate
  568.     ScratchX ScratchY ScratchWidth ScratchHeight rectfill
  569.     0 setgray
  570. } bind def
  571.  
  572. % Blit textline onto the screen
  573. /endscratch { %
  574.     mygstate setgstate
  575.     0 0 ScratchWidth ScratchHeight Textgstate ScratchX ScratchY Copy composite
  576.     % Copy was Sover
  577. } bind def
  578.  
  579.  
  580. /insideedgebox { % w h x y t => -
  581.     /t exch def
  582.     GS
  583.     0 setgray
  584.     4 copy rectpath
  585.     t add exch t add exch
  586.     M                % w h
  587.     /t t dup add def
  588.     t sub exch t sub exch  % w h
  589.     dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  590.     eofill
  591.     GR
  592. } bind def
  593.  
  594. % fill a box with a pattern
  595. /replbox { % string datastring, string proc, int w, int h, int x, int y
  596.     M dup 0 exch rlineto exch 0 rlineto neg 0 exch rlineto C
  597.     currentgray .5 setgray fill setgray pop pop
  598. } def
  599.  
  600.  
  601. /graybox { % x y w h => -
  602.     currentgray 5 1 roll
  603.     .6666666 setgray rectfill setgray
  604. } bind def
  605.  
  606. /darkgraybox { % x y w h => -
  607.     currentgray 5 1 roll
  608.     .333333 setgray rectfill setgray
  609. } bind def
  610.  
  611. /arcpath { % int th, int dth, int w, int h, int x, int y
  612.     newpath
  613.     TR
  614.     /h exch def
  615.     /w exch def
  616.     /dth exch def
  617.     /th exch def
  618.     90 th dth add sub 90 th sub       % theta1 theta2
  619.     dth 0 lt
  620.         { exch } if
  621.     1 h w div neg scale
  622.     0 0 w 2 div 5 -2 roll arc
  623. } def
  624.  
  625. /AS { % int th, int dth, int w, int h, int x, int y
  626.     smat
  627.     arcpath
  628.     rmat
  629.     stroke
  630. } bind def
  631.  
  632. /AP { % int th, int dth, int w, int h, int x, int y
  633.     smat
  634.     arcpath
  635.     rmat
  636.     A Z
  637. } bind def
  638.  
  639. /AF { % int th, int dth, int w, int h, int x, int y
  640.     smat
  641.     arcpath
  642.     0 0 lineto
  643.     rmat
  644.     fill
  645. } bind def
  646.  
  647. /AQ { % int th, int dth, int w, int h, int x, int y
  648.     smat
  649.     arcpath
  650.     0 0 lineto
  651.     rmat
  652.     Z
  653. } bind def
  654.  
  655. /mymakefont { % i name size => -
  656.     /size exch def
  657.     /name exch def
  658.     /i exch def
  659.     /myfontdict name cvn findfont def
  660.     myfontdict /Encoding get NextStepEncoding eq {
  661.         myfontdict FmEncode /gfontdict exch def
  662.         /gfontdict (F   ) dup 1 i (   ) cvs putinterval cvn
  663.             gfontdict definefont def
  664.     } {
  665.         /gfontdict myfontdict def
  666.     } ifelse
  667.  
  668.     /myfonts [ myfonts aload pop null ] def
  669.     myfonts i  gfontdict  [size 0 0 size neg 0 0 ] makefont put
  670. } def
  671.  
  672. /mymakefontmetric { % i name size printermetrics => -
  673.     /BitmapWidths exch 0 eq def   % the font reencoding will add this to font
  674.     mymakefont
  675. } def
  676.  
  677. /FF { % i => -
  678.     myfonts exch get setfont
  679. } bind def
  680.  
  681. % close clipping down to this rectangle
  682. /CR { % x y w h => -
  683.     initclip
  684.     rectclip
  685. } bind def
  686.  
  687. /CRnotrans { % x y w h => -
  688.     mymatrix currentmatrix pop
  689.     initmatrix 1 -1 scale
  690.     mymatrix setmatrix
  691. } bind def
  692.  
  693. /cliptowindow {
  694.     initclip
  695. } def
  696.  
  697. /beginprintcode { % -x -y w h scale dx dy => -
  698.     GS
  699.     newpath 1 setlinewidth 0 setlinecap 0 setlinejoin
  700.     [] 0 setdash 0 setgray 10 setmiterlimit
  701.     /FMdicttop countdictstack 1 add def % high-water mark of dict stack
  702.     /FMoptop count 7 sub def % tricky! 7 params on stack, plus "/FMoptop"
  703.     200 dict begin
  704.  
  705.     TR                        % translate to bottom left
  706.     dup neg scale            % convert to postscript coordinates
  707.     1.0 setgray 2 copy 0 0 4 -2 roll rectfill 0 setgray  % clear underneath
  708.     0.0 0.0 M
  709. } def
  710.  
  711. /endprintcode {
  712.     count -1 FMoptop {pop pop} for % clear user junk from operand stack
  713.     countdictstack -1 FMdicttop {pop end} for % ditto for dict stack
  714.     GR
  715. } def
  716.  
  717. /beginPSInsetprintcode {
  718.     /insetsave save def
  719.     newpath 1 setlinewidth 0 setlinecap 0 setlinejoin
  720.     [] 0 setdash 0 setgray 10 setmiterlimit
  721.     /FMdicttop countdictstack 1 add def % high-water mark of dict stack
  722.     /FMoptop count def % tricky!           +1 in both cases for the 'for' loop.
  723.     200 dict begin %
  724. } def
  725.  
  726. /endPSInsetprintcode {
  727.     count -1 FMoptop {pop pop} for % clear user junk from operand stack
  728.     countdictstack -1 FMdicttop {pop end} for % ditto for dict stack
  729.     insetsave restore
  730. } def
  731.  
  732.  
  733. /cacheimage { % destX destY destWidth destHeight w h bps theta flip => -
  734.     /flip exch def
  735.     /theta exch def
  736.     /bps exch def
  737.     /h exch def
  738.     /w exch def
  739.     /destHeight exch def
  740.     /destWidth exch def
  741.     /destY exch def
  742.     /destX exch def
  743.     /rowbytes w bps mul 7 add 8 idiv def
  744.     /buffer rowbytes string def
  745.  
  746.     GS
  747.     destX destY TR
  748.     theta rotate
  749.     destWidth flip {neg} if destHeight scale
  750.     w h bps
  751.     [w 0 0 h neg 0 h ]
  752.     { currentfile buffer readstring pop } bind
  753.     image
  754.     GR
  755. } def
  756.  
  757. % sbs 910917
  758. /FmHorrible{}def
  759. /FmEndHorrible{}def
  760.  
  761. /FMBEGINPAGE { } def
  762. /FMENDPAGE { } def
  763. %
  764. % screen capture code
  765. %
  766. /grabdict 50 dict def
  767. grabdict begin
  768.  
  769. /winx 0 def /winy 0 def
  770. /winw 0 def /winh 0 def
  771. /lastwin null def /mywin null def
  772. /catcherradius 20 def
  773.  
  774. /mousedownx 0 def /mousedowny 0 def
  775. /curmousex 0 def /curmousey 0 def
  776.  
  777. /min    % a b => min(a, b)
  778. {
  779.     2 copy gt {exch} if pop
  780. } bind def
  781.  
  782. /max    % a b => max(a, b)
  783. {
  784.     2 copy lt {exch} if pop
  785. } bind def
  786.  
  787. /abs    %    a => abs(a)
  788. {
  789.     dup 0 lt {neg} if
  790. } bind def
  791.  
  792.  
  793. /updatewin % - => didchange
  794. {
  795.     /winw winw 1 max def        % Warning: no zero-height windows!
  796.     /winh winh 1 max def
  797.  
  798.     mywin currentwindowbounds
  799.     winh ne exch winw ne or exch winy ne or exch winx ne or dup {
  800.         % Warning: keep a window under mouse so we get all clicks!
  801.         /lastwin mywin def
  802.  
  803.         /mywin winx winy winw winh Buffered window def
  804.         mywin windowdeviceround
  805.         100 mywin setwindowlevel
  806.         Below lastwin mywin fillwindow
  807.         Above 0 mywin orderwindow
  808.  
  809.         lastwin termwindow
  810.     } if
  811. } def
  812.  
  813.  
  814. /framewin
  815. {
  816.     0 1 winw 1 sub winh 1 sub rectstroke
  817.     flushgraphics
  818. } def
  819.  
  820. /getcurmouse
  821. {
  822.     mywin currentmouse
  823.     /curmousey exch winy add def
  824.     /curmousex exch winx add def
  825. } def
  826.  
  827. /captureloops
  828. {
  829.     {
  830.         getcurmouse
  831.         /winx curmousex catcherradius sub def
  832.         /winy curmousey catcherradius sub def
  833.         /winw catcherradius catcherradius add def
  834.         /winh catcherradius catcherradius add def
  835.         updatewin {} if
  836.         buttondown {exit} if
  837.     } loop
  838.     
  839.     /mousedownx curmousex 1 sub def        % Offset mousedown point over our
  840.     /mousedowny curmousey 1 sub def        %  window so we get the click.
  841.     
  842.     {
  843.         getcurmouse
  844.         /winx mousedownx curmousex min def
  845.         /winy mousedowny curmousey min def
  846.         /winw mousedownx curmousex sub abs def
  847.         /winh mousedowny curmousey sub abs def
  848.         mousedownx curmousex gt            % Adjust coordinates to
  849.             {                %  capture pixels under
  850.             /winx winx 1 sub def        %  the current frame.
  851.             /winw winw 2 add def
  852.             } if
  853.         mousedowny curmousey gt            % Adjust coordinates to
  854.             {                %  capture pixels under
  855.             /winy winy 1 sub def        %  the current frame.
  856.             /winh winh 2 add def
  857.             } if
  858.         updatewin {framewin} if
  859.         buttondown not {exit} if
  860.     } loop
  861. } def
  862.  
  863. /setcrosshaircursor
  864. {
  865.     0 0 16 16 Retained window
  866.     windowdeviceround
  867.     0 0 16 16 Clear compositerect
  868.     7 1 moveto 0 16 rlineto stroke
  869.     0 8 moveto 16 0 rlineto stroke
  870.     0 16 8 -8 setcursor
  871.     currentwindow termwindow
  872. } def
  873.  
  874. end % grabdict
  875.  
  876. /docapture % - => w h bps
  877. {
  878.     grabdict begin
  879.         
  880.     {
  881.         setcrosshaircursor
  882.         /mywin 0 0 0 0 Buffered window def
  883.         captureloops
  884.         Below mywin mywin fillwindow
  885.         0 0 winw winh matrix currentmatrix sizeimage pop pop pop
  886.     } stopped pop
  887. } def
  888.  
  889. /cleanupcapture % - => -
  890. {
  891.     {
  892.         mywin termwindow
  893.     } stopped pop
  894.     
  895.     end
  896. } def
  897.