| 1 |
/* |
| 2 |
* ttf2tfm.c |
| 3 |
* |
| 4 |
* This file is part of the ttf2pk package. |
| 5 |
* |
| 6 |
* Copyright 1997-1999, 2000, 2002 by |
| 7 |
* Frederic Loyer <[email protected]> |
| 8 |
* Werner Lemberg <[email protected]>. |
| 9 |
* Copyright 2009-2013 by |
| 10 |
* Peter Breitenlohner <[email protected]> |
| 11 |
*/ |
| 12 |
|
| 13 |
/* |
| 14 |
* This program converts TTF files to TeX TFM files, and optionally |
| 15 |
* to TeX VPL files that retain all kerning and ligature information. |
| 16 |
* Both files make the characters not normally encoded by TeX available |
| 17 |
* by character codes greater than 0x7F. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* Adapted from afm2tfm by F. Loyer <[email protected]>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifdef HAVE_CONFIG_H |
| 25 |
#include <config.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include <stdio.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <stddef.h> /* for size_t */ |
| 31 |
#include <string.h> |
| 32 |
|
| 33 |
#ifdef MIKTEX |
| 34 |
#include <miktex.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
#include "ttf2tfm.h" |
| 38 |
#include "newobj.h" |
| 39 |
#include "ttfenc.h" |
| 40 |
#include "ligkern.h" |
| 41 |
#include "texenc.h" |
| 42 |
#include "ttfaux.h" |
| 43 |
#include "tfmaux.h" |
| 44 |
#include "vplaux.h" |
| 45 |
#include "errormsg.h" |
| 46 |
#include "filesrch.h" |
| 47 |
#include "parse.h" |
| 48 |
#include "subfont.h" |
| 49 |
|
| 50 |
|
| 51 |
char ident[] = "ttf2tfm version 2.0"; |
| 52 |
const char *progname = "ttf2tfm"; /* for error/warning messages */ |
| 53 |
|
| 54 |
/* command line options */ |
| 55 |
|
| 56 |
static char makevpl; /* can be 1 or 2 */ |
| 57 |
static Boolean pedantic; |
| 58 |
static Boolean quiet; |
| 59 |
static Boolean forceoctal; |
| 60 |
|
| 61 |
|
| 62 |
/* |
| 63 |
* Re-encode the TTF font. |
| 64 |
*/ |
| 65 |
|
| 66 |
static void |
| 67 |
handlereencoding(Font *fnt) |
| 68 |
{ |
| 69 |
int i; |
| 70 |
ttfinfo *ti; |
| 71 |
const char *p; |
| 72 |
|
| 73 |
|
| 74 |
if (fnt->inencname) |
| 75 |
{ |
| 76 |
fnt->inencoding = readencoding(&(fnt->inencname), fnt, True); |
| 77 |
|
| 78 |
/* reset all pointers in the mapping table */ |
| 79 |
for (i = 0; i <= 0xFF; i++) |
| 80 |
if (NULL != (ti = fnt->inencptrs[i])) |
| 81 |
{ |
| 82 |
ti->incode = -1; |
| 83 |
fnt->inencptrs[i] = NULL; |
| 84 |
} |
| 85 |
|
| 86 |
/* |
| 87 |
* Reencode TTF <--> raw TeX. Only these code points will be used |
| 88 |
* for the output encoding. |
| 89 |
*/ |
| 90 |
|
| 91 |
for (i = 0; i <= 0xFF; i++) |
| 92 |
{ |
| 93 |
p = fnt->inencoding->vec[i]; |
| 94 |
if (p && *p) |
| 95 |
{ |
| 96 |
if ((ti = findadobe(p, fnt->charlist))) |
| 97 |
{ |
| 98 |
if (ti->incode >= 0) |
| 99 |
{ |
| 100 |
warning("Character `%s' encoded twice in input encoding\n" |
| 101 |
" (positions %x and %x; the latter is ignored).", |
| 102 |
p, ti->incode, i); |
| 103 |
fnt->inencoding->vec[i] = ".notdef"; |
| 104 |
continue; |
| 105 |
} |
| 106 |
if (ti->charcode >= 0) |
| 107 |
{ |
| 108 |
ti->incode = i; |
| 109 |
fnt->inencptrs[i] = ti; |
| 110 |
} |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
warning("Cannot find character `%s'\n" |
| 115 |
" specified in input encoding.", p); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
fnt->codingscheme = fnt->inencoding->name; |
| 120 |
} |
| 121 |
|
| 122 |
if (!quiet) |
| 123 |
{ |
| 124 |
if (fnt->inencname) |
| 125 |
printf("\nUsing %s as input encoding.\n", fnt->inencname); |
| 126 |
else |
| 127 |
{ |
| 128 |
printf( |
| 129 |
"\nUsing the first 256 glyphs in the following input encoding:\n\n"); |
| 130 |
for (i = 0; i <= 0xFF; i++) |
| 131 |
{ |
| 132 |
if ((ti = fnt->inencptrs[i])) |
| 133 |
printf(" 0x%02x %s\n", i, ti->adobename); |
| 134 |
} |
| 135 |
printf("\n"); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
if (fnt->outencname) |
| 140 |
fnt->outencoding = readencoding(&(fnt->outencname), fnt, False); |
| 141 |
else |
| 142 |
fnt->outencoding = readencoding(NULL, fnt, False); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
static void |
| 147 |
assignchars(Font *fnt) |
| 148 |
{ |
| 149 |
register const char **p; |
| 150 |
register int i, j, k; |
| 151 |
register ttfinfo *ti; |
| 152 |
int nextfree = 0x80; |
| 153 |
|
| 154 |
|
| 155 |
/* |
| 156 |
* First, we assign all those that match perfectly. |
| 157 |
*/ |
| 158 |
|
| 159 |
for (i = 0, p = fnt->outencoding->vec; i <= 0xFF; i++, p++) |
| 160 |
if ((ti = findmappedadobe(*p, fnt->inencptrs))) |
| 161 |
{ |
| 162 |
if (ti->outcode >= 0) |
| 163 |
fnt->nextout[i] = ti->outcode; /* linked list */ |
| 164 |
ti->outcode = i; |
| 165 |
fnt->outencptrs[i] = ti; |
| 166 |
} |
| 167 |
else if (strcmp(*p, ".notdef") != 0) |
| 168 |
warning("Cannot map character `%s'\n" |
| 169 |
" specified in output encoding.", *p); |
| 170 |
|
| 171 |
if (pedantic) |
| 172 |
goto end; |
| 173 |
|
| 174 |
/* |
| 175 |
* Next, we assign all the others, retaining the TTF code positions, |
| 176 |
* possibly multiplying assigned characters, unless the output encoding |
| 177 |
* was precisely specified. |
| 178 |
*/ |
| 179 |
|
| 180 |
for (i = 0; i <= 0xFF; i++) |
| 181 |
if ((ti = fnt->inencptrs[i]) && |
| 182 |
ti->charcode >= 0 && ti->charcode <= 0xFF && |
| 183 |
ti->outcode < 0 && fnt->outencptrs[ti->charcode] == NULL) |
| 184 |
{ |
| 185 |
ti->outcode = ti->charcode; |
| 186 |
fnt->outencptrs[ti->charcode] = ti; |
| 187 |
} |
| 188 |
|
| 189 |
/* |
| 190 |
* Finally, we map all remaining characters into free locations beginning |
| 191 |
* with 0x80. |
| 192 |
*/ |
| 193 |
|
| 194 |
for (i = 0; i <= 0xFF; i++) |
| 195 |
if ((ti = fnt->inencptrs[i]) && ti->outcode < 0) |
| 196 |
{ |
| 197 |
while (fnt->outencptrs[nextfree]) |
| 198 |
{ |
| 199 |
nextfree = (nextfree + 1) & 0xFF; |
| 200 |
if (nextfree == 0x80) |
| 201 |
goto finishup; /* all slots full */ |
| 202 |
} |
| 203 |
ti->outcode = nextfree; |
| 204 |
fnt->outencptrs[nextfree] = ti; |
| 205 |
} |
| 206 |
|
| 207 |
finishup: |
| 208 |
|
| 209 |
/* |
| 210 |
* Now, if any of the characters are encoded multiple times, we want |
| 211 |
* ti->outcode to be the first one assigned, since that is most likely |
| 212 |
* to be the most important one. So we reverse the above lists. |
| 213 |
*/ |
| 214 |
|
| 215 |
for (i = 0; i <= 0xFF; i++) |
| 216 |
if ((ti = fnt->inencptrs[i]) && ti->outcode >= 0) |
| 217 |
{ |
| 218 |
k = -1; |
| 219 |
while (fnt->nextout[ti->outcode] >= 0) |
| 220 |
{ |
| 221 |
j = fnt->nextout[ti->outcode]; |
| 222 |
fnt->nextout[ti->outcode] = k; |
| 223 |
k = ti->outcode; |
| 224 |
ti->outcode = j; |
| 225 |
} |
| 226 |
fnt->nextout[ti->outcode] = k; |
| 227 |
} |
| 228 |
|
| 229 |
end: |
| 230 |
|
| 231 |
if (!quiet) |
| 232 |
{ |
| 233 |
printf("\nUsing the following output encoding:\n\n"); |
| 234 |
for (i = 0; i <= 0xFF; i++) |
| 235 |
{ |
| 236 |
if ((ti = fnt->outencptrs[i])) |
| 237 |
printf(" 0x%02x %s\n", i, ti->adobename); |
| 238 |
} |
| 239 |
printf("\n"); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
#define MAX_SFLIST 10 |
| 245 |
static void |
| 246 |
add_subfont_list(Font *fnt) |
| 247 |
{ |
| 248 |
if (fnt->subfont_list == NULL) |
| 249 |
fnt->subfont_list = (sflist *)mymalloc(MAX_SFLIST * sizeof(sflist)); |
| 250 |
else if (fnt->subfont_num % MAX_SFLIST == 0) |
| 251 |
fnt->subfont_list = (sflist *)myrealloc(fnt->subfont_list, |
| 252 |
(fnt->subfont_num / MAX_SFLIST + 1) * MAX_SFLIST * sizeof(sflist)); |
| 253 |
|
| 254 |
(fnt->subfont_list[fnt->subfont_num]).name = |
| 255 |
(char *)mymalloc(strlen(fnt->fullname)+1); |
| 256 |
strcpy((fnt->subfont_list[fnt->subfont_num]).name, fnt->fullname); |
| 257 |
(fnt->subfont_list[fnt->subfont_num]).cksum = fnt->cksum; |
| 258 |
|
| 259 |
fnt->subfont_num++; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
static void |
| 264 |
release_subfont_list(Font *fnt) |
| 265 |
{ |
| 266 |
register int i; |
| 267 |
|
| 268 |
for (i = 0; i < fnt->subfont_num; i++) |
| 269 |
free((fnt->subfont_list[i]).name); |
| 270 |
|
| 271 |
free(fnt->subfont_list); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
#define VERSION "\ |
| 276 |
Copyright (C) 1997-1999, 2000, 2002 Frederic Loyer and Werner Lemberg.\n\ |
| 277 |
2009-2013 Peter Breitenlohner\n\ |
| 278 |
There is NO warranty. You may redistribute this software\n\ |
| 279 |
under the terms of the GNU General Public License\n\ |
| 280 |
and the Dvips copyright.\n\ |
| 281 |
\n\ |
| 282 |
For more information about these matters, see the files\n\ |
| 283 |
named COPYING and ttf2tfm.c.\n\ |
| 284 |
\n\ |
| 285 |
Primary authors of ttf2tfm: F. Loyer and W. Lemberg.\n\ |
| 286 |
\n\ |
| 287 |
ttf2tfm is based on afm2tfm from T. Rokicki\n\ |
| 288 |
and the FreeType project from\n\ |
| 289 |
David Turner, Robert Wilhelm, and Werner Lemberg.\n\ |
| 290 |
" |
| 291 |
|
| 292 |
static void |
| 293 |
version(void) |
| 294 |
{ |
| 295 |
fputs(ident, stdout); |
| 296 |
fprintf(stdout, " (%s, %s)\n", TeX_search_version(), TL_VERSION); |
| 297 |
fputs(VERSION, stdout); |
| 298 |
exit(0); |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
#define USAGE "\ |
| 303 |
Convert a TrueType font table to TeX's font metric format.\n\ |
| 304 |
\n\ |
| 305 |
-c REAL use REAL for height of small caps made with -V [0.8]\n\ |
| 306 |
-e REAL widen (extend) characters by a factor of REAL [1.0]\n\ |
| 307 |
-E INT select INT as the TTF encoding ID [1]\n\ |
| 308 |
-f INT select INT as the font index in a TTC [0]\n\ |
| 309 |
-l create 1st/2nd byte ligatures in subfonts\n\ |
| 310 |
-L LIGFILE[.sfd] create 1st/2nd byte ligatures in subfonts using LIGFILE\n\ |
| 311 |
-n use PS names of TrueType font\n\ |
| 312 |
-N use only PS names and no cmap\n\ |
| 313 |
-o FILE[.ovp] make an OVP file for conversion to OVF and OFM\n\ |
| 314 |
-O use octal for all character codes in the vpl file\n\ |
| 315 |
-p ENCFILE[.enc] read ENCFILE for the TTF->raw TeX mapping\n\ |
| 316 |
-P INT select INT as the TTF platform ID [3]\n\ |
| 317 |
-q suppress informational output\n\ |
| 318 |
-r OLDNAME NEWNAME replace glyph name OLDNAME with NEWNAME\n\ |
| 319 |
-R RPLFILE[.rpl] read RPLFILE containing glyph replacement names\n\ |
| 320 |
-s REAL oblique (slant) characters by REAL, usually <<1 [0.0]\n\ |
| 321 |
-t ENCFILE[.enc] read ENCFILE for the encoding of the vpl file\n\ |
| 322 |
-T ENCFILE[.enc] equivalent to -p ENCFILE -t ENCFILE\n\ |
| 323 |
-u output only characters from encodings, nothing extra\n\ |
| 324 |
-v FILE[.vpl] make a VPL file for conversion to VF\n\ |
| 325 |
-V SCFILE[.vpl] like -v, but synthesize smallcaps as lowercase\n\ |
| 326 |
-w generate subfont enc. vectors containing glyph indices\n\ |
| 327 |
-x rotate subfont glyphs by 90 degrees\n\ |
| 328 |
-y REAL move rotated glyphs down by a factor of REAL [0.25]\n\ |
| 329 |
--help print this message and exit\n\ |
| 330 |
--version print version number and exit\n\ |
| 331 |
\n\ |
| 332 |
Report bugs to " PACKAGE_BUGREPORT ".\n\ |
| 333 |
" |
| 334 |
|
| 335 |
static void |
| 336 |
usage(void) |
| 337 |
{ |
| 338 |
fputs("Usage: ttf2tfm FILE[.ttf|.ttc] [OPTION]... [FILE[.tfm]]\n", stdout); |
| 339 |
fputs(USAGE, stdout); |
| 340 |
exit(0); |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
static void |
| 345 |
handle_options(int argc, char *argv[], Font *fnt) |
| 346 |
{ |
| 347 |
register int lastext; |
| 348 |
register int i; |
| 349 |
size_t l; |
| 350 |
int arginc; |
| 351 |
char *temp; |
| 352 |
char c; |
| 353 |
char *vpl_name = NULL; |
| 354 |
Boolean have_capheight = 0; |
| 355 |
Boolean have_sfd = 0; |
| 356 |
int sfd_begin, postfix_begin; |
| 357 |
int base_name; |
| 358 |
stringlist* sl; |
| 359 |
|
| 360 |
|
| 361 |
/* scan first whether the -q switch is set */ |
| 362 |
for (i = 1; i < argc; i++) |
| 363 |
if (argv[i][0] == '-' && argv[i][1] == 'q') |
| 364 |
quiet = True; |
| 365 |
|
| 366 |
if (!quiet) |
| 367 |
printf("This is %s\n", ident); |
| 368 |
|
| 369 |
/* Make VPL file identical to that created under Unix */ |
| 370 |
fnt->titlebuf = (char *)mymalloc(strlen(progname) + strlen(argv[1]) + |
| 371 |
1 + 1); |
| 372 |
sprintf(fnt->titlebuf, "%s %s", progname, argv[1]); |
| 373 |
|
| 374 |
|
| 375 |
/* |
| 376 |
* TrueType font name. |
| 377 |
*/ |
| 378 |
|
| 379 |
fnt->ttfname = newstring(argv[1]); |
| 380 |
|
| 381 |
/* |
| 382 |
* The other arguments. We delay the final processing of some switches |
| 383 |
* until the tfm font name has been scanned -- if it contains two `@'s, |
| 384 |
* many switches are ignored. |
| 385 |
*/ |
| 386 |
|
| 387 |
while (argc > 2 && *argv[2] == '-') |
| 388 |
{ |
| 389 |
arginc = 2; |
| 390 |
i = argv[2][1]; |
| 391 |
|
| 392 |
switch (i) |
| 393 |
{ |
| 394 |
case 'v': |
| 395 |
makevpl = 1; |
| 396 |
if (argc <= 3) |
| 397 |
oops("Missing parameter for -v option."); |
| 398 |
if (vpl_name) |
| 399 |
free(vpl_name); |
| 400 |
vpl_name = newstring(argv[3]); |
| 401 |
handle_extension(&vpl_name, ".vpl"); |
| 402 |
break; |
| 403 |
|
| 404 |
case 'V': |
| 405 |
makevpl = 2; |
| 406 |
if (argc <= 3) |
| 407 |
oops("Missing parameter for -V option."); |
| 408 |
if (vpl_name) |
| 409 |
free(vpl_name); |
| 410 |
vpl_name = newstring(argv[3]); |
| 411 |
handle_extension(&vpl_name, ".vpl"); |
| 412 |
break; |
| 413 |
|
| 414 |
case 'f': |
| 415 |
if (argc <= 3) |
| 416 |
oops("Missing parameter for -f option."); |
| 417 |
if (sscanf(argv[3], "%lu", &(fnt->fontindex)) == 0) |
| 418 |
oops("Invalid font index."); |
| 419 |
fnt->fontindexparam = argv[3]; |
| 420 |
break; |
| 421 |
|
| 422 |
case 'E': |
| 423 |
if (argc <= 3) |
| 424 |
oops("Missing parameter for -E option."); |
| 425 |
if (sscanf(argv[3], "%hu", &(fnt->eid)) == 0) |
| 426 |
oops("Invalid encoding ID."); |
| 427 |
fnt->eidparam = argv[3]; |
| 428 |
break; |
| 429 |
|
| 430 |
case 'P': |
| 431 |
if (argc <= 3) |
| 432 |
oops("Missing parameter for -P option."); |
| 433 |
if (sscanf(argv[3], "%hu", &(fnt->pid)) == 0) |
| 434 |
oops("Invalid platform ID."); |
| 435 |
fnt->pidparam = argv[3]; |
| 436 |
break; |
| 437 |
|
| 438 |
case 'e': |
| 439 |
if (argc <= 3) |
| 440 |
oops("Missing parameter for -e option."); |
| 441 |
if (sscanf(argv[3], "%f", &(fnt->efactor)) == 0 || fnt->efactor < 0.01) |
| 442 |
oops("Bad extension factor."); |
| 443 |
fnt->efactorparam = argv[3]; |
| 444 |
break; |
| 445 |
|
| 446 |
case 'c': |
| 447 |
if (argc <= 3) |
| 448 |
oops("Missing parameter for -c option."); |
| 449 |
have_capheight = True; |
| 450 |
if (sscanf(argv[3], "%f", &(fnt->capheight)) == 0) |
| 451 |
fnt->capheight = 0; |
| 452 |
break; |
| 453 |
|
| 454 |
case 's': |
| 455 |
if (argc <= 3) |
| 456 |
oops("Missing parameter for -s option."); |
| 457 |
if (sscanf(argv[3], "%f", &(fnt->slant)) == 0) |
| 458 |
oops("Bad slant parameter."); |
| 459 |
fnt->slantparam = argv[3]; |
| 460 |
break; |
| 461 |
|
| 462 |
case 'p': |
| 463 |
if (argc <= 3) |
| 464 |
oops("Missing parameter for -p option."); |
| 465 |
if (fnt->inencname) |
| 466 |
free(fnt->inencname); |
| 467 |
fnt->inencname = newstring(argv[3]); |
| 468 |
break; |
| 469 |
|
| 470 |
case 'T': |
| 471 |
if (argc <= 3) |
| 472 |
oops("Missing parameter for -T option."); |
| 473 |
if (fnt->inencname) |
| 474 |
free(fnt->inencname); |
| 475 |
if (fnt->outencname) |
| 476 |
free(fnt->outencname); |
| 477 |
fnt->inencname = newstring(argv[3]); |
| 478 |
fnt->outencname = newstring(argv[3]); |
| 479 |
break; |
| 480 |
|
| 481 |
case 't': |
| 482 |
if (argc <= 3) |
| 483 |
oops("Missing parameter for -T option."); |
| 484 |
if (fnt->outencname) |
| 485 |
free(fnt->outencname); |
| 486 |
fnt->outencname = newstring(argv[3]); |
| 487 |
break; |
| 488 |
|
| 489 |
case 'r': |
| 490 |
if (argc <= 4) |
| 491 |
oops("Not enough parameters for -r option."); |
| 492 |
sl = newstringlist(); |
| 493 |
sl->old_name = newstring(argv[3]); |
| 494 |
sl->new_name = newstring(argv[4]); |
| 495 |
sl->single_replacement = True; |
| 496 |
sl->next = fnt->replacements; |
| 497 |
fnt->replacements = sl; |
| 498 |
arginc = 3; |
| 499 |
break; |
| 500 |
|
| 501 |
case 'R': |
| 502 |
if (argc <= 3) |
| 503 |
oops("Missing parameter for -R option."); |
| 504 |
if (fnt->replacementname) |
| 505 |
free(fnt->replacementname); |
| 506 |
fnt->replacementname = newstring(argv[3]); |
| 507 |
break; |
| 508 |
|
| 509 |
case 'y': |
| 510 |
if (argc <= 3) |
| 511 |
oops("Missing parameter for -y option."); |
| 512 |
if (sscanf(argv[3], "%f", &(fnt->y_offset)) == 0) |
| 513 |
oops("Invalid y-offset."); |
| 514 |
fnt->y_offsetparam = argv[3]; |
| 515 |
break; |
| 516 |
|
| 517 |
case 'O': |
| 518 |
forceoctal = True; |
| 519 |
arginc = 1; |
| 520 |
break; |
| 521 |
|
| 522 |
case 'n': |
| 523 |
fnt->PSnames = Yes; |
| 524 |
arginc = 1; |
| 525 |
break; |
| 526 |
|
| 527 |
case 'N': |
| 528 |
fnt->PSnames = Only; |
| 529 |
arginc = 1; |
| 530 |
break; |
| 531 |
|
| 532 |
case 'u': |
| 533 |
pedantic = True; |
| 534 |
arginc = 1; |
| 535 |
break; |
| 536 |
|
| 537 |
case 'q': |
| 538 |
quiet = True; |
| 539 |
arginc = 1; |
| 540 |
break; |
| 541 |
|
| 542 |
case 'L': |
| 543 |
if (argc <= 3) |
| 544 |
oops("Missing parameter for -L option."); |
| 545 |
if (fnt->ligname) |
| 546 |
free(fnt->ligname); |
| 547 |
fnt->ligname = newstring(argv[3]); |
| 548 |
fnt->subfont_ligs = True; |
| 549 |
break; |
| 550 |
|
| 551 |
case 'l': |
| 552 |
fnt->subfont_ligs = True; |
| 553 |
arginc = 1; |
| 554 |
break; |
| 555 |
|
| 556 |
case 'w': |
| 557 |
fnt->write_enc = True; |
| 558 |
arginc = 1; |
| 559 |
break; |
| 560 |
|
| 561 |
case 'x': |
| 562 |
fnt->rotate = True; |
| 563 |
arginc = 1; |
| 564 |
break; |
| 565 |
|
| 566 |
case 'o': |
| 567 |
if (argc <= 3) |
| 568 |
oops("Missing parameter for -o option."); |
| 569 |
if (vpl_name) |
| 570 |
free(vpl_name); |
| 571 |
vpl_name = newstring(argv[3]); |
| 572 |
handle_extension(&vpl_name, ".ovp"); |
| 573 |
break; |
| 574 |
|
| 575 |
default: |
| 576 |
if (argc <= 3 || argv[3][0] == '-') |
| 577 |
{ |
| 578 |
warning("Unknown option `%s' will be ignored.\n", argv[2]); |
| 579 |
arginc = 1; |
| 580 |
} |
| 581 |
else |
| 582 |
warning("Unknown option `%s %s' will be ignored.\n", |
| 583 |
argv[2], argv[3]); |
| 584 |
} |
| 585 |
|
| 586 |
for (i = 0; i < arginc; i++) |
| 587 |
{ |
| 588 |
l = strlen(fnt->titlebuf); |
| 589 |
fnt->titlebuf = (char *)myrealloc((void *)fnt->titlebuf, |
| 590 |
l + strlen(argv[2]) + 1 + 1); |
| 591 |
sprintf(fnt->titlebuf + strlen(fnt->titlebuf), " %s", argv[2]); |
| 592 |
argv++; |
| 593 |
argc--; |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
/* Read replacement glyph name file */ |
| 598 |
|
| 599 |
get_replacements(fnt); |
| 600 |
|
| 601 |
if (argc > 3 || (argc == 3 && *argv[2] == '-')) |
| 602 |
oops("Need at most two non-option arguments."); |
| 603 |
|
| 604 |
/* |
| 605 |
* The tfm file name. |
| 606 |
*/ |
| 607 |
|
| 608 |
if (argc == 2) |
| 609 |
temp = newstring(fnt->ttfname); |
| 610 |
else |
| 611 |
{ |
| 612 |
temp = newstring(argv[2]); |
| 613 |
l = strlen(fnt->titlebuf); |
| 614 |
fnt->titlebuf = (char *)myrealloc((void *)fnt->titlebuf, |
| 615 |
l + strlen(argv[2]) + 1 + 1); |
| 616 |
sprintf(fnt->titlebuf + strlen(fnt->titlebuf), " %s", argv[2]); |
| 617 |
} |
| 618 |
|
| 619 |
handle_sfd(temp, &sfd_begin, &postfix_begin); |
| 620 |
|
| 621 |
if (sfd_begin > -1) |
| 622 |
{ |
| 623 |
have_sfd = True; |
| 624 |
i = sfd_begin - 2; |
| 625 |
} |
| 626 |
else |
| 627 |
i = strlen(temp) - 1; |
| 628 |
|
| 629 |
/* |
| 630 |
* Now we search the beginning of the name without directory. |
| 631 |
*/ |
| 632 |
|
| 633 |
for (; i >= 0; i--) |
| 634 |
if (temp[i] == '/' || temp[i] == ':' || temp[i] == '\\') |
| 635 |
break; |
| 636 |
|
| 637 |
base_name = i + 1; |
| 638 |
|
| 639 |
/* |
| 640 |
* We store the path (with the final directory separator). |
| 641 |
*/ |
| 642 |
|
| 643 |
if (base_name > 0) |
| 644 |
{ |
| 645 |
c = temp[base_name]; |
| 646 |
temp[base_name] = '\0'; |
| 647 |
fnt->tfm_path = newstring(temp); |
| 648 |
temp[base_name] = c; |
| 649 |
} |
| 650 |
|
| 651 |
if (have_sfd) |
| 652 |
{ |
| 653 |
/* the prefix and the sfd file name */ |
| 654 |
|
| 655 |
if (temp[base_name]) |
| 656 |
fnt->outname = newstring(temp + base_name); |
| 657 |
|
| 658 |
fnt->sfdname = newstring(temp + sfd_begin); |
| 659 |
} |
| 660 |
else |
| 661 |
postfix_begin = base_name; |
| 662 |
|
| 663 |
/* |
| 664 |
* Get the extension. |
| 665 |
*/ |
| 666 |
|
| 667 |
lastext = -1; |
| 668 |
for (i = postfix_begin; temp[i]; i++) |
| 669 |
if (temp[i] == '.') |
| 670 |
lastext = i; |
| 671 |
|
| 672 |
if (argc == 2 && lastext >= 0) |
| 673 |
{ |
| 674 |
temp[lastext] = '\0'; /* remove TTF file extension */ |
| 675 |
lastext = -1; |
| 676 |
} |
| 677 |
|
| 678 |
if (lastext == -1) |
| 679 |
fnt->tfm_ext = newstring(".tfm"); |
| 680 |
else |
| 681 |
{ |
| 682 |
fnt->tfm_ext = newstring(temp + lastext); |
| 683 |
temp[lastext] = '\0'; |
| 684 |
} |
| 685 |
|
| 686 |
if (have_sfd) |
| 687 |
{ |
| 688 |
if (temp[postfix_begin]) |
| 689 |
fnt->outname_postfix = newstring(temp + postfix_begin); |
| 690 |
} |
| 691 |
else |
| 692 |
{ |
| 693 |
if (temp[base_name]) |
| 694 |
fnt->outname = newstring(temp + base_name); |
| 695 |
else |
| 696 |
oops("Invalid tfm file name."); |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
/* |
| 701 |
* Now we can process the remaining parameters. |
| 702 |
*/ |
| 703 |
|
| 704 |
if (have_sfd) |
| 705 |
{ |
| 706 |
if (makevpl) |
| 707 |
{ |
| 708 |
warning("Ignoring `-v' and `-V' switches for subfonts."); |
| 709 |
makevpl = 0; |
| 710 |
} |
| 711 |
if (vpl_name) |
| 712 |
if ((fnt->vplout = fopen(vpl_name, "wb")) == NULL) |
| 713 |
oops("Cannot open ovp output file."); |
| 714 |
if (have_capheight) |
| 715 |
warning("Ignoring `-c' switch for subfonts."); |
| 716 |
if (fnt->inencname || fnt->outencname) |
| 717 |
{ |
| 718 |
warning("Ignoring `-p', `-t', and `-T' switches for subfonts."); |
| 719 |
fnt->inencname = NULL; |
| 720 |
fnt->outencname = NULL; |
| 721 |
} |
| 722 |
if (fnt->y_offsetparam && !fnt->rotate) |
| 723 |
warning("Ignoring `-y' switch for non-rotated subfonts."); |
| 724 |
if (fnt->PSnames) |
| 725 |
{ |
| 726 |
warning("Ignoring `-n' or '-N' switch for subfonts."); |
| 727 |
fnt->PSnames = No; |
| 728 |
} |
| 729 |
|
| 730 |
init_sfd(fnt, True); |
| 731 |
} |
| 732 |
else |
| 733 |
{ |
| 734 |
if (have_capheight && fnt->capheight < 0.01) |
| 735 |
oops("Bad small caps height."); |
| 736 |
|
| 737 |
if (vpl_name) |
| 738 |
if ((fnt->vplout = fopen(vpl_name, "wb")) == NULL) |
| 739 |
oops("Cannot open vpl output file."); |
| 740 |
|
| 741 |
if (fnt->subfont_ligs) |
| 742 |
{ |
| 743 |
warning("Ignoring `-l' switch for non-subfont."); |
| 744 |
fnt->subfont_ligs = False; |
| 745 |
} |
| 746 |
|
| 747 |
if (fnt->rotate) |
| 748 |
{ |
| 749 |
warning("Ignoring `-x' switch for non-subfont."); |
| 750 |
fnt->rotate = False; |
| 751 |
} |
| 752 |
|
| 753 |
if (fnt->write_enc) |
| 754 |
{ |
| 755 |
warning("Ignoring `-w' switch for non-subfont."); |
| 756 |
fnt->write_enc = False; |
| 757 |
} |
| 758 |
|
| 759 |
if (fnt->y_offsetparam) |
| 760 |
warning("Ignoring `-y' switch for non-subfont."); |
| 761 |
} |
| 762 |
|
| 763 |
if (fnt->PSnames == Only) |
| 764 |
{ |
| 765 |
if (fnt->pidparam || fnt->eidparam) |
| 766 |
{ |
| 767 |
warning("Ignoring `-P' and `-E' options if `-N' switch is selected."); |
| 768 |
fnt->pidparam = NULL; |
| 769 |
fnt->eidparam = NULL; |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
if (vpl_name) |
| 774 |
free(vpl_name); |
| 775 |
free(temp); |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
/* |
| 780 |
* This routine prints out the line that needs to be added to ttfonts.map. |
| 781 |
*/ |
| 782 |
|
| 783 |
static void |
| 784 |
consttfonts(Font *fnt) |
| 785 |
{ |
| 786 |
if (!quiet) |
| 787 |
printf("\n"); |
| 788 |
if (fnt->outname) |
| 789 |
printf("%s", fnt->outname); |
| 790 |
if (fnt->sfdname) |
| 791 |
printf("@%s@", fnt->sfdname); |
| 792 |
if (fnt->outname_postfix) |
| 793 |
printf("%s", fnt->outname_postfix); |
| 794 |
|
| 795 |
printf(" %s", fnt->ttfname); |
| 796 |
|
| 797 |
if (fnt->slantparam || fnt->efactorparam || |
| 798 |
fnt->inencname || |
| 799 |
fnt->pidparam || fnt->eidparam || |
| 800 |
fnt->fontindexparam || |
| 801 |
fnt->replacements || |
| 802 |
fnt->replacementname || |
| 803 |
fnt->PSnames || |
| 804 |
fnt->rotate || fnt->y_offsetparam) |
| 805 |
{ |
| 806 |
if (fnt->slantparam) |
| 807 |
printf(" Slant=%s", fnt->slantparam); |
| 808 |
if (fnt->efactorparam) |
| 809 |
printf(" Extend=%s", fnt->efactorparam); |
| 810 |
if (fnt->inencname) |
| 811 |
printf(" Encoding=%s", fnt->inencname); |
| 812 |
if (fnt->pidparam) |
| 813 |
printf(" Pid=%s", fnt->pidparam); |
| 814 |
if (fnt->eidparam) |
| 815 |
printf(" Eid=%s", fnt->eidparam); |
| 816 |
if (fnt->fontindexparam) |
| 817 |
printf(" Fontindex=%s", fnt->fontindexparam); |
| 818 |
if (fnt->PSnames) |
| 819 |
printf(" PS=%s", fnt->PSnames == Yes ? "Yes" : "Only"); |
| 820 |
if (fnt->rotate) |
| 821 |
printf(" Rotate=Yes"); |
| 822 |
if (fnt->y_offsetparam) |
| 823 |
printf(" Y-Offset=%s", fnt->y_offsetparam); |
| 824 |
if (fnt->replacementname && fnt->inencoding) |
| 825 |
printf(" Replacement=%s", fnt->replacementname); |
| 826 |
if (fnt->replacements && fnt->inencoding) |
| 827 |
{ |
| 828 |
stringlist *sl; |
| 829 |
|
| 830 |
|
| 831 |
for (sl = fnt->replacements; sl; sl = sl->next) |
| 832 |
if (sl->single_replacement) |
| 833 |
printf(" %s=%s", sl->old_name, sl->new_name); |
| 834 |
} |
| 835 |
} |
| 836 |
printf("\n"); |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
int |
| 841 |
main(int argc, char *argv[]) |
| 842 |
{ |
| 843 |
Font font; |
| 844 |
ttfinfo *ti; |
| 845 |
|
| 846 |
|
| 847 |
#ifdef MIKTEX |
| 848 |
miktex_initialize(); |
| 849 |
#endif |
| 850 |
|
| 851 |
init_font_structure(&font); |
| 852 |
|
| 853 |
TeX_search_init(argv[0], "ttf2tfm", "TTF2TFM"); |
| 854 |
|
| 855 |
if (argc == 1) |
| 856 |
{ |
| 857 |
fputs("ttf2tfm: Need at least one file argument.\n", stderr); |
| 858 |
fputs("Try `ttf2tfm --help' for more information.\n", stderr); |
| 859 |
exit(1); |
| 860 |
} |
| 861 |
if (argc == 2) |
| 862 |
{ |
| 863 |
if (strcmp(argv[1], "--help") == 0) |
| 864 |
usage(); |
| 865 |
else if (strcmp(argv[1], "--version") == 0) |
| 866 |
version(); |
| 867 |
} |
| 868 |
|
| 869 |
handle_options(argc, argv, &font); |
| 870 |
|
| 871 |
if (font.sfdname) |
| 872 |
{ |
| 873 |
while (get_sfd(&font, True)) |
| 874 |
{ |
| 875 |
char *temp, *ttemp; |
| 876 |
int i, start, end, len; |
| 877 |
|
| 878 |
|
| 879 |
get_tfm_fullname(&font); |
| 880 |
|
| 881 |
/* |
| 882 |
* Extract base name of sfd file. |
| 883 |
*/ |
| 884 |
|
| 885 |
temp = newstring(font.sfdname); |
| 886 |
len = strlen(temp); |
| 887 |
|
| 888 |
start = 0; |
| 889 |
for (i = len - 1; i >= 0; i--) |
| 890 |
if (temp[i] == '/' || temp[i] == ':' || temp[i] == '\\') |
| 891 |
{ |
| 892 |
start = i + 1; |
| 893 |
break; |
| 894 |
} |
| 895 |
|
| 896 |
end = len; |
| 897 |
for (i = len - 1; i >= 0; i--) |
| 898 |
if (temp[i] == '.') |
| 899 |
{ |
| 900 |
end = i; |
| 901 |
break; |
| 902 |
} |
| 903 |
temp[end] = '\0'; |
| 904 |
|
| 905 |
ttemp = (char *)mymalloc(strlen(temp + start) + 4 + 1); |
| 906 |
sprintf(ttemp, "CJK-%s", temp + start); |
| 907 |
font.codingscheme = ttemp; |
| 908 |
free(temp); |
| 909 |
|
| 910 |
readttf(&font, quiet, True); |
| 911 |
if (font.replacements) |
| 912 |
warning("Replacement glyphs will be ignored."); |
| 913 |
|
| 914 |
/* second try to get an xheight value */ |
| 915 |
if (font.xheight == 0) |
| 916 |
{ |
| 917 |
if (NULL != (ti = findadobe("x", font.charlist))) |
| 918 |
font.xheight = ti->ury; |
| 919 |
else if (font.pid == 3 && font.eid == 1 && |
| 920 |
NULL != (ti = findadobe(".c0x78", font.charlist))) |
| 921 |
font.xheight = ti->ury; |
| 922 |
else |
| 923 |
font.xheight = 400; |
| 924 |
} |
| 925 |
|
| 926 |
if (NULL != (ti = findadobe("space", font.charlist))) |
| 927 |
font.fontspace = ti->width; |
| 928 |
else if (NULL != (ti = findadobe(".c0x20", font.charlist))) |
| 929 |
font.fontspace = ti->width; |
| 930 |
else |
| 931 |
font.fontspace = transform(500, 0, font.efactor, font.slant); |
| 932 |
|
| 933 |
if (font.ligname) |
| 934 |
get_sfd(&font, False); /* read sfd files for ligatures */ |
| 935 |
|
| 936 |
if (buildtfm(&font)) |
| 937 |
{ |
| 938 |
writetfm(&font); |
| 939 |
if (font.write_enc) |
| 940 |
writeenc(&font); |
| 941 |
if (font.vplout) |
| 942 |
add_subfont_list(&font); |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
close_sfd(); |
| 947 |
|
| 948 |
if (font.vplout) |
| 949 |
{ |
| 950 |
writeovp(&font); |
| 951 |
fclose(font.vplout); |
| 952 |
release_subfont_list(&font); |
| 953 |
} |
| 954 |
} |
| 955 |
else |
| 956 |
{ |
| 957 |
get_tfm_fullname(&font); |
| 958 |
|
| 959 |
readttf(&font, quiet, False); |
| 960 |
replace_glyphs(&font); |
| 961 |
|
| 962 |
/* second try to get an xheight value */ |
| 963 |
if (font.xheight == 0) |
| 964 |
{ |
| 965 |
if (NULL != (ti = findadobe("x", font.charlist))) |
| 966 |
font.xheight = ti->ury; |
| 967 |
else if (font.pid == 3 && font.eid == 1 && |
| 968 |
NULL != (ti = findadobe(".c0x78", font.charlist))) |
| 969 |
font.xheight = ti->ury; |
| 970 |
else |
| 971 |
font.xheight = 400; |
| 972 |
} |
| 973 |
|
| 974 |
if (NULL != (ti = findadobe("space", font.charlist))) |
| 975 |
font.fontspace = ti->width; |
| 976 |
else if (NULL != (ti = findadobe(".c0x20", font.charlist))) |
| 977 |
font.fontspace = ti->width; |
| 978 |
else |
| 979 |
font.fontspace = transform(500, 0, font.efactor, font.slant); |
| 980 |
|
| 981 |
handlereencoding(&font); |
| 982 |
|
| 983 |
buildtfm(&font); |
| 984 |
writetfm(&font); |
| 985 |
} |
| 986 |
|
| 987 |
if (makevpl) |
| 988 |
{ |
| 989 |
assignchars(&font); |
| 990 |
if (makevpl > 1) |
| 991 |
upmap(&font); |
| 992 |
writevpl(&font, makevpl, forceoctal); |
| 993 |
fclose(font.vplout); |
| 994 |
} |
| 995 |
|
| 996 |
consttfonts(&font); |
| 997 |
|
| 998 |
exit(0); /* for safety reasons */ |
| 999 |
return 0; /* never reached */ |
| 1000 |
} |
| 1001 |
|
| 1002 |
|
| 1003 |
/* end */ |