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