3 % Copyright (c) 1995-1998 Markku Rossi.
5 % Author: Markku Rossi <mtr@iki.fi>
8 % This file is part of GNU Enscript.
10 % Enscript is free software: you can redistribute it and/or modify
11 % it under the terms of the GNU General Public License as published by
12 % the Free Software Foundation, either version 3 of the License, or
13 % (at your option) any later version.
15 % Enscript is distributed in the hope that it will be useful,
16 % but WITHOUT ANY WARRANTY; without even the implied warranty of
17 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 % GNU General Public License for more details.
20 % You should have received a copy of the GNU General Public License
21 % along with Enscript. If not, see <http://www.gnu.org/licenses/>.
24 % -- code follows this line --
29 /_S { % save current state
32 /_R { % restore from saved state
36 /S { % showpage protecting gstate
42 /MF { % fontname newfontname -> - make a new encoded font
46 /fontdict fontname findfont def
47 /newfont fontdict maxlength dict def
55 % copy to the new font dictionary
56 exch newfont 3 1 roll put
60 newfont /FontName newfontname put
62 % insert only valid encoding vectors
63 encoding_vector length 256 eq {
64 newfont /Encoding encoding_vector put
67 newfontname newfont definefont pop
70 /MF_PS { % fontname newfontname -> - make a new font preserving its enc
74 /fontdict fontname findfont def
75 /newfont fontdict maxlength dict def
83 % copy to the new font dictionary
84 exch newfont 3 1 roll put
88 newfont /FontName newfontname put
90 newfontname newfont definefont pop
93 /SF { % fontname width height -> - set a new font
98 [width 0 0 height 0 0] makefont setfont
101 /SUF { % fontname width height -> - set a new user font
106 /F-gs-user-font width height SF
109 /SUF_PS { % fontname width height -> - set a new user font preserving its enc
113 /F-gs-user-font MF_PS
114 /F-gs-user-font width height SF
120 /Box { % x y w h -> - define box path
121 /d_h exch def /d_w exch def /d_y exch def /d_x exch def
129 /bgs { % x y height blskip gray str -> - show string with bg color
138 x y blskip sub str stringwidth pop height Box
145 /bgcs { % x y height blskip red green blue str -> - show string with bg color
156 x y blskip sub str stringwidth pop height Box
157 red green blue setrgbcolor
164 /highlight_bars { % nlines lineheight output_y_margin gray -> -
171 % This 2 is just a magic number to sync highlight lines to text.
172 0 d_header_y ymarg sub 2 sub translate
174 /cw d_output_w cols div def
175 /nrows d_output_h ymarg 2 mul sub lineheight div cvi def
184 rn lineheight mul neg /yp exch def
185 rn nlines idiv 2 mod 0 eq {
186 % Draw highlight bar. 4 is just a magic indentation.
187 xp 4 add yp cw 8 sub lineheight neg Box fill
195 % Line highlight bar.
196 /line_highlight { % x y width height gray -> -
199 Box gray setgray fill
203 % Column separator lines.
207 0 d_footer_h translate
208 /cw d_output_w cols div def
211 0 d_output_h rlineto stroke
223 0 d_output_h neg rlineto
228 % Do the actual underlay drawing
231 ul_str true charpath stroke
241 d_page_h neg d_page_w atan rotate
245 /dw d_page_h dup mul d_page_w dup mul add sqrt def
246 ul_str stringwidth pop dw exch sub 2 div ul_h_ptsize -2 div moveto
251 /user_underlay { % - -> -
257 0 0 ul_h_ptsize 2 div sub moveto
263 /page_prefeed { % bool -> -
264 statusdict /prefeed known {
265 statusdict exch /prefeed exch put
271 % Wrapped line markers
272 /wrapped_line_mark { % x y charwith charheight type -> -
280 % Black boxes (like TeX does)
284 0 h rlineto w 2 div 0 rlineto 0 h neg rlineto
292 x w 2 div add y h 2 div add M
294 x w 4 div add y lineto stroke
296 x w 4 div add w 8 div add y h 4 div add M
297 x w 4 div add y lineto
298 w 4 div h 8 div rlineto stroke
309 /b4_Inc_state save def % Save state for cleanup
310 /dict_count countdictstack def % Count objects on dict stack
311 /op_count count 1 sub def % Count objects on operand stack
314 0 setgray 0 setlinecap
315 1 setlinewidth 0 setlinejoin
316 10 setmiterlimit [ ] 0 setdash newpath
317 /languagelevel where {
320 false setstrokeadjust false setoverprint
326 count op_count sub { pos } repeat % Clean up stacks
327 countdictstack dict_count sub { end } repeat
331 % Check PostScript language level.
332 /languagelevel where {
333 pop /gs_languagelevel languagelevel def
335 /gs_languagelevel 1 def