summaryrefslogtreecommitdiff
path: root/language/chinese/CJK/cjk-4.8.5/utils/hbf2gf/dvidrv.btm
blob: 9b43c091001b16c7def944bebab886474ca35fa4 (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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
setdos /y1
::
:: Copyright (C) 1994-2021  Werner Lemberg <wl@gnu.org>
::
:: This program is free software; you can redistribute it and/or modify
:: it under the terms of the GNU General Public License as published by
:: the Free Software Foundation; either version 2 of the License, or
:: (at your option) any later version.
::
:: This program is distributed in the hope that it will be useful,
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
:: GNU General Public License for more details.
::
:: You should have received a copy of the GNU General Public License
:: along with this program in doc/COPYING; if not, write to the Free
:: Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
:: MA 02110-1301 USA
::
::
::  This is dvidrv.btm, a batch file for 4DOS/4OS2 written by
::  Werner Lemberg <wl@gnu.org> partially based on the
::  dvidrv.btm file of the 4allTeX package written by Phons Bloemen.
::
::  It is a replacement for dvidrv.exe of the emTeX package.
::
::  Additional features: support of ps2pk
::                       support of ttf2pk
::                       support of hbf2gf for HBFs (Hanzi bitmap fonts)
::
::      Only quadratic printer modes are supported for ttf2pk!
::
::  All needed binaries will be searched in the path.

iff %# lt 2 then
  echo ``
  echo Usage: %0 dvi-driver dvi-file [parameters]
  quit
endiff

setlocal
  :: we set a default value only if the corresponding environment variable
  :: is empty. The `=' must follow the variable name immediately.
  alias set_def `iff "%[%@word["=",0,%1]]" eq "" then %+ set %& %+ endiff`

  :: =========================================
  :: ======== User defined variables. ========
  :: =========================================
  ::
  :: Can be overridden in the environment (except %ps2pk, %ttf2pk, %hbf2gf,
  :: %pre_dpi, and %post_dpi).

  :: Comment out the programs you don't want to use.
  set ps2pk=yes
  set ttf2pk=yes
  set hbf2gf=yes

  :: where the PK files will be installed created by ps2pk, ttf2pk, and
  :: hbf2gf.
  :: dvidrv.btm adds `\modeless\XXXdpi' to this string (see below for the
  :: exact string).
  set_def pkdir=%emtexdir\pixel\tmp\pk

  :: where the TrueType fonts reside.
  set_def ttfonts=%emtexdir\fonts\truetype
  :: where auxiliary files of ttf2pk are located.
  set_def ttfcfg=%emtexdir\ttf2pk

  :: where the HBF files reside.
  set_def hbfonts=%emtexdir\fonts\hbf
  :: where the hbf2gf config files are.
  set_def hbfcfg=%emtexdir\hbf2gf

  :: the dpi-subdirectory has various forms; the most common are XXXdpi and
  :: dpiXXX, e.g. 300dpi and dpi300. Here we define two variables which
  :: control this behaviour.
  :: [dpiXXX is used for TDS compatible TeX trees.]
  set pre_dpi=dpi
  set post_dpi=

  :: ================================================
  :: ======== End of user defined variables. ========
  :: ================================================

  :: the base name for log files etc.
  set basename=%@name[%1]

  :: do we run dvips?
  iff "%basename" ne "dvips" then
    goto nodvips1
  endiff

  :: we delete dvips.mfj if it exists.
  del dvips.mfj >& nul

  :: now we run dvips with all supplied parameters.
  %&

  :: do we have to generate fonts?
  iff exist dvips.mfj then
    goto generate_fonts
  endiff

  :: else all is done.
  goto end


:nodvips1
  :: here we call the dvi driver with all supplied parameters.
  %& -pj:%basename.mfj

  :: do we have to generate fonts?
  iff errorlevel 8 then
    goto generate_fonts
  endiff

  :: else all is done.
  goto end


:generate_fonts
  gosub call_mfjob

  :: do we run dvips?
  iff "%basename" ne "dvips" then
    goto nodvips2
  endiff

  :: we now call dvips a second time
  %&

  :: since no fonts will be generated in the second run we remove dvips.mfj
  del dvips.mfj >& nul

  goto end


:nodvips2
  :: we call the dvi driver a second time (without font generation).
  %& -pj -fm

  del %basename.mfj >& nul

  goto end


:: this is the main subroutine which calls mfjob and then parses the mfjob
:: file for fonts which can be handled by ps2pk, ttf2pk, or hbf2gf.
:call_mfjob
  :: this alias prints a message on the screen and writes it into the logfile.
  alias echolog=`echo %& | tee /a %basename.mlg`

  echo ======== DVIDRV.BTM logfile ========  > %basename.mlg
  echo Commandline: dvidrv.btm %&           >> %basename.mlg
  echo ``                                   >> %basename.mlg
  echo basename=%basename                   >> %basename.mlg
  echo emtexdir=%emtexdir                   >> %basename.mlg
  echo dvidrvfonts=%dvidrvfonts             >> %basename.mlg
  echo mfinput=%mfinput                     >> %basename.mlg
  echo mfjobopt=%mfjobopt                   >> %basename.mlg
  echo textfm=%textfm                       >> %basename.mlg
  echo psfonts=%psfonts                     >> %basename.mlg
  echo ttfonts=%ttfonts                     >> %basename.mlg
  echo ttfcfg=%ttfcfg                       >> %basename.mlg
  echo hbfonts=%hbfonts                     >> %basename.mlg
  echo hbfcfg=%hbfcfg                       >> %basename.mlg
  echo ``                                   >> %basename.mlg

  iff "%@search[mfjob]" eq "" then
    echolog MFJOB not found in the path.
    echolog Can't generate PK fonts from METAFONT automatically.
    echo ``
    quit
  endiff

  :: now we call mfjob.
  echolog mfjob %mfjobopt -g%basename.mfl %basename.mfj
  mfjob %mfjobopt -g%basename.mfl %basename.mfj
  iff %? gt 0 then
    echolog ``
    echolog Something went wrong while running METAFONT.
    echolog Look into the log files...
    echolog ``
  endiff

  :: after running mfjob we scan the mfjob input file for fonts which can
  :: be handled by ps2pk, ttf2pk or hbf2gf.
  set lnnr=0
  set totlines=%@lines[%basename.mfj]

  do while %lnnr le %totlines
    :: input a line.
    set scratch=%@line[%basename.mfj,%lnnr]
    set lnnr=%@inc[%lnnr]

    :: get resolutions (METAFONT mode will be ignored).
    :: example:
    ::   mode=lqlores[180 180];
    iff %@index[%scratch,mode] ge 0 then
      set temp=%@word["[]",1,%scratch]
      set xdpi=%@word[0,%temp]
      set ydpi=%@word[1,%temp]
    endiff

    :: get fontname and magnification; we then compute the font resolutions
    :: (rounded to the nearest integer---there is no necessity to adjust
    :: these values further because of possible rounding errors since both
    :: emTeX's dvi drivers and dvips check neighbored values too).
    :: example:
    ::   {font=cmr10; mag=0.5;}
    iff %@index[%scratch,{font] ge 0 then
      set testfont=%@word["=;",1,%scratch]
      set temp=%@word["=;",3,%scratch]
      :: we use highest arithmetic precision for these calculations.
      :: Additionally we write 1/2 instead of 0.5 to avoid problems with
      :: countries which use a comma instead of a colon as the decimal
      :: separator.
      set fontresx=%@int[%@eval[%xdpi*%temp+1/2=8]]
      set fontresy=%@int[%@eval[%ydpi*%temp+1/2=8]]
      set pksubdir=modeless\%[pre_dpi]%[fontresx]%post_dpi

      set success=0

      :: check whether %testfont leads to a PS font (we call ps2pkmfj).
      iff %success == 0 .and. "%ps2pk" ne "" then
        gosub call_ps2pk
      endiff

      :: check whether %testfont leads to a TrueType font.
      iff %success == 0 .and. "%ttf2pk" ne "" then
        gosub call_ttf2pk
      endiff

      :: check whether %testfont leads to a HBF file.
      iff %success == 0 .and. "%hbf2gf" ne "" then
        gosub call_hbf2gf
      endiff
    endiff
  enddo

  iff exist %basename.mfp then
    echo ``                              >> %basename.mlg
    echo ``                              >> %basename.mlg
    echo ======== PS2PK logfile ======== >> %basename.mlg
    echo ``                              >> %basename.mlg
    type %basename.mfp                   >> %basename.mlg
    echo ``                              >> %basename.mlg
    del %basename.mfp >& nul
  endiff

  iff exist %basename.mfl then
    echo ``                              >> %basename.mlg
    type %basename.mfl                   >> %basename.mlg
    echo ``                              >> %basename.mlg
    del %basename.mfl >& nul
  endiff

  return


:call_ttf2pk
  iff "%@search[ttf2pk]" eq "" then
    echolog TTF2PK not found in the path.
    echolog Can't generate PK fonts from TrueType fonts automatically.
    echo ``
    quit
  endiff

  echolog ttf2pk -q -n %testfont %fontresx
  ttf2pk -q -n %testfont %fontresx

  iff %? == 0 then
    echolog Font %pkdir\%pksubdir\%testfont.pk generated.
    mkdir /s %pkdir\%pksubdir >& nul
    move %testfont.pk %pkdir\%pksubdir >& nul
    set success=1
  elseiff %? == 2 then
    echolog (%lnnr/%totlines): Font %testfont is no TrueType font.
    set success=0
  else
    echolog Error running TTF2PK for font %testfont!
  endiff

  return


:call_hbf2gf
  iff "%@search[hbf2gf]" eq "" then
    echolog HBF2GF not found in the path.
    echolog Can't generate PK fonts from HBF files automatically.
    echo ``
    quit
  endiff

  echolog hbf2gf -q -p -n %testfont %fontresx %fontresy
  hbf2gf -q -p -n %testfont %fontresx %fontresy

  iff %? == 0 then
    echolog Font %pkdir\%pksubdir\%testfont.pk generated.
    mkdir /s %pkdir\%pksubdir >& nul
    gftopk %testfont.gf %testfont.pk
    move %testfont.pk %pkdir\%pksubdir >& nul
    del %testfont.gf >& nul
    set success=1
  elseiff %? == 2 then
    echolog (%lnnr/%totlines): Font %testfont is no HBF.
    set success=0
  else
    echolog Error running HBF2GF for font %testfont!
  endiff

  return


:call_ps2pk
  iff not exist %pkdir\%pksubdir\%testfont.pk then
    iff "%@search[ps2pkmfj]" eq "" .or. "%@search[ps2pk]" eq "" then
      echolog PS2PKMFJ and/or PS2PK not found in the path.
      echolog Can't generate PK fonts from PostScript fonts automatically.
      echo ``
      quit
    endiff

    echolog ps2pkmfj -X%fontresx -Y%fontresy %testfont %testfont.pk
    ps2pkmfj -X%fontresx -Y%fontresy %testfont %testfont.pk | input %%pspkline

    iff errorlevel != 1 then
      %pspkline >> %basename.mfp
      iff %? == 0 then
        echolog Font %pkdir\%pksubdir\%testfont.pk generated.
        mkdir /s %pkdir\%pksubdir >& nul
        move %testfont.pk %pkdir\%pksubdir >& nul
        success=1
      else
        echolog Error running PS2PK for font %testfont!
      endiff
    else
      echolog (%lnnr/%totlines): Font %testfont is no PS font.
      success=0
    endiff
  else
    echolog Font %pkdir\%pksubdir\%testfont.pk already exists.
  endiff

  return


:end

endlocal

:: ==== end of dvidrv.btm ====