home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1070 / a2ps.prologue < prev    next >
Encoding:
Text File  |  1990-12-28  |  5.8 KB  |  195 lines

  1. %  File: imag:/users/local/a2ps/header.ps
  2. %  Created: Tue Nov 29 12:14:02 1988 by miguel@imag (Miguel Santana)
  3. %  Version: 4.0
  4. %  Description: PostScript prolog for a2ps ascii to PostScript program.
  5. %  Edit History:
  6. %  - Original version by evan@csli (Evan Kirshenbaum).
  7. %  - Modified by miguel@imag to:
  8. %    1) Correct an overflow bug when printing page number 10 (operator
  9. %    cvs).
  10. %    2) Define two other variables (sheetwidth, sheetheight) describing
  11. %    the physical page (by default A4 format).
  12. %    3) Minor changes (reorganization, comments, etc).
  13. %  - Modified by tullemans@apolloway.prl.philips.nl
  14. %    1) Correct stack overflows with regard to operators cvs and copy.
  15. %       The resulting substrings where in some cases not popped off 
  16. %       the stack, what can result in a stack overflow.
  17. %    2) Replaced copypage and erasepage by showpage. Page througput
  18. %       degrades severely (see red book page 140) on our ps-printer
  19. %       after printing sheet 16 (i.e. page 8) of a file which was 
  20. %       actually bigger. For this purpose the definitions of startdoc
  21. %       and startpage are changed.
  22. %  - Modified by Tim Clark <T.Clark@uk.ac.warwick> to:
  23. %    1) Print one page per sheet (portrait) as an option.
  24. %    2) Reduce size of file name heading, if it's too big.
  25. %    3) Save and restore PostScript state at begining/end. It now uses
  26. %    conventional %%Page %%Trailer markers.
  27. %    4) Print one wide page per sheet in landscape mode as an option.
  28. %  - Modified by miguel@imag.fr to
  29. %    1) Add new option to print n copies of a file.
  30. %    2) Add new option to suppress heading printing.
  31. %    3) Add new option to suppress page surrounding border printing.
  32. %    4) Add new option to change font size. Number of lines and columns
  33. %    are now automatically adjusted, depending on font size and
  34. %    printing mode used.
  35. %    5) Minor changes (best layout, usage message, etc).
  36. %  - Modified heavily by tml@tik.vtt.fi:
  37. %    1) Simpified a lot (removed 2-up printing)
  38. %    2) Produce confirming PostScript
  39.  
  40. % Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  41. %
  42. % Permission is granted to copy and distribute this file in modified
  43. % or unmodified form, for noncommercial use, provided (a) this copyright
  44. % notice is preserved, (b) no attempt is made to restrict redistribution
  45. % of this file, and (c) this file is not distributed as part of any
  46. % collection whose redistribution is restricted by a compilation copyright.
  47. %
  48.  
  49.  
  50. % General macros.
  51. /getfont {findfont exch scalefont} bind def
  52.  
  53. % Page description variables and inch function are defined by a2ps program.
  54.  
  55. % Character size for differents fonts.
  56. landscape
  57.    { /filenamefontsize 12 def }
  58.    { /filenamefontsize 16 def }
  59. ifelse
  60. /datefontsize filenamefontsize 0.8 mul def
  61. /headermargin filenamefontsize 0.25 mul def
  62. /bodymargin bodyfontsize 0.7 mul def
  63.  
  64. % Font assignment to differents kinds of "objects"
  65. /filenamefontname /Helvetica-Bold def
  66. /stdfilenamefont filenamefontsize filenamefontname getfont def
  67. /datefont datefontsize /Helvetica getfont def
  68. /bodyfont bodyfontsize /Courier getfont def
  69.  
  70. % Logical page attributes
  71. /pagewidth
  72.    bodyfont setfont (0) stringwidth pop columns mul bodymargin dup add add
  73.    def
  74. /pageheight
  75.    bodyfontsize lines mul bodymargin dup add add headersize add
  76.    def
  77.  
  78. % Coordinates for upper corner of a logical page
  79. % Coordinates depend on format mode used.
  80. /rightmargin margin def
  81. /leftmargin margin def
  82. /topmargin margin def
  83. landscape
  84. {  % Landscape format
  85.    /uppery rightmargin pageheight add bodymargin add def
  86.    /upperx topmargin def
  87. }
  88. {  % Portrait format
  89.    /uppery topmargin pageheight add def
  90.    /upperx leftmargin def
  91. }
  92. ifelse
  93.  
  94. % Strings used to make easy printing numbers
  95. /pnum 12 string def
  96. /empty 12 string def
  97.  
  98. % Other initializations.
  99. /datewidth date stringwidth pop def
  100. /filenameroom
  101.          pagewidth
  102.      filenamefontsize 4 mul datewidth add (Page 999) stringwidth pop add
  103.       sub
  104.    def
  105.  
  106.  
  107. % Function setfilename
  108. /setfilename
  109.     { /filename exch def
  110.       /filenamewidth filename stringwidth pop def
  111.       /filenamefont
  112.      filenamewidth filenameroom gt
  113.      {
  114.            filenamefontsize filenameroom mul filenamewidth div
  115.            filenamefontname
  116.         getfont
  117.      }
  118.      {  stdfilenamefont }
  119.      ifelse
  120.      def
  121.     } bind def
  122.  
  123. % Function startpage: prints page header and page border and initializes
  124. % printing of the file lines.
  125. /startpage
  126.     { landscape
  127.     { sheetwidth 0 inch translate
  128.       90 rotate
  129.     } if
  130.       noborder not { printborder } if
  131.       noheader not { printheader } if
  132.      upperx bodymargin add
  133.         uppery
  134.         bodymargin bodyfontsize add  noheader {0} {headersize} ifelse  add
  135.      sub
  136.       moveto
  137.       bodyfont setfont
  138.     } bind def
  139.  
  140. % Function printheader: prints page header.
  141. /printheader
  142.     { upperx uppery headersize sub 1 add  moveto
  143.       datefont setfont
  144.       gsave
  145.         datefontsize headermargin rmoveto
  146.     date show                    % date/hour
  147.       grestore
  148.       gsave
  149.     pagenum pnum cvs pop
  150.        pagewidth (Page 999) stringwidth pop sub
  151.        headermargin
  152.     rmoveto
  153.         (Page ) show pnum show                % page number
  154.       grestore
  155.       empty pnum copy pop
  156.       gsave
  157.         filenamefont setfont
  158.           filenameroom filename stringwidth pop sub 2 div datewidth add
  159.           bodymargin 2 mul 
  160.        add 
  161.        headermargin
  162.     rmoveto
  163.         filename show                        % file name
  164.       grestore
  165.     } bind def
  166.  
  167. % Function printborder: prints border page.
  168. /printborder 
  169.     { upperx uppery moveto
  170.       noheader not
  171.          { 0 headersize neg rmoveto pagewidth 0 rlineto stroke }
  172.       if
  173.     } bind def
  174.  
  175. /epsilon 0.07 def
  176.  
  177. % Function toggle: plus/minus epsilon
  178. /toggle { toggleval 1 lt
  179.         { epsilon }
  180.         { epsilon neg }
  181.       ifelse
  182.       dup /toggleval exch def
  183. } def
  184. /toggleval epsilon def
  185.  
  186. % Function bs: backspace
  187. /bs { show (0) stringwidth pop neg toggle add 0 rmoveto } bind def
  188.  
  189. % Function s: print a source line and newline
  190. /s  { show
  191.       grestore
  192.       0 bodyfontsize neg rmoveto
  193.     } bind def
  194.