home *** CD-ROM | disk | FTP | other *** search
- %! PostScript Source Code
- %
- % File: imag:/users/local/a2ps/header.ps
- % Created: Tue Nov 29 12:14:02 1988 by miguel@imag (Miguel Santana)
- % Version: 2.0
- % Description: PostScript prolog for a2ps ascii to PostScript program.
- %
- % Edit History:
- % - Original version by evan@csli (Evan Kirshenbaum).
- % - Modified by miguel@imag to:
- % 1) Correct an overflow bug when printing page number 10 (operator
- % cvs).
- % 2) Define two other variables (sheetwidth, sheetheight) describing
- % the physical page (actually A4 format).
- % 3) Minor changes (reorganization, comments, etc).
- %
-
- % Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
- %
- % Permission is granted to copy and distribute this file in modified
- % or unmodified form, for noncommercial use, provided (a) this copyright
- % notice is preserved, (b) no attempt is made to restrict redistribution
- % of this file, and (c) this file is not distributed as part of any
- % collection whose redistribution is restricted by a compilation copyright.
- %
-
-
- % General macros.
- /xdef {exch def} bind def
- /inch {72 mul} bind def
- /getfont {exch findfont exch scalefont} bind def
-
- % Dimensions of a physical page.
- /sheetwidth 11.7 inch def
- /sheetheight 8.25 inch def
-
- % Character size for differents fonts.
- /filenamefontsize 12 def
- /datefontsize filenamefontsize 2 sub def
- /headerfontsize filenamefontsize 4 add def
- /bodyfontsize 6.8 def
-
- % Font assignment to differents kinds of "objects"
- /filenamefont /Helvetica-Bold filenamefontsize getfont def
- /datefont /Helvetica datefontsize getfont def
- /bodyfont /Courier bodyfontsize getfont def
-
-
- % Logical page attributs (a half of a real page or sheet).
- /linesperpage 66 def
- /sidemargin 4 def
- /topmargin 4 def
- /pagewidth
- bodyfont setfont (0) stringwidth pop 86 mul sidemargin dup add add
- def
- /pageheight
- bodyfontsize linesperpage mul topmargin dup add add headerfontsize add
- def
-
- % Upper corner for a logical page. Coordinate x is not the same for left
- % and right pages: upperx is an array of two elements, indexed by sheetside.
- /uppery sheetheight pageheight add 2 div def
- /upperx [ sheetwidth pagewidth 2 mul sub 3 div % upperx for left page
- dup 2 mul pagewidth add % upperx for right page
- ] def
-
- % String used to make easy printing numbers
- /pnum 12 string def
- /empty 12 string def
-
-
- % Function startdoc: initializes printer and global variables.
- /startdoc
- { sheetheight 0 inch translate % new origin for the coordinate system
- 90 rotate % landscape format
- /sheetside 0 def % sheet side that contains current page
- /sheet 1 def % sheet number
- } bind def
-
- % Function newfile: init file name and reset page number for each new file.
- /newfile
- { /filename xdef
- /pagenum 1 def
- cleanup
- } bind def
-
- % Function cleanup: terminates printing, flushing last page if necessary.
- /cleanup
- { sheetside 1 eq
- { /sheetside 0 def
- sheetnumber
- /sheet sheet 1 add def
- copypage
- erasepage
- }
- if
- } bind def
-
- %
- % Function startpage: prints page header and page border and initializes
- % printing of the file lines.
- /startpage
- { printheader
- printborder
- upperx sheetside get sidemargin add
- uppery topmargin sub bodyfontsize sub headerfontsize sub
- moveto
- bodyfont setfont
- } bind def
-
- % Function printheader: prints page header.
- /printheader
- { upperx sheetside get uppery headerfontsize sub 1 add moveto
- datefont setfont
- gsave
- sidemargin 2 rmoveto date show % date/hour
- grestore
- gsave
- pagenum pnum cvs
- pagewidth sidemargin sub pnum stringwidth pop sub
- (Page ) stringwidth pop sub 3 rmoveto
- (Page ) show pnum show % page number
- grestore
- empty pnum copy
- gsave
- filenamefont setfont
- pagewidth filename stringwidth pop sub 2 div 2 rmoveto
- filename show % file name
- grestore
- } bind def
-
- % Function printborder: prints border page.
- /printborder
- { upperx sheetside get uppery moveto
- gsave % print the four sides
- pagewidth 0 rlineto % of the square
- 0 pageheight neg rlineto
- pagewidth neg 0 rlineto
- closepath stroke
- grestore
- 0 headerfontsize neg rmoveto pagewidth 0 rlineto stroke
- } bind def
-
- %
- % Function endpage: adds a sheet number to the page (footnote) and prints
- % the formatted page (physical impression). Activated at the end of each
- % source page (linesperpage reached or FF character).
- /endpage
- { sheetside 1 eq
- { /sheetside 0 def
- sheetnumber
- copypage
- erasepage
- /sheet sheet 1 add def
- }
- { /sheetside 1 def }
- ifelse
- /pagenum pagenum 1 add def
- } bind def
-
- % Function sheetnumber: prints the sheet number.
- /sheetnumber
- { sheetwidth upperx 0 get sub sidemargin add
- sheetheight uppery sub headerfontsize sub
- moveto
- datefont setfont
- sheet pnum cvs show
- empty pnum copy
- } bind def
-
- % Function s: print a source line
- /s { gsave
- show
- grestore
- 0 bodyfontsize neg rmoveto
- } bind def
-