Debian Codegraph @

texk/cjkutils/cjkutils-src/hbf2gf/dvidrv.btm

raw
1 setdos /y1
2 ::
3 :: Copyright (C) 1994-2021 Werner Lemberg <[email protected]>
4 ::
5 :: This program is free software; you can redistribute it and/or modify
6 :: it under the terms of the GNU General Public License as published by
7 :: the Free Software Foundation; either version 2 of the License, or
8 :: (at your option) any later version.
9 ::
10 :: This program is distributed in the hope that it will be useful,
11 :: but WITHOUT ANY WARRANTY; without even the implied warranty of
12 :: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 :: GNU General Public License for more details.
14 ::
15 :: You should have received a copy of the GNU General Public License
16 :: along with this program in doc/COPYING; if not, write to the Free
17 :: Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 :: MA 02110-1301 USA
19 ::
20 ::
21 :: This is dvidrv.btm, a batch file for 4DOS/4OS2 written by
22 :: Werner Lemberg <[email protected]> partially based on the
23 :: dvidrv.btm file of the 4allTeX package written by Phons Bloemen.
24 ::
25 :: It is a replacement for dvidrv.exe of the emTeX package.
26 ::
27 :: Additional features: support of ps2pk
28 :: support of ttf2pk
29 :: support of hbf2gf for HBFs (Hanzi bitmap fonts)
30 ::
31 :: Only quadratic printer modes are supported for ttf2pk!
32 ::
33 :: All needed binaries will be searched in the path.
34
35 iff %# lt 2 then
36 echo ``
37 echo Usage: %0 dvi-driver dvi-file [parameters]
38 quit
39 endiff
40
41 setlocal
42 :: we set a default value only if the corresponding environment variable
43 :: is empty. The `=' must follow the variable name immediately.
44 alias set_def `iff "%[%@word["=",0,%1]]" eq "" then %+ set %& %+ endiff`
45
46 :: =========================================
47 :: ======== User defined variables. ========
48 :: =========================================
49 ::
50 :: Can be overridden in the environment (except %ps2pk, %ttf2pk, %hbf2gf,
51 :: %pre_dpi, and %post_dpi).
52
53 :: Comment out the programs you don't want to use.
54 set ps2pk=yes
55 set ttf2pk=yes
56 set hbf2gf=yes
57
58 :: where the PK files will be installed created by ps2pk, ttf2pk, and
59 :: hbf2gf.
60 :: dvidrv.btm adds `\modeless\XXXdpi' to this string (see below for the
61 :: exact string).
62 set_def pkdir=%emtexdir\pixel\tmp\pk
63
64 :: where the TrueType fonts reside.
65 set_def ttfonts=%emtexdir\fonts\truetype
66 :: where auxiliary files of ttf2pk are located.
67 set_def ttfcfg=%emtexdir\ttf2pk
68
69 :: where the HBF files reside.
70 set_def hbfonts=%emtexdir\fonts\hbf
71 :: where the hbf2gf config files are.
72 set_def hbfcfg=%emtexdir\hbf2gf
73
74 :: the dpi-subdirectory has various forms; the most common are XXXdpi and
75 :: dpiXXX, e.g. 300dpi and dpi300. Here we define two variables which
76 :: control this behaviour.
77 :: [dpiXXX is used for TDS compatible TeX trees.]
78 set pre_dpi=dpi
79 set post_dpi=
80
81 :: ================================================
82 :: ======== End of user defined variables. ========
83 :: ================================================
84
85 :: the base name for log files etc.
86 set basename=%@name[%1]
87
88 :: do we run dvips?
89 iff "%basename" ne "dvips" then
90 goto nodvips1
91 endiff
92
93 :: we delete dvips.mfj if it exists.
94 del dvips.mfj >& nul
95
96 :: now we run dvips with all supplied parameters.
97 %&
98
99 :: do we have to generate fonts?
100 iff exist dvips.mfj then
101 goto generate_fonts
102 endiff
103
104 :: else all is done.
105 goto end
106
107
108 :nodvips1
109 :: here we call the dvi driver with all supplied parameters.
110 %& -pj:%basename.mfj
111
112 :: do we have to generate fonts?
113 iff errorlevel 8 then
114 goto generate_fonts
115 endiff
116
117 :: else all is done.
118 goto end
119
120
121 :generate_fonts
122 gosub call_mfjob
123
124 :: do we run dvips?
125 iff "%basename" ne "dvips" then
126 goto nodvips2
127 endiff
128
129 :: we now call dvips a second time
130 %&
131
132 :: since no fonts will be generated in the second run we remove dvips.mfj
133 del dvips.mfj >& nul
134
135 goto end
136
137
138 :nodvips2
139 :: we call the dvi driver a second time (without font generation).
140 %& -pj -fm
141
142 del %basename.mfj >& nul
143
144 goto end
145
146
147 :: this is the main subroutine which calls mfjob and then parses the mfjob
148 :: file for fonts which can be handled by ps2pk, ttf2pk, or hbf2gf.
149 :call_mfjob
150 :: this alias prints a message on the screen and writes it into the logfile.
151 alias echolog=`echo %& | tee /a %basename.mlg`
152
153 echo ======== DVIDRV.BTM logfile ======== > %basename.mlg
154 echo Commandline: dvidrv.btm %& >> %basename.mlg
155 echo `` >> %basename.mlg
156 echo basename=%basename >> %basename.mlg
157 echo emtexdir=%emtexdir >> %basename.mlg
158 echo dvidrvfonts=%dvidrvfonts >> %basename.mlg
159 echo mfinput=%mfinput >> %basename.mlg
160 echo mfjobopt=%mfjobopt >> %basename.mlg
161 echo textfm=%textfm >> %basename.mlg
162 echo psfonts=%psfonts >> %basename.mlg
163 echo ttfonts=%ttfonts >> %basename.mlg
164 echo ttfcfg=%ttfcfg >> %basename.mlg
165 echo hbfonts=%hbfonts >> %basename.mlg
166 echo hbfcfg=%hbfcfg >> %basename.mlg
167 echo `` >> %basename.mlg
168
169 iff "%@search[mfjob]" eq "" then
170 echolog MFJOB not found in the path.
171 echolog Can't generate PK fonts from METAFONT automatically.
172 echo ``
173 quit
174 endiff
175
176 :: now we call mfjob.
177 echolog mfjob %mfjobopt -g%basename.mfl %basename.mfj
178 mfjob %mfjobopt -g%basename.mfl %basename.mfj
179 iff %? gt 0 then
180 echolog ``
181 echolog Something went wrong while running METAFONT.
182 echolog Look into the log files...
183 echolog ``
184 endiff
185
186 :: after running mfjob we scan the mfjob input file for fonts which can
187 :: be handled by ps2pk, ttf2pk or hbf2gf.
188 set lnnr=0
189 set totlines=%@lines[%basename.mfj]
190
191 do while %lnnr le %totlines
192 :: input a line.
193 set scratch=%@line[%basename.mfj,%lnnr]
194 set lnnr=%@inc[%lnnr]
195
196 :: get resolutions (METAFONT mode will be ignored).
197 :: example:
198 :: mode=lqlores[180 180];
199 iff %@index[%scratch,mode] ge 0 then
200 set temp=%@word["[]",1,%scratch]
201 set xdpi=%@word[0,%temp]
202 set ydpi=%@word[1,%temp]
203 endiff
204
205 :: get fontname and magnification; we then compute the font resolutions
206 :: (rounded to the nearest integer---there is no necessity to adjust
207 :: these values further because of possible rounding errors since both
208 :: emTeX's dvi drivers and dvips check neighbored values too).
209 :: example:
210 :: {font=cmr10; mag=0.5;}
211 iff %@index[%scratch,{font] ge 0 then
212 set testfont=%@word["=;",1,%scratch]
213 set temp=%@word["=;",3,%scratch]
214 :: we use highest arithmetic precision for these calculations.
215 :: Additionally we write 1/2 instead of 0.5 to avoid problems with
216 :: countries which use a comma instead of a colon as the decimal
217 :: separator.
218 set fontresx=%@int[%@eval[%xdpi*%temp+1/2=8]]
219 set fontresy=%@int[%@eval[%ydpi*%temp+1/2=8]]
220 set pksubdir=modeless\%[pre_dpi]%[fontresx]%post_dpi
221
222 set success=0
223
224 :: check whether %testfont leads to a PS font (we call ps2pkmfj).
225 iff %success == 0 .and. "%ps2pk" ne "" then
226 gosub call_ps2pk
227 endiff
228
229 :: check whether %testfont leads to a TrueType font.
230 iff %success == 0 .and. "%ttf2pk" ne "" then
231 gosub call_ttf2pk
232 endiff
233
234 :: check whether %testfont leads to a HBF file.
235 iff %success == 0 .and. "%hbf2gf" ne "" then
236 gosub call_hbf2gf
237 endiff
238 endiff
239 enddo
240
241 iff exist %basename.mfp then
242 echo `` >> %basename.mlg
243 echo `` >> %basename.mlg
244 echo ======== PS2PK logfile ======== >> %basename.mlg
245 echo `` >> %basename.mlg
246 type %basename.mfp >> %basename.mlg
247 echo `` >> %basename.mlg
248 del %basename.mfp >& nul
249 endiff
250
251 iff exist %basename.mfl then
252 echo `` >> %basename.mlg
253 type %basename.mfl >> %basename.mlg
254 echo `` >> %basename.mlg
255 del %basename.mfl >& nul
256 endiff
257
258 return
259
260
261 :call_ttf2pk
262 iff "%@search[ttf2pk]" eq "" then
263 echolog TTF2PK not found in the path.
264 echolog Can't generate PK fonts from TrueType fonts automatically.
265 echo ``
266 quit
267 endiff
268
269 echolog ttf2pk -q -n %testfont %fontresx
270 ttf2pk -q -n %testfont %fontresx
271
272 iff %? == 0 then
273 echolog Font %pkdir\%pksubdir\%testfont.pk generated.
274 mkdir /s %pkdir\%pksubdir >& nul
275 move %testfont.pk %pkdir\%pksubdir >& nul
276 set success=1
277 elseiff %? == 2 then
278 echolog (%lnnr/%totlines): Font %testfont is no TrueType font.
279 set success=0
280 else
281 echolog Error running TTF2PK for font %testfont!
282 endiff
283
284 return
285
286
287 :call_hbf2gf
288 iff "%@search[hbf2gf]" eq "" then
289 echolog HBF2GF not found in the path.
290 echolog Can't generate PK fonts from HBF files automatically.
291 echo ``
292 quit
293 endiff
294
295 echolog hbf2gf -q -p -n %testfont %fontresx %fontresy
296 hbf2gf -q -p -n %testfont %fontresx %fontresy
297
298 iff %? == 0 then
299 echolog Font %pkdir\%pksubdir\%testfont.pk generated.
300 mkdir /s %pkdir\%pksubdir >& nul
301 gftopk %testfont.gf %testfont.pk
302 move %testfont.pk %pkdir\%pksubdir >& nul
303 del %testfont.gf >& nul
304 set success=1
305 elseiff %? == 2 then
306 echolog (%lnnr/%totlines): Font %testfont is no HBF.
307 set success=0
308 else
309 echolog Error running HBF2GF for font %testfont!
310 endiff
311
312 return
313
314
315 :call_ps2pk
316 iff not exist %pkdir\%pksubdir\%testfont.pk then
317 iff "%@search[ps2pkmfj]" eq "" .or. "%@search[ps2pk]" eq "" then
318 echolog PS2PKMFJ and/or PS2PK not found in the path.
319 echolog Can't generate PK fonts from PostScript fonts automatically.
320 echo ``
321 quit
322 endiff
323
324 echolog ps2pkmfj -X%fontresx -Y%fontresy %testfont %testfont.pk
325 ps2pkmfj -X%fontresx -Y%fontresy %testfont %testfont.pk | input %%pspkline
326
327 iff errorlevel != 1 then
328 %pspkline >> %basename.mfp
329 iff %? == 0 then
330 echolog Font %pkdir\%pksubdir\%testfont.pk generated.
331 mkdir /s %pkdir\%pksubdir >& nul
332 move %testfont.pk %pkdir\%pksubdir >& nul
333 success=1
334 else
335 echolog Error running PS2PK for font %testfont!
336 endiff
337 else
338 echolog (%lnnr/%totlines): Font %testfont is no PS font.
339 success=0
340 endiff
341 else
342 echolog Font %pkdir\%pksubdir\%testfont.pk already exists.
343 endiff
344
345 return
346
347
348 :end
349
350 endlocal
351
352 :: ==== end of dvidrv.btm ====