home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 19 Printer / 19-Printer.zip / PS_LIST.ZIP / HEADER.PS < prev    next >
Text File  |  1989-10-19  |  5KB  |  177 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 (actually A4 format).
  14. %    3) Minor changes (reorganization, comments, etc).
  15. %
  16.  
  17. % Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  18. %
  19. % Permission is granted to copy and distribute this file in modified
  20. % or unmodified form, for noncommercial use, provided (a) this copyright
  21. % notice is preserved, (b) no attempt is made to restrict redistribution
  22. % of this file, and (c) this file is not distributed as part of any
  23. % collection whose redistribution is restricted by a compilation copyright.
  24. %
  25.  
  26.  
  27. % General macros.
  28. /xdef {exch def} bind def
  29. /inch {72 mul} bind def
  30. /getfont {exch findfont exch scalefont} bind def
  31.  
  32. % Dimensions of a physical page.
  33. /sheetwidth 11.7 inch def
  34. /sheetheight 8.25 inch def
  35.  
  36. % Character size for differents fonts.
  37. /filenamefontsize 12 def
  38. /datefontsize filenamefontsize 2 sub def
  39. /headerfontsize filenamefontsize 4 add def
  40. /bodyfontsize 6.8 def
  41.  
  42. % Font assignment to differents kinds of "objects"
  43. /filenamefont /Helvetica-Bold filenamefontsize getfont def
  44. /datefont /Helvetica datefontsize getfont def
  45. /bodyfont /Courier bodyfontsize getfont def
  46.  
  47.  
  48. % Logical page attributs (a half of a real page or sheet).
  49. /linesperpage 66 def
  50. /sidemargin 4 def
  51. /topmargin 4 def
  52. /pagewidth 
  53.    bodyfont setfont (0) stringwidth pop 86 mul sidemargin dup add add
  54.    def
  55. /pageheight
  56.    bodyfontsize linesperpage mul topmargin dup add add headerfontsize add
  57.    def
  58.  
  59. % Upper corner for a logical page. Coordinate x is not the same for left
  60. % and right pages: upperx is an array of two elements, indexed by sheetside.
  61. /uppery sheetheight pageheight add 2 div def
  62. /upperx [ sheetwidth pagewidth 2 mul sub 3 div    % upperx for left page
  63.           dup 2 mul pagewidth add        % upperx for right page
  64.         ] def
  65.  
  66. % String used to make easy printing numbers
  67. /pnum 12 string def
  68. /empty 12 string def
  69.  
  70.  
  71. % Function startdoc: initializes printer and global variables.
  72. /startdoc
  73.     { sheetheight 0 inch translate    % new origin for the coordinate system
  74.       90 rotate                % landscape format
  75.       /sheetside 0 def            % sheet side that contains current page
  76.       /sheet 1 def            % sheet number
  77.     } bind def
  78.  
  79. % Function newfile: init file name and reset page number for each new file.
  80. /newfile
  81.     { /filename xdef
  82.       /pagenum 1 def 
  83.       cleanup
  84.     } bind def
  85.  
  86. % Function cleanup: terminates printing, flushing last page if necessary.
  87. /cleanup
  88.     { sheetside 1 eq
  89.          { /sheetside 0 def
  90.            sheetnumber
  91.            /sheet sheet 1 add def
  92.            copypage
  93.            erasepage
  94.          }
  95.       if
  96.     } bind def
  97.  
  98. %
  99. % Function startpage: prints page header and page border and initializes
  100. % printing of the file lines.
  101. /startpage
  102.     { printheader
  103.       printborder
  104.       upperx sheetside get  sidemargin  add
  105.       uppery topmargin sub  bodyfontsize  sub  headerfontsize  sub
  106.          moveto
  107.       bodyfont setfont
  108.     } bind def
  109.  
  110. % Function printheader: prints page header.
  111. /printheader
  112.     { upperx sheetside get  uppery headerfontsize sub 1 add  moveto
  113.       datefont setfont
  114.       gsave
  115.         sidemargin 2 rmoveto date show                % date/hour
  116.       grestore
  117.       gsave
  118.         pagenum pnum cvs
  119.         pagewidth sidemargin sub pnum stringwidth pop sub
  120.         (Page ) stringwidth pop sub 3 rmoveto
  121.         (Page ) show pnum show                    % page number
  122.       grestore
  123.       empty pnum copy
  124.       gsave
  125.         filenamefont setfont
  126.         pagewidth filename stringwidth pop sub 2 div 2 rmoveto
  127.         filename show                        % file name
  128.       grestore
  129.     } bind def
  130.  
  131. % Function printborder: prints border page.
  132. /printborder 
  133.     { upperx sheetside get uppery moveto
  134.       gsave                    % print the four sides
  135.         pagewidth 0 rlineto            % of the square
  136.         0 pageheight neg rlineto
  137.         pagewidth neg 0 rlineto
  138.         closepath stroke
  139.       grestore
  140.       0 headerfontsize neg rmoveto pagewidth 0 rlineto stroke
  141.     } bind def
  142.  
  143. %
  144. % Function endpage: adds a sheet number to the page (footnote) and prints
  145. % the formatted page (physical impression). Activated at the end of each
  146. % source page (linesperpage reached or FF character).
  147. /endpage
  148.    { sheetside 1 eq
  149.         { /sheetside 0 def
  150.           sheetnumber
  151.           copypage
  152.           erasepage 
  153.           /sheet sheet 1 add def
  154.         }
  155.         { /sheetside 1 def }
  156.      ifelse
  157.      /pagenum pagenum 1 add def
  158.     } bind def
  159.  
  160. % Function sheetnumber: prints the sheet number.
  161. /sheetnumber
  162.     { sheetwidth  upperx 0 get  sub  sidemargin  add
  163.       sheetheight  uppery  sub  headerfontsize  sub
  164.          moveto
  165.       datefont setfont
  166.       sheet pnum cvs show
  167.       empty pnum copy
  168.     } bind def
  169.  
  170. % Function s: print a source line
  171. /s  { gsave
  172.         show
  173.       grestore
  174.       0 bodyfontsize neg rmoveto
  175.     } bind def
  176.