home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d07xx / d0797.lha / A2ps / a2ps-header.ps < prev    next >
Text File  |  1993-01-10  |  8KB  |  267 lines

  1. %!  PostScript Source Code
  2. %
  3. %  File: imag:/users/local/a2ps/header.ps
  4. %  Created: Tue Nov 29 12:14:02 1988 by miguel@imag (Miguel Santana)
  5. %  Version: 2.0
  6. %  Description: PostScript prolog for a2ps ascii to PostScript program.
  7. %  Edit History:
  8. %  - Original version by evan@csli (Evan Kirshenbaum).
  9. %  - Modified by miguel@imag to:
  10. %    1) Correct an overflow bug when printing page number 10 (operator
  11. %    cvs).
  12. %    2) Define two other variables (sheetwidth, sheetheight) describing
  13. %    the physical page (by default A4 format).
  14. %    3) Minor changes (reorganization, comments, etc).
  15. %  - Modified by tullemans@apolloway.prl.philips.nl
  16. %    1) Correct stack overflows with regard to operators cvs and copy.
  17. %       The resulting substrings where in some cases not popped off 
  18. %       the stack, what can result in a stack overflow.
  19. %    2) Replaced copypage and erasepage by showpage. Page througput
  20. %       degrades severely (see red book page 140) on our ps-printer
  21. %       after printing sheet 16 (i.e. page 8) of a file which was 
  22. %       actually bigger. For this purpose the definitions of startdoc
  23. %       and startpage are changed.
  24. %  - Modified by Tim Clark <T.Clark@uk.ac.warwick> to:
  25. %    1) Print one page per sheet (portrait) as an option.
  26. %    2) Reduce size of file name heading, if it's too big.
  27. %    3) Save and restore PostScript state at begining/end. It now uses
  28. %    conventional %%Page %%Trailer markers.
  29. %    4) Print one wide page per sheet in landscape mode as an option.
  30. %  - Modified by miguel@imag.fr to
  31. %    1) Add new option to print n copies of a file.
  32. %    2) Add new option to suppress heading printing.
  33. %    3) Add new option to suppress page surrounding border printing.
  34. %    4) Add new option to change font size. Number of lines and columns
  35. %    are now automatically adjusted, depending on font size and
  36. %    printing mode used.
  37. %    5) Minor changes (best layout, usage message, etc).
  38. %
  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. /xdef {exch def} bind def
  52. /getfont {exch findfont exch scalefont} bind def
  53.  
  54. % Page description variables and inch function are defined by a2ps program.
  55.  
  56. % Character size for differents fonts.
  57.    landscape
  58.    { /filenamefontsize 12 def }
  59.    { /filenamefontsize 16 def }
  60. ifelse
  61. /datefontsize filenamefontsize 0.8 mul def
  62. /headermargin filenamefontsize 0.25 mul def
  63. /bodymargin bodyfontsize 0.7 mul def
  64.  
  65. % Font assignment to differents kinds of "objects"
  66. /filenamefontname /Helvetica-Bold def
  67. /stdfilenamefont filenamefontname filenamefontsize getfont def
  68. /datefont /Helvetica datefontsize getfont def
  69. /bodyfont /Courier bodyfontsize getfont def
  70.  
  71. % Logical page attributs (a half of a real page or sheet).
  72. /pagewidth
  73.    bodyfont setfont (0) stringwidth pop columns mul bodymargin dup add add
  74.    def
  75. /pageheight
  76.    bodyfontsize lines mul bodymargin dup add add headersize add
  77.    def
  78.  
  79. % Coordinates for upper corner of a logical page and for sheet number.
  80. % Coordinates depend on format mode used.
  81. % In twinpage mode, coordinate x of upper corner is not the same for left
  82. % and right pages: upperx is an array of two elements, indexed by sheetside.
  83. /rightmargin margin 3 div def
  84. /leftmargin margin 2 mul 3 div def
  85. /topmargin margin twinpage {3} {2} ifelse div def
  86. landscape
  87. {  % Landscape format
  88.    /uppery rightmargin pageheight add bodymargin add def
  89.    /sheetnumbery sheetwidth leftmargin pageheight add datefontsize add sub def
  90.    twinpage
  91.    {  % Two logical pages
  92.       /upperx [ topmargin            % upperx for left page
  93.         dup 2 mul pagewidth add        % upperx for right page
  94.           ] def
  95.       /sheetnumberx sheetheight topmargin sub def
  96.    }
  97.    {  /upperx [ topmargin dup ] def
  98.       /sheetnumberx sheetheight topmargin sub datefontsize sub def
  99.    }
  100.    ifelse
  101. }
  102. {  % Portrait format
  103.    /uppery topmargin pageheight add def
  104.    /upperx [ leftmargin dup ] def
  105.    /sheetnumberx sheetwidth rightmargin sub datefontsize sub def
  106.    /sheetnumbery
  107.      sheetheight 
  108.      topmargin pageheight add datefontsize add headermargin add
  109.       sub
  110.       def
  111.  
  112. }
  113. ifelse
  114.  
  115. % Strings used to make easy printing numbers
  116. /pnum 12 string def
  117. /empty 12 string def
  118.  
  119. % Other initializations.
  120. /datewidth date stringwidth pop def
  121. /filenameroom
  122.          pagewidth
  123.      filenamefontsize 4 mul datewidth add (Page 999) stringwidth pop add
  124.       sub
  125.    def
  126.  
  127.  
  128. % Function startdoc: initializes printer and global variables.
  129. /startdoc
  130.     { /sheetside 0 def            % sheet side that contains current page
  131.       /sheet 1 def            % sheet number
  132.    } bind def
  133.  
  134. % Function newfile: init file name and reset page number for each new file.
  135. /newfile
  136.     { cleanup
  137.       /filename xdef
  138.       /filenamewidth filename stringwidth pop def
  139.       /filenamefont
  140.      filenamewidth filenameroom gt
  141.      {
  142.            filenamefontname
  143.            filenamefontsize filenameroom mul filenamewidth div
  144.         getfont
  145.      }
  146.      {  stdfilenamefont }
  147.      ifelse
  148.      def
  149.       /pagenum 1 def
  150.     } bind def
  151.  
  152. % Function printpage: Print a physical page.
  153. /printpage
  154.     { /sheetside 0 def
  155.       twinpage
  156.       {  noborder not
  157.         { sheetnumber }
  158.      if
  159.       }
  160.       {  noheader noborder not and
  161.         { sheetnumber }
  162.      if
  163.       }
  164.       ifelse
  165.       showpage 
  166. %      pagesave restore
  167.       /sheet sheet 1 add def
  168.     } bind def
  169.  
  170. % Function cleanup: terminates printing, flushing last page if necessary.
  171. /cleanup
  172.     { twinpage sheetside 1 eq and
  173.          { printpage }
  174.       if
  175.     } bind def
  176.  
  177. %
  178. % Function startpage: prints page header and page border and initializes
  179. % printing of the file lines.
  180. /startpage
  181.     { sheetside 0 eq
  182.     { % /pagesave save def
  183.       landscape
  184.         { sheetwidth 0 inch translate    % new coordinates system origin
  185.           90 rotate                % landscape format
  186.         } if
  187.     } if
  188.       noborder not { printborder } if
  189.       noheader not { printheader } if
  190.      upperx sheetside get  bodymargin  add
  191.         uppery
  192.         bodymargin bodyfontsize add  noheader {0} {headersize} ifelse  add
  193.      sub
  194.       moveto
  195.       bodyfont setfont
  196.     } bind def
  197.  
  198. % Function printheader: prints page header.
  199. /printheader
  200.     { upperx sheetside get  uppery headersize sub 1 add  moveto
  201.       datefont setfont
  202.       gsave
  203.         datefontsize headermargin rmoveto
  204.     date show                    % date/hour
  205.       grestore
  206.       gsave
  207.     pagenum pnum cvs pop
  208.        pagewidth (Page 999) stringwidth pop sub
  209.        headermargin
  210.     rmoveto
  211.         (Page ) show pnum show                % page number
  212.       grestore
  213.       empty pnum copy pop
  214.       gsave
  215.         filenamefont setfont
  216.           filenameroom filename stringwidth pop sub 2 div datewidth add
  217.           bodymargin 2 mul 
  218.        add 
  219.        headermargin
  220.     rmoveto
  221.         filename show                        % file name
  222.       grestore
  223.     } bind def
  224.  
  225. % Function printborder: prints border page.
  226. /printborder 
  227.     { upperx sheetside get uppery moveto
  228.       gsave                    % print the four sides
  229.         pagewidth 0 rlineto            % of the square
  230.         0 pageheight neg rlineto
  231.         pagewidth neg 0 rlineto
  232.         closepath stroke
  233.       grestore
  234.       noheader not
  235.          { 0 headersize neg rmoveto pagewidth 0 rlineto stroke }
  236.       if
  237.     } bind def
  238.  
  239. %
  240. % Function endpage: adds a sheet number to the page (footnote) and prints
  241. % the formatted page (physical impression). Activated at the end of each
  242. % source page (lines reached or FF character).
  243. /endpage
  244.    { /pagenum pagenum 1 add def
  245.      twinpage  sheetside 0 eq  and
  246.         { /sheetside 1 def }
  247.         { printpage }
  248.      ifelse
  249.    } bind def
  250.  
  251. % Function sheetnumber: prints the sheet number.
  252. /sheetnumber
  253.     { sheetnumberx sheetnumbery moveto
  254.       datefont setfont
  255.       sheet pnum cvs
  256.      dup stringwidth pop (0) stringwidth pop sub neg 0 rmoveto show
  257.       empty pnum copy pop
  258.     } bind def
  259.  
  260. % Function s: print a source line
  261. /s  { gsave
  262.         show
  263.       grestore
  264.       0 bodyfontsize neg rmoveto
  265.     } bind def
  266.