home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-alpha / enscript-1.4.0-bin.lha / share / enscript / enscript.pro < prev    next >
Encoding:
Text File  |  1996-10-14  |  4.6 KB  |  223 lines

  1. %
  2. % PostScript prolog.
  3. % Copyright (c) 1995 Markku Rossi.
  4. %
  5. % Author: Markku Rossi <mtr@iki.fi>
  6. %
  7. %
  8. % This file is part of GNU enscript.
  9. %
  10. % This program is free software; you can redistribute it and/or modify
  11. % it under the terms of the GNU General Public License as published by
  12. % the Free Software Foundation; either version 2, or (at your option)
  13. % any later version.
  14. %
  15. % This program is distributed in the hope that it will be useful,
  16. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. % GNU General Public License for more details.
  19. %
  20. % You should have received a copy of the GNU General Public License
  21. % along with this program; see the file COPYING.  If not, write to
  22. % the Free Software Foundation, 59 Temple Place - Suite 330,
  23. % Boston, MA 02111-1307, USA.
  24. %
  25.  
  26. % -- code follows this line --
  27. %
  28. % Procedures.
  29. %
  30.  
  31. /_S {    % save current state
  32.   /_s save def
  33. } def
  34. /_R {    % restore from saved state
  35.   _s restore
  36. } def
  37.  
  38. /S {    % showpage protecting gstate
  39.   gsave
  40.   showpage
  41.   grestore
  42. } bind def
  43.  
  44. /MF {    % fontname newfontname -> -    make a new encoded font
  45.   /newfontname exch def
  46.   /fontname exch def
  47.  
  48.   /fontdict fontname findfont def
  49.   /newfont fontdict maxlength dict def
  50.  
  51.   fontdict {
  52.     exch 
  53.     dup /FID eq {
  54.       % skip FID pair
  55.       pop pop
  56.     } {
  57.       % copy to the new font dictionary
  58.       exch newfont 3 1 roll put
  59.     } ifelse
  60.   } forall
  61.   
  62.   newfont /FontName newfontname put
  63.  
  64.   % insert only valid encoding vectors
  65.   encoding_vector length 256 eq {
  66.     newfont /Encoding encoding_vector put
  67.   } if
  68.   
  69.   newfontname newfont definefont pop
  70. } def
  71.  
  72. /M {moveto} bind def
  73. /s {show} bind def
  74.  
  75. /Box {    % x y w h -> -            define box path
  76.   /d_h exch def /d_w exch def /d_y exch def /d_x exch def
  77.   d_x d_y  moveto 
  78.   d_w 0 rlineto 
  79.   0 d_h rlineto 
  80.   d_w neg 0 rlineto 
  81.   closepath
  82. } def
  83.  
  84. % Highlight bars.
  85. /highlight_bars {    % nlines lineheight output_y_margin gray -> -
  86.   gsave
  87.     setgray
  88.     /ymarg exch def
  89.     /lineheight exch def
  90.     /nlines exch def
  91.  
  92.     % This 2 is just a magic number to sync highlight lines to text.
  93.     0 d_header_y ymarg sub 2 sub translate
  94.     
  95.     /cw d_output_w cols div def
  96.     /nrows d_output_h ymarg 2 mul sub lineheight div floor def
  97.  
  98.     % for each column
  99.     0 1 cols 1 sub {
  100.       cw mul /xp exch def
  101.  
  102.       % for each rows
  103.       0 1 nrows 1 sub {
  104.         /rn exch def 
  105.         rn lineheight mul neg /yp exch def
  106.         rn nlines idiv 2 mod 0 eq {
  107.       % Draw highlight bar.  4 is just a magic indentation.
  108.       xp 4 add yp cw 8 sub lineheight neg Box fill      
  109.     } if
  110.       } for
  111.     } for
  112.     
  113.   grestore
  114. } def
  115.  
  116. % Line highlight bar.
  117. /line_highlight {    % x y width height gray -> -
  118.   gsave
  119.     /gray exch def
  120.     Box gray setgray fill
  121.   grestore
  122. } def
  123.  
  124. % Column separator lines.
  125. /column_lines {
  126.   gsave
  127.     .1 setlinewidth
  128.     0 d_footer_h translate
  129.     /cw d_output_w cols div def
  130.     1 1 cols 1 sub {
  131.       cw mul 0 moveto
  132.       0 d_output_h rlineto stroke
  133.     } for
  134.   grestore
  135. } def
  136.  
  137. % Column borders.
  138. /column_borders {
  139.   gsave
  140.     .1 setlinewidth
  141.     0 d_footer_h moveto 
  142.     0 d_output_h rlineto
  143.     d_output_w 0 rlineto
  144.     0 d_output_h neg rlineto
  145.     closepath stroke
  146.   grestore
  147. } def
  148.  
  149. % Do the actual underlay drawing
  150. /draw_underlay {
  151.   ul_style 0 eq {
  152.     ul_str true charpath stroke
  153.   } { 
  154.     ul_str show
  155.   } ifelse
  156. } def
  157.  
  158. % Underlay
  159. /underlay {    % - -> -
  160.   gsave
  161.     0 d_page_h translate
  162.     d_page_h neg d_page_w atan rotate
  163.  
  164.     ul_gray setgray
  165.     ul_font setfont
  166.     /dw d_page_h dup mul d_page_w dup mul add sqrt def
  167.     ul_str stringwidth pop dw exch sub 2 div ul_ptsize -2 div moveto 
  168.     draw_underlay
  169.   grestore
  170. } def
  171.  
  172. /user_underlay {    % - -> -
  173.   gsave
  174.     ul_x ul_y translate
  175.     ul_angle rotate
  176.     ul_gray setgray
  177.     ul_font setfont 
  178.     0 0 ul_ptsize 2 div sub moveto 
  179.     draw_underlay
  180.   grestore
  181. } def
  182.  
  183. % Page prefeed
  184. /page_prefeed {        % bool -> -
  185.   statusdict /prefeed known {
  186.     statusdict exch /prefeed exch put
  187.   } {
  188.     pop
  189.   } ifelse
  190. } def
  191.  
  192. % EPSF import.
  193.  
  194. /BeginEPSF {
  195.   /b4_Inc_state save def            % Save state for cleanup
  196.   /dict_count countdictstack def    % Count objects on dict stack
  197.   /op_count count 1 sub def        % Count objects on operand stack 
  198.   userdict begin
  199.   /showpage { } def
  200.   0 setgray 0 setlinecap
  201.   1 setlinewidth 0 setlinejoin
  202.   10 setmiterlimit [ ] 0 setdash newpath
  203.   /languagelevel where {
  204.     pop languagelevel
  205.     1 ne {
  206.       false setstrokeadjust false setoverprint 
  207.     } if
  208.   } if
  209. } bind def
  210.  
  211. /EndEPSF {
  212.   count op_count sub { pos } repeat    % Clean up stacks
  213.   countdictstack dict_count sub { end } repeat
  214.   b4_Inc_state restore
  215. } bind def
  216.  
  217. % Check PostScript language level.
  218. /languagelevel where {
  219.   pop /gs_languagelevel languagelevel def
  220. } {
  221.   /gs_languagelevel 1 def
  222. } ifelse
  223.