summaryrefslogtreecommitdiff
path: root/dviware/psprint/vms/tex.ps
blob: 36ac9cc08d043e56bee8382b459f8fa92119a4c6 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
% Prologue for a DVI job.
% It assumes *_print.com has defined dev (string), land (bool) and res (int).

dev (LW) eq                               % LaserWriter?
{ land
  {                                       % /landscape given
    % rotate/scale/translate can cause scaling problems, so use setmatrix:
    version cvr 38.0 le
    { [ 0 -1 1 0 235 3100 ] setmatrix }   % LaserWriter
    { version cvr 47.0 lt
    { [ 0 -1 1 0 235 3130 ] setmatrix }   % LaserWriter Plus
    { [ 0 -1 1 0 235 3160 ] setmatrix }   % LaserWriter II NTX
                 % add y to move origin down by y pixels
                     % add x to move origin left by x pixels
    ifelse } ifelse
  }
  {                                       % /landscape not given
    % scale/translate can cause scaling problems, so use setmatrix:
    version cvr 38.0 le
    { [ 1 0 0 1 235 190 ] setmatrix }     % LaserWriter
    { version cvr 47.0 lt
    { [ 1 0 0 1 235 215 ] setmatrix }     % LaserWriter Plus
    { [ 1 0 0 1 235 265 ] setmatrix }     % LaserWriter II NTX
                % add x to move origin right by x pixels
                    % add y to move origin down by y pixels
    ifelse } ifelse
  } ifelse
} if

dev (PS40) eq                         % PrintServer?
{ land
  { [ 1 0 0 1 300 300 ] setmatrix     % /landscape given
  }
  { [ 0 1 -1 0 3210 300 ] setmatrix   % /landscape not given
  } ifelse
} if

dev (LINO) eq                         % Linotronic?
{ land
  { initmatrix                        % /landscape given
    90 rotate                         % rotate axes 90deg anticlockwise
    72 res div dup neg scale          % units now dots (y increases to right)
    res res translate                 % move to TeX origin

    % setmatrix won't work properly with a3/a4/a5/b5 page setups
    % [1 0 0 1 1270 margin 72 div 1270 mul add 1270] setmatrix   % res=1270
    % [2 0 0 2 1270 margin 72 div 1270 mul add 1270] setmatrix   % res=635
  }
  { initmatrix                        % /landscape not given
    newpath clippath pathbbox         % push LLx LLy URx URy
    /paperht exch 72 div def          % paper height in inches (URy = ht in pts)
    pop pop pop                       % URx LLy LLx
    72 res div dup neg scale          % units now dots (y increases down page)
    res paperht res mul neg res add
                          translate   % move to TeX origin

    % setmatrix won't work properly with a3/a4/a5/b5 page setups
    % [0 1 -1 0 paperht 1270 mul 1270 sub                        % res=1270
    %           margin 72 div 1270 mul add 1270] setmatrix
    % [0 2 -2 0 paperht 1270 mul 1270 sub                        % res=635
    %           margin 72 div 1270 mul add 1270] setmatrix
  } ifelse
} if

/mtrx 6 array def
mtrx currentmatrix pop                % save our new transformation matrix

/@newfont                             % initialize new font dict
{ /fontid exch def
  fontid 7 dict def
  fontid load begin
     /FontType 3 def
     /FontMatrix [1 0 0 -1 0 0] def   % -1 because y scale is negative
     /FontBBox [0 0 1 1] def
     /BitMaps 128 array def
     /BuildChar {CharBuilder} def
     /Encoding 128 array def
     0 1 127 {Encoding exch /.notdef put} for
     end
  fontid fontid load definefont pop
} def

% @saveVM and @restoreVM are only used if we are conserving VM
% by downloading font bitmaps more often:

/@saveVM                              % save state of VM before using font
{ /prefontVM save def
  @newfont
} def

/@restoreVM {prefontVM restore} def

% The char data, a bitmap descriptor, is an array with 6 elements:

/ch-image  {ch-data 0 get} def        % the hex string image
/ch-width  {ch-data 1 get} def        % the number of pixels across
/ch-height {ch-data 2 get} def        % the number of pixels tall
/ch-xoff   {ch-data 3 get} def        % number of pixels to left of origin
/ch-yoff   {ch-data 4 get} def        % number of pixels below origin
/ch-advw   {ch-data 5 get} def        % advance width

% The following character builder looks up the char data in the BitMaps array
% and paints the character:

/CharBuilder                          % image one char
{ /ch-code exch def                   % save the char code
  /font-dict exch def                 % and the font dict
  /ch-data font-dict /BitMaps get
  ch-code get def
     ch-advw 0
     ch-xoff neg ch-height ch-yoff sub 1 sub neg   % -xo , -(ht-yo-1)
     ch-width ch-xoff sub 1 sub ch-yoff            % (wd-xo-1) , yo
  setcachedevice
     ch-width ch-height true
     [1 0 0 -1 ch-xoff ch-yoff]       % bitmap sent top to bottom
     {ch-image}
  imagemask
} def

/sf {setfont} def                     % set current font

/dc                                   % define new character
{ /ch-code exch def
  /ch-data exch def

  % The following code should be enabled if you have an old LaserWriter.
  % It attempts to overcome a bug that causes the printer to crash
  % and print a test page rather then report a VMerror.
  %
  % vmstatus                          % returns: savelevel vmused vmmax
  % 10000 sub gt                      % is vmused > (vmmax-10000)?
  %   { pop VMERROR }                 % causes error message (avoiding crash)
  %   { pop }                         % pop savelevel
  % ifelse

  currentfont /BitMaps get ch-code ch-data put
  currentfont /Encoding get ch-code
  dup (   ) cvs cvn put               % generate unique name
} bind def

/@bop0 {pop} def                      % begin DVI page n

/@bop1                                % begin setting DVI page n
{ pop                                 % throw away page number
  initgraphics                        % start with a clean slate
  mtrx setmatrix                      % switch to our TeX coordinate system
  /prepageVM save def                 % save state of VM at start of page
} def

/@eop                                 % end DVI page n
{ pop                                 % throw away page number
  prepageVM restore                   % restore VM to state at start of page
  showpage
} def

/@end { } def                         % end of file

% h and s are used to typeset downloaded bitmap fonts:

/h {exch 0 rmoveto show} bind def     % move right by dh and show (...)

/s {3 1 roll moveto show} bind def    % move to h,v and show (...)

% H and S are used to typeset resident PostScript fonts.
% We can't use relative horizontal positioning because the advance widths in
% a PostScript font are not integers and rounding errors would accumulate:

/H {exch v moveto show} bind def      % move to h,v and show (...)

/S                                    % ditto, and save v position
{ 3 1 roll dup /v exch def
  moveto show
} bind def

% Some fine-tuning of the code used to draw a rule is necessary:

dev (LW) eq                           % LaserWriter?
version cvr 38.0 le and               % and version <= 38.0?
{
  /r                                  % set a wd by ht rule at h,v
  { newpath
    1 add moveto                      % move to h,v+1 (don't ask me why)
    /ht exch 1 sub def                % reduce height by 1
    /wd exch 1 sub def                % ditto for width
    wd 0 rlineto
    0 ht neg rlineto
    wd neg 0 rlineto
    fill
  } bind def
}
{
  /r                                  % set a wd by ht rule at h,v
  { newpath
    moveto                            % move to h,v
    /ht exch 1 sub def                % reduce height by 1
    /wd exch 1 sub def                % ditto for width
    wd 0 rlineto
    0 ht neg rlineto
    wd neg 0 rlineto
    fill
  } bind def
} ifelse

% Following procedures are invoked as the result of a \special command.
% We change all scaling and graphics back to defaults, but shift the origin
% to the current position on the page:

/p {moveto} bind def                  % move to h,v

/@bsp                                 % begin special mode
{ gsave
  /prespecialVM save def              % save showpage, TeX procedures etc.
  currentpoint transform
  initgraphics itransform translate
  land { 90 rotate } if               % rotate axes if /landscape given
  /showpage { } def                   % user does not have to remove showpage
} bind def

/@esp                                 % end special mode
{ prespecialVM restore                % restore saved showpage value etc.
  grestore
} bind def

% Here are the definitions needed to handle resident PostScript fonts:

/sp                                   % scaled pts to dots
{ 16#10000 div                        % scaled pts to pts
  res mul 72.27 div                   % pts to dots
} bind def

/PSfont                               % uses dot size and TFM name
{ dup /Times-Slanted eq
  {pop /Times-Roman findfont [1 0 .268 -1 0 0] makefont exch scalefont setfont}
  {findfont [1 0 0 -1 0 0] makefont exch scalefont setfont}
  ifelse
} bind def