summaryrefslogtreecommitdiff
path: root/dviware/psprint/unix/text.ps
blob: d3ff19e932c6fb0fc7df3e864f149086d4cbbdea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
% Prologue for a -text job.
% It assumes psprint has defined land and dev.
% Every character after this file (until ^D) will be treated as a printing
% character (or control character) instead of being interpreted as PostScript.

land
{ /setlocation                             % if /landscape
  { 0 11.7 72 mul translate                % shift origin up 11.7in
    -90 rotate                             % rotate axes 90deg clockwise
    72 0 translate                         % 1in left margin
    0 535 moveto                           % start of top line
    /line 0 def                            % initialize line counter
    /char 0 def                            % initialize chars/line counter
  } bind def
  /maxline 50 def                          % maximum lines per page
  /maxchar 132 def                         % maximum chars per line
  /interline -10 def                       % baseline skip
  /Courier findfont 9 scalefont setfont    % use 9pt Courier
}
{ /setlocation                             % if no /landscape
  { 72 0 translate                         % 1in left margin
    0 764 moveto                           % start of top line
    /line 0 def                            % initialize line counter
    /char 0 def                            % initialize chars/line counter
  } bind def
  /maxline 66 def                          % maximum lines per page
  /maxchar 80 def                          % maximum chars per line
  /interline -11 def                       % baseline skip
  /Courier findfont 10 scalefont setfont   % use 10pt Courier
} ifelse

/formfeed { line 0 gt { showpage setlocation } if } bind def

/linefeed
{ /char 0 def                                     % reset chars/line counter
  /line line 1 add def                            % increment line counter
  line maxline eq                                 % line = max lines per page?
     { formfeed }                                 % if so, show page
     { currentpoint pop neg interline rmoveto }   % else start next line
  ifelse
} bind def

/backspace
{ /char char 1 sub def
  char 0 ge { charwidth neg 0 rmoveto } if  % move back one character
} def

/showchar
{ currentchar 0 thischar put                % put thischar into 1-char string
  /char char 1 add def                      % increment chars/line counter
  char maxchar le { currentchar show } if   % ignore chars > maxchar
} bind def

/eachchar
{ infile read not {exit} if          % get next char
  /thischar exch def                 % save it in thischar
  thischar 32 ge                     % thischar >= space?
  { showchar }                       % if so, show it
  { thischar 8 eq                    % or does thischar = backspace?
    { backspace }
    { thischar 10 eq                 % or does thischar = linefeed?
      { linefeed }
      { thischar 12 eq               % or does thischar = formfeed?
        { formfeed }
        {                            % ignore any other control char
        } ifelse
      } ifelse
    } ifelse
  } ifelse
} bind def

(%stdin) (r) file /infile exch def
/currentchar 1 string def
setlocation
/charwidth (a) stringwidth pop def

/charloop
{ {eachchar} loop
  line 0 gt { showpage } if        % flush last page if necessary
  dev (LW) eq { @bannerpage } if   % print banner page if LaserWriter
} def

charloop