Debian Codegraph @

texk/cjkutils/hbf2gf.tex

raw
1 \input cwebmac
2 % This is the cweb file hbf2gf.w of the CJK package ver. 4.8.5 16-Oct-2021
3
4 % Copyright (C) 1994-2021 Werner Lemberg <[email protected]>
5 %
6 % This program is free software; you can redistribute it and/or modify
7 % it under the terms of the GNU General Public License as published by
8 % the Free Software Foundation; either version 2 of the License, or
9 % (at your option) any later version.
10 %
11 % This program is distributed in the hope that it will be useful,
12 % but WITHOUT ANY WARRANTY; without even the implied warranty of
13 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 % GNU General Public License for more details.
15 %
16 % You should have received a copy of the GNU General Public License
17 % along with this program in doc/COPYING; if not, write to the Free
18 % Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 % MA 02110-1301 USA
20
21 % To print this CWEB file you should (but not must) use the CWEAVE of the
22 % c2cweb-package (found at the CTAN archives, e.g. ftp.dante.de) and then say
23 %
24 % cweave +ai hbf2gf.w
25 %
26 % This (fully compatible) CWEAVE can transform CWEB-files with alternative
27 % output rules (look at the position of braces below!) the author (it's me
28 % too :-) prefer. Otherwise this file will be formatted traditionally.
29
30 \font\meta=logo10
31 \def\mf{{\meta META}\-{\meta FONT}}
32 \def\Om{\char "0A} % Omega symbol
33
34 \def\title{hbf2gf (CJK Version 4.8.5)}
35
36 \def\topofcontents{
37 \null\vfill
38 \centerline{\titlefont The {\ttitlefont hbf2gf} program}
39 \vskip 20pt
40 \centerline{(CJK Version 4.8.5)}
41 \vfill}
42
43 \def\botofcontents{
44 \vfill
45 \noindent
46 Copyright \copyright~1996-1999 by Werner Lemberg
47 \bigskip\noindent
48 Permission is granted to make and distribute verbatim copies of this
49 document provided that the copyright notice and this permission notice are
50 preserved on all copies.
51
52 \smallskip\noindent
53 Permission is granted to copy and distribute modified versions of this
54 document under the conditions for verbatim copying, provided that the
55 entire resulting derived work is distributed under the terms of a
56 permission notice identical to this one.}
57
58 \pageno=\contentspagenumber \advance\pageno by 1
59 \let\maybe=\iftrue
60 \fullpageheight=240mm
61 \pageheight=223mm
62 \pagewidth=158mm
63 \setpage
64 \frenchspacing
65
66
67 \def\msdos{\.{msdos}}
68
69
70
71
72
73 \N{1}{1}Introduction.
74 This is the \.{hbf2gf} program by Werner Lemberg
75 (\.{[email protected]}).
76
77 The ``banner line'' defined here should be changed whenever \.{hbf2gf} is
78 modified.
79
80 \Y\B\4\D\\{banner}\5
81 \.{"hbf2gf\ (CJK\ ver.\ 4.}\)\.{8.5)"}\par
82 \fi
83
84 \M{2}
85 \.{hbf2gf} is intended to convert Hanzi Bitmap Fonts (HBF) into \TeX\
86 generic font files (\.{GF} files) according to the \\{CJK} package, which
87 \.{hbf2gf} is part of.
88
89 The outline of \.{hbf2gf} is simple: a CJK (Chinese/Japanese/Korean) bitmap
90 file will be scaled and written in at most \PB{\\{nmb\_files}} \.{GF} files,
91 each
92 file containing \PB{\T{256}}~characters (except the last and possibly the first
93 one). In the normal case it's not necessary to compute the right value of
94 \PB{\\{nmb\_files}} because \.{hbf2gf} will do this; you should use \PB{${-}%
95 \T{1}$} instead to
96 indicate this. See the last section for an example.
97
98 Alternatively you can call \.{hbf2gf} similar to \mf, i.e., the program will
99 compute one font on demand. This mode will be used if two or three input
100 parameters instead of one are given: the font name, the horizontal
101 resolution, and optionally a vertical scaling factor or resolution to allow
102 modes for e.g.\ $300\times600\,\hbox{dpi}$ printers. \.{hbf2gf} will extract
103 the configuration file name from the font name; if this file isn't found,
104 the program exits with error code~\PB{\T{2}} (this is useful for scripts like
105 \.{mktexpk}). If the configuration file is found but an error occurs while
106 computing the font, error code~\PB{\T{1}} is returned. In case of success, the
107 exit
108 code is zero.
109
110 The characters in the input font files are completely described by the HBF
111 header file. This program uses the HBF API implementation of Ross Paterson
112 (\.{[email protected]}; with small extensions). You will find a
113 description of the HBF standard at \.{ftp.ifcss.org}.
114
115 A batch file created by \.{hbf2gf} too (if the program computes a whole set
116 of subfonts) will convert the \.{GF} files to \.{PK} files using
117 \.{GFtoPK}, a part of every \TeX\ package.
118
119 \Y\B\4\D\.{TRUE}\5
120 \T{1}\par
121 \B\4\D\.{FALSE}\5
122 \T{0}\Y\par
123 \B\4\D\.{STRING\_LENGTH}\5
124 \T{255}\C{ the maximal length of an input string in the configuration file }\par
125 \B\4\D\.{FILE\_NAME\_LENGTH}\5
126 \T{1024}\C{ the maximal length (including the path) of a filename }\Y\par
127 \Y\B\4\X2:Global variables\X${}\E{}$\6
128 \&{int} \\{nmb\_files}${}\K{-}\T{1}{}$;\C{ create all files by default }\6
129 \&{int} \\{unicode}${}\K\.{FALSE}{}$;\C{ whether a Unicode font should be
130 processed }\7
131 \&{int} \\{testing}${}\K\.{FALSE}{}$;\C{ whether we test only the font name }\7
132 \&{int} \\{mf\_like}${}\K\.{FALSE}{}$;\C{ whether we are in the \mf-like mode }%
133 \6
134 \&{int} \\{file\_number}${}\K\T{0}{}$;\C{ the subfont number }\7
135 \&{double} \\{x\_resolution}${}\K\T{0.0}{}$;\C{ the second and third input
136 parameter }\6
137 \&{double} \\{y\_scale}${}\K\T{1.0}{}$;\7
138 \&{int} \\{pk\_files}${}\K\.{TRUE}{}$;\C{ command line options }\6
139 \&{int} \\{tfm\_files}${}\K\.{TRUE};{}$\6
140 \&{int} \\{long\_extension}${}\K\.{TRUE};{}$\6
141 \&{int} \\{quiet}${}\K\.{FALSE}{}$;\7
142 \&{char} ${}\\{config\_file}[\.{FILE\_NAME\_LENGTH}+\T{4}+\T{1}]{}$;\C{ we
143 probably must add `\.{.cfg}' }\6
144 \&{char} ${}\\{output\_name}[\.{STRING\_LENGTH}+\T{1}]{}$;\7
145 \&{FILE} ${}{*}\\{config},{}$ ${}{*}\\{out};{}$\6
146 \&{HBF} ${}{*}\\{hbf}{}$;\7
147 \8\#\&{ifdef} \.{WIN32}\6
148 \8\#\&{define} \.{WRITE\_BIN}\5\.{"wb"}\6
149 \8\#\&{define} \.{WRITE\_TXT}\5\.{"wb"}\6
150 \8\#\&{define} \.{READ\_BIN}\5\.{"rb"}\6
151 \8\#\&{define} \.{READ\_TXT}\5\.{"rt"}\6
152 \8\#\&{else}\6
153 \8\#\&{define} \.{WRITE\_BIN}\5\.{"w"}\6
154 \8\#\&{define} \.{WRITE\_TXT}\5\.{"w"}\6
155 \8\#\&{define} \.{READ\_BIN}\5\.{"r"}\6
156 \8\#\&{define} \.{READ\_TXT}\5\.{"r"}\6
157 \8\#\&{endif}\7
158 \&{int} \\{end\_of\_file}${}\K\.{FALSE}{}$;\par
159 \As15, 19, 27, 38, 49, 53, 58, 60, 62, 70, 73\ETs76.
160 \U4.\fi
161
162 \M{3}
163 One \.{PL} file will be created additionally, which describes the font
164 metrics in a readable way. Because all CJK characters have identical
165 bounding boxes, one metrics file is enough---the batch job created by
166 \.{hbf2gf} calls \.{PLtoTF} to produce this \.{TFM} file and then copies
167 it into \PB{\\{nmb\_files}} metrics files. There usually will be a discrepancy
168 between the number of characters in the last \.{GF} file and the
169 \.{TFM} file, but this does not harm.
170
171 If you specify the \.{ofm\_file} option in the configuration file, an
172 extended virtual property file (such files have the extension \.{.ovp}) for
173 the \Om\ system is written; this will be then converted with
174 \.{ovp2ovf} into an \.{OFM} and an \.{OVF} file to map all the subfonts
175 into one large virtual font.
176
177
178
179 \fi
180
181 \N{1}{4}The main routine.
182 The main routine takes \PB{\\{file\_name}}, \PB{\\{x\_resolution}}, and \PB{%
183 \\{y\_scale}} as command
184 line parameters if in \mf-like mode, otherwise \PB{\\{config\_file}} as the
185 only
186 argument. \PB{\\{read\_config}(\,)} scans the configuration file and fills the
187 global
188 variables, \PB{\\{write\_file}(\,)} writes the \.{GF} files, \PB{\\{write\_pl}(%
189 \,)} and
190 \PB{\\{write\_ovp}(\,)} write the \.{PL} and \.{OVP} files respectively, and
191 \PB{\\{write\_job}(\,)} the batch file.
192
193 \Y\B\X10:Include files\X\6
194 \X11:Prototypes\X\6
195 \X2:Global variables\X\7
196 \1\1\&{int} \\{main}(\&{int} \\{argc}${},\39{}$\&{char} ${}{*}\\{argv}[\,])\2%
197 \2{}$\6
198 ${}\{{}$\1\6
199 \&{char} ${}{*}\|p;{}$\7
200 \X78:Initialize \TeX\ file searching\X\7
201 \X7:Scan options\X\7
202 \&{if} ${}(\R\\{quiet}){}$\1\5
203 ${}\\{printf}(\.{"\\n\%s\\n\\n"},\39\\{banner}){}$;\2\7
204 ${}\\{strncpy}(\\{config\_file},\39\\{argv}[\T{1}],\39\.{FILE\_NAME%
205 \_LENGTH});{}$\6
206 ${}\\{config\_file}[\.{FILE\_NAME\_LENGTH}]\K\.{'\\0'}{}$;\7
207 \&{if} ${}(\\{argc}>\T{2}\V\\{testing}){}$\5
208 ${}\{{}$\1\6
209 \&{int} \|l${}\K\\{strlen}(\\{config\_file});{}$\7
210 \&{if} ${}(\|l>\T{2}){}$\1\5
211 ${}\\{config\_file}[\|l-\T{2}]\K\.{'\\0'}{}$;\C{ strip subfont number from file
212 name }\2\6
213 \&{else}\5
214 ${}\{{}$\1\6
215 \&{if} ${}(\R\\{quiet}){}$\1\5
216 ${}\\{printf}(\.{"`\%s'\ can't\ be\ a\ sub}\)\.{font\ created\ by\ hbf2}\)\.{gf%
217 \\n"},\39\\{config\_file});{}$\2\6
218 \\{exit}(\T{2});\6
219 \4${}\}{}$\2\7
220 ${}\\{mf\_like}\K\.{TRUE};{}$\6
221 \4${}\}{}$\2\7
222 \\{read\_config}(\,);\C{ will call \PB{\\{exit}(\T{1})} on errors }\7
223 \&{if} (\\{mf\_like})\1\5
224 \X8:Check other arguments\X\2\7
225 \X28:Initialize variables\X\7
226 \X9:Write files\X\7
227 \&{if} (\\{tfm\_files})\1\5
228 \\{write\_pl}(\,);\2\6
229 \&{if} (\\{ofm\_file})\1\5
230 \\{write\_ovp}(\,);\2\6
231 \&{if} ${}(\R\\{mf\_like}){}$\1\5
232 \\{write\_job}(\,);\2\7
233 \\{hbfClose}(\\{hbf});\7
234 \\{exit}(\T{0});\6
235 \&{return} \T{0};\C{ never reached }\6
236 \4${}\}{}$\2\par
237 \fi
238
239 \M{5}
240 \Y\B\4\D\.{VERSION}\6
241 \.{"\\n"}\6
242 \.{"Copyright\ (C)\ 1996-}\)\.{1999\ Werner\ Lemberg.}\)\.{\\n"}\6
243 \.{"There\ is\ NO\ warrant}\)\.{y.\ \ You\ may\ redistri}\)\.{bute\ this\
244 software\\n}\)\.{"}\6
245 \.{"under\ the\ terms\ of\ }\)\.{the\ GNU\ General\ Publ}\)\.{ic\ License\\n"}\6
246 \.{"and\ the\ HBF\ library}\)\.{\ copyright.\\n"}\6
247 \.{"\\n"}\6
248 \.{"For\ more\ informatio}\)\.{n\ about\ these\ matter}\)\.{s,\ see\ the\ files%
249 \\n"}\6
250 \.{"named\ COPYING\ and\ h}\)\.{bf.c.\\n"}\6
251 \.{"\\n"}\par
252 \Y\B\4\X5:Print version\X${}\E{}$\6
253 ${}\{{}$\1\6
254 \\{printf}(\.{"\\n"});\6
255 \\{printf}(\\{banner});\6
256 ${}\\{printf}(\.{"\ (\%s)\\n"},\39\\{TeX\_search\_version}(\,));{}$\6
257 \\{printf}(\.{VERSION});\6
258 \\{exit}(\T{0});\6
259 \4${}\}{}$\2\par
260 \U7.\fi
261
262 \M{6}
263 \Y\B\4\D\.{USAGE}\6
264 \.{"\\n"}\6
265 \.{"Usage:\ hbf2gf\ [-q]\ }\)\.{configuration\_file[.}\)\.{cfg]\\n"}\6
266 \.{"\ \ \ \ \ \ \ hbf2gf\ [opti}\)\.{ons]\ font\_name\ x\_res}\)\.{olution\ [y%
267 \_scale\ |\ y}\)\.{\_resolution]\\n"}\6
268 \.{"\ \ \ \ \ \ \ hbf2gf\ -t\ [-}\)\.{q]\ font\_name\\n"}\6
269 \.{"\\n"}\6
270 \.{"\ \ Convert\ a\ font\ in}\)\.{\ HBF\ format\ to\ TeX's}\)\.{\ GF\ resp.\ PK%
271 \ format.}\)\.{\\n"}\6
272 \.{"\\n"}\6
273 \.{"\ \ \ \ \ \ \ \ \ -q\ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ be\ silent\\n"}\6
274 \.{"\ \ \ \ \ \ \ \ \ -p\ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ don't\ produce\ a}\)\.{%
275 \ PL\ file\\n"}\6
276 \.{"\ \ \ \ \ \ \ \ \ -g\ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ don't\ produce\ a}\)\.{%
277 \ GF\ file\\n"}\6
278 \.{"\ \ \ \ \ \ \ \ \ -n\ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ use\ no\ resoluti}\)%
279 \.{on\ in\ extension\ (onl}\)\.{y\ `.gf')\\n"}\6
280 \.{"\ \ \ \ \ \ \ \ \ -t\ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ test\ for\ font\_n}\)%
281 \.{ame\ (returns\ 0\ on\ su}\)\.{ccess)\\n"}\6
282 \.{"\ \ \ \ \ \ \ \ \ --help\ \ \ \ }\)\.{\ \ \ \ \ print\ this\ mess}\)\.{age\
283 and\ exit\\n"}\6
284 \.{"\ \ \ \ \ \ \ \ \ --version\ }\)\.{\ \ \ \ \ print\ version\ n}\)\.{umber\
285 and\ exit\\n"}\6
286 \.{"\\n"}\par
287 \Y\B\4\X6:Print help information\X${}\E{}$\6
288 ${}\{{}$\1\6
289 \\{printf}(\.{USAGE});\6
290 \\{exit}(\T{0});\6
291 \4${}\}{}$\2\par
292 \U7.\fi
293
294 \M{7}
295 Three options can be specified to the program (\.{-p}, \.{-g}, and \.{-n})
296 if in \mf-like mode to suppress creation of a \.{PL} resp.\ a
297 \.{GF} file, and to force a `\.{.gf}' extension (instead of
298 e.g.\ `\.{.300gf}'). The corresponding setting of a particular switch in the
299 configuration file is ignored then.
300
301 Additionally, the option \.{-t} tests whether the specified subfont name
302 leads to an \.{hbf2gf} configuration file. It returns 0 on success and prints
303 out the name of that configuration file (provided the \.{-q} switch isn't
304 set). This test isn't a thorough one; it only removes the last two characters
305 and checks whether a configuration file with that name exists.
306
307 \Y\B\4\X7:Scan options\X${}\E{}$\6
308 \&{if} ${}(\\{argc}\E\T{2}){}$\5
309 ${}\{{}$\1\6
310 \&{if} ${}(\\{strcmp}(\\{argv}[\T{1}],\39\.{"--help"})\E\T{0}){}$\1\5
311 \X6:Print help information\X\2\6
312 \&{else} \&{if} ${}(\\{strcmp}(\\{argv}[\T{1}],\39\.{"--version"})\E\T{0}){}$\1%
313 \5
314 \X5:Print version\X\2\6
315 \4${}\}{}$\2\7
316 \&{while} ${}(\\{argc}>\T{1}){}$\5
317 ${}\{{}$\1\6
318 ${}\|p\K\\{argv}[\T{1}];{}$\6
319 \&{if} ${}(\|p[\T{0}]\I\.{'-'}){}$\1\5
320 \&{break};\2\6
321 \&{if} ${}(\|p[\T{1}]\E\.{'p'}){}$\1\5
322 ${}\\{tfm\_files}\K\.{FALSE};{}$\2\6
323 \&{else} \&{if} ${}(\|p[\T{1}]\E\.{'g'}){}$\1\5
324 ${}\\{pk\_files}\K\.{FALSE};{}$\2\6
325 \&{else} \&{if} ${}(\|p[\T{1}]\E\.{'n'}){}$\1\5
326 ${}\\{long\_extension}\K\.{FALSE};{}$\2\6
327 \&{else} \&{if} ${}(\|p[\T{1}]\E\.{'q'}){}$\1\5
328 ${}\\{quiet}\K\.{TRUE};{}$\2\6
329 \&{else} \&{if} ${}(\|p[\T{1}]\E\.{'t'}){}$\1\5
330 ${}\\{testing}\K\.{TRUE}{}$;\2\7
331 ${}\\{argv}\PP;{}$\6
332 ${}\\{argc}\MM;{}$\6
333 \4${}\}{}$\2\7
334 \&{if} (\\{testing})\5
335 ${}\{{}$\1\6
336 \&{if} ${}(\\{argc}\I\T{2}){}$\5
337 ${}\{{}$\1\6
338 ${}\\{fprintf}(\\{stderr},\39\.{"Need\ exactly\ one\ pa}\)\.{rameter\ for\ `-t'%
339 \ opt}\)\.{ion.\\n"});{}$\6
340 ${}\\{fprintf}(\\{stderr},\39\.{"Try\ `hbf2gf\ --help'}\)\.{\ for\ more\
341 informatio}\)\.{n.\\n"});{}$\6
342 \\{exit}(\T{1});\6
343 \4${}\}{}$\2\6
344 \4${}\}{}$\2\6
345 \&{else} \&{if} ${}(\\{argc}<\T{2}\V\\{argc}>\T{4}){}$\5
346 ${}\{{}$\1\6
347 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ number\ of\ p}\)\.{arameters.%
348 \\n"});{}$\6
349 ${}\\{fprintf}(\\{stderr},\39\.{"Try\ `hbf2gf\ --help'}\)\.{\ for\ more\
350 informatio}\)\.{n.\\n"});{}$\6
351 \\{exit}(\T{1});\6
352 \4${}\}{}$\2\Y\par
353 \U4.\fi
354
355 \M{8}
356 If the (optional) argument is larger than~\PB{\T{10}}, we treat it as a value
357 for
358 the vertical resolution (in dpi), otherwise as a vertical scaling factor.
359
360 \Y\B\4\X8:Check other arguments\X${}\E{}$\6
361 ${}\{{}$\1\6
362 \&{if} (\\{unicode})\1\5
363 ${}\\{file\_number}\K{}$(\&{int}) \\{strtol}${}({\AND}\\{argv}[\T{1}][%
364 \\{strlen}(\\{argv}[\T{1}])-\T{2}],\39{}$(\&{char} ${}{*}{*}){}$ ${}\NULL,\39%
365 \T{16});{}$\2\6
366 \&{else}\1\5
367 ${}\\{file\_number}\K\\{atoi}({\AND}\\{argv}[\T{1}][\\{strlen}(\\{argv}[%
368 \T{1}])-\T{2}]){}$;\2\7
369 ${}\\{x\_resolution}\K\\{atof}(\\{argv}[\T{2}]);{}$\6
370 \&{if} ${}(\\{x\_resolution}<\.{PRINTER\_MIN\_RES\_X}){}$\5
371 ${}\{{}$\1\6
372 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ horizontal\ }\)\.{resolution%
373 \\n"});{}$\6
374 \\{exit}(\T{1});\6
375 \4${}\}{}$\2\7
376 \&{if} ${}(\\{argc}>\T{3}){}$\5
377 ${}\{{}$\1\6
378 ${}\\{y\_scale}\K\\{atof}(\\{argv}[\T{3}]);{}$\6
379 \&{if} ${}(\\{y\_scale}<\T{0.01}){}$\5
380 ${}\{{}$\1\6
381 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ vertical\ sc}\)\.{aling\ factor\ or\
382 reso}\)\.{lution\\n"});{}$\6
383 \\{exit}(\T{1});\6
384 \4${}\}{}$\2\6
385 \&{if} ${}(\\{y\_scale}>\T{10.0}){}$\1\5
386 ${}\\{y\_scale}\K{}$(\&{double}) \\{x\_resolution}${}/\\{y\_scale};{}$\2\6
387 \4${}\}{}$\2\6
388 \4${}\}{}$\2\par
389 \U4.\fi
390
391 \M{9}
392 If \PB{\\{unicode}} is \PB{\.{TRUE}}, the start value of the running number
393 appended to
394 the base name of the output font files is taken from the HBF header file,
395 otherwise it starts with~`\.{01}'. \PB{\\{min\_char}} represents the lower
396 bound of
397 the code range.
398
399 If we are in \mf-like mode, \PB{\\{file\_number}} is taken from the command
400 line,
401 and \PB{\\{max\_numb}} will be set to~\PB{\T{1}}.
402
403 \Y\B\4\X9:Write files\X${}\E{}$\6
404 ${}\{{}$\1\6
405 \&{int} \|j${},{}$ \\{max\_numb};\7
406 \&{if} ${}(\R\\{mf\_like}){}$\5
407 ${}\{{}$\1\6
408 ${}\\{file\_number}\K(\\{unicode}\E\.{TRUE}\?(\\{min\_char}\GG\T{8}):\T{1});{}$%
409 \6
410 \&{if} ${}(\\{nmb\_files}\E{-}\T{1}){}$\1\5
411 ${}\\{max\_numb}\K(\\{unicode}\E\.{TRUE}\?\T{\^100}:\T{100});{}$\2\6
412 \&{else}\1\5
413 ${}\\{max\_numb}\K\\{nmb\_files};{}$\2\6
414 \4${}\}{}$\2\6
415 \&{else}\1\5
416 ${}\\{max\_numb}\K\T{1}{}$;\2\7
417 \&{for} ${}(\|j\K\T{0};{}$ ${}(\|j<\\{max\_numb})\W\R\\{end\_of\_file};{}$ ${}%
418 \\{file\_number}\PP,\39\|j\PP){}$\1\5
419 \\{write\_file}(\,);\2\7
420 ${}\\{nmb\_files}\K\|j{}$;\C{ the real number of output font files }\6
421 \4${}\}{}$\2\par
422 \U4.\fi
423
424 \M{10}
425 \Y\B\4\X10:Include files\X${}\E{}$\6
426 \8\#\&{ifdef} \.{HAVE\_CONFIG\_H}\6
427 \8\#\&{include} \.{<c-auto.h>}\6
428 \8\#\&{endif}\6
429 \8\#\&{include} \.{<ctype.h>}\6
430 \8\#\&{include} \.{<stdio.h>}\6
431 \8\#\&{include} \.{<stdlib.h>}\6
432 \8\#\&{include} \.{<string.h>}\6
433 \8\#\&{include} \.{<time.h>}\6
434 \8\#\&{ifdef} \.{TM\_IN\_SYS\_TIME}\6
435 \8\#\&{include} \.{<sys/time.h>}\6
436 \8\#\&{endif}\6
437 \8\#\&{include} \.{"hbf.h"}\par
438 \A69.
439 \U4.\fi
440
441 \N{1}{11}The functions.
442 The first function to be described is \PB{\\{write\_file}(\,)}. Each \.{GF}
443 file
444 consists of three sections: a preamble, a data section, and a postamble. The
445 functions \PB{\\{write\_pre}(\,)}, \PB{\\{write\_data}(\,)}, and \PB{\\{write%
446 \_post}(\,)} handle this.
447
448 \Y\B\4\X11:Prototypes\X${}\E{}$\6
449 \&{static} \&{void} \\{write\_file}(\&{void});\par
450 \As13, 16, 20, 25, 29, 36, 39, 41, 45, 47, 50, 54, 64, 67, 71, 74\ETs79.
451 \U4.\fi
452
453 \M{12}
454 In \mf-like mode we create font file name extensions similar to \mf\ if
455 the \.{-n} option isn't specified; otherwise only `\.{.gf}' will be appended.
456
457 \Y\B\1\1\&{static} \&{void} \\{write\_file}(\&{void})\2\2\6
458 ${}\{{}$\1\6
459 \&{char} ${}\\{output\_file}[\.{FILE\_NAME\_LENGTH}+\T{1}];{}$\7
460 \&{if} (\\{pk\_files})\5
461 ${}\{{}$\1\6
462 \&{if} (\\{mf\_like})\5
463 ${}\{{}$\1\6
464 \&{if} (\\{unicode})\1\5
465 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s\%02x.\%.0igf"},{}$\6
466 \\{output\_name}${},\39\\{file\_number},\39\\{long\_extension}\?(\&{int})(\\{x%
467 \_resolution}+\T{0.5}):\T{0});{}$\2\6
468 \&{else}\1\5
469 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s\%02i.\%.0igf"},{}$\6
470 \\{output\_name}${},\39\\{file\_number},\39\\{long\_extension}\?(\&{int})(\\{x%
471 \_resolution}+\T{0.5}):\T{0});{}$\2\6
472 \4${}\}{}$\2\6
473 \&{else}\5
474 ${}\{{}$\1\6
475 \&{if} (\\{unicode})\1\5
476 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s\%02x.gf"},\39\\{output\_name},\39%
477 \\{file\_number});{}$\2\6
478 \&{else}\1\5
479 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s\%02i.gf"},\39\\{output\_name},\39%
480 \\{file\_number});{}$\2\6
481 \4${}\}{}$\2\6
482 \&{if} ${}(\R(\\{out}\K\\{fopen}(\\{output\_file},\39\.{WRITE\_BIN}))){}$\5
483 ${}\{{}$\1\6
484 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ open\ `\%s'\\}\)\.{n"},\39\\{output%
485 \_file});{}$\6
486 \\{exit}(\T{1});\6
487 \4${}\}{}$\2\6
488 \&{if} ${}(\R\\{quiet}){}$\1\5
489 ${}\\{printf}(\.{"Writing\ `\%s'\ "},\39\\{output\_file}){}$;\2\7
490 \\{write\_pre}(\,);\6
491 \\{write\_data}(\,);\6
492 \\{write\_post}(\,);\6
493 \\{fclose}(\\{out});\7
494 \&{if} ${}(\R\\{quiet}){}$\1\5
495 \\{printf}(\.{"\\n"});\2\6
496 \4${}\}{}$\2\6
497 \&{else}\1\5
498 \\{write\_data}(\,);\2\6
499 \4${}\}{}$\2\par
500 \fi
501
502 \M{13}
503 The preamble has two bytes at the very beginning, \PB{\.{PRE}} and \PB{\.{GF%
504 \_ID}}. \PB{\.{PRE}}
505 starts the preamble, and \PB{\.{GF\_ID}} is the Generic Font Identity Byte. The
506 next
507 bytes are a string in Pascal format containing a header, the date, and the
508 time. Strings in Pascal format start with the length of the string and have
509 no terminating NULL byte.
510
511 \Y\B\4\D\.{GF\_ID}\5
512 \T{131}\par
513 \B\4\D\.{PRE}\5
514 \T{247}\Y\par
515 \B\4\D\\{headerstring}\5
516 \.{"\ hbf2gf\ output\ "}\par
517 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
518 \&{static} \&{void} \\{write\_pre}(\&{void});\par
519 \fi
520
521 \M{14}
522 \Y\B\1\1\&{static} \&{void} \\{write\_pre}(\&{void})\2\2\6
523 ${}\{{}$\1\6
524 \&{char} \\{out\_s}[\T{40}]${},{}$ \|s[\T{20}];\6
525 \&{time\_t} \\{secs\_now};\6
526 \&{struct} \&{tm} ${}{*}\\{time\_now};{}$\7
527 ${}\\{strcpy}(\\{out\_s},\39\\{headerstring}){}$;\7
528 ${}\\{secs\_now}\K\\{time}(\NULL){}$;\C{ system date and time }\6
529 ${}\\{time\_now}\K\\{localtime}({\AND}\\{secs\_now});{}$\6
530 ${}\\{strftime}(\|s,\39\T{20},\39\.{"\%Y.\%m.\%d:\%H.\%M"},\39\\{time%
531 \_now});{}$\6
532 ${}\\{strcat}(\\{out\_s},\39\|s){}$;\7
533 ${}\\{fputc}(\.{PRE},\39\\{out});{}$\6
534 ${}\\{fputc}(\.{GF\_ID},\39\\{out});{}$\6
535 ${}\\{fputc}(\\{strlen}(\\{out\_s}),\39\\{out});{}$\6
536 ${}\\{fputs}(\\{out\_s},\39\\{out});{}$\6
537 \4${}\}{}$\2\par
538 \fi
539
540 \M{15}
541 \PB{\\{write\_data}(\,)} produces the middle part of the \.{GF} file. It first
542 sets
543 \PB{\\{char\_adr\_p}} equal to the address of \PB{\\{char\_adr}[\,]} which will
544 contain file
545 offsets of the compressed characters.
546
547 \PB{\\{input\_size\_x}} and \PB{\\{input\_size\_y}} reflect the original
548 dimensions of the
549 bitmap font, \PB{\\{pk\_output\_size\_x}} and \PB{\\{pk\_output\_size\_y}}
550 contain the width and
551 height of the output character box (in pixels), \PB{\\{pk\_offset\_x}} and
552 \PB{\\{pk\_offset\_y}} define the baseline of the font. The same names starting
553 with
554 `\\{tfm\_}' instead of `\\{pk\_}' are used for \.{TFM} files (values are
555 multiples of design size). \PB{\\{mag\_x}} and \PB{\\{mag\_y}} hold the scaling
556 factors
557 which are needed to reach \PB{\\{design\_size}}. \PB{\\{slant}} defines the
558 slant ($\Delta
559 x / \Delta y$), \PB{\\{target\_size\_x}} and \PB{\\{target\_size\_y}} will be
560 the final
561 dimensions; \PB{$\\{magstep\_x}\K\\{target\_size\_x}/\\{design\_size}$} is %
562 \TeX's
563 \.{\\magstep}.
564
565 The \CEE/ standard specifies that all global values will be automatically
566 set to~\PB{\T{0}} if no initialization value is given.
567
568 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
569 \&{long} \\{char\_adr}[\T{256}];\6
570 \&{long} ${}{*}\\{char\_adr\_p}{}$;\7
571 \&{int} \\{pk\_offset\_x};\C{ horizontal offset (increase character width a
572 bit; will be applied on both the left and the right side) }\6
573 \&{double} \\{tfm\_offset\_x};\6
574 \&{int} \\{pk\_offset\_y};\C{ vertical offset (must be configured to desired
575 font size) }\6
576 \&{double} \\{tfm\_offset\_y};\7
577 \&{int} \\{input\_size\_x};\6
578 \&{int} \\{input\_size\_y};\6
579 \&{const} \&{char} ${}{*}\\{font\_encoding}{}$;\C{ taken from the HBF file }\6
580 \&{int} \\{pk\_width};\C{ without slant }\6
581 \&{int} \\{pk\_output\_size\_x};\C{ the output character box dimensions without
582 offsets }\6
583 \&{double} \\{tfm\_output\_size\_x};\6
584 \&{int} \\{pk\_output\_size\_y};\6
585 \&{double} \\{tfm\_output\_size\_y};\7
586 \&{double} \\{design\_size}${}\K\T{10.0}{}$;\C{ in points }\6
587 \&{double} \\{target\_size\_x};\C{ in points }\6
588 \&{double} \\{target\_size\_y};\6
589 \&{double} \\{magstep\_x};\6
590 \&{double} \\{magstep\_y};\6
591 \&{double} \\{slant};\6
592 \&{int} \\{rotation};\7
593 \&{double} \\{mag\_x};\C{ horizontal and vertical magnification values }\6
594 \&{double} \\{mag\_y};\7
595 \&{int} \\{empty\_char};\C{ a flag whether the character does not exist or is
596 empty }\6
597 \&{int} \\{last\_char};\C{ the last valid character in a \.{GF} file }\7
598 \&{int} \\{dot\_count};\C{ this counts the processed characters;
599 every ten characters a dot is output to the screen }\par
600 \fi
601
602 \M{16}
603 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
604 \&{static} \&{void} \\{write\_data}(\&{void});\par
605 \fi
606
607 \M{17}
608 \Y\B\1\1\&{static} \&{void} \\{write\_data}(\&{void})\2\2\6
609 ${}\{{}$\1\6
610 ${}\\{dot\_count}\K\T{0};{}$\6
611 ${}\\{char\_adr\_p}\K\\{char\_adr}{}$;\7
612 \&{for} ${}(\\{last\_char}\K\T{0};{}$ ${}(\\{last\_char}<\T{256})\W\R\\{end\_of%
613 \_file};{}$ ${}\\{last\_char}\PP){}$\1\5
614 \X18:Write character\X\2\6
615 \4${}\}{}$\2\par
616 \fi
617
618 \M{18}
619 The code in this section saves the current file position first and calls
620 \PB{\\{make\_pixel\_array}(\,)}, which expands and scales the character bitmap.
621
622 \PB{\.{BOC}} (and \PB{\.{BOC1}}), the Begin Of Character command byte, must be
623 followed by
624 the character code and the dimensions of the character as explained in
625 ``\mf---the program'' (corrected by vertical and horizontal offsets).
626
627 \PB{\\{write\_coding}(\,)} compresses and outputs the bitmap; \PB{\.{EOC}} (End
628 Of Character)
629 finishes the current character.
630
631 \Y\B\4\D\.{BOC}\5
632 \T{67}\par
633 \B\4\D\.{BOC1}\5
634 \T{68}\C{ simplified version of \PB{\.{BOC}} }\par
635 \B\4\D\.{EOC}\5
636 \T{69}\par
637 \Y\B\4\X18:Write character\X${}\E{}$\6
638 ${}\{{}$\1\6
639 \&{if} ${}(\\{dot\_count}\PP\MOD\T{10}\E\T{0}{}$)\C{ a progress report for
640 impatient users }\1\6
641 \&{if} ${}(\\{pk\_files}\W\R\\{quiet}){}$\5
642 ${}\{{}$\1\6
643 \\{printf}(\.{"."});\6
644 \\{fflush}(\\{stdout});\6
645 \4${}\}{}$\2\2\7
646 ${}\\{empty\_char}\K\.{FALSE};{}$\6
647 \\{make\_pixel\_array}(\,);\6
648 \&{if} (\\{end\_of\_file})\1\5
649 \&{return};\2\7
650 \&{if} (\\{pk\_files})\5
651 ${}\{{}$\1\6
652 ${}{*}\\{char\_adr\_p}\K\\{ftell}(\\{out});{}$\6
653 ${}\\{char\_adr\_p}\PP{}$;\7
654 \&{if} (\\{empty\_char})\5
655 ${}\{{}$\1\6
656 ${}\\{fputc}(\.{BOC1},\39\\{out});{}$\6
657 \\{fputc}((\&{unsigned} \&{char}) \\{last\_char}${},\39\\{out});{}$\6
658 ${}\\{fputc}(\T{0},\39\\{out});{}$\6
659 ${}\\{fputc}(\T{0},\39\\{out});{}$\6
660 ${}\\{fputc}(\T{0},\39\\{out});{}$\6
661 ${}\\{fputc}(\T{0},\39\\{out});{}$\6
662 ${}\\{fputc}(\.{EOC},\39\\{out});{}$\6
663 \4${}\}{}$\2\6
664 \&{else}\5
665 ${}\{{}$\1\6
666 ${}\\{fputc}(\.{BOC},\39\\{out});{}$\6
667 ${}\\{fputl}(\\{last\_char},\39\\{out});{}$\6
668 ${}\\{fputl}({-}\T{1\$L},\39\\{out});{}$\6
669 ${}\\{fputl}(\\{pk\_offset\_x},\39\\{out});{}$\6
670 ${}\\{fputl}(\\{pk\_output\_size\_x}+\\{pk\_offset\_x},\39\\{out});{}$\6
671 ${}\\{fputl}(\\{pk\_offset\_y},\39\\{out});{}$\6
672 ${}\\{fputl}(\\{pk\_output\_size\_y}+\\{pk\_offset\_y},\39\\{out}){}$;\7
673 \\{write\_coding}(\,);\7
674 ${}\\{fputc}(\.{EOC},\39\\{out});{}$\6
675 \4${}\}{}$\2\6
676 \4${}\}{}$\2\6
677 \4${}\}{}$\2\par
678 \U17.\fi
679
680 \M{19}
681 The current \.{GF} file will be completed with data written by
682 \PB{\\{write\_post}(\,)}. The end consists of three sections: ``special'',
683 ``post'',
684 and ``postpost''. The first contains material not used by \TeX\ itself but
685 which can be used by other programs like \.{GFtoDVI} or for documentary
686 purposes (\PB{\\{coding}[\,]} and \PB{\\{comment}[\,]}). The second describes
687 the font as a
688 whole, and the last marks the end of the file.
689
690 \PB{\\{pk\_total\_min\_x}} up to \PB{\\{pk\_total\_max\_y}} define the greatest
691 bounding box of
692 this file (including offsets); the horizontal character escapement after
693 drawing the character is \PB{\\{pk\_dx}}. \PB{\\{tfm\_width}} is the width in
694 multiples of
695 the design size ignoring the target size.
696
697 \Y\B\4\D\.{\_2\_16}\5
698 \T{65536.0}\C{ $2^{16}$ }\par
699 \B\4\D\.{\_2\_20}\5
700 \T{1048576.0}\C{ $2^{20}$ }\par
701 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
702 \&{char} ${}\\{coding}[\.{STRING\_LENGTH}+\T{1}]{}$;\C{ a comment describing
703 the font encoding }\6
704 \&{char} ${}\\{comment}[\.{STRING\_LENGTH}+\T{1}]{}$;\C{ a comment describing
705 the font }\7
706 \&{unsigned} \&{long} \\{checksum};\7
707 \&{long} \\{pk\_total\_min\_x};\6
708 \&{long} \\{pk\_total\_max\_x};\6
709 \&{long} \\{pk\_total\_min\_y};\6
710 \&{long} \\{pk\_total\_max\_y};\7
711 \&{int} \\{dpi\_x};\C{ printer resolution }\6
712 \&{int} \\{dpi\_y};\6
713 \&{double} \\{ppp\_x};\C{ pixels per point }\6
714 \&{double} \\{ppp\_y};\par
715 \fi
716
717 \M{20}
718 To clarify the meaning of these values see the sections about the metrics
719 and configuration file also.
720
721 \TeX\ defines that 72.27~points are exactly 1~inch.
722
723 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
724 \&{static} \&{void} \\{write\_post}(\&{void});\par
725 \fi
726
727 \M{21}
728 \Y\B\1\1\&{static} \&{void} \\{write\_post}(\&{void})\2\2\6
729 ${}\{{}$\1\6
730 \&{long} \\{special\_adr};\6
731 \&{long} \\{post\_adr};\7
732 \&{long} \\{designsize}${}\K\\{design\_size}*\.{\_2\_20}{}$;\C{ design size $*
733 2^{20}$ }\7
734 \&{int} \\{pk\_dx};\6
735 \&{long} \\{tfm\_width};\7
736 \&{int} \|i;\6
737 \&{long} \\{temp};\7
738 ${}\\{ppp\_x}\K\\{dpi\_x}/\T{72.27}*\\{magstep\_x};{}$\6
739 ${}\\{ppp\_y}\K\\{dpi\_y}/\T{72.27}*\\{magstep\_y}{}$;\7
740 ${}\\{pk\_total\_min\_x}\K\\{pk\_offset\_x};{}$\6
741 ${}\\{pk\_total\_max\_x}\K\\{pk\_output\_size\_x}+\T{2}*\\{pk\_offset\_x};{}$\6
742 ${}\\{pk\_total\_min\_y}\K\\{pk\_offset\_y};{}$\6
743 ${}\\{pk\_total\_max\_y}\K\\{pk\_output\_size\_y}+\\{pk\_offset\_y}{}$;\7
744 ${}\\{pk\_dx}\K\\{pk\_width}+\T{2}*\\{pk\_offset\_x}{}$;\C{ no slant }\6
745 ${}\\{tfm\_width}\K(\\{tfm\_output\_size\_x}+\T{2}*\\{tfm\_offset\_x})*\.{\_2%
746 \_20}{}$;\C{ width in multiples of design size $* 2^{20}$ }\7
747 \X22:Special section\X\6
748 \X23:Post section\X\6
749 \X24:Postpost section\X\6
750 \4${}\}{}$\2\par
751 \fi
752
753 \M{22}
754 \.{XXXn} will be followed by n~bytes representing the length of a string
755 which follows immediately. \PB{\.{YYY}} is a 32~bit integer which is normally
756 connected with the preceding string (but not used here). \PB{\\{special\_adr}}
757 contains the address of the ``special section''. All items here are
758 optional.
759
760 \Y\B\4\D\.{XXX1}\5
761 \T{239}\C{ these are all special command bytes }\par
762 \B\4\D\.{XXX2}\5
763 \T{240}\C{ not used }\par
764 \B\4\D\.{XXX3}\5
765 \T{241}\C{ not used }\par
766 \B\4\D\.{XXX4}\5
767 \T{242}\C{ not used }\Y\par
768 \B\4\D\.{YYY}\5
769 \T{243}\C{ not used }\par
770 \Y\B\4\X22:Special section\X${}\E{}$\6
771 $\\{special\_adr}\K\\{ftell}(\\{out}){}$;\7
772 \&{if} ${}({*}\\{coding}){}$\5
773 ${}\{{}$\1\6
774 ${}\\{fputc}(\.{XXX1},\39\\{out}){}$;\C{ \PB{\.{XXX1}} implies a string length %
775 \PB{$<$ \T{256}} }\6
776 ${}\\{fputc}(\\{strlen}(\\{coding}),\39\\{out});{}$\6
777 ${}\\{fputs}(\\{coding},\39\\{out});{}$\6
778 \4${}\}{}$\2\7
779 \&{if} ${}({*}\\{comment}){}$\5
780 ${}\{{}$\1\6
781 ${}\\{fputc}(\.{XXX1},\39\\{out});{}$\6
782 ${}\\{fputc}(\\{strlen}(\\{comment}),\39\\{out});{}$\6
783 ${}\\{fputs}(\\{comment},\39\\{out});{}$\6
784 \4${}\}{}$\2\par
785 \U21.\fi
786
787 \M{23}
788 All character offsets collected in \PB{\\{char\_adr}} will be written to the
789 output
790 file. \PB{\\{fputl}(\,)} writes a 32~bit integer into a file.
791
792 \PB{\.{CHAR\_LOC0}} (and \PB{\.{CHAR\_LOC}}) is the first byte of a character
793 locator
794 (i.e., offset, character code, and width information). \PB{\.{POST}} starts the
795 postamble, and \PB{\\{post\_adr}} points to the beginning byte of the
796 postamble.
797
798 \Y\B\4\D\.{POST}\5
799 \T{248}\Y\par
800 \B\4\D\.{CHAR\_LOC}\5
801 \T{245}\par
802 \B\4\D\.{CHAR\_LOC0}\5
803 \T{246}\C{ simplified version of \PB{\.{CHAR\_LOC}} }\par
804 \Y\B\4\X23:Post section\X${}\E{}$\6
805 $\\{post\_adr}\K\\{ftell}(\\{out});{}$\6
806 ${}\\{fputc}(\.{POST},\39\\{out});{}$\6
807 ${}\\{fputl}(\\{special\_adr},\39\\{out}){}$;\7
808 ${}\\{fputl}(\\{designsize},\39\\{out});{}$\6
809 ${}\\{fputl}(\\{checksum},\39\\{out});{}$\6
810 ${}\\{fputl}(\\{ppp\_x}*\.{\_2\_16},\39\\{out});{}$\6
811 ${}\\{fputl}(\\{ppp\_y}*\.{\_2\_16},\39\\{out});{}$\6
812 ${}\\{fputl}(\\{pk\_total\_min\_x},\39\\{out});{}$\6
813 ${}\\{fputl}(\\{pk\_total\_max\_x},\39\\{out});{}$\6
814 ${}\\{fputl}(\\{pk\_total\_min\_y},\39\\{out});{}$\6
815 ${}\\{fputl}(\\{pk\_total\_max\_y},\39\\{out}){}$;\7
816 ${}\\{char\_adr\_p}\K\\{char\_adr}{}$;\7
817 \&{if} ${}(\\{pk\_dx}<\T{256}){}$\5
818 ${}\{{}$\1\6
819 \&{for} ${}(\|i\K\T{0};{}$ ${}\|i<\\{last\_char};{}$ ${}\|i\PP{}$)\C{ the
820 character locators }\6
821 ${}\{{}$\1\6
822 ${}\\{fputc}(\.{CHAR\_LOC0},\39\\{out});{}$\6
823 ${}\\{fputc}(\|i,\39\\{out});{}$\6
824 ${}\\{fputc}(\\{pk\_dx},\39\\{out});{}$\6
825 ${}\\{fputl}(\\{tfm\_width},\39\\{out});{}$\6
826 ${}\\{fputl}({*}\\{char\_adr\_p}\PP,\39\\{out});{}$\6
827 \4${}\}{}$\2\6
828 \4${}\}{}$\2\6
829 \&{else}\C{ will only happen if \PB{$\.{MAX\_CHAR\_SIZE}\G\T{256}$} }\6
830 ${}\{{}$\1\6
831 \&{for} ${}(\|i\K\T{0};{}$ ${}\|i<\\{last\_char};{}$ ${}\|i\PP){}$\5
832 ${}\{{}$\1\6
833 ${}\\{fputc}(\.{CHAR\_LOC},\39\\{out});{}$\6
834 ${}\\{fputc}(\|i,\39\\{out});{}$\6
835 ${}\\{fputl}(\\{pk\_dx}*\.{\_2\_16},\39\\{out});{}$\6
836 ${}\\{fputl}(\T{0},\39\\{out});{}$\6
837 ${}\\{fputl}(\\{tfm\_width},\39\\{out});{}$\6
838 ${}\\{fputl}({*}\\{char\_adr\_p}\PP,\39\\{out});{}$\6
839 \4${}\}{}$\2\6
840 \4${}\}{}$\2\par
841 \U21.\fi
842
843 \M{24}
844 \PB{\.{POSTPOST}} starts the section after the postamble. To get all
845 information in
846 a \.{GF} file, you must start here. The very last bytes of the file have
847 the value \PB{\.{POSTPOST\_ID}} (the file is filled with at least 4 of these
848 bytes
849 until a file length of a multiple of~4 is reached). Going backwards a
850 \PB{\.{GF\_ID}} will be next, then comes the address of the postamble section.
851
852 Jumping to the postamble, a \PB{\.{POST}} byte comes first, then the address of
853 the special section, and afterwards all character offsets. These offsets and
854 addresses describe the whole file.
855
856 \Y\B\4\D\.{POSTPOST}\5
857 \T{249}\par
858 \B\4\D\.{POSTPOST\_ID}\5
859 \T{223}\par
860 \Y\B\4\X24:Postpost section\X${}\E{}$\6
861 $\\{fputc}(\.{POSTPOST},\39\\{out});{}$\6
862 ${}\\{fputl}(\\{post\_adr},\39\\{out});{}$\6
863 ${}\\{fputc}(\.{GF\_ID},\39\\{out});{}$\6
864 ${}\\{temp}\K\\{ftell}(\\{out});{}$\6
865 ${}\|i\K(\&{int})(\\{temp}\MOD\T{4})+\T{4};{}$\6
866 \&{while} ${}(\|i\MM){}$\1\5
867 ${}\\{fputc}(\.{POSTPOST\_ID},\39\\{out}){}$;\2\par
868 \U21.\fi
869
870 \M{25}
871 \TeX\ wants the most significant byte first.
872
873 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
874 \&{static} \&{void} ${}\\{fputl}(\&{long},\39{}$\&{FILE} ${}{*}){}$;\par
875 \fi
876
877 \M{26}
878 \Y\B\1\1\&{static} \&{void} \\{fputl}(\&{long} \\{num}${},\39{}$\&{FILE} ${}{*}%
879 \|f)\2\2{}$\6
880 ${}\{{}$\1\6
881 ${}\\{fputc}(\\{num}\GG\T{24},\39\|f);{}$\6
882 ${}\\{fputc}(\\{num}\GG\T{16},\39\|f);{}$\6
883 ${}\\{fputc}(\\{num}\GG\T{8},\39\|f);{}$\6
884 ${}\\{fputc}(\\{num},\39\|f);{}$\6
885 \4${}\}{}$\2\par
886 \fi
887
888 \M{27}
889 \PB{\\{make\_pixel\_array}(\,)} scales a character into the array \PB{\\{out%
890 \_char}[\,]} where
891 each \\{byte} represents one pixel, contrary to the input file where each
892 \\{bit} is used to store the character bitmap. \PB{\.{BLACK}} indicates a black
893 pixel.
894
895 The scaling routine was modeled after the program \.{pnmscale} of the
896 \.{pbmplus} package. \.{pbmplus} was designed to handle arbitrary pictures,
897 and bitmaps are only a special case of a graymap with values from~0 for
898 white up to \PB{$\.{PIXEL\_MAXVAL}\K\T{255}$} for black.
899
900 If \PB{\.{EOF}} is encountered, \PB{\\{end\_of\_file}} is set and the function
901 returns
902 immediately.
903
904 \Y\B\4\D\.{BLACK}\5
905 \T{1}\par
906 \B\4\D\.{WHITE}\5
907 \T{0}\Y\par
908 \B\4\D\.{PIXEL\_MAXVAL}\5
909 \T{255}\par
910 \B\4\D\.{SCALE}\5
911 \T{4096}\par
912 \B\4\D\.{HALFSCALE}\5
913 \T{2048}\Y\par
914 \B\4\D\.{MAX\_CHAR\_SIZE}\5
915 \T{1023}\par
916 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
917 \&{HBF\_CHAR} \\{code};\6
918 \&{const} \&{unsigned} \&{char} ${}{*}\\{bitmap}{}$;\C{ a proper input bitmap
919 array will be allocated by the HBF API }\6
920 \&{const} \&{unsigned} \&{char} ${}{*}\\{bP}{}$;\7
921 \&{unsigned} \&{char} ${}\\{out\_char}[\.{MAX\_CHAR\_SIZE}*\.{MAX\_CHAR\_SIZE}+%
922 \T{1}]{}$;\C{ the output bitmap array }\6
923 \&{unsigned} \&{char} ${}{*}\\{out\_char\_p}{}$;\7
924 \&{unsigned} \&{char} \\{pixelrow}[\.{MAX\_CHAR\_SIZE}];\6
925 \&{unsigned} \&{char} \\{temp\_pixelrow}[\.{MAX\_CHAR\_SIZE}];\6
926 \&{unsigned} \&{char} ${}\\{new\_pixelrow}[\.{MAX\_CHAR\_SIZE}+\T{1}]{}$;\C{ we
927 need space to append a white pixel }\7
928 \&{int} \\{curr\_row};\C{ for \PB{\\{read\_row}(\,)} if we access the glyph
929 rotated }\6
930 \&{long} \\{grayrow}[\.{MAX\_CHAR\_SIZE}];\7
931 \&{long} \\{s\_mag\_x}${},{}$ \\{s\_mag\_y}${},{}$ \\{s\_slant};\par
932 \fi
933
934 \M{28}
935 We need to initialize the \PB{\\{grayrow}[\,]} array together with some other
936 variables.
937
938 Two steps are necessary to compute the \PB{\\{code}} if we are in the \mf-like
939 mode. Assuming that we search the code \.{0xXXYY}, we first set \PB{\\{code}}
940 to
941 the value \.{0xXXAA}, where \.{0xAA} is equal to \PB{\\{min\_2\_byte}} (getting
942 \PB{\\{offset}} as the number of remaining characters to reach the first
943 character
944 in our given subfont), then we increment \PB{\\{code}} (and decrement \PB{%
945 \\{offset}})
946 until \PB{\\{offset}} equals~0.
947
948 \Y\B\4\X28:Initialize variables\X${}\E{}$\6
949 ${}\{{}$\1\6
950 \&{int} \\{col}${},{}$ \\{offset};\7
951 \&{if} (\\{rotation})\5
952 ${}\{{}$\1\6
953 \&{int} \\{tmp};\7
954 ${}\\{tmp}\K\\{input\_size\_x};{}$\6
955 ${}\\{input\_size\_x}\K\\{input\_size\_y};{}$\6
956 ${}\\{input\_size\_y}\K\\{tmp};{}$\6
957 \4${}\}{}$\2\7
958 \&{if} (\\{mf\_like})\5
959 ${}\{{}$\1\6
960 ${}\\{target\_size\_x}\K\\{design\_size}*(\\{x\_resolution}/\\{dpi\_x});{}$\6
961 ${}\\{target\_size\_y}\K\\{design\_size}*(\\{x\_resolution}*\\{y\_scale}/\\{dpi%
962 \_y});{}$\6
963 \4${}\}{}$\2\6
964 \&{else}\1\5
965 ${}\\{target\_size\_x}\K\\{target\_size\_y}\K\\{design\_size};{}$\2\6
966 ${}\\{magstep\_x}\K\\{target\_size\_x}/\\{design\_size};{}$\6
967 ${}\\{magstep\_y}\K\\{target\_size\_y}/\\{design\_size}{}$;\7
968 ${}\\{pk\_offset\_x}\K\\{offset\_x}*\\{magstep\_x}+\T{0.5};{}$\6
969 ${}\\{pk\_offset\_y}\K\\{offset\_y}*\\{magstep\_y}+\T{0.5};{}$\6
970 ${}\\{tfm\_offset\_x}\K\\{offset\_x}/(\\{dpi\_x}/\T{72.27})/\\{design%
971 \_size};{}$\6
972 ${}\\{tfm\_offset\_y}\K\\{offset\_y}/(\\{dpi\_y}/\T{72.27})/\\{design%
973 \_size}{}$;\7
974 ${}\\{pk\_width}\K\\{input\_size\_x}*\\{mag\_x}*\\{magstep\_x}+\T{0.5}{}$;\C{
975 without slant }\6
976 ${}\\{pk\_output\_size\_x}\K\\{input\_size\_x}*\\{mag\_x}*\\{magstep\_x}+%
977 \\{input\_size\_y}*\\{mag\_y}*\\{magstep\_y}*\\{slant}+\T{0.5};{}$\6
978 ${}\\{pk\_output\_size\_y}\K\\{input\_size\_y}*\\{mag\_y}*\\{magstep\_y}+%
979 \T{0.5};{}$\6
980 ${}\\{tfm\_output\_size\_x}\K\\{input\_size\_x}*\\{mag\_x}/(\\{dpi\_x}/%
981 \T{72.27})/\\{design\_size};{}$\6
982 ${}\\{tfm\_output\_size\_y}\K\\{input\_size\_y}*\\{mag\_y}/(\\{dpi\_y}/%
983 \T{72.27})/\\{design\_size};{}$\6
984 \&{if} ${}(\\{pk\_output\_size\_x}>\.{MAX\_CHAR\_SIZE}){}$\5
985 ${}\{{}$\1\6
986 ${}\\{fprintf}(\\{stderr},\39\.{"Output\ character\ bo}\)\.{x\ width\ too\ big%
987 \\n"});{}$\6
988 \\{exit}(\T{1});\6
989 \4${}\}{}$\2\6
990 \&{if} ${}(\\{pk\_output\_size\_y}>\.{MAX\_CHAR\_SIZE}){}$\5
991 ${}\{{}$\1\6
992 ${}\\{fprintf}(\\{stderr},\39\.{"Output\ character\ bo}\)\.{x\ height\ too\ big%
993 \\n"});{}$\6
994 \\{exit}(\T{1});\6
995 \4${}\}{}$\2\7
996 \&{for} ${}(\\{col}\K\T{0};{}$ ${}\\{col}<\\{input\_size\_x};{}$ ${}\PP%
997 \\{col}){}$\1\5
998 ${}\\{grayrow}[\\{col}]\K\.{HALFSCALE}{}$;\2\7
999 \&{if} ${}(\R\\{mf\_like}){}$\1\5
1000 ${}\\{code}\K(\\{min\_char}\AND\T{\^FF00})+\\{min\_2\_byte};{}$\2\6
1001 \&{else}\5
1002 ${}\{{}$\1\6
1003 \&{if} ${}((\\{file\_number}<(\\{unicode}\?\T{0}:\T{1}))\V(\\{file\_number}\G%
1004 \T{\^100})){}$\5
1005 ${}\{{}$\1\6
1006 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ subfile\ num}\)\.{ber\\n"});{}$\6
1007 \\{exit}(\T{1});\6
1008 \4${}\}{}$\2\7
1009 \&{if} (\\{unicode})\5
1010 ${}\{{}$\1\6
1011 ${}\\{offset}\K\T{0};{}$\6
1012 ${}\\{code}\K\\{file\_number}*\T{\^100};{}$\6
1013 \4${}\}{}$\2\6
1014 \&{else}\5
1015 ${}\{{}$\1\6
1016 ${}\\{offset}\K(\\{file\_number}-\T{1})*\T{256}\MOD\\{nmb\_2\_bytes};{}$\6
1017 ${}\\{code}\K(\\{min\_char}\AND\T{\^FF00})+\\{min\_2\_byte}+(\\{file\_number}-%
1018 \T{1})*\T{256}/\\{nmb\_2\_bytes}*\T{\^100};{}$\6
1019 \4${}\}{}$\2\7
1020 \&{while} ${}(\\{offset}\MM){}$\1\6
1021 \&{while} ${}(\R\\{b2\_codes}[\\{code}\PP\AND\T{\^FF}]{}$)\C{ eliminate invalid
1022 \PB{\\{b2\_codes}} }\1\6
1023 ;\2\2\7
1024 \&{if} ${}(\\{code}>\\{max\_char}){}$\5
1025 ${}\{{}$\1\6
1026 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ subfile\ num}\)\.{ber\\n"});{}$\6
1027 \\{exit}(\T{1});\6
1028 \4${}\}{}$\2\6
1029 \4${}\}{}$\2\6
1030 ${}\\{s\_mag\_x}\K\\{mag\_x}*\\{magstep\_x}*\.{SCALE};{}$\6
1031 ${}\\{s\_mag\_y}\K\\{mag\_y}*\\{magstep\_y}*\.{SCALE};{}$\6
1032 ${}\\{s\_slant}\K\\{slant}*\.{SCALE};{}$\6
1033 \4${}\}{}$\2\par
1034 \U4.\fi
1035
1036 \M{29}
1037 All arrays of the \\{pixelrow} family contain gray values. While scaling
1038 with non-integer values a pixel of the input bitmap will normally not align
1039 with the pixel grid of the output bitmap (geometrically spoken). In this
1040 case we first compute the fractions of input pixel rows scaled vertically
1041 and add the corresponding gray values until a temporary row is produced.
1042 Then we repeat this procedure horizontally pixel by pixel and write the
1043 result into an output array.
1044
1045
1046 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
1047 \&{static} \&{void} \\{make\_pixel\_array}(\&{void});\par
1048 \fi
1049
1050 \M{30}
1051 \Y\B\1\1\&{static} \&{void} \\{make\_pixel\_array}(\&{void})\2\2\6
1052 ${}\{{}$\1\6
1053 \&{unsigned} \&{char} ${}{*}\\{prP};{}$\6
1054 \&{unsigned} \&{char} ${}{*}\\{temp\_prP};{}$\6
1055 \&{unsigned} \&{char} ${}{*}\\{new\_prP};{}$\6
1056 \&{long} ${}{*}\\{grP}{}$;\7
1057 \&{register} \&{unsigned} \&{char} ${}{*}\\{xP};{}$\6
1058 \&{register} \&{unsigned} \&{char} ${}{*}\\{nxP}{}$;\7
1059 \&{register} \&{int} \\{row}${},{}$ \\{col};\6
1060 \&{int} \\{rows\_read}${}\K\T{0};{}$\6
1061 \&{register} \&{int} \\{need\_to\_read\_row}${}\K\T{1}{}$;\7
1062 \&{long} \\{frac\_row\_to\_fill}${}\K\.{SCALE};{}$\6
1063 \&{long} \\{frac\_row\_left}${}\K\\{s\_mag\_y}{}$;\7
1064 \&{int} \\{no\_code}${}\K\.{FALSE};{}$\7
1065 ${}\\{prP}\K\\{pixelrow};{}$\6
1066 ${}\\{temp\_prP}\K\\{temp\_pixelrow};{}$\6
1067 ${}\\{new\_prP}\K\\{new\_pixelrow};{}$\6
1068 ${}\\{grP}\K\\{grayrow};{}$\6
1069 ${}\\{out\_char\_p}\K\\{out\_char}{}$;\C{ will be increased by \PB{\\{write%
1070 \_row}(\,)} }\7
1071 \4\\{again}:\6
1072 \&{if} ${}(\\{b2\_codes}[\\{code}\AND\T{\^FF}]{}$)\C{ a valid second byte? }\6
1073 ${}\{{}$\1\6
1074 \&{if} (\\{pk\_files})\5
1075 ${}\{{}$\1\6
1076 ${}\\{bitmap}\K\\{hbfGetBitmap}(\\{hbf},\39\\{code});{}$\6
1077 ${}\\{bP}\K\\{bitmap}{}$;\C{ will be increased by \PB{\\{read\_row}(\,)} }\7
1078 \&{if} ${}(\R\\{bitmap}){}$\1\5
1079 ${}\\{empty\_char}\K\.{TRUE};{}$\2\6
1080 \&{else}\1\5
1081 \X31:Scale row by row\X\2\6
1082 \4${}\}{}$\2\6
1083 \4${}\}{}$\2\6
1084 \&{else}\1\5
1085 ${}\\{no\_code}\K\.{TRUE}{}$;\2\7
1086 \&{if} ${}((\\{code}\AND\T{\^FF})\E\\{max\_2\_byte}){}$\1\5
1087 ${}\\{code}\MRL{+{\K}}\T{\^FF}-(\\{max\_2\_byte}-\\{min\_2\_byte}){}$;\C{ go to
1088 next plane }\2\6
1089 \&{if} ${}(\\{code}\G\\{max\_char}){}$\5
1090 ${}\{{}$\1\6
1091 ${}\\{end\_of\_file}\K\.{TRUE};{}$\6
1092 \&{return};\6
1093 \4${}\}{}$\2\7
1094 ${}\\{code}\PP{}$;\7
1095 \&{if} (\\{no\_code})\5
1096 ${}\{{}$\1\6
1097 ${}\\{no\_code}\K\.{FALSE};{}$\6
1098 \&{goto} \\{again};\6
1099 \4${}\}{}$\2\6
1100 \4${}\}{}$\2\par
1101 \fi
1102
1103 \M{31}
1104 \Y\B\4\X31:Scale row by row\X${}\E{}$\6
1105 ${}\{{}$\1\6
1106 \&{if} ${}(\\{pk\_output\_size\_y}\E\\{input\_size\_y}{}$)\C{ shortcut
1107 Y~scaling if possible }\1\6
1108 ${}\\{temp\_prP}\K\\{prP}{}$;\2\7
1109 ${}\\{curr\_row}\K\\{input\_size\_y}-\T{1}{}$;\C{ only needed for rotated
1110 glyphs }\6
1111 \&{for} ${}(\\{row}\K\T{0};{}$ ${}\\{row}<\\{pk\_output\_size\_y};{}$ ${}\PP%
1112 \\{row}){}$\5
1113 ${}\{{}$\1\6
1114 \X32:Scale Y from \PB{\\{pixelrow}[\,]} into \PB{\\{temp\_pixelrow}[\,]}\X\6
1115 \X34:Scale X from \PB{\\{temp\_pixelrow}[\,]} into \PB{\\{new\_pixelrow}[\,]}
1116 and write it into \PB{\\{out\_char}[\,]}\X\6
1117 \4${}\}{}$\2\6
1118 \4${}\}{}$\2\par
1119 \U30.\fi
1120
1121 \M{32}
1122 \Y\B\4\X32:Scale Y from \PB{\\{pixelrow}[\,]} into \PB{\\{temp\_pixelrow}[\,]}%
1123 \X${}\E{}$\6
1124 \&{if} ${}(\\{pk\_output\_size\_y}\E\\{input\_size\_y}{}$)\C{ shortcut
1125 Y~scaling if possible }\1\6
1126 \\{read\_row}(\\{prP});\2\6
1127 \&{else}\5
1128 ${}\{{}$\1\6
1129 \&{while} ${}(\\{frac\_row\_left}<\\{frac\_row\_to\_fill}){}$\5
1130 ${}\{{}$\1\6
1131 \&{if} (\\{need\_to\_read\_row})\1\6
1132 \&{if} ${}(\\{rows\_read}<\\{input\_size\_y}){}$\5
1133 ${}\{{}$\1\6
1134 \\{read\_row}(\\{prP});\6
1135 ${}\PP\\{rows\_read};{}$\6
1136 \4${}\}{}$\2\2\7
1137 \&{for} ${}(\\{col}\K\T{0},\39\\{xP}\K\\{prP};{}$ ${}\\{col}<\\{input\_size%
1138 \_x};{}$ ${}\PP\\{col},\39\PP\\{xP}){}$\1\5
1139 ${}\\{grP}[\\{col}]\MRL{+{\K}}\\{frac\_row\_left}*({*}\\{xP}){}$;\2\7
1140 ${}\\{frac\_row\_to\_fill}\MRL{-{\K}}\\{frac\_row\_left};{}$\6
1141 ${}\\{frac\_row\_left}\K\\{s\_mag\_y};{}$\6
1142 ${}\\{need\_to\_read\_row}\K\T{1};{}$\6
1143 \4${}\}{}$\2\7
1144 \X33:Produce a temporary row\X\6
1145 \4${}\}{}$\2\par
1146 \U31.\fi
1147
1148 \M{33}
1149 Now \PB{$\\{frac\_row\_left}\G\\{frac\_row\_to\_fill}$}, so we can produce a
1150 row.
1151
1152 \Y\B\4\X33:Produce a temporary row\X${}\E{}$\6
1153 \&{if} (\\{need\_to\_read\_row})\1\6
1154 \&{if} ${}(\\{rows\_read}<\\{input\_size\_y}){}$\5
1155 ${}\{{}$\1\6
1156 \\{read\_row}(\\{prP});\6
1157 ${}\PP\\{rows\_read};{}$\6
1158 ${}\\{need\_to\_read\_row}\K\T{0};{}$\6
1159 \4${}\}{}$\2\2\7
1160 \&{for} ${}(\\{col}\K\T{0},\39\\{xP}\K\\{prP},\39\\{nxP}\K\\{temp\_prP};{}$ ${}%
1161 \\{col}<\\{input\_size\_x};{}$ ${}\PP\\{col},\39\PP\\{xP},\39\PP\\{nxP}){}$\5
1162 ${}\{{}$\1\6
1163 \&{register} \&{long} \|g;\7
1164 ${}\|g\K\\{grP}[\\{col}]+\\{frac\_row\_to\_fill}*({*}\\{xP});{}$\6
1165 ${}\|g\MRL{{/}{\K}}\.{SCALE};{}$\6
1166 \&{if} ${}(\|g>\.{PIXEL\_MAXVAL}){}$\1\5
1167 ${}\|g\K\.{PIXEL\_MAXVAL}{}$;\2\7
1168 ${}{*}\\{nxP}\K\|g;{}$\6
1169 ${}\\{grP}[\\{col}]\K\.{HALFSCALE};{}$\6
1170 \4${}\}{}$\2\7
1171 ${}\\{frac\_row\_left}\MRL{-{\K}}\\{frac\_row\_to\_fill};{}$\6
1172 \&{if} ${}(\\{frac\_row\_left}\E\T{0}){}$\5
1173 ${}\{{}$\1\6
1174 ${}\\{frac\_row\_left}\K\\{s\_mag\_y};{}$\6
1175 ${}\\{need\_to\_read\_row}\K\T{1};{}$\6
1176 \4${}\}{}$\2\6
1177 ${}\\{frac\_row\_to\_fill}\K\.{SCALE}{}$;\par
1178 \U32.\fi
1179
1180 \M{34}
1181 To implement the slant we move the starting point \PB{\\{nxP}} to the right
1182 according to the corresponding \PB{\|y}~value. To simplify life only positive
1183 shift values are allowed.
1184
1185 We always append a white pixel to avoid artefacts at the end of the line
1186 produced by the last line. This rule sets the second condition that the
1187 slant must not be greater than~\PB{\T{1}}---such a large slant would be
1188 unusable
1189 anyway for typesetting purposes.
1190
1191 \Y\B\4\X34:Scale X from \PB{\\{temp\_pixelrow}[\,]} into \PB{\\{new\_pixelrow}[%
1192 \,]} and write it into \PB{\\{out\_char}[\,]}\X${}\E{}$\6
1193 \&{if} ${}(\\{pk\_width}\E\\{input\_size\_x}\W\\{s\_slant}\E\T{0}{}$)\C{
1194 shortcut X~scaling if possible }\1\6
1195 \\{write\_row}(\\{temp\_prP});\2\6
1196 \&{else}\5
1197 ${}\{{}$\1\6
1198 \&{register} \&{long} \|g${}\K\.{HALFSCALE};{}$\6
1199 \&{register} \&{long} \\{frac\_col\_to\_fill}${}\K\.{SCALE};{}$\6
1200 \&{register} \&{long} \\{frac\_col\_left};\6
1201 \&{register} \&{int} \\{need\_col}${}\K\T{0};{}$\7
1202 ${}\\{nxP}\K\\{new\_prP}{}$;\7
1203 ${}\\{frac\_col\_left}\K(\\{pk\_output\_size\_y}-\\{row})*\\{s\_slant};{}$\6
1204 \&{while} ${}(\\{frac\_col\_left}\G\\{frac\_col\_to\_fill}){}$\5
1205 ${}\{{}$\1\6
1206 ${}{*}(\\{nxP}\PP)\K\T{0};{}$\6
1207 ${}\\{frac\_col\_left}\MRL{-{\K}}\\{frac\_col\_to\_fill};{}$\6
1208 \4${}\}{}$\2\7
1209 \&{if} ${}(\\{frac\_col\_left}>\T{0}){}$\1\5
1210 ${}\\{frac\_col\_to\_fill}\MRL{-{\K}}\\{frac\_col\_left}{}$;\2\7
1211 \&{for} ${}(\\{col}\K\T{0},\39\\{xP}\K\\{temp\_prP};{}$ ${}\\{col}<\\{input%
1212 \_size\_x};{}$ ${}\PP\\{col},\39\PP\\{xP}){}$\5
1213 ${}\{{}$\1\6
1214 ${}\\{frac\_col\_left}\K\\{s\_mag\_x};{}$\6
1215 \&{while} ${}(\\{frac\_col\_left}\G\\{frac\_col\_to\_fill}){}$\5
1216 ${}\{{}$\1\6
1217 \&{if} (\\{need\_col})\5
1218 ${}\{{}$\1\6
1219 ${}\PP\\{nxP};{}$\6
1220 ${}\|g\K\.{HALFSCALE};{}$\6
1221 \4${}\}{}$\2\7
1222 ${}\|g\MRL{+{\K}}\\{frac\_col\_to\_fill}*({*}\\{xP});{}$\6
1223 ${}\|g\MRL{{/}{\K}}\.{SCALE};{}$\6
1224 \&{if} ${}(\|g>\.{PIXEL\_MAXVAL}){}$\1\5
1225 ${}\|g\K\.{PIXEL\_MAXVAL}{}$;\2\7
1226 ${}{*}\\{nxP}\K\|g;{}$\6
1227 ${}\\{frac\_col\_left}\MRL{-{\K}}\\{frac\_col\_to\_fill};{}$\6
1228 ${}\\{frac\_col\_to\_fill}\K\.{SCALE};{}$\6
1229 ${}\\{need\_col}\K\T{1};{}$\6
1230 \4${}\}{}$\2\7
1231 \&{if} ${}(\\{frac\_col\_left}>\T{0}){}$\5
1232 ${}\{{}$\1\6
1233 \&{if} (\\{need\_col})\5
1234 ${}\{{}$\1\6
1235 ${}\PP\\{nxP};{}$\6
1236 ${}\|g\K\.{HALFSCALE};{}$\6
1237 ${}\\{need\_col}\K\T{0};{}$\6
1238 \4${}\}{}$\2\7
1239 ${}\|g\MRL{+{\K}}\\{frac\_col\_left}*({*}\\{xP});{}$\6
1240 ${}\\{frac\_col\_to\_fill}\MRL{-{\K}}\\{frac\_col\_left};{}$\6
1241 \4${}\}{}$\2\6
1242 \4${}\}{}$\2\7
1243 \X35:Write out a row\X\6
1244 \4${}\}{}$\2\par
1245 \U31.\fi
1246
1247 \M{35}
1248 \Y\B\4\X35:Write out a row\X${}\E{}$\6
1249 \&{if} ${}(\\{frac\_col\_to\_fill}>\T{0}){}$\5
1250 ${}\{{}$\1\6
1251 ${}\MM\\{xP};{}$\6
1252 ${}\|g\MRL{+{\K}}\\{frac\_col\_to\_fill}*({*}\\{xP});{}$\6
1253 \4${}\}{}$\2\7
1254 \&{if} ${}(\R\\{need\_col}){}$\5
1255 ${}\{{}$\1\6
1256 ${}\|g\MRL{{/}{\K}}\.{SCALE};{}$\6
1257 \&{if} ${}(\|g>\.{PIXEL\_MAXVAL}){}$\1\5
1258 ${}\|g\K\.{PIXEL\_MAXVAL};{}$\2\6
1259 ${}{*}\\{nxP}\K\|g;{}$\6
1260 \4${}\}{}$\2\7
1261 ${}{*}(\PP\\{nxP})\K\T{0}{}$;\C{ append a blank pixel }\7
1262 \\{write\_row}(\\{new\_prP});\par
1263 \U34.\fi
1264
1265 \M{36}
1266 \PB{\\{read\_row}(\,)} reads a row from \PB{\\{bitmap}[\,]} and converts it
1267 into a graymap row.
1268 If the \PB{\\{rotation}} flag has been set, we get the proper column instead
1269 (note
1270 that in this case \PB{\\{input\_size\_x}} already reflects the width of the
1271 rotated
1272 glyph).
1273
1274 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
1275 \&{static}\6
1276 \8\#\&{ifdef} \.{\_\_GNUC\_\_}\6
1277 \&{\_\_inline\_\_}\6
1278 \8\#\&{endif}\6
1279 \&{void} \\{read\_row}(\&{unsigned} \&{char} ${}{*}){}$;\par
1280 \fi
1281
1282 \M{37}
1283 \Y\B\1\1\&{static}\6
1284 \8\#\&{ifdef} \.{\_\_GNUC\_\_}\6
1285 \&{\_\_inline\_\_}\6
1286 \8\#\&{endif}\6
1287 \&{void} \\{read\_row}(\&{unsigned} \&{char} ${}{*}\\{pixelrow})\2\2{}$\6
1288 ${}\{{}$\1\6
1289 \&{register} \&{int} \\{col}${},{}$ \\{bitshift}${},{}$ \\{offset};\6
1290 \&{register} \&{unsigned} \&{char} ${}{*}\\{xP};{}$\6
1291 \&{register} \&{unsigned} \&{char} \\{item}${}\K\T{0};{}$\7
1292 \&{if} (\\{rotation})\5
1293 ${}\{{}$\1\6
1294 ${}\\{bitshift}\K\T{7}-(\\{curr\_row}\MOD\T{8});{}$\6
1295 ${}\\{offset}\K(\\{input\_size\_y}+\T{7})/\T{8};{}$\6
1296 ${}\\{bP}\K\\{bitmap}+\\{curr\_row}/\T{8};{}$\6
1297 \&{for} ${}(\\{col}\K\T{0},\39\\{xP}\K\\{pixelrow};{}$ ${}\\{col}<\\{input%
1298 \_size\_x};{}$ ${}\PP\\{col},\39\PP\\{xP}){}$\5
1299 ${}\{{}$\1\6
1300 ${}{*}\\{xP}\K(({*}\\{bP}\GG\\{bitshift})\AND\T{1})\E\T{1}\?\.{PIXEL\_MAXVAL}:%
1301 \T{0};{}$\6
1302 ${}\\{bP}\MRL{+{\K}}\\{offset};{}$\6
1303 \4${}\}{}$\2\6
1304 ${}\\{curr\_row}\MM;{}$\6
1305 \4${}\}{}$\2\6
1306 \&{else}\5
1307 ${}\{{}$\1\6
1308 ${}\\{bitshift}\K{-}\T{1};{}$\6
1309 \&{for} ${}(\\{col}\K\T{0},\39\\{xP}\K\\{pixelrow};{}$ ${}\\{col}<\\{input%
1310 \_size\_x};{}$ ${}\PP\\{col},\39\PP\\{xP}){}$\5
1311 ${}\{{}$\1\6
1312 \&{if} ${}(\\{bitshift}\E{-}\T{1}){}$\5
1313 ${}\{{}$\1\6
1314 ${}\\{item}\K{*}(\\{bP}\PP){}$;\C{ increase input bitmap pointer }\6
1315 ${}\\{bitshift}\K\T{7};{}$\6
1316 \4${}\}{}$\2\6
1317 ${}{*}\\{xP}\K((\\{item}\GG\\{bitshift})\AND\T{1})\E\T{1}\?\.{PIXEL\_MAXVAL}:%
1318 \T{0};{}$\6
1319 ${}\MM\\{bitshift};{}$\6
1320 \4${}\}{}$\2\6
1321 \4${}\}{}$\2\6
1322 \4${}\}{}$\2\par
1323 \fi
1324
1325 \M{38}
1326 \PB{\\{write\_row}(\,)} converts the graymap back into a bitmap using a simple
1327 threshold.
1328
1329 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
1330 \&{int} \\{threshold}${}\K\T{128}{}$;\par
1331 \fi
1332
1333 \M{39}
1334 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
1335 \&{static}\6
1336 \8\#\&{ifdef} \.{\_\_GNUC\_\_}\6
1337 \&{\_\_inline\_\_}\6
1338 \8\#\&{endif}\6
1339 \&{void} \\{write\_row}(\&{unsigned} \&{char} ${}{*}){}$;\par
1340 \fi
1341
1342 \M{40}
1343 \Y\B\1\1\&{static}\6
1344 \8\#\&{ifdef} \.{\_\_GNUC\_\_}\6
1345 \&{\_\_inline\_\_}\6
1346 \8\#\&{endif}\6
1347 \&{void} \\{write\_row}(\&{unsigned} \&{char} ${}{*}\\{pixelrow})\2\2{}$\6
1348 ${}\{{}$\1\6
1349 \&{register} \&{int} \\{col};\6
1350 \&{register} \&{unsigned} \&{char} ${}{*}\\{xP};{}$\7
1351 \&{for} ${}(\\{col}\K\T{0},\39\\{xP}\K\\{pixelrow};{}$ ${}\\{col}<\\{pk\_output%
1352 \_size\_x};{}$ ${}\PP\\{col},\39\PP\\{xP}){}$\1\5
1353 ${}{*}(\\{out\_char\_p}\PP)\K({*}\\{xP}\G\\{threshold})\?\T{1}:\T{0}{}$;\C{
1354 increase output bitmap pointer }\2\6
1355 \4${}\}{}$\2\par
1356 \fi
1357
1358 \M{41}
1359 Now comes the most interesting routine. The pixel array will be compressed
1360 in sequences of black and white pixels.
1361
1362 \PB{\.{SKIP0}}, \PB{\.{SKIP1}}, and \PB{\.{SKIP2}} indicate how many blank
1363 lines will be skipped.
1364 \PB{\.{PAINT\_}(\|x)} means that the next x~pixels will have the same color,
1365 then the
1366 color changes. \PB{\.{NEW\_ROW\_}(\|x)} is the first black pixel in the next
1367 row.
1368
1369 An example: the pixel sequence 111100011001 [new row] 000111011110 will be
1370 output as 4 3 2 2 1 77 3 1 4 1.
1371
1372 Commands with an ending~`n' in its name indicate that the next n~bytes
1373 should be read as the counter. Example: \PB{\.{SKIP1}}~26 means `skip the next
1374 26~rows'.
1375
1376 For further details please refer to ``\mf---the program''.
1377
1378 \Y\B\4\D\.{PAINT\_}$(\|x)$\5
1379 (\|x)\C{ $0 \le x \le 63$ }\par
1380 \B\4\D\.{PAINT1}\5
1381 \T{64}\par
1382 \B\4\D\.{PAINT2}\5
1383 \T{65}\par
1384 \B\4\D\.{PAINT3}\5
1385 \T{66}\C{ not used }\Y\par
1386 \B\4\D\.{SKIP0}\5
1387 \T{70}\par
1388 \B\4\D\.{SKIP1}\5
1389 \T{71}\par
1390 \B\4\D\.{SKIP2}\5
1391 \T{72}\par
1392 \B\4\D\.{SKIP3}\5
1393 \T{73}\C{ not used }\Y\par
1394 \B\4\D\.{NEW\_ROW\_}$(\|x)$\5
1395 $((\|x)+\T{74}{}$)\C{ $0 \le x \le 164$ }\Y\par
1396 \B\4\D\.{NOOP}\5
1397 \T{244}\C{ not used }\par
1398 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
1399 \&{static} \&{void} \\{write\_coding}(\&{void});\par
1400 \fi
1401
1402 \M{42}
1403 The \PB{\&{goto} \\{start}} instruction causes some compilers to complain about
1404 ``Unreachable code $\ldots$'' or something similar.
1405
1406 \Y\B\1\1\&{static} \&{void} \\{write\_coding}(\&{void})\2\2\6
1407 ${}\{{}$\1\6
1408 \&{register} \&{int} \\{count}${},{}$ \\{skip};\6
1409 \&{register} \&{unsigned} \&{char} \\{paint};\6
1410 \&{register} \&{int} \|x${},{}$ \|y;\6
1411 \&{register} \&{unsigned} \&{char} ${}{*}\\{cp};{}$\7
1412 ${}\|x\K\T{0};{}$\6
1413 ${}\|y\K\T{0};{}$\6
1414 ${}\\{cp}\K\\{out\_char}+\|y*\\{pk\_output\_size\_x}+\|x;{}$\6
1415 ${}\\{count}\K\\{skip}\K\T{0};{}$\6
1416 ${}\\{paint}\K\.{WHITE};{}$\6
1417 \&{goto} \\{start};\7
1418 \&{while} ${}(\|y<\\{pk\_output\_size\_y}){}$\5
1419 ${}\{{}$\1\6
1420 \X43:Search blank lines\X\6
1421 \4\\{start}:\5
1422 \X44:Process rest of line\X\6
1423 ${}\|y\PP;{}$\6
1424 \4${}\}{}$\2\6
1425 \4${}\}{}$\2\Y\par
1426 \fi
1427
1428 \M{43}
1429 \Y\B\4\X43:Search blank lines\X${}\E{}$\6
1430 $\\{count}\K\T{0};{}$\6
1431 ${}\|x\K\T{0};{}$\6
1432 ${}\\{cp}\K\\{out\_char}+\|y*\\{pk\_output\_size\_x}+\|x{}$;\7
1433 \&{while} ${}(\|x<\\{pk\_output\_size\_x}){}$\5
1434 ${}\{{}$\1\6
1435 \&{if} ${}({*}\\{cp}\E\\{paint}){}$\1\5
1436 ${}\\{count}\PP;{}$\2\6
1437 \&{else}\5
1438 ${}\{{}$\1\6
1439 \&{if} ${}(\\{skip}\E\T{0}){}$\5
1440 ${}\{{}$\1\6
1441 \&{if} ${}(\\{count}\Z\T{164}){}$\1\5
1442 ${}\\{fputc}(\.{NEW\_ROW\_}(\\{count}),\39\\{out});{}$\2\6
1443 \&{else}\5
1444 ${}\{{}$\1\6
1445 ${}\\{fputc}(\.{SKIP0},\39\\{out}){}$;\7
1446 \&{if} ${}(\\{count}<\T{256}){}$\5
1447 ${}\{{}$\1\6
1448 ${}\\{fputc}(\.{PAINT1},\39\\{out});{}$\6
1449 ${}\\{fputc}(\\{count},\39\\{out});{}$\6
1450 \4${}\}{}$\2\6
1451 \&{else}\5
1452 ${}\{{}$\1\6
1453 ${}\\{fputc}(\.{PAINT2},\39\\{out});{}$\6
1454 ${}\\{fputc}(\\{count}\GG\T{8},\39\\{out});{}$\6
1455 ${}\\{fputc}(\\{count}\AND\T{\^FF},\39\\{out});{}$\6
1456 \4${}\}{}$\2\6
1457 \4${}\}{}$\2\6
1458 \4${}\}{}$\2\6
1459 \&{else}\5
1460 ${}\{{}$\1\6
1461 \&{if} ${}(\\{skip}\E\T{1}){}$\1\5
1462 ${}\\{fputc}(\.{SKIP0},\39\\{out});{}$\2\6
1463 \&{else}\5
1464 ${}\{{}$\1\6
1465 \&{if} ${}(\\{skip}<\T{256}){}$\5
1466 ${}\{{}$\1\6
1467 ${}\\{fputc}(\.{SKIP1},\39\\{out});{}$\6
1468 ${}\\{fputc}(\\{skip},\39\\{out});{}$\6
1469 \4${}\}{}$\2\6
1470 \&{else}\5
1471 ${}\{{}$\1\6
1472 ${}\\{fputc}(\.{SKIP2},\39\\{out});{}$\6
1473 ${}\\{fputc}(\\{skip}\GG\T{8},\39\\{out});{}$\6
1474 ${}\\{fputc}(\\{skip}\AND\T{\^FF},\39\\{out});{}$\6
1475 \4${}\}{}$\2\6
1476 \4${}\}{}$\2\6
1477 ${}\\{skip}\K\T{0};{}$\6
1478 \&{if} ${}(\\{count}<\T{64}){}$\1\5
1479 ${}\\{fputc}(\.{PAINT\_}(\\{count}),\39\\{out});{}$\2\6
1480 \&{else} \&{if} ${}(\\{count}<\T{256}){}$\5
1481 ${}\{{}$\1\6
1482 ${}\\{fputc}(\.{PAINT1},\39\\{out});{}$\6
1483 ${}\\{fputc}(\\{count},\39\\{out});{}$\6
1484 \4${}\}{}$\2\6
1485 \&{else}\5
1486 ${}\{{}$\1\6
1487 ${}\\{fputc}(\.{PAINT2},\39\\{out});{}$\6
1488 ${}\\{fputc}(\\{count}\GG\T{8},\39\\{out});{}$\6
1489 ${}\\{fputc}(\\{count}\AND\T{\^FF},\39\\{out});{}$\6
1490 \4${}\}{}$\2\6
1491 \4${}\}{}$\2\6
1492 ${}\\{count}\K\T{0};{}$\6
1493 ${}\\{paint}\K\.{BLACK};{}$\6
1494 \&{break};\6
1495 \4${}\}{}$\2\6
1496 ${}\|x\PP;{}$\6
1497 ${}\\{cp}\PP;{}$\6
1498 \4${}\}{}$\2\6
1499 \&{if} ${}(\|x\G\\{pk\_output\_size\_x}){}$\5
1500 ${}\{{}$\1\6
1501 ${}\\{skip}\PP;{}$\6
1502 ${}\|y\PP;{}$\6
1503 \&{continue};\6
1504 \4${}\}{}$\2\par
1505 \U42.\fi
1506
1507 \M{44}
1508 \Y\B\4\X44:Process rest of line\X${}\E{}$\6
1509 \&{while} ${}(\|x<\\{pk\_output\_size\_x}){}$\5
1510 ${}\{{}$\1\6
1511 \&{if} ${}({*}\\{cp}\E\\{paint}){}$\1\5
1512 ${}\\{count}\PP;{}$\2\6
1513 \&{else}\5
1514 ${}\{{}$\1\6
1515 \&{if} ${}(\\{count}<\T{64}){}$\1\5
1516 ${}\\{fputc}(\.{PAINT\_}(\\{count}),\39\\{out});{}$\2\6
1517 \&{else} \&{if} ${}(\\{count}<\T{256}){}$\5
1518 ${}\{{}$\1\6
1519 ${}\\{fputc}(\.{PAINT1},\39\\{out});{}$\6
1520 ${}\\{fputc}(\\{count},\39\\{out});{}$\6
1521 \4${}\}{}$\2\6
1522 \&{else}\5
1523 ${}\{{}$\1\6
1524 ${}\\{fputc}(\.{PAINT2},\39\\{out});{}$\6
1525 ${}\\{fputc}(\\{count}\GG\T{8},\39\\{out});{}$\6
1526 ${}\\{fputc}(\\{count}\AND\T{\^FF},\39\\{out});{}$\6
1527 \4${}\}{}$\2\6
1528 ${}\\{count}\K\T{1};{}$\6
1529 ${}\\{paint}\K\.{BLACK}-\\{paint};{}$\6
1530 \4${}\}{}$\2\6
1531 ${}\|x\PP;{}$\6
1532 ${}\\{cp}\PP;{}$\6
1533 \4${}\}{}$\2\6
1534 \&{if} ${}(\\{paint}\E\.{BLACK}){}$\5
1535 ${}\{{}$\1\6
1536 \&{if} ${}(\\{count}<\T{64}){}$\1\5
1537 ${}\\{fputc}(\.{PAINT\_}(\\{count}),\39\\{out});{}$\2\6
1538 \&{else} \&{if} ${}(\\{count}<\T{256}){}$\5
1539 ${}\{{}$\1\6
1540 ${}\\{fputc}(\.{PAINT1},\39\\{out});{}$\6
1541 ${}\\{fputc}(\\{count},\39\\{out});{}$\6
1542 \4${}\}{}$\2\6
1543 \&{else}\5
1544 ${}\{{}$\1\6
1545 ${}\\{fputc}(\.{PAINT2},\39\\{out});{}$\6
1546 ${}\\{fputc}(\\{count}\GG\T{8},\39\\{out});{}$\6
1547 ${}\\{fputc}(\\{count}\AND\T{\^FF},\39\\{out});{}$\6
1548 \4${}\}{}$\2\6
1549 ${}\\{paint}\K\.{WHITE};{}$\6
1550 \4${}\}{}$\2\par
1551 \U42.\fi
1552
1553 \N{1}{45}The font metrics file.
1554 This routine creates one \.{PL} file with the font properties. None of the
1555 \TeX\ font dimensions are needed because you never will use CJK fonts
1556 directly, and intercharacter stretching is handled by the \\{CJK} macro
1557 \.{\\CJKglue}. (Other packages may define similar commands.)
1558
1559 The name of the \.{PL} file will contain the running two digits in
1560 \mf-like mode only.
1561
1562 It makes sense \\{not} to compute the check sum automatically for two
1563 reasons. Firstly, since \TeX's checksum algorithm is based on the character
1564 width, the number of valid characters, and the designsize, there is a much
1565 higher chance that two subfonts from different HBF fonts have the same check
1566 sum than it is for ordinary fonts, because all characters have the same
1567 width, usually 256~characters in a subfont, and very often the same design
1568 size. Secondly, and this is more important, we create just one
1569 \.{TFM} file for all subfonts regardless of the real number of characters
1570 in a particular subfont.
1571
1572 To have an identification string in the \.{TFM} file, we split it into
1573 single bytes and use the \.{HEADER} command repeatedly.
1574
1575 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
1576 \&{static} \&{void} \\{write\_pl}(\&{void});\par
1577 \fi
1578
1579 \M{46}
1580 \Y\B\1\1\&{static} \&{void} \\{write\_pl}(\&{void})\2\2\6
1581 ${}\{{}$\1\6
1582 \&{int} \|i${},{}$ \\{pos};\6
1583 \&{char} ${}\\{output\_file}[\.{FILE\_NAME\_LENGTH}+\T{1}];{}$\6
1584 \&{long} \|t${},{}$ \\{sc};\6
1585 \&{char} ${}{*}\|s;{}$\6
1586 \&{char} \\{tfm\_header}[\,]${}\K\.{"Created\ by\ hbf2gf"};{}$\7
1587 ${}\\{file\_number}\MM{}$;\C{ for \mf-like mode }\7
1588 \&{if} (\\{mf\_like})\5
1589 ${}\{{}$\1\6
1590 \&{if} (\\{unicode})\1\5
1591 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s\%02x.pl"},\39\\{output\_name},\39%
1592 \\{file\_number});{}$\2\6
1593 \&{else}\1\5
1594 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s\%02i.pl"},\39\\{output\_name},\39%
1595 \\{file\_number});{}$\2\6
1596 \4${}\}{}$\2\6
1597 \&{else}\1\5
1598 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s.pl"},\39\\{output\_name}){}$;\2\7
1599 \&{if} ${}(\R(\\{out}\K\\{fopen}(\\{output\_file},\39\.{WRITE\_TXT}))){}$\5
1600 ${}\{{}$\1\6
1601 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ open\ `\%s'\\}\)\.{n"},\39\\{output%
1602 \_file});{}$\6
1603 \\{exit}(\T{1});\6
1604 \4${}\}{}$\2\6
1605 \&{if} ${}(\R\\{quiet}){}$\1\5
1606 ${}\\{printf}(\.{"\\nWriting\ `\%s'\\n"},\39\\{output\_file}){}$;\2\7
1607 ${}\\{fprintf}(\\{out},{}$\6
1608 \.{"\\n(FAMILY\ \%s\%d)"}\6
1609 \.{"\\n(CODINGSCHEME\ CJK}\)\.{-\%s)"}${},\39\\{output\_name},\39\\{file%
1610 \_number},\39\\{font\_encoding}){}$;\7
1611 ${}\\{fprintf}(\\{out},{}$\6
1612 \.{"\\n(DESIGNSIZE\ R\ \%.6}\)\.{f)"}\6
1613 \.{"\\n(COMMENT\ DESIGNSI}\)\.{ZE\ IS\ IN\ POINTS)"}\6
1614 \.{"\\n(COMMENT\ OTHER\ SI}\)\.{ZES\ ARE\ MULTIPLES\ OF}\)\.{\ DESIGNSIZE)"}\6
1615 \.{"\\n(CHECKSUM\ O\ \%lo)"}\6
1616 \.{"\\n(FONTDIMEN"}\6
1617 \.{"\\n\ \ \ (SLANT\ R\ \%.6f)}\)\.{"}\6
1618 \.{"\\n\ \ \ (SPACE\ R\ 0.0)"}\6
1619 \.{"\\n\ \ \ (STRETCH\ R\ 0.0}\)\.{)"}\6
1620 \.{"\\n\ \ \ (SHRINK\ R\ 0.0)}\)\.{"}\6
1621 \.{"\\n\ \ \ (XHEIGHT\ R\ 1.0}\)\.{)"}\6
1622 \.{"\\n\ \ \ (QUAD\ R\ 1.0)"}\6
1623 \.{"\\n\ \ \ (EXTRASPACE\ R\ }\)\.{0.0)"}\6
1624 \.{"\\n\ \ \ )"}${},\39\\{design\_size},\39\\{checksum},\39\\{slant}){}$;\7
1625 ${}\|s\K\\{tfm\_header};{}$\6
1626 ${}\|i\K\\{strlen}(\|s);{}$\6
1627 ${}\|t\K{}$((\&{long}) \|i)${}\LL\T{24};{}$\6
1628 ${}\\{sc}\K\T{16};{}$\6
1629 ${}\\{pos}\K\T{18}{}$;\7
1630 ${}\\{fprintf}(\\{out},\39\.{"\\n"});{}$\6
1631 \&{while} ${}(\|i>\T{0}){}$\5
1632 ${}\{{}$\1\6
1633 ${}\|t\MRL{{\OR}{\K}}((\&{long})({*}{}$(\&{unsigned} \&{char} ${}{*}){}$ \|s${}%
1634 \PP))\LL\\{sc};{}$\6
1635 ${}\\{sc}\MRL{-{\K}}\T{8};{}$\6
1636 \&{if} ${}(\\{sc}<\T{0}){}$\5
1637 ${}\{{}$\1\6
1638 ${}\\{fprintf}(\\{out},\39\.{"\\n(HEADER\ D\ \%d\ O\ \%l}\)\.{o)"},\39\\{pos},%
1639 \39\|t);{}$\6
1640 ${}\|t\K\T{0};{}$\6
1641 ${}\\{sc}\K\T{24};{}$\6
1642 ${}\\{pos}\PP;{}$\6
1643 \4${}\}{}$\2\6
1644 ${}\|i\MM;{}$\6
1645 \4${}\}{}$\2\6
1646 \&{if} (\|t)\1\5
1647 ${}\\{fprintf}(\\{out},\39\.{"\\n(HEADER\ D\ \%d\ O\ \%l}\)\.{o)"},\39\\{pos},%
1648 \39\|t);{}$\2\6
1649 ${}\\{fprintf}(\\{out},\39\.{"\\n"}){}$;\7
1650 \&{for} ${}(\|i\K\T{0};{}$ ${}\|i<\T{256};{}$ ${}\|i\PP){}$\5
1651 ${}\{{}$\1\6
1652 ${}\\{fprintf}(\\{out},{}$\6
1653 \.{"\\n(CHARACTER\ O\ \%o"}\6
1654 \.{"\\n\ \ \ (CHARWD\ R\ \%.6f}\)\.{)"}\6
1655 \.{"\\n\ \ \ (CHARHT\ R\ \%.6f}\)\.{)"}\6
1656 \.{"\\n\ \ \ (CHARDP\ R\ \%.6f}\)\.{)"}\6
1657 \.{"\\n\ \ \ (CHARIC\ R\ \%.6f}\)\.{)"}\6
1658 \.{"\\n\ \ \ )"}${},{}$\6
1659 \|i${},\39\\{tfm\_output\_size\_x}+\T{2}*\\{tfm\_offset\_x},\39\\{tfm\_output%
1660 \_size\_y}+\\{tfm\_offset\_y},\39{-}\\{tfm\_offset\_y},\39\\{slant}*(\\{tfm%
1661 \_output\_size\_y}+\\{tfm\_offset\_y}));{}$\6
1662 \4${}\}{}$\2\7
1663 \\{fclose}(\\{out});\6
1664 \4${}\}{}$\2\par
1665 \fi
1666
1667 \N{1}{47}The extended virtual font file for \Om.
1668 The following is very similar to \PB{\\{write\_pl}(\,)}; we simply map the
1669 glyphs
1670 of the subfonts back to the original encoding positions.
1671
1672 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
1673 \&{static} \&{void} \\{write\_ovp}(\&{void});\par
1674 \fi
1675
1676 \M{48}
1677 \Y\B\1\1\&{static} \&{void} \\{write\_ovp}(\&{void})\2\2\6
1678 ${}\{{}$\1\6
1679 \&{int} \|c${},{}$ \|i${},{}$ \\{nmb\_subfonts}${},{}$ \\{remainder}${},{}$ %
1680 \\{count}${},{}$ \\{pos};\6
1681 \&{char} ${}\\{output\_file}[\.{FILE\_NAME\_LENGTH}+\T{1}];{}$\6
1682 \&{long} \|t${},{}$ \\{sc};\6
1683 \&{char} ${}{*}\|s;{}$\6
1684 \&{char} \\{ofm\_header}[\,]${}\K\.{"Created\ by\ hbf2gf"};{}$\7
1685 ${}\\{nmb\_subfonts}\K((\\{max\_char}-(\\{min\_char}\AND\T{\^FF00}))/\T{256}*%
1686 \\{nmb\_2\_bytes})/\T{256}+\T{1};{}$\6
1687 ${}\\{remainder}\K((\\{max\_char}-(\\{min\_char}\AND\T{\^FF00}))/\T{256}*\\{nmb%
1688 \_2\_bytes})\MOD\T{256}{}$;\C{ correction for the last incomplete second byte
1689 range }\6
1690 \&{for} ${}(\\{count}\K\T{0};{}$ ${}\\{count}<(\\{max\_char}\AND\T{\^FF});{}$
1691 ${}\\{count}\PP){}$\1\6
1692 \&{if} (\\{b2\_codes}[\\{count}])\1\5
1693 ${}\\{remainder}\PP;{}$\2\2\6
1694 \&{if} ${}(\\{remainder}\G\T{256}){}$\1\5
1695 ${}\\{nmb\_subfonts}\PP{}$;\2\7
1696 ${}\\{sprintf}(\\{output\_file},\39\.{"\%s.ovp"},\39\\{output\_name}){}$;\7
1697 \&{if} ${}(\R(\\{out}\K\\{fopen}(\\{output\_file},\39\.{WRITE\_TXT}))){}$\5
1698 ${}\{{}$\1\6
1699 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ open\ `\%s'\\}\)\.{n"},\39\\{output%
1700 \_file});{}$\6
1701 \\{exit}(\T{1});\6
1702 \4${}\}{}$\2\6
1703 \&{if} ${}(\R\\{quiet}){}$\1\5
1704 ${}\\{printf}(\.{"\\nWriting\ `\%s'\\n"},\39\\{output\_file}){}$;\2\7
1705 ${}\\{fprintf}(\\{out},{}$\6
1706 \.{"\\n(VTITLE\ Omega\ vir}\)\.{tual\ font\ created\ by}\)\.{\ hbf2gf)"}\6
1707 \.{"\\n(DESIGNSIZE\ R\ \%.6}\)\.{f)"}\6
1708 \.{"\\n(COMMENT\ DESIGNSI}\)\.{ZE\ IS\ IN\ POINTS)"}\6
1709 \.{"\\n(COMMENT\ OTHER\ SI}\)\.{ZES\ ARE\ MULTIPLES\ OF}\)\.{\ DESIGNSIZE)"}\6
1710 \.{"\\n(CHECKSUM\ O\ \%lo)"}\6
1711 \.{"\\n(FONTDIMEN"}\6
1712 \.{"\\n\ \ \ (SLANT\ R\ \%.6f)}\)\.{"}\6
1713 \.{"\\n\ \ \ (SPACE\ R\ 0.0)"}\6
1714 \.{"\\n\ \ \ (STRETCH\ R\ 0.0}\)\.{)"}\6
1715 \.{"\\n\ \ \ (SHRINK\ R\ 0.0)}\)\.{"}\6
1716 \.{"\\n\ \ \ (XHEIGHT\ R\ 1.0}\)\.{)"}\6
1717 \.{"\\n\ \ \ (QUAD\ R\ 1.0)"}\6
1718 \.{"\\n\ \ \ (EXTRASPACE\ R\ }\)\.{0.0)"}\6
1719 \.{"\\n\ \ \ )"}${},\39\\{design\_size},\39\\{checksum},\39\\{slant}){}$;\7
1720 ${}\|s\K\\{ofm\_header};{}$\6
1721 ${}\|i\K\\{strlen}(\|s);{}$\6
1722 ${}\|t\K{}$((\&{long}) \|i)${}\LL\T{24};{}$\6
1723 ${}\\{sc}\K\T{16};{}$\6
1724 ${}\\{pos}\K\T{18}{}$;\7
1725 ${}\\{fprintf}(\\{out},\39\.{"\\n"});{}$\6
1726 \&{while} ${}(\|i>\T{0}){}$\5
1727 ${}\{{}$\1\6
1728 ${}\|t\MRL{{\OR}{\K}}((\&{long})({*}{}$(\&{unsigned} \&{char} ${}{*}){}$ \|s${}%
1729 \PP))\LL\\{sc};{}$\6
1730 ${}\\{sc}\MRL{-{\K}}\T{8};{}$\6
1731 \&{if} ${}(\\{sc}<\T{0}){}$\5
1732 ${}\{{}$\1\6
1733 ${}\\{fprintf}(\\{out},\39\.{"\\n(HEADER\ D\ \%d\ O\ \%l}\)\.{o)"},\39\\{pos},%
1734 \39\|t);{}$\6
1735 ${}\|t\K\T{0};{}$\6
1736 ${}\\{sc}\K\T{24};{}$\6
1737 ${}\\{pos}\PP;{}$\6
1738 \4${}\}{}$\2\6
1739 ${}\|i\MM;{}$\6
1740 \4${}\}{}$\2\6
1741 \&{if} (\|t)\1\5
1742 ${}\\{fprintf}(\\{out},\39\.{"\\n(HEADER\ D\ \%d\ O\ \%l}\)\.{o)"},\39\\{pos},%
1743 \39\|t);{}$\2\6
1744 ${}\\{fprintf}(\\{out},\39\.{"\\n"}){}$;\7
1745 \&{for} ${}(\|i\K\T{0};{}$ ${}\|i<\\{nmb\_subfonts};{}$ ${}\|i\PP){}$\5
1746 ${}\{{}$\1\6
1747 ${}\\{fprintf}(\\{out},{}$\6
1748 \.{"\\n(MAPFONT\ D\ \%i"}\6
1749 \.{"\\n\ \ \ (FONTNAME\ \%s\%0}\)\.{2i)"}\6
1750 \.{"\\n\ \ \ (FONTCHECKSUM\ }\)\.{O\ \%lo)"}\6
1751 \.{"\\n\ \ \ (FONTAT\ R\ 1.0)}\)\.{"}\6
1752 \.{"\\n\ \ \ (FONTDSIZE\ R\ \%}\)\.{.6f)"}\6
1753 \.{"\\n\ \ \ )"}${},\39\|i,\39\\{output\_name},\39\|i+\T{1},\39\\{checksum},\39%
1754 \\{design\_size});{}$\6
1755 \4${}\}{}$\2\7
1756 \&{for} ${}(\|c\K\\{min\_char},\39\|i\K\T{0},\39\\{count}\K\T{0};{}$ ${}\|c\Z%
1757 \\{max\_char};{}$ ${}\|c\PP){}$\5
1758 ${}\{{}$\1\6
1759 \&{if} ${}(\\{b2\_codes}[\|c\AND\T{\^FF}]\E\.{VALID\_SUBCODE}){}$\5
1760 ${}\{{}$\1\6
1761 ${}\\{fprintf}(\\{out},{}$\6
1762 \.{"\\n(CHARACTER\ O\ \%o"}\6
1763 \.{"\\n\ \ \ (CHARWD\ R\ \%.6f}\)\.{)"}\6
1764 \.{"\\n\ \ \ (CHARHT\ R\ \%.6f}\)\.{)"}\6
1765 \.{"\\n\ \ \ (CHARDP\ R\ \%.6f}\)\.{)"}\6
1766 \.{"\\n\ \ \ (CHARIC\ R\ \%.6f}\)\.{)"}\6
1767 \.{"\\n\ \ \ (MAP"}\6
1768 \.{"\\n\ \ \ \ \ \ (SELECTFONT}\)\.{\ D\ \%i)"}\6
1769 \.{"\\n\ \ \ \ \ \ (SETCHAR\ O\ }\)\.{\%o)"}\6
1770 \.{"\\n\ \ \ \ \ \ )"}\6
1771 \.{"\\n\ \ \ )"}${},{}$\6
1772 \|c${},\39\\{tfm\_output\_size\_x}+\T{2}*\\{tfm\_offset\_x},\39\\{tfm\_output%
1773 \_size\_y}+\\{tfm\_offset\_y},\39{-}\\{tfm\_offset\_y},\39\\{slant}*(\\{tfm%
1774 \_output\_size\_y}+\\{tfm\_offset\_y}),\39\|i,\39\\{count}){}$;\7
1775 ${}\\{count}\PP;{}$\6
1776 \&{if} ${}(\\{count}\E\T{256}){}$\5
1777 ${}\{{}$\1\6
1778 ${}\\{count}\K\T{0};{}$\6
1779 ${}\|i\PP;{}$\6
1780 \4${}\}{}$\2\6
1781 \4${}\}{}$\2\6
1782 \&{else}\1\5
1783 \&{continue};\2\6
1784 \4${}\}{}$\2\7
1785 \\{fclose}(\\{out});\6
1786 \4${}\}{}$\2\par
1787 \fi
1788
1789 \N{1}{49}The job file.
1790 This routine is the most system specific one. If your operating system needs
1791 a different outline, make appropriate changes here.
1792
1793 You have to call this batch file after \.{hbf2gf} has finished (if not in
1794 \mf-like mode). It will transform the \.{GF} files into \.{PK} files and
1795 delete the now unnecessary \.{GF} files, then transform the \.{PL} file into
1796 a \.{TFM} file and copy it \PB{\\{nmb\_files}} times. The name of the job file
1797 is
1798 \PB{\\{output\_name}}.
1799
1800 \Y\B\4\D\.{EXTENSION\_LENGTH}\5
1801 \T{8}\C{ the maximal length of a file extension }\Y\par
1802 \B\4\D\.{GFTOPK\_NAME}\5
1803 \.{"gftopk"}\par
1804 \B\4\D\.{PLTOTF\_NAME}\5
1805 \.{"pltotf"}\par
1806 \B\4\D\.{OVP2OVF\_NAME}\5
1807 \.{"ovp2ovf"}\par
1808 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
1809 \&{char} ${}\\{job\_extension}[\.{EXTENSION\_LENGTH}+\T{1}];{}$\6
1810 \&{char} ${}\\{rm\_command}[\.{STRING\_LENGTH}+\T{1}];{}$\6
1811 \&{char} ${}\\{cp\_command}[\.{STRING\_LENGTH}+\T{1}];{}$\6
1812 \&{char} ${}\\{pk\_directory}[\.{STRING\_LENGTH}+\T{1}];{}$\6
1813 \&{char} ${}\\{tfm\_directory}[\.{STRING\_LENGTH}+\T{1}]{}$;\7
1814 \&{int} \\{ofm\_file}${}\K\.{FALSE}{}$;\par
1815 \fi
1816
1817 \M{50}
1818 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
1819 \&{static} \&{void} \\{write\_job}(\&{void});\par
1820 \fi
1821
1822 \M{51}
1823 \Y\B\1\1\&{static} \&{void} \\{write\_job}(\&{void})\2\2\6
1824 ${}\{{}$\1\6
1825 \&{FILE} ${}{*}\\{out};{}$\6
1826 \&{int} \|i${},{}$ \|j;\6
1827 \&{char} ${}\\{buffer}[\.{FILE\_NAME\_LENGTH}+\T{1}];{}$\7
1828 ${}\\{strcpy}(\\{buffer},\39\\{output\_name});{}$\6
1829 ${}\\{strcat}(\\{buffer},\39\\{job\_extension});{}$\6
1830 \&{if} ${}(\R(\\{out}\K\\{fopen}(\\{buffer},\39\.{WRITE\_TXT}))){}$\5
1831 ${}\{{}$\1\6
1832 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ open\ `\%s'\\}\)\.{n"},\39%
1833 \\{buffer});{}$\6
1834 \\{exit}(\T{1});\6
1835 \4${}\}{}$\2\6
1836 \&{if} ${}(\R\\{quiet}){}$\1\5
1837 ${}\\{printf}(\.{"\\nWriting\ `\%s'\\n"},\39\\{buffer}){}$;\2\7
1838 \&{if} (\\{pk\_files})\5
1839 ${}\{{}$\1\6
1840 \&{if} (\\{unicode})\5
1841 ${}\{{}$\1\6
1842 \&{for} ${}(\|i\K(\\{min\_char}\GG\T{8}),\39\|j\K\T{0};{}$ ${}\|j<\\{nmb%
1843 \_files};{}$ ${}\|i\PP,\39\|j\PP){}$\1\5
1844 ${}\\{fprintf}(\\{out},{}$\6
1845 \.{"\%s\ \%s\%02x.gf\ \%s\%s\%0}\)\.{2x.\%.0ipk\\n"}\6
1846 \.{"\%s\ \%s\%02x.gf\\n"}${},{}$\6
1847 \.{GFTOPK\_NAME}${},\39\\{output\_name},\39\|i,{}$\6
1848 \\{pk\_directory}${},\39\\{output\_name},\39\|i,\39\\{long\_extension}\?(%
1849 \&{int})(\\{dpi\_x}*\\{magstep\_x}+\T{0.5}):\T{0},{}$\6
1850 \\{rm\_command}${},\39\\{output\_name},\39\|i);{}$\2\6
1851 \4${}\}{}$\2\6
1852 \&{else}\5
1853 ${}\{{}$\1\6
1854 \&{for} ${}(\|i\K\T{1};{}$ ${}\|i\Z\\{nmb\_files};{}$ ${}\|i\PP){}$\1\5
1855 ${}\\{fprintf}(\\{out},{}$\6
1856 \.{"\%s\ \%s\%02i.gf\ \%s\%s\%0}\)\.{2i.\%.0ipk\\n"}\6
1857 \.{"\%s\ \%s\%02i.gf\\n"}${},{}$\6
1858 \.{GFTOPK\_NAME}${},\39\\{output\_name},\39\|i,{}$\6
1859 \\{pk\_directory}${},\39\\{output\_name},\39\|i,\39\\{long\_extension}\?(%
1860 \&{int})(\\{dpi\_x}*\\{magstep\_x}+\T{0.5}):\T{0},{}$\6
1861 \\{rm\_command}${},\39\\{output\_name},\39\|i);{}$\2\6
1862 \4${}\}{}$\2\6
1863 \4${}\}{}$\2\7
1864 \&{if} (\\{tfm\_files})\5
1865 ${}\{{}$\1\6
1866 ${}\\{fprintf}(\\{out},{}$\6
1867 \.{"\\n"}\6
1868 \.{"\%s\ \%s.pl\ \%s.tfm\\n"}\6
1869 \.{"\%s\ \%s.pl\\n"}\6
1870 \.{"\\n"}${},{}$\6
1871 \.{PLTOTF\_NAME}${},\39\\{output\_name},\39\\{output\_name},{}$\6
1872 \\{rm\_command}${},\39\\{output\_name}){}$;\7
1873 \&{if} (\\{unicode})\5
1874 ${}\{{}$\1\6
1875 \&{for} ${}(\|i\K(\\{min\_char}\GG\T{8}),\39\|j\K\T{0};{}$ ${}\|j<\\{nmb%
1876 \_files};{}$ ${}\|i\PP,\39\|j\PP){}$\1\5
1877 ${}\\{fprintf}(\\{out},{}$\6
1878 \.{"\%s\ \%s.tfm\ \%s\%s\%02x.}\)\.{tfm\\n"}${},{}$\6
1879 \\{cp\_command}${},\39\\{output\_name},\39\\{tfm\_directory},\39\\{output%
1880 \_name},\39\|i);{}$\2\6
1881 \4${}\}{}$\2\6
1882 \&{else}\5
1883 ${}\{{}$\1\6
1884 \&{for} ${}(\|i\K\T{1};{}$ ${}\|i\Z\\{nmb\_files};{}$ ${}\|i\PP){}$\1\5
1885 ${}\\{fprintf}(\\{out},{}$\6
1886 \.{"\%s\ \%s.tfm\ \%s\%s\%02i.}\)\.{tfm\\n"}${},{}$\6
1887 \\{cp\_command}${},\39\\{output\_name},\39\\{tfm\_directory},\39\\{output%
1888 \_name},\39\|i);{}$\2\6
1889 \4${}\}{}$\2\7
1890 ${}\\{fprintf}(\\{out},{}$\6
1891 \.{"\\n"}\6
1892 \.{"\%s\ \%s.tfm"}${},{}$\6
1893 \\{rm\_command}${},\39\\{output\_name});{}$\6
1894 \4${}\}{}$\2\7
1895 \&{if} (\\{ofm\_file})\5
1896 ${}\{{}$\1\6
1897 ${}\\{fprintf}(\\{out},{}$\6
1898 \.{"\\n"}\6
1899 \.{"\%s\ \%s.ovp\ \%s.ovf\ \%s}\)\.{.ofm\\n"}\6
1900 \.{"\%s\ \%s.ovp\\n"}\6
1901 \.{"\\n"}${},{}$\6
1902 \.{OVP2OVF\_NAME}${},\39\\{output\_name},\39\\{output\_name},\39\\{output%
1903 \_name},{}$\6
1904 \\{rm\_command}${},\39\\{output\_name});{}$\6
1905 \4${}\}{}$\2\7
1906 \\{fclose}(\\{out});\6
1907 \4${}\}{}$\2\par
1908 \fi
1909
1910 \N{1}{52}The configuration file.
1911 Here is a list with all necessary keywords (and parameters):
1912 \medskip
1913 \halign{\quad\.{#}\hfil&\quad#\hfil\cr
1914 hbf\_header & the HBF header file name of the input font(s). \cr
1915 output\_name & the name stem of the output files. \cr
1916 & Should be equal to the name of the configuration file
1917 in most cases.\cr
1918 & A running two digit decimal number starting with
1919 \.{01} will be appended. \cr
1920 & (For Unicode fonts see the keyword \.{unicode}
1921 below.) \cr
1922 }
1923 \bigskip
1924 And now all optional keywords:
1925 \medskip
1926 \halign{\quad\.{#}\hfil&\quad#\hfil\cr
1927 x\_offset & increases the character width. \cr
1928 & Will be applied on both sides; \cr
1929 & default is the value given in the HBF header
1930 (\.{HBF\_BITMAP\_BOUNDING\_BOX}) \cr
1931 & scaled to \\{design\/}size (in pixels). \cr
1932 y\_offset & shifts all characters up or down; \cr
1933 & default is the value given in the HBF header
1934 (\.{HBF\_BITMAP\_BOUNDING\_BOX}) \cr
1935 & scaled to \\{design\/}size (in pixels). \cr
1936 design\_size & the design size (in points) of the font. \cr
1937 & \.{x\_offset} and \.{y\_offset} refer to this
1938 size. \cr
1939 & Default is \PB{\T{10.0}} \cr
1940 target\_size & This command is obsolete now and will be
1941 ignored.\cr
1942 & \cr
1943 slant & the slant of the font (given as $\Delta x /
1944 \Delta y$). \cr
1945 & Only values in the range \PB{$\T{0}\Z\\{slant}\Z\T{1}$}
1946 are allowed. \cr
1947 & Default is \PB{\T{0.0}} \cr
1948 rotation & if set to `yes'. the glyphs are rotated
1949 90~degrees counter-clockwise. \cr
1950 & The default offsets as given in the HBF header
1951 will be ignored (and set to~\PB{\T{0}}). \cr
1952 & Default is `no'. \cr
1953 & \cr
1954 mag\_x & \cr
1955 mag\_y & scaling values of the characters to reach
1956 design size. \cr
1957 & If only one magnification is given, x and y
1958 values are assumed to be equal. \cr
1959 & Default is \.{mag\_x} $=$ \.{mag\_y} $=$ \PB{\T{1.0}}
1960 \cr
1961 threshold & A value between \PB{\T{1}} and \PB{\T{254}} defining a
1962 threshold for converting the internal \cr
1963 & graymap into the output bitmap; lower values
1964 cut more pixels. \cr
1965 & Default value is \PB{\T{128}}. \cr
1966 & \cr
1967 comment & a comment describing the font; \cr
1968 & default is none. \cr
1969 & \cr
1970 nmb\_fonts & the number of the fonts. \cr
1971 & Default value is~\PB{${-}\T{1}$} for creating all
1972 fonts. \cr
1973 unicode & if `yes', a two digit hexadecimal number will
1974 be used as a running number, \cr
1975 & starting with the value of the first byte of
1976 the first code range. \cr
1977 & Default is `no'. \cr
1978 min\_char & the minimum of the encoding range. \cr
1979 & Specify this value if it is not identical to
1980 the lowest code value \cr
1981 & in the HBF file (to which it defaults). \cr
1982 & \cr
1983 dpi\_x & \cr
1984 dpi\_y & the horizontal and vertical resolution (in
1985 dpi) of the printer. \cr
1986 & If only one resolution is given, x and y
1987 values are assumed to be equal. \cr
1988 & Default is \PB{\T{300}}. \cr
1989 checksum & a checksum to identify the \.{GF} files
1990 with the appropriate \.{TFM} files. \cr
1991 & The default of this 32~bit unsigned integer
1992 is \PB{\T{0}}. \cr
1993 coding & a comment describing the coding scheme; \cr
1994 & default is none. \cr
1995 & \cr
1996 pk\_directory & the destination directory of the
1997 \.{PK} files; \cr
1998 & default: none. \cr
1999 & Attention! The batch file will not check
2000 whether this directory exists. \cr
2001 tfm\_directory & the destination directory of the
2002 \.{TFM} files; \cr
2003 & default: none. \cr
2004 & Attention! The batch file will not check
2005 whether this directory exists. \cr
2006 pk\_files & whether to create \.{PK} files or not; \cr
2007 & default is `yes'. \cr
2008 tfm\_files & whether to create \.{TFM} files or not; \cr
2009 & default is `yes'. \cr
2010 ofm\_file & whether to create an \.{OFM} and an
2011 \.{OVF} file or not; \cr
2012 & default is `no'. \cr
2013 long\_extension & if `yes', \.{PK} files will include the
2014 resolution in the extension \cr
2015 & (e.g. \.{gsso1201.300pk}). \cr
2016 & This affects the batch file only (default is
2017 `yes'). \cr
2018 rm\_command & this shell command removes files; \cr
2019 & default: `rm'. \cr
2020 cp\_command & this shell command copies files; \cr
2021 & default: `cp'. \cr
2022 job\_extension & the extension of the batch file which calls
2023 \.{GFtoPK} and \.{PLtoTF} \cr
2024 & to convert the \.{GF} and the
2025 \.{PL} files into \.{PK} and
2026 \.{TFM} files; \cr
2027 & default is none. \cr
2028 }
2029 \bigskip
2030
2031 The searching algorithm (for the keywords) of \.{hbf2gf} is case
2032 insensitive; it makes no difference whether you write for example \.{comment}
2033 or \.{CommenT}. The keywords must start a line (be in the first column), and
2034 the corresponding parameters must be on the same line with the keyword and
2035 separated by at least one space or tabulator stop. Lines starting not with a
2036 keyword are ignored.
2037
2038 Key values \\{are} case sensitive (except \.{yes} and \.{no}).
2039
2040 The default system dependent values are for \UNIX/-like operating systems;
2041 if you use for example DOS, you must write
2042 \medskip
2043 \halign{\quad\.{#}\hfil&\quad\.{#}\hfil\cr
2044 long\_extension & no \cr
2045 rm\_command & del \cr
2046 cp\_command & copy \cr
2047 job\_extension & .bat \cr
2048 }
2049 \medskip
2050
2051 Both the values \PB{\\{pk\_output\_size\_x}} and \PB{\\{pk\_output\_size\_y}}
2052 must not exceed
2053 \PB{\.{MAX\_CHAR\_SIZE}}; \.{x\_offset} and \.{y\_offset} are related to the
2054 design size (and not to the input size).
2055
2056 In \mf-like mode, one \.{GF} file and one \.{PL} file will be computed
2057 (depending on the command line options \.{-g} and \.{-p}), taking
2058 \PB{\\{x\_resolution}} and \PB{\\{y\_scale}} from the command line. \.{nmb%
2059 \_fonts} will
2060 always be set to~\PB{\T{1}}; no job file will be created.
2061
2062
2063 \fi
2064
2065 \M{53}
2066 \Y\B\4\D\.{PRINTER\_MIN\_RES\_X}\5
2067 \T{50}\par
2068 \B\4\D\.{PRINTER\_MIN\_RES\_Y}\5
2069 \T{50}\par
2070 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
2071 \&{char} ${}\\{Buffer}[\.{STRING\_LENGTH}+\T{1}]{}$;\par
2072 \fi
2073
2074 \M{54}
2075 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
2076 \&{static} \&{void} \\{read\_config}(\&{void});\par
2077 \fi
2078
2079 \M{55}
2080 If \PB{\\{config\_file}} isn't found in \mf-like mode we assume that the font
2081 isn't a HBF font at all.
2082
2083 \Y\B\1\1\&{static} \&{void} \\{read\_config}(\&{void})\2\2\6
2084 ${}\{{}$\1\6
2085 \&{HBF\_BBOX} ${}{*}\\{boxp};{}$\6
2086 \&{char} ${}{*}\\{real\_config\_file};{}$\7
2087 \X56:Handle extension\X\7
2088 ${}\\{real\_config\_file}\K\\{TeX\_search\_cfg\_file}(\\{config\_file});{}$\6
2089 \&{if} ${}(\R\\{real\_config\_file}){}$\5
2090 ${}\{{}$\1\6
2091 \&{if} (\\{mf\_like})\5
2092 ${}\{{}$\1\6
2093 \&{if} ${}(\R\\{quiet}){}$\1\5
2094 ${}\\{printf}(\.{"Couldn't\ find\ `\%s'\\}\)\.{n"},\39\\{config\_file});{}$\2\6
2095 \\{exit}(\T{2});\6
2096 \4${}\}{}$\2\6
2097 \&{else}\5
2098 ${}\{{}$\1\6
2099 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ find\ `\%s'\\}\)\.{n"},\39\\{config%
2100 \_file});{}$\6
2101 \\{exit}(\T{1});\6
2102 \4${}\}{}$\2\6
2103 \4${}\}{}$\2\7
2104 \&{if} ${}(\R(\\{config}\K\\{fopen}(\\{real\_config\_file},\39\.{READ%
2105 \_TXT}))){}$\5
2106 ${}\{{}$\1\6
2107 \&{if} ${}(\R\\{testing}){}$\5
2108 ${}\{{}$\1\6
2109 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ open\ `\%s'\\}\)\.{n"},\39\\{config%
2110 \_file});{}$\6
2111 \\{exit}(\T{1});\6
2112 \4${}\}{}$\2\6
2113 \&{else}\C{ We reach this point only if no searching library is used }\6
2114 ${}\{{}$\1\6
2115 \&{if} ${}(\R\\{quiet}){}$\1\5
2116 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ find\ or\ op}\)\.{en\ `\%s'\\n"},\39%
2117 \\{config\_file});{}$\2\6
2118 \\{exit}(\T{2});\6
2119 \4${}\}{}$\2\6
2120 \4${}\}{}$\2\7
2121 \&{if} (\\{testing})\5
2122 ${}\{{}$\1\6
2123 \&{if} ${}(\R\\{quiet}){}$\1\5
2124 ${}\\{printf}(\.{"\%s\\n"},\39\\{real\_config\_file});{}$\2\6
2125 \\{exit}(\T{0});\6
2126 \4${}\}{}$\2\6
2127 \X57:Necessary parameters\X\6
2128 \X59:Optional parameters\X\7
2129 \X61:Get code range\X\6
2130 \X63:Get sub code range\X\7
2131 \\{fclose}(\\{config});\6
2132 \4${}\}{}$\2\par
2133 \fi
2134
2135 \M{56}
2136 Here we check whether we have to add an extension.
2137
2138 \Y\B\4\X56:Handle extension\X${}\E{}$\6
2139 ${}\{{}$\1\6
2140 \&{int} \|i${},{}$ \\{lastext}${}\K{-}\T{1};{}$\7
2141 \&{for} ${}(\|i\K\T{0};{}$ \\{config\_file}[\|i]; ${}\|i\PP){}$\1\6
2142 \&{if} ${}(\\{config\_file}[\|i]\E\.{'.'}){}$\1\5
2143 ${}\\{lastext}\K\|i;{}$\2\6
2144 \&{else} \&{if} ${}(\\{config\_file}[\|i]\E\.{'/'}\V\\{config\_file}[\|i]\E%
2145 \.{':'}\V\\{config\_file}[\|i]\E\.{'\\\\'}){}$\1\5
2146 ${}\\{lastext}\K{-}\T{1}{}$;\2\2\7
2147 \&{if} ${}(\\{lastext}\E{-}\T{1}){}$\1\5
2148 ${}\\{strcat}(\\{config\_file},\39\.{".cfg"});{}$\2\6
2149 \4${}\}{}$\2\par
2150 \U55.\fi
2151
2152 \M{57}
2153 \Y\B\4\X57:Necessary parameters\X${}\E{}$\6
2154 ${}\{{}$\1\6
2155 \&{char} ${}\\{hbf\_header}[\.{STRING\_LENGTH}+\T{1}];{}$\6
2156 \&{char} ${}{*}\\{real\_hbf\_header};{}$\7
2157 \&{if} ${}(\R\\{fsearch}(\.{"hbf\_header"})){}$\1\5
2158 \\{config\_error}(\.{"hbf\_header"});\2\6
2159 \&{else}\1\5
2160 ${}\\{strcpy}(\\{hbf\_header},\39\\{Buffer}){}$;\2\7
2161 ${}\\{real\_hbf\_header}\K\\{TeX\_search\_hbf\_file}(\\{hbf\_header});{}$\6
2162 \&{if} ${}(\R\\{real\_hbf\_header}){}$\5
2163 ${}\{{}$\1\6
2164 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ find\ `\%s'\\}\)\.{n"},\39\\{hbf%
2165 \_header});{}$\6
2166 \\{exit}(\T{1});\6
2167 \4${}\}{}$\2\7
2168 ${}\\{hbfDebug}\K\T{1}{}$;\C{ we activate error messages of the HBF API
2169 while scanning the HBF header file }\7
2170 \&{if} ${}(\R(\\{hbf}\K\\{hbfOpen}(\\{real\_hbf\_header}))){}$\1\5
2171 \\{exit}(\T{1});\2\7
2172 ${}\\{hbfDebug}\K\T{0}{}$;\7
2173 ${}\\{boxp}\K\\{hbfBitmapBBox}(\\{hbf});{}$\6
2174 ${}\\{input\_size\_x}\K\\{boxp}\MG\\{hbf\_height}{}$;\C{ will be checked later
2175 for rotation }\6
2176 ${}\\{input\_size\_y}\K\\{boxp}\MG\\{hbf\_width};{}$\6
2177 ${}\\{font\_encoding}\K\\{hbfProperty}(\\{hbf},\39\.{"HBF\_CODE\_SCHEME"}){}$;\7
2178 \&{if} ${}(\R\\{fsearch}(\.{"output\_name"})){}$\1\5
2179 \\{config\_error}(\.{"output\_name"});\2\6
2180 \&{else}\1\5
2181 ${}\\{strcpy}(\\{output\_name},\39\\{Buffer});{}$\2\6
2182 \4${}\}{}$\2\par
2183 \U55.\fi
2184
2185 \M{58}
2186 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
2187 \&{int} \\{offset\_x};\6
2188 \&{int} \\{offset\_y};\7
2189 \&{HBF\_CHAR} \\{user\_min\_char};\6
2190 \&{int} \\{have\_min\_char}${}\K\.{FALSE}{}$;\par
2191 \fi
2192
2193 \M{59}
2194 \Y\B\4\X59:Optional parameters\X${}\E{}$\6
2195 ${}\{{}$\1\6
2196 \&{if} (\\{fsearch}(\.{"nmb\_files"}))\1\5
2197 ${}\\{nmb\_files}\K\\{atoi}(\\{Buffer});{}$\2\6
2198 \&{if} (\\{fsearch}(\.{"unicode"}))\1\6
2199 \&{if} ${}(\\{Buffer}[\T{0}]\E\.{'y'}\V\\{Buffer}[\T{0}]\E\.{'Y'}){}$\1\5
2200 ${}\\{unicode}\K\.{TRUE};{}$\2\2\6
2201 \&{if} (\\{fsearch}(\.{"min\_char"}))\5
2202 ${}\{{}$\1\6
2203 ${}\\{user\_min\_char}\K\\{strtoul}(\\{Buffer},\39{}$(\&{char} ${}{*}{*}){}$
2204 ${}\NULL,\39\T{0});{}$\6
2205 ${}\\{have\_min\_char}\K\.{TRUE};{}$\6
2206 \4${}\}{}$\2\7
2207 \&{if} ${}(\R\\{mf\_like}){}$\5
2208 ${}\{{}$\1\6
2209 \&{if} (\\{fsearch}(\.{"pk\_files"}))\1\6
2210 \&{if} ${}(\\{Buffer}[\T{0}]\E\.{'n'}\V\\{Buffer}[\T{0}]\E\.{'N'}){}$\1\5
2211 ${}\\{pk\_files}\K\.{FALSE};{}$\2\2\6
2212 \&{if} (\\{fsearch}(\.{"tfm\_files"}))\1\6
2213 \&{if} ${}(\\{Buffer}[\T{0}]\E\.{'n'}\V\\{Buffer}[\T{0}]\E\.{'N'}){}$\1\5
2214 ${}\\{tfm\_files}\K\.{FALSE};{}$\2\2\6
2215 \&{if} (\\{fsearch}(\.{"ofm\_file"}))\1\6
2216 \&{if} ${}(\\{Buffer}[\T{0}]\E\.{'y'}\V\\{Buffer}[\T{0}]\E\.{'Y'}){}$\1\5
2217 ${}\\{ofm\_file}\K\.{TRUE};{}$\2\2\6
2218 \&{if} (\\{fsearch}(\.{"long\_extension"}))\1\6
2219 \&{if} ${}(\\{Buffer}[\T{0}]\E\.{'n'}\V\\{Buffer}[\T{0}]\E\.{'N'}){}$\1\5
2220 ${}\\{long\_extension}\K\.{FALSE};{}$\2\2\6
2221 \4${}\}{}$\2\7
2222 \&{if} (\\{fsearch}(\.{"slant"}))\1\5
2223 ${}\\{slant}\K\\{atof}(\\{Buffer});{}$\2\6
2224 \&{if} ${}(\\{slant}<\T{0.0}\V\\{slant}>\T{1.0}){}$\5
2225 ${}\{{}$\1\6
2226 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ slant\\n"});{}$\6
2227 \\{exit}(\T{1});\6
2228 \4${}\}{}$\2\6
2229 \&{if} (\\{fsearch}(\.{"rotation"}))\1\6
2230 \&{if} ${}(\\{Buffer}[\T{0}]\E\.{'y'}\V\\{Buffer}[\T{0}]\E\.{'Y'}){}$\1\5
2231 ${}\\{rotation}\K\.{TRUE}{}$;\2\2\7
2232 \&{if} (\\{fsearch}(\.{"mag\_x"}))\1\5
2233 ${}\\{mag\_x}\K\\{atof}(\\{Buffer});{}$\2\6
2234 \&{if} (\\{fsearch}(\.{"mag\_y"}))\1\5
2235 ${}\\{mag\_y}\K\\{atof}(\\{Buffer});{}$\2\6
2236 \&{if} ${}(\R\\{mag\_x}\W\R\\{mag\_y}){}$\5
2237 ${}\{{}$\1\6
2238 ${}\\{mag\_x}\K\T{1.0};{}$\6
2239 ${}\\{mag\_y}\K\T{1.0};{}$\6
2240 \4${}\}{}$\2\6
2241 \&{if} ${}(\\{mag\_x}\W\R\\{mag\_y}){}$\1\5
2242 ${}\\{mag\_y}\K\\{mag\_x};{}$\2\6
2243 \&{if} ${}(\\{mag\_y}\W\R\\{mag\_x}){}$\1\5
2244 ${}\\{mag\_x}\K\\{mag\_y};{}$\2\6
2245 \&{if} ${}(\\{mag\_x}\Z\T{0.0}){}$\5
2246 ${}\{{}$\1\6
2247 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ horizontal\ }\)\.{magnification%
2248 \\n"});{}$\6
2249 \\{exit}(\T{1});\6
2250 \4${}\}{}$\2\6
2251 \&{if} ${}(\\{mag\_y}\Z\T{0.0}){}$\5
2252 ${}\{{}$\1\6
2253 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ vertical\ ma}\)\.{gnification%
2254 \\n"});{}$\6
2255 \\{exit}(\T{1});\6
2256 \4${}\}{}$\2\7
2257 \&{if} (\\{fsearch}(\.{"dpi\_x"}))\1\5
2258 ${}\\{dpi\_x}\K\\{atoi}(\\{Buffer});{}$\2\6
2259 \&{if} (\\{fsearch}(\.{"dpi\_y"}))\1\5
2260 ${}\\{dpi\_y}\K\\{atoi}(\\{Buffer});{}$\2\6
2261 \&{if} ${}(\R\\{dpi\_x}\W\R\\{dpi\_y}){}$\5
2262 ${}\{{}$\1\6
2263 ${}\\{dpi\_x}\K\T{300};{}$\6
2264 ${}\\{dpi\_y}\K\T{300};{}$\6
2265 \4${}\}{}$\2\6
2266 \&{if} ${}(\\{dpi\_x}\W\R\\{dpi\_y}){}$\1\5
2267 ${}\\{dpi\_y}\K\\{dpi\_x};{}$\2\6
2268 \&{if} ${}(\\{dpi\_y}\W\R\\{dpi\_x}){}$\1\5
2269 ${}\\{dpi\_x}\K\\{dpi\_y};{}$\2\6
2270 \&{if} ${}(\\{dpi\_x}\Z\.{PRINTER\_MIN\_RES\_X}){}$\5
2271 ${}\{{}$\1\6
2272 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ horizontal\ }\)\.{printer\ resolution%
2273 \\n}\)\.{"});{}$\6
2274 \\{exit}(\T{1});\6
2275 \4${}\}{}$\2\6
2276 \&{if} ${}(\\{dpi\_y}\Z\.{PRINTER\_MIN\_RES\_Y}){}$\5
2277 ${}\{{}$\1\6
2278 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ vertical\ pr}\)\.{inter\ resolution%
2279 \\n"});{}$\6
2280 \\{exit}(\T{1});\6
2281 \4${}\}{}$\2\7
2282 \&{if} (\\{fsearch}(\.{"design\_size"}))\1\5
2283 ${}\\{design\_size}\K\\{atof}(\\{Buffer}){}$;\2\7
2284 \&{if} (\\{fsearch}(\.{"x\_offset"}))\1\5
2285 ${}\\{offset\_x}\K\\{atoi}(\\{Buffer});{}$\2\6
2286 \&{else}\1\5
2287 ${}\\{offset\_x}\K\\{rotation}\?\T{0}:(\\{boxp}\MG\\{hbf\_xDisplacement}*\\{mag%
2288 \_x}+\T{0.5});{}$\2\6
2289 \&{if} (\\{fsearch}(\.{"y\_offset"}))\1\5
2290 ${}\\{offset\_y}\K\\{atoi}(\\{Buffer});{}$\2\6
2291 \&{else}\1\5
2292 ${}\\{offset\_y}\K\\{rotation}\?\T{0}:(\\{boxp}\MG\\{hbf\_yDisplacement}*\\{mag%
2293 \_y}+\T{0.5});{}$\2\6
2294 \&{if} ${}(\R\\{fsearch}(\.{"comment"})){}$\1\5
2295 ${}\\{comment}[\T{0}]\K\.{'\\0'};{}$\2\6
2296 \&{else}\1\5
2297 ${}\\{strcpy}(\\{comment},\39\\{Buffer}){}$;\2\7
2298 \&{if} (\\{fsearch}(\.{"threshold"}))\1\5
2299 ${}\\{threshold}\K\\{atoi}(\\{Buffer});{}$\2\6
2300 \&{if} ${}(\\{threshold}\Z\T{0}\V\\{threshold}\G\T{255}){}$\5
2301 ${}\{{}$\1\6
2302 ${}\\{fprintf}(\\{stderr},\39\.{"Invalid\ threshold\\n}\)\.{"});{}$\6
2303 \\{exit}(\T{1});\6
2304 \4${}\}{}$\2\7
2305 \&{if} ${}(\R\\{fsearch}(\.{"checksum"})){}$\1\5
2306 ${}\\{checksum}\K\T{0};{}$\2\6
2307 \&{else}\1\5
2308 ${}\\{checksum}\K\\{strtoul}(\\{Buffer},\39{}$(\&{char} ${}{*}{*}){}$ ${}\NULL,%
2309 \39\T{0}){}$;\2\7
2310 \&{if} ${}(\R\\{fsearch}(\.{"coding"})){}$\1\5
2311 ${}\\{coding}[\T{0}]\K\.{'\\0'};{}$\2\6
2312 \&{else}\1\5
2313 ${}\\{strcpy}(\\{coding},\39\\{Buffer}){}$;\2\7
2314 \&{if} ${}(\R\\{fsearch}(\.{"pk\_directory"})){}$\1\5
2315 ${}\\{pk\_directory}[\T{0}]\K\.{'\\0'};{}$\2\6
2316 \&{else}\1\5
2317 ${}\\{strcpy}(\\{pk\_directory},\39\\{Buffer}){}$;\2\7
2318 \&{if} ${}(\R\\{fsearch}(\.{"tfm\_directory"})){}$\1\5
2319 ${}\\{tfm\_directory}[\T{0}]\K\.{'\\0'};{}$\2\6
2320 \&{else}\1\5
2321 ${}\\{strcpy}(\\{tfm\_directory},\39\\{Buffer}){}$;\2\7
2322 \&{if} (\\{fsearch}(\.{"rm\_command"}))\1\5
2323 ${}\\{strcpy}(\\{rm\_command},\39\\{Buffer});{}$\2\6
2324 \&{else}\1\5
2325 ${}\\{strcpy}(\\{rm\_command},\39\.{"rm"}){}$;\2\7
2326 \&{if} (\\{fsearch}(\.{"cp\_command"}))\1\5
2327 ${}\\{strcpy}(\\{cp\_command},\39\\{Buffer});{}$\2\6
2328 \&{else}\1\5
2329 ${}\\{strcpy}(\\{cp\_command},\39\.{"cp"}){}$;\2\7
2330 \&{if} ${}(\R\\{fsearch}(\.{"job\_extension"})){}$\1\5
2331 ${}\\{job\_extension}[\T{0}]\K\.{'\\0'};{}$\2\6
2332 \&{else}\5
2333 ${}\{{}$\1\6
2334 ${}\\{strncpy}(\\{job\_extension},\39\\{Buffer},\39\.{EXTENSION\_LENGTH});{}$\6
2335 ${}\\{job\_extension}[\.{EXTENSION\_LENGTH}]\K\.{'\\0'};{}$\6
2336 \4${}\}{}$\2\6
2337 \4${}\}{}$\2\par
2338 \U55.\fi
2339
2340 \M{60}
2341 The function \PB{\\{hbfGetCodeRange}(\,)} is an extension to the HBF API.
2342
2343 Successive calls return the code ranges in ascending order; we only need the
2344 extrema of the whole code range.
2345
2346 In case \PB{\\{min\_char}} has been supplied in the configuration file, we use
2347 that
2348 value instead.
2349
2350 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
2351 \&{HBF\_CHAR} \\{min\_char}${},{}$ \\{max\_char};\par
2352 \fi
2353
2354 \M{61}
2355 \Y\B\4\X61:Get code range\X${}\E{}$\6
2356 ${}\{{}$\1\6
2357 \&{const} \&{void} ${}{*}\\{cp};{}$\6
2358 \&{HBF\_CHAR} \\{dummy};\7
2359 ${}\\{cp}\K\\{hbfGetCodeRange}(\\{hbf},\39\NULL,\39{\AND}\\{min\_char},\39{%
2360 \AND}\\{max\_char});{}$\6
2361 \&{for} ( ; ${}\\{cp}\I\NULL;{}$ ${}\\{cp}\K\\{hbfGetCodeRange}(\\{hbf},\39%
2362 \\{cp},\39{\AND}\\{dummy},\39{\AND}\\{max\_char})){}$\1\5
2363 ;\2\7
2364 \&{if} (\\{have\_min\_char})\1\5
2365 ${}\\{min\_char}\K\\{user\_min\_char};{}$\2\6
2366 \4${}\}{}$\2\par
2367 \U55.\fi
2368
2369 \M{62}
2370 The function \PB{\\{hbfGetByte2Range}(\,)} is an extension to the HBF API.
2371
2372 Successive calls return the byte~2 ranges in ascending order. We raise
2373 \PB{\.{VALID\_SUBCODE}} in the array \PB{\\{b2\_codes}[\,]} for all characters
2374 in subcode
2375 ranges.
2376
2377 \Y\B\4\D\.{VALID\_SUBCODE}\5
2378 \T{1}\par
2379 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
2380 \&{char} \\{b2\_codes}[\T{256}];\6
2381 \&{unsigned} \&{char} \\{min\_2\_byte}${},{}$ \\{max\_2\_byte};\6
2382 \&{int} \\{nmb\_2\_bytes}${}\K\T{0}{}$;\par
2383 \fi
2384
2385 \M{63}
2386 \Y\B\4\X63:Get sub code range\X${}\E{}$\6
2387 ${}\{{}$\1\6
2388 \&{const} \&{void} ${}{*}\\{b2r};{}$\6
2389 \&{unsigned} \&{char} \\{dummy};\6
2390 \&{int} \|i;\7
2391 \&{for} ${}(\|i\K\T{0};{}$ ${}\|i<\T{256};{}$ ${}\|i\PP){}$\1\5
2392 ${}\\{b2\_codes}[\|i]\K\T{0}{}$;\2\7
2393 ${}\\{b2r}\K\\{hbfGetByte2Range}(\\{hbf},\39\NULL,\39{\AND}\\{min\_2\_byte},%
2394 \39{\AND}\\{max\_2\_byte});{}$\6
2395 ${}\\{dummy}\K\\{min\_2\_byte};{}$\6
2396 \&{for} ( ; ${}\\{b2r}\I\NULL;{}$ ${}\\{b2r}\K\\{hbfGetByte2Range}(\\{hbf},\39%
2397 \\{b2r},\39{\AND}\\{dummy},\39{\AND}\\{max\_2\_byte})){}$\5
2398 ${}\{{}$\1\6
2399 \&{for} ${}(\|i\K\\{dummy};{}$ ${}\|i\Z\\{max\_2\_byte};{}$ ${}\|i\PP){}$\1\5
2400 ${}\\{b2\_codes}[\|i]\K\.{VALID\_SUBCODE};{}$\2\6
2401 \4${}\}{}$\2\7
2402 \&{for} ${}(\|i\K\T{0};{}$ ${}\|i<\T{256};{}$ ${}\|i\PP{}$)\C{ compute the
2403 number of valid \PB{\\{b2\_codes}} }\1\6
2404 \&{if} ${}(\\{b2\_codes}[\|i]\E\.{VALID\_SUBCODE}){}$\1\5
2405 ${}\\{nmb\_2\_bytes}\PP;{}$\2\2\6
2406 \4${}\}{}$\2\par
2407 \U55.\fi
2408
2409 \M{64}
2410 This search routine is case insignificant. Each keyword must start a line;
2411 the function checks whether the character before the keyword is a newline
2412 character (\PB{\.{'\\n'}}). It also checks the presence of a parameter and
2413 fills
2414 \PB{\\{Buffer}} if existent. \PB{\\{fsearch}(\,)} returns~1 on success.
2415
2416 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
2417 \&{static} \&{int} \\{fsearch}(\&{const} \&{char} ${}{*}){}$;\par
2418 \fi
2419
2420 \M{65}
2421 \Y\B\1\1\&{static} \&{int} \\{fsearch}(\&{const} \&{char} ${}{*}\\{search%
2422 \_string})\2\2{}$\6
2423 ${}\{{}$\1\6
2424 \&{char} ${}{*}\|P,{}$ \|p;\6
2425 \&{const} \&{char} ${}{*}\|Q;{}$\6
2426 \&{char} ${}\\{temp\_buffer}[\.{STRING\_LENGTH}+\T{1}];{}$\6
2427 \&{char} ${}\\{env\_name}[\.{STRING\_LENGTH}+\T{1}];{}$\6
2428 \&{char} ${}{*}\\{env\_p};{}$\6
2429 \&{char} ${}{*}\\{env\_value};{}$\6
2430 \&{char} ${}{*}\\{Buf\_p};{}$\6
2431 \&{int} \\{Ch}${},{}$ \\{ch}${},{}$ \\{old\_ch}${}\K\.{'\\n'};{}$\6
2432 \&{int} \\{count}${}\K\.{STRING\_LENGTH};{}$\7
2433 \\{rewind}(\\{config});\C{ we start at offset~0 }\7
2434 \&{do}\5
2435 ${}\{{}$\1\6
2436 ${}\|Q\K\\{search\_string};{}$\6
2437 ${}\|p\K\\{tolower}{}$((\&{unsigned} \&{char}) ${}{*}\|Q);{}$\6
2438 ${}\\{Ch}\K\\{fgetc}(\\{config});{}$\6
2439 ${}\\{ch}\K\\{tolower}(\\{Ch});{}$\6
2440 \&{while} ${}(\R(\\{ch}\E\|p\W\\{old\_ch}\E\.{'\\n'})\W\\{Ch}\I\.{EOF}{}$)\C{
2441 search first character of \PB{\\{search\_string}};
2442 \PB{\.{'\\n'}} must be the character before }\6
2443 ${}\{{}$\1\6
2444 ${}\\{old\_ch}\K\\{ch};{}$\6
2445 ${}\\{Ch}\K\\{fgetc}(\\{config});{}$\6
2446 ${}\\{ch}\K\\{tolower}(\\{Ch});{}$\6
2447 \4${}\}{}$\2\7
2448 \&{for} ( ; ; \,)\5
2449 ${}\{{}$\1\6
2450 \&{if} ${}({*}(\PP\|Q)\E\.{'\\0'}){}$\1\6
2451 \&{if} ${}((\\{Ch}\K\\{fgetc}(\\{config}))\E\.{'\ '}\V\\{Ch}\E\.{'\\t'}{}$)\C{
2452 there must be a space or a tab stop after the keyword }\1\6
2453 \&{goto} \\{success};\2\2\6
2454 ${}\\{Ch}\K\\{fgetc}(\\{config});{}$\6
2455 \&{if} ${}(\\{tolower}(\\{Ch})\I\\{tolower}{}$((\&{unsigned} \&{char}) ${}{*}%
2456 \|Q)){}$\1\5
2457 \&{break};\2\6
2458 \4${}\}{}$\2\6
2459 \4${}\}{}$\2\5
2460 \&{while} ${}(\\{Ch}\I\.{EOF}){}$;\7
2461 \&{return} \T{0};\7
2462 \4\\{success}:\5
2463 ${}\|P\K\\{temp\_buffer}{}$;\7
2464 \&{while} ${}((\\{Ch}\K\\{fgetc}(\\{config}))\E\.{'\ '}\V\\{Ch}\E\.{'\\t'}{}$)%
2465 \C{ remove leading blanks and tabs }\1\6
2466 ;\2\6
2467 \&{while} ${}(\\{Ch}\I\.{'\\n'}\W\MM\\{count}>\T{0}\W\\{Ch}\I\.{EOF}{}$)\C{
2468 fill \PB{\\{Buffer}} }\6
2469 ${}\{{}$\1\6
2470 ${}{*}\|P\PP\K\\{Ch};{}$\6
2471 ${}\\{Ch}\K\\{fgetc}(\\{config});{}$\6
2472 \4${}\}{}$\2\6
2473 ${}{*}\|P\K\.{'\\0'}{}$;\7
2474 \&{if} ${}({*}\\{temp\_buffer}){}$\1\5
2475 \X66:Check for environment variables\X\2\6
2476 \&{else}\1\5
2477 ${}{*}\\{Buffer}\K\.{'\\0'}{}$;\2\7
2478 \&{return} ${}({*}\\{Buffer})\?\T{1}:\T{0}{}$;\C{ is there something in the
2479 buffer? }\6
2480 \4${}\}{}$\2\par
2481 \fi
2482
2483 \M{66}
2484 To make the configuration file more flexible we allow environment variables
2485 in the arguments. We scan the parameter stored in \PB{\\{temp\_buffer}} whether
2486 it
2487 contains a `\.{\$}' character. If yes, the following code fragment tries to
2488 get an environment variable name whose value will be then fetched with
2489 \PB{\\{getenv}(\,)}. An environment variable name recognized by \.{hbf2gf} must
2490 start
2491 with a letter or underscore; the other characters may be alphanumeric or an
2492 underscore. You can surround the environment variable name with braces to
2493 indicate where the name ends, e.g. \.{\$\{FOO\}}. The interpolated
2494 configuration parameter will be truncated to \PB{\.{STRING\_LENGTH}}
2495 characters. If
2496 you want to have `\.{\$}' you must write `\.{\$\$}'.
2497
2498 Note that you should avoid to use such environment variables for specifying
2499 the location of the configuration file in case you have support for a file
2500 searching library like kpathsea. Its primary aim is to specify the target
2501 directories for the \.{pk\_directory} and the \.{tfm\_directory} keywords.
2502
2503 \Y\B\4\X66:Check for environment variables\X${}\E{}$\6
2504 ${}\{{}$\1\6
2505 ${}\|P\K\\{temp\_buffer};{}$\6
2506 ${}\\{Buf\_p}\K\\{Buffer};{}$\6
2507 ${}\\{count}\K\.{STRING\_LENGTH}-\T{1}{}$;\7
2508 \&{while} ${}({*}\|P\W\\{count}>\T{0}){}$\5
2509 ${}\{{}$\1\6
2510 ${}\\{env\_p}\K\\{env\_name}{}$;\7
2511 \&{if} ${}({*}\|P\E\.{'\$'}){}$\5
2512 ${}\{{}$\1\6
2513 ${}\|P\PP;{}$\6
2514 \&{if} ${}({*}\|P\E\.{'\$'}){}$\5
2515 ${}\{{}$\1\6
2516 ${}{*}(\\{Buf\_p}\PP)\K{*}(\|P\PP);{}$\6
2517 ${}\\{count}\MM;{}$\6
2518 \&{continue};\6
2519 \4${}\}{}$\2\6
2520 \&{while} ${}({*}\|P\E\.{'\{'}){}$\1\5
2521 ${}\|P\PP;{}$\2\6
2522 \&{if} ${}(\R{}$(\\{isalpha}((\&{unsigned} \&{char}) ${}{*}\|P)\V{*}\|P\E\.{'%
2523 \_'})){}$\5
2524 ${}\{{}$\1\6
2525 ${}\\{fprintf}(\\{stderr},{}$\6
2526 \.{"Invalid\ environment}\)\.{\ variable\ name\ in\ co}\)\.{nfiguration\ file%
2527 \\n"});\6
2528 \\{exit}(\T{1});\6
2529 \4${}\}{}$\2\6
2530 ${}{*}(\\{env\_p}\PP)\K{*}(\|P\PP);{}$\6
2531 \&{while} ${}({*}\|P){}$\5
2532 ${}\{{}$\1\6
2533 \&{if} (\\{isalnum}((\&{unsigned} \&{char}) ${}{*}\|P)\V{*}\|P\E\.{'\_'}){}$\1\5
2534 ${}{*}(\\{env\_p}\PP)\K{*}(\|P\PP);{}$\2\6
2535 \&{else}\5
2536 ${}\{{}$\1\6
2537 \&{while} ${}({*}\|P\E\.{'\}'}){}$\1\5
2538 ${}\|P\PP;{}$\2\6
2539 ${}{*}\\{env\_p}\K\.{'\\0'};{}$\6
2540 \&{break};\6
2541 \4${}\}{}$\2\6
2542 \4${}\}{}$\2\7
2543 ${}\\{env\_value}\K\\{getenv}(\\{env\_name});{}$\6
2544 \&{if} (\\{env\_value})\C{ append the environment value to \PB{\\{Buffer}} }\6
2545 ${}\{{}$\1\6
2546 \&{while} ${}({*}\\{env\_value}\W\\{count}>\T{0}){}$\5
2547 ${}\{{}$\1\6
2548 ${}{*}(\\{Buf\_p}\PP)\K{*}(\\{env\_value}\PP);{}$\6
2549 ${}\\{count}\MM;{}$\6
2550 \4${}\}{}$\2\6
2551 \4${}\}{}$\2\6
2552 \4${}\}{}$\2\6
2553 \&{else}\5
2554 ${}\{{}$\1\6
2555 ${}{*}(\\{Buf\_p}\PP)\K{*}(\|P\PP);{}$\6
2556 ${}\\{count}\MM;{}$\6
2557 \4${}\}{}$\2\6
2558 \4${}\}{}$\2\6
2559 ${}{*}\\{Buf\_p}\K\.{'\\0'};{}$\6
2560 \4${}\}{}$\2\par
2561 \U65.\fi
2562
2563 \M{67}
2564 If an error occurs, \PB{\\{config\_error}(\,)} will leave the program with an
2565 error
2566 message.
2567
2568 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
2569 \&{static} \&{void} \\{config\_error}(\&{const} \&{char} ${}{*}){}$;\par
2570 \fi
2571
2572 \M{68}
2573 \Y\B\1\1\&{static} \&{void} \\{config\_error}(\&{const} \&{char} ${}{*}%
2574 \\{message})\2\2{}$\6
2575 ${}\{{}$\1\6
2576 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ find\ `\%s'\ }\)\.{entry\ in\
2577 configurati}\)\.{on\ file\\n"},\39\\{message});{}$\6
2578 \\{exit}(\T{1});\6
2579 \4${}\}{}$\2\par
2580 \fi
2581
2582 \N{1}{69}File searching.
2583
2584 We support three searching engines: emtexdir, kpathsea, and MiKTeX (which is
2585 a Win32 port of kpathsea). For emtexdir, define \PB{\.{HAVE\_EMTEXDIR}} while
2586 compiling. For kpathsea, define \PB{\.{HAVE\_LIBKPATHSEA}}. For MikTeX, define
2587 \PB{\.{HAVE\_MIKTEX}}. If none of these macros is defined, a simple \PB{%
2588 \\{fopen}(\,)} will
2589 be used instead.
2590
2591 \Y\B\4\X10:Include files\X${}\mathrel+\E{}$\6
2592 \8\#\&{if} \&{defined} (\.{HAVE\_LIBKPATHSEA})\6
2593 \8\#\&{include} \.{"kpathsea/kpathsea.h}\)\.{"}\6
2594 \8\#\&{elif} \&{defined} (\.{HAVE\_EMTEXDIR})\6
2595 \8\#\&{include} \.{"emtexdir.h"}\6
2596 \8\#\&{elif} \&{defined} (\.{HAVE\_MIKTEX})\6
2597 \8\#\&{include} \.{"miktex.h"}\6
2598 \8\#\&{endif}\par
2599 \fi
2600
2601 \M{70}
2602 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
2603 \8\#\&{if} \&{defined} (\.{HAVE\_EMTEXDIR})\6
2604 \&{char} \\{emtex\_version\_string}[\,]${}\K\.{"emTeXdir"};{}$\6
2605 \8\#\&{elif} ${}\R{}$\&{defined} (\.{HAVE\_MIKTEX})\6
2606 \&{char} \\{no\_version\_string}[\,]${}\K\.{"no\ search\ library"};{}$\6
2607 \8\#\&{endif}\par
2608 \fi
2609
2610 \M{71}
2611 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
2612 \&{static} \&{const} \&{char} ${}{*}\\{TeX\_search\_version}(\&{void}){}$;\par
2613 \fi
2614
2615 \M{72}
2616 \Y\B\1\1\&{static} \&{const} \&{char} ${}{*}\\{TeX\_search\_version}(\&{void})%
2617 \2\2{}$\6
2618 ${}\{{}$\6
2619 \8\#\&{if} \&{defined} (\.{HAVE\_LIBKPATHSEA})\1\6
2620 \&{return} \\{kpathsea\_version\_string};\6
2621 \8\#\&{elif} \&{defined} (\.{HAVE\_EMTEXDIR})\6
2622 \&{return} \\{emtex\_version\_string};\6
2623 \8\#\&{elif} \&{defined} (\.{HAVE\_MIKTEX})\7
2624 \&{char} \\{buf}[\T{200}];\7
2625 ${}\\{strcpy}(\\{buf},\39\.{"MiKTeX\ "});{}$\6
2626 ${}\\{miktex\_get\_miktex\_version\_string\_ex}(\\{buf}+\T{7},\39{}$\&{sizeof}
2627 (\\{buf})${}-\T{7});{}$\6
2628 \&{return} \\{buf};\6
2629 \8\#\&{else}\6
2630 \&{return} \\{no\_version\_string};\6
2631 \8\#\&{endif}\6
2632 \4${}\}{}$\2\par
2633 \fi
2634
2635 \M{73}
2636 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
2637 \8\#\&{ifdef} \.{HAVE\_EMTEXDIR}\6
2638 \&{struct} \&{emtex\_dir} \\{cfg\_path}${},{}$ \\{hbf\_path};\6
2639 \8\#\&{endif}\par
2640 \fi
2641
2642 \M{74}
2643 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
2644 \8\#\&{ifdef} \.{HAVE\_EMTEXDIR}\6
2645 \&{extern} \&{int} \\{setup\_list}(\&{struct} \&{emtex\_dir} ${}{*},\39{}$%
2646 \&{char} ${}{*},\39{}$\&{const} \&{char} ${}{*},\39\&{unsigned});{}$\6
2647 \&{static} \&{int} \\{dir\_setup}(\&{struct} \&{emtex\_dir} ${}{*},\39{}$%
2648 \&{const} \&{char} ${}{*},\39{}$\&{const} \&{char} ${}{*},\39\&{unsigned});{}$\6
2649 \&{static} \&{char} ${}{*}{}$\\{file\_find}(\&{char} ${}{*},\39{}$\&{struct} %
2650 \&{emtex\_dir} ${}{*});{}$\6
2651 \8\#\&{endif}\par
2652 \fi
2653
2654 \M{75}
2655 We slightly modify \PB{\\{emtex\_dir\_setup}(\,)} (from the file %
2656 \.{emtexdir.c}) to
2657 output a warning in case the environment variable \PB{\\{env}} isn't set
2658 properly.
2659
2660 \Y\B\1\1\6
2661 \8\#\&{ifdef} \.{HAVE\_EMTEXDIR}\6
2662 \&{static} \&{int} ${}\\{dir\_setup}(\\{ed},\39\\{env},\39\\{dir},\39%
2663 \\{flags}){}$\6
2664 \&{struct} \&{emtex\_dir} ${}{*}\\{ed};{}$\6
2665 \&{const} \&{char} ${}{*}\\{env};{}$\6
2666 \&{const} \&{char} ${}{*}\\{dir};{}$\6
2667 \&{unsigned} \\{flags};\2\2\6
2668 ${}\{{}$\1\6
2669 \&{const} \&{char} ${}{*}\\{val};{}$\6
2670 \&{char} \\{path}[\T{260}];\7
2671 ${}\\{ed}\MG\\{alloc}\K\T{0};{}$\6
2672 ${}\\{ed}\MG\\{used}\K\T{0};{}$\6
2673 ${}\\{ed}\MG\\{list}\K\NULL{}$;\7
2674 \&{if} ${}(\\{env}\I\NULL\W(\\{val}\K\\{getenv}(\\{env}))\I\NULL){}$\1\5
2675 \&{return} \\{setup\_list}${}(\\{ed},\39\\{path},\39\\{val},\39\\{flags});{}$\2%
2676 \6
2677 \&{else}\1\5
2678 ${}\\{fprintf}(\\{stderr},\39\.{"Environment\ variabl}\)\.{e\ `\%s'\ not\ set;\
2679 use\ }\)\.{current\ directory\\n"},\39\\{env}){}$;\2\7
2680 \&{return} \.{TRUE};\6
2681 \4${}\}{}$\2\6
2682 \8\#\&{endif}\par
2683 \fi
2684
2685 \M{76}
2686 \Y\B\4\X2:Global variables\X${}\mathrel+\E{}$\6
2687 \8\#\&{ifdef} \.{HAVE\_EMTEXDIR}\6
2688 \&{char} ${}\\{name\_buffer}[\.{FILE\_NAME\_LENGTH}+\T{1}];{}$\6
2689 \8\#\&{endif}\par
2690 \fi
2691
2692 \M{77}
2693 \Y\B\1\1\6
2694 \8\#\&{ifdef} \.{HAVE\_EMTEXDIR}\6
2695 \&{static} \&{char} ${}{*}\\{file\_find}(\\{name},\39\\{list}){}$\6
2696 \&{char} ${}{*}\\{name};{}$\6
2697 \&{struct} \&{emtex\_dir} ${}{*}\\{list};\2\2{}$\6
2698 ${}\{{}$\1\6
2699 \&{if} ${}(\\{emtex\_dir\_find}(\\{name\_buffer},\39{}$\&{sizeof} (\\{name%
2700 \_buffer})${},\39\\{list},\39\\{name},\39\.{EDF\_CWD})){}$\1\5
2701 \&{return} \\{name\_buffer};\2\7
2702 \&{return} ${}\NULL;{}$\6
2703 \4${}\}{}$\2\6
2704 \8\#\&{endif}\par
2705 \fi
2706
2707 \M{78}
2708 For emtexdir we use the environment variables \.{HBFCFG} and \.{HBFONTS} for
2709 configuration resp.\ HBF header files.
2710
2711 \Y\B\4\X78:Initialize \TeX\ file searching\X${}\E{}$\6
2712 \8\#\&{if} \&{defined} (\.{HAVE\_LIBKPATHSEA})\6
2713 $\\{kpse\_set\_program\_name}(\\{argv}[\T{0}],\39\.{"hbf2gf"});{}$\6
2714 ${}\\{kpse\_init\_prog}(\.{"HBF2GF"},\39\T{300},\39\.{"cx"},\39\.{"cmr10"}){}$;%
2715 \7
2716 \8\#\&{elif} \&{defined} (\.{HAVE\_EMTEXDIR})\6
2717 \&{if} ${}(\R\\{dir\_setup}({\AND}\\{cfg\_path},\39\.{"HBFCFG"},\39\NULL,\39%
2718 \.{EDS\_BANG})){}$\5
2719 ${}\{{}$\1\6
2720 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ setup\ sear}\)\.{ch\ path\ for\
2721 configur}\)\.{ation\ files\\n"});{}$\6
2722 \\{exit}(\T{1});\6
2723 \4${}\}{}$\2\6
2724 \&{if} ${}(\R\\{dir\_setup}({\AND}\\{hbf\_path},\39\.{"HBFONTS"},\39\NULL,\39%
2725 \.{EDS\_BANG})){}$\5
2726 ${}\{{}$\1\6
2727 ${}\\{fprintf}(\\{stderr},\39\.{"Couldn't\ setup\ sear}\)\.{ch\ path\ for\ HBF\
2728 head}\)\.{er\ files\\n"});{}$\6
2729 \\{exit}(\T{1});\6
2730 \4${}\}{}$\2\6
2731 \8\#\&{endif}\par
2732 \U4.\fi
2733
2734 \M{79}
2735 Finally, here are the searching routines. A special format in the kpathsea
2736 library for fonts which are neither PostScript nor TrueType (\.{MISCFONTS})
2737 is available with version~3.3 and newer. For older versions we use the path
2738 for PostScript fonts (\.{T1FONTS}) to find HBF files. Configuration files
2739 are searched in the path specified within \.{TEXCONFIG} for old kpathsea
2740 versions, and within \.{HBF2GFINPUTS} for new versions.
2741
2742 \Y\B\4\X11:Prototypes\X${}\mathrel+\E{}$\6
2743 \&{static} \&{char} ${}{*}{}$\\{TeX\_search\_cfg\_file}(\&{char} ${}{*});{}$\6
2744 \&{static} \&{char} ${}{*}{}$\\{TeX\_search\_hbf\_file}(\&{char} ${}{*}){}$;\par
2745 \fi
2746
2747 \M{80}
2748 \Y\B\1\1\6
2749 \8\#\&{if} \&{defined} (\.{HAVE\_LIBKPATHSEA})\6
2750 \&{static} \&{char} ${}{*}{}$\\{TeX\_search\_cfg\_file}(\&{char} ${}{*}%
2751 \\{name})\2\2{}$\6
2752 ${}\{{}$\1\6
2753 \&{return} \\{kpse\_find\_file}${}(\\{name},\39\\{kpse\_program\_text\_format},%
2754 \39\.{TRUE});{}$\6
2755 \4${}\}{}$\2\7
2756 \1\1\&{static} \&{char} ${}{*}{}$\\{TeX\_search\_hbf\_file}(\&{char} ${}{*}%
2757 \\{name})\2\2{}$\6
2758 ${}\{{}$\1\6
2759 \&{return} \\{kpse\_find\_file}${}(\\{name},\39\\{kpse\_miscfonts\_format},\39%
2760 \.{TRUE});{}$\6
2761 \4${}\}{}$\2\7
2762 \8\#\&{elif} \&{defined} (\.{HAVE\_EMTEXDIR})\7
2763 \1\1\&{static} \&{char} ${}{*}{}$\\{TeX\_search\_cfg\_file}(\&{char} ${}{*}%
2764 \\{name})\2\2{}$\6
2765 ${}\{{}$\1\6
2766 \&{return} \\{file\_find}${}(\\{name},\39{\AND}\\{cfg\_path});{}$\6
2767 \4${}\}{}$\2\7
2768 \1\1\&{static} \&{char} ${}{*}{}$\\{TeX\_search\_hbf\_file}(\&{char} ${}{*}%
2769 \\{name})\2\2{}$\6
2770 ${}\{{}$\1\6
2771 \&{return} \\{file\_find}${}(\\{name},\39{\AND}\\{hbf\_path});{}$\6
2772 \4${}\}{}$\2\7
2773 \8\#\&{elif} \&{defined} (\.{HAVE\_MIKTEX})\7
2774 \1\1\&{static} \&{char} ${}{*}{}$\\{TeX\_search\_cfg\_file}(\&{char} ${}{*}%
2775 \\{name})\2\2{}$\6
2776 ${}\{{}$\1\6
2777 \&{char} \\{result}[\.{\_MAX\_PATH}];\7
2778 \&{if} ${}(\R\\{miktex\_find\_input\_file}(\.{"hbf2gf"},\39{*}\\{name},\39%
2779 \\{result})){}$\1\5
2780 \&{return} \T{0};\2\6
2781 \&{return} \\{strdup}(\\{result});\6
2782 \4${}\}{}$\2\7
2783 \1\1\&{static} \&{char} ${}{*}{}$\\{TeX\_search\_hbf\_file}(\&{char} ${}{*}%
2784 \\{name})\2\2{}$\6
2785 ${}\{{}$\1\6
2786 \&{char} \\{result}[\.{\_MAX\_PATH}];\7
2787 \&{if} ${}(\R\\{miktex\_find\_miscfont\_file}({*}\\{name},\39\\{result})){}$\1\5
2788 \&{return} \T{0};\2\6
2789 \&{return} \\{strdup}(\\{result});\6
2790 \4${}\}{}$\2\7
2791 \8\#\&{else}\7
2792 \1\1\&{static} \&{char} ${}{*}{}$\\{TeX\_search\_cfg\_file}(\&{char} ${}{*}%
2793 \\{name})\2\2{}$\6
2794 ${}\{{}$\1\6
2795 \&{return} \\{name};\6
2796 \4${}\}{}$\2\7
2797 \1\1\&{static} \&{char} ${}{*}{}$\\{TeX\_search\_hbf\_file}(\&{char} ${}{*}%
2798 \\{name})\2\2{}$\6
2799 ${}\{{}$\1\6
2800 \&{return} \\{name};\6
2801 \4${}\}{}$\2\6
2802 \8\#\&{endif}\par
2803 \fi
2804
2805 \N{1}{81}An example.
2806 This is the example configuration file \.{b5so12.cfg} (for use with DOS or
2807 OS/2 and the emtexdir searching engine):
2808 \bigskip
2809 \halign{\quad\.{#}\hfil&\quad\.{#}\hfil\cr
2810 hbf\_header & et24.hbf \cr
2811 mag\_x & 2.076 \cr
2812 x\_offset & 3 \cr
2813 y\_offset & -8 \cr
2814 comment & fanti songti 24x24 pixel font scaled and
2815 adapted to 12 pt \cr
2816 & \cr
2817 design\_size & 12.0 \cr
2818 & \cr
2819 nmb\_fonts & -1 \cr
2820 & \cr
2821 output\_name & b5so12 \cr
2822 & \cr
2823 dpi\_x & 300 \cr
2824 checksum & 123456789 \cr
2825 coding & codingscheme Big 5 encoded TeX text \cr
2826 & \cr
2827 long\_extension & no \cr
2828 job\_extension & .cmd \cr
2829 rm\_command & del \cr
2830 cp\_command & copy \cr
2831 pk\_directory & \$HBF\_TARGET\\pk\\360dpi\\ \cr
2832 tfm\_directory & \$HBF\_TARGET\\tfm\\ \cr
2833 }
2834 \bigskip
2835 If you say e.g.
2836 \medskip
2837 \quad \.{set HBF\_TARGET=c:\\emtex\\texfonts}
2838 \medskip
2839 on your DOS prompt (or in your \.{autoexec.bat} file), then the interpolated
2840 value of the \.{tfm\_directory} keyword is \.{c:\\emtex\\texfonts\\tfm\\}.
2841 The HBF header file \.{et24.hbf} will be searched in the path specified by
2842 the \.{HBFCFG} environment variable.
2843 \bigskip
2844 The call
2845 \medskip
2846 \quad \.{hbf2gf b5so12.cfg}
2847 \medskip
2848 creates the files
2849 \medskip
2850 \quad \.{b5so1201.gf}, \.{b5so1202.gf}, $\ldots$ , \.{b5so1255.gf},
2851 \.{b5so12.pl}, and \.{b5so12.cmd}
2852 \bigskip
2853 After calling
2854 \medskip
2855 \quad \.{b5so12.cmd}
2856 \medskip
2857 you will find the \.{PK} files in the
2858 \.{c:\\emtex\\texfonts\\pk\\360dpi} directory and the \.{TFM} files in
2859 the \.{c:\\emtex\\texfonts\\tfm} directory; all \.{GF} files and
2860 \.{b5so12.pl} will be deleted.
2861 \bigskip
2862 The call
2863 \medskip
2864 \quad \.{hbf2gf -n b5so1220 417}
2865 \medskip
2866 creates two files:
2867 \medskip
2868 \quad \.{b5so1220.gf} and \.{b5so1220.pl}
2869 \medskip
2870 using the configuration file \.{b5so12.cfg}. The \.{GF} file would be
2871 named \.{b5so1220.417gf} if the flag \.{-n} had not been used.
2872
2873 \medskip
2874
2875 It is possible to convert bitmap fonts to \.{PK} files almost
2876 automatically. The HBF header file already has the entry
2877 \.{HBF\_BITMAP\_BOUNDING\_BOX} which defines vertical and horizontal offsets
2878 (in pixels), but these values are not in all cases optimal. If you omit
2879 \.{x\_offset} and \.{y\_offset} in the configuration file, the third and
2880 fourth parameter of \.{HBF\_BITMAP\_BOUNDING\_BOX} is used, scaled to design
2881 size (to say it in other words: \.{x\_offset} and \.{y\_offset} will always
2882 apply to the design size to be synchronous with the \.{TFM} files).
2883
2884 Don't confuse scaling and magnification: Scaling here means that you choose
2885 a (arbitrary) design size and compute scaling values (\.{mag\_x} and
2886 \.{mag\_y}) which scales the bitmap to this particular design size at a
2887 certain (arbitrarily chosen) resolution (\.{dpi\_x} and \.{dpi\_y}).
2888 Magnification means that the scaled bitmap will be then magnified to a
2889 certain target size while still using the font parameters (i.e., the
2890 \.{TFM} file) of the design size.
2891
2892 In the sample, you have a $24 \times 24$ bitmap font which will be scaled to
2893 $12\,\hbox{pt}$ having a resolution of $300\,\hbox{dpi}$:
2894 \medskip
2895 \quad $1\,\hbox{pt}$ are $300 / 72.27 = 4.1511$ pixel;
2896
2897 \quad $12\,\hbox{pt}$ are $4.1511 * 12 = 49.813$ pixel;
2898
2899 \quad thus the theoretical scaling value is $49.813 / 24 = 2.076$.
2900
2901 \medskip
2902
2903 But especially for small sizes, this may not be the best value if the font
2904 should harmonize with, say, Knuth's Computer Modern fonts. I recommend to
2905 compute, say, 5~\.{PK} fonts, then check the CJK font with different \TeX\
2906 fonts to see whether the offsets and/or the scaling value is good. The
2907 greater the design size the finer you can control the offsets---as an
2908 example you could use a design size of $30\,\hbox{pt}$ (nevertheless there
2909 is a compile-time constant \PB{\.{MAX\_CHAR\_SIZE}} which limits the maximal
2910 character size; default is 255~pixels).
2911
2912 If you have found optimal offsets, you can produce many different
2913 magnifications of the CJK font using the same set of \.{TFM} files
2914 analogous to ordinary \TeX\ fonts; as a simplification, we assume that
2915 \.{PK} files with a resolution of $300\,\hbox{dpi}$ and a design size of
2916 $10\,\hbox{pt}$ have the extension `\.{.300pk}' (respectively come into a
2917 `\.{300dpi}' subdirectory)---this is the reason why in the above example for
2918 the $12\,\hbox{pt}$ design size a `\.{360dpi}' target directory has been
2919 used. Now we can use the following formula:
2920
2921 $$ \\{needed\_dpi} = \\{your\_horizontal\_resolution} *
2922 {\\{your\_target\_size} \over 10.0} $$
2923
2924 Example: assuming that your printer has a resolution of
2925 $300\times400\,\hbox{dpi}$, and you want $14.4\,\hbox{pt}$:
2926
2927 $$ 300 * {14.4 \over 10.0} = 432 $$
2928
2929 The vertical scaling value is $400 / 300 = 1.3333$. Use these values now to
2930 call \.{hbf2gf} in \mf-like mode:
2931
2932 \quad \.{hbf2gf b5so1220 432 1.3333}
2933
2934
2935
2936 \fi
2937
2938 \N{1}{82}Index.
2939 \fi
2940
2941 \inx
2942 \fin
2943 \con