| 1 |
/* afm2pl |
| 2 |
* Copyright (C) 2002, 2005, 2009 Siep Kroonenberg |
| 3 |
* [email protected] |
| 4 |
* based on afm2tfm. |
| 5 |
*/ |
| 6 |
|
| 7 |
/* Here the opening comments from afm2tfm: |
| 8 |
********************************************************************* |
| 9 |
* (Modified by Don Knuth from Tom Rokicki's pre-VPL version.) |
| 10 |
* |
| 11 |
* VM/CMS port by J. Hafner ([email protected]), based on |
| 12 |
* the port by Alessio Guglielmi ([email protected]) |
| 13 |
* and Marco Prevedelli ([email protected]). |
| 14 |
* This port is still in test state. No guarantees. |
| 15 |
* 11/3/92: more corrections to VM/CMS port. Now it looks correct |
| 16 |
* and will be supported by J. Hafner. |
| 17 |
* |
| 18 |
* More changes, primarily from Karl Berry, enough for a new version |
| 19 |
* number to 8.0; 1 December 1996. Note that this version computes |
| 20 |
* checksums differently (more intelligently). |
| 21 |
* |
| 22 |
*********************************************************************/ |
| 23 |
|
| 24 |
/* Changed features: |
| 25 |
* writes pl with lig- and kern info instead of tfm |
| 26 |
* never adds characters not explicitly specified in the encoding |
| 27 |
* extra ligkern info, previously hardwired in the source, is now |
| 28 |
* read from an external file. This may include accented char ligatures. |
| 29 |
* Default behavior still matches afm2tfm, given the right ligkern |
| 30 |
* files. |
| 31 |
* letterspacing option, implemented as kerning pairs between any |
| 32 |
* two characters. |
| 33 |
* |
| 34 |
* For VM/CMS we no longer need asciified names for the font or the |
| 35 |
* encoding since we write an ascii pl file instead of a binary tfm. |
| 36 |
* |
| 37 |
* This version doesn't try as hard to always give sensible output. |
| 38 |
* On the other hand, since it uses simpler logic, it should be |
| 39 |
* easier for the user to figure out the cause of failures. |
| 40 |
* |
| 41 |
* changes in structure: |
| 42 |
* writes character metrics directly to an array |
| 43 |
* metric information is transformed in stages |
| 44 |
* does not create smallcaps |
| 45 |
*/ |
| 46 |
|
| 47 |
/* differences between afm and tfm: |
| 48 |
* afm usually has a space char |
| 49 |
* afm lists chars by name and also includes unencoded chars |
| 50 |
* afm lists ligatures together with their first `component', |
| 51 |
* and lists kerns separately. |
| 52 |
* afm implies 3-way ligs by recursive application of 2-way glyphs |
| 53 |
* afm allows negative heights and depths |
| 54 |
* |
| 55 |
* tfm usually doesn't have a space char |
| 56 |
* tfm may have boundarychar ligkerns instead of space ligkerns |
| 57 |
* tfm is lists chars by code and is glyphname-agnostic |
| 58 |
* tfm contains a ligkern table, where entries are sorted by left |
| 59 |
* `component'. 3-way ligs are written out in one lig `program'. |
| 60 |
* tfm may contain some special-purpose ligs such as |
| 61 |
* question quoteleft =: questiondown |
| 62 |
*/ |
| 63 |
|
| 64 |
/******************************************************************* |
| 65 |
* includes, defines, system */ |
| 66 |
|
| 67 |
#ifdef HAVE_CONFIG_H |
| 68 |
#define KPATHSEA 1 |
| 69 |
#include <kpathsea/config.h> |
| 70 |
#include <kpathsea/debug.h> |
| 71 |
#include <kpathsea/tex-file.h> |
| 72 |
#include "c-auto.h" |
| 73 |
#include <kpathsea/c-ctype.h> |
| 74 |
#include <kpathsea/progname.h> |
| 75 |
#include <kpathsea/version.h> |
| 76 |
#else /* HAVE_CONFIG_H */ |
| 77 |
#include <stdio.h> |
| 78 |
#include <stdlib.h> |
| 79 |
#include <ctype.h> |
| 80 |
#include <string.h> |
| 81 |
#include <math.h> |
| 82 |
#ifdef ATARIST |
| 83 |
#include <float.h> |
| 84 |
#endif |
| 85 |
#endif /* HAVE_CONFIG_H */ |
| 86 |
|
| 87 |
#ifdef VMCMS |
| 88 |
#define interesting lookstr /* for 8 character truncation conflicts */ |
| 89 |
#include "dvipscms.h" |
| 90 |
extern FILE *cmsfopen (); |
| 91 |
extern char ascii2ebcdic[]; |
| 92 |
#ifdef fopen |
| 93 |
#undef fopen |
| 94 |
#endif |
| 95 |
#define fopen cmsfopen |
| 96 |
#endif |
| 97 |
|
| 98 |
#ifdef WIN32 |
| 99 |
#define R_MODE "rb" |
| 100 |
#define W_MODE "wb" |
| 101 |
#else |
| 102 |
#define R_MODE "r" |
| 103 |
#define W_MODE "w" |
| 104 |
#endif |
| 105 |
|
| 106 |
/* from dvips.h: */ |
| 107 |
|
| 108 |
#ifdef VMS |
| 109 |
#include "[.vms]vms.h" |
| 110 |
#endif /* VMS */ |
| 111 |
|
| 112 |
/* |
| 113 |
* Is your malloc big? |
| 114 |
*/ |
| 115 |
#if defined(MSDOS) && !defined(__EMX__) && !defined(DJGPP) |
| 116 |
#define SMALLMALLOC |
| 117 |
#endif |
| 118 |
#if defined(OS2) && defined(_MSC_VER) |
| 119 |
#define SMALLMALLOC |
| 120 |
#endif |
| 121 |
|
| 122 |
#if (defined(MSDOS) && !defined(DJGPP)) || (defined(OS2) && defined(_MSC_VER)) || defined(ATARIST) |
| 123 |
typedef long integer; |
| 124 |
#else |
| 125 |
typedef int integer; |
| 126 |
#endif |
| 127 |
|
| 128 |
#ifndef KPATHSEA |
| 129 |
typedef char boolean; |
| 130 |
#endif |
| 131 |
|
| 132 |
#ifdef WIN32 |
| 133 |
#define Boolean boolean |
| 134 |
#else |
| 135 |
#ifndef __THINK__ |
| 136 |
typedef short Boolean ; |
| 137 |
#endif |
| 138 |
#endif |
| 139 |
|
| 140 |
/************************************************************** |
| 141 |
* data structures */ |
| 142 |
|
| 143 |
/* Adobe char metrics; one lig- and kern linked list for each |
| 144 |
* adobechar |
| 145 |
*/ |
| 146 |
|
| 147 |
struct lig { |
| 148 |
struct lig *next; |
| 149 |
const char *succ, *sub; |
| 150 |
short op, boundright; /* boundright: succ is rboundarychar */ |
| 151 |
}; |
| 152 |
|
| 153 |
struct kern { |
| 154 |
struct kern *next; |
| 155 |
const char *succ; |
| 156 |
int delta; |
| 157 |
}; |
| 158 |
|
| 159 |
/* metric info for one char */ |
| 160 |
struct adobeinfo { |
| 161 |
int adobenum, tfmnum, width; |
| 162 |
const char *adobename; |
| 163 |
int llx, lly, urx, ury; |
| 164 |
int nonstd_lk; /* non-standard ligs and/or kerns */ |
| 165 |
struct lig *ligs; |
| 166 |
struct kern *kerns; |
| 167 |
}; |
| 168 |
/* The nonstd_lk field is for efficiency in case of letterspacing. |
| 169 |
* With letterspacing, all glyphs originally without ligs or |
| 170 |
* kerns do show up in the ligkern table, but with identical |
| 171 |
* information. We write them in one go to the ligkern table. |
| 172 |
*/ |
| 173 |
|
| 174 |
/* encodings */ |
| 175 |
struct encoding { |
| 176 |
const char *name; |
| 177 |
const char *vec[256]; |
| 178 |
}; |
| 179 |
|
| 180 |
/* struct to store the names of files with extra ligkern info */ |
| 181 |
struct nstrings { |
| 182 |
int n; |
| 183 |
const char **names; |
| 184 |
}; |
| 185 |
|
| 186 |
/************************************************************* |
| 187 |
* global vars */ |
| 188 |
|
| 189 |
#define buflen 256 |
| 190 |
char buffer[buflen]; /* input buffer (modified while parsing) */ |
| 191 |
char obuffer[buflen]; /* unmodified copy of input buffer */ |
| 192 |
char *param; /* current position in input buffer */ |
| 193 |
|
| 194 |
const char *fontname = "Unknown"; |
| 195 |
|
| 196 |
struct encoding *afmencoding = NULL; |
| 197 |
struct encoding *outencoding = NULL; |
| 198 |
const char *ligoption = "1"; /* which extra ligkerns? */ |
| 199 |
const char *Ligoption = "1"; /* extra ligkern info after letterspacing */ |
| 200 |
int based_on; /* name output file based on name afm file? */ |
| 201 |
int no_prefix = 0; /* don't look for afm2pl- prefixed filenames */ |
| 202 |
FILE *infile, *outfile; |
| 203 |
const char *afmname, *outname; /* names of input and output files */ |
| 204 |
const char *encfilename; /* encoding file */ |
| 205 |
struct nstrings *ligfilenames; /* for files with extra ligkern info */ |
| 206 |
struct nstrings *Ligfilenames; /* same; for after letterspacing */ |
| 207 |
const char *ligfilename; |
| 208 |
|
| 209 |
struct adobeinfo |
| 210 |
**adobechars, /* array of adobeinfo structs, from afm and in afm order */ |
| 211 |
*tfmptrs[256]; /* same, but indexed by tfm order */ |
| 212 |
|
| 213 |
int tfmnext[256]; /* for characters encoded multiple times in output */ |
| 214 |
|
| 215 |
/* global font info */ |
| 216 |
int iglyph, nglyphs, nglyphsb; /* glyph no., n. of glyphs in afm */ |
| 217 |
float italicangle = 0.0; |
| 218 |
float newslant = 0.0; /* computed from slant and italicangle */ |
| 219 |
int fixedpitch; |
| 220 |
int afm2tfm_compat = 0; /* create afm2tfm-compatible font dimensions */ |
| 221 |
int xheight = 0; |
| 222 |
int fontspace = -1; |
| 223 |
int fstretch = -1; |
| 224 |
int fshrink = -1; |
| 225 |
int fextra = -1; |
| 226 |
int fquad = -1; |
| 227 |
int charwidth = 0; |
| 228 |
|
| 229 |
float efactor = 1.0, slant = 0.0; /* requested transformation */ |
| 230 |
int lspace = 0; /* for letterspacing */ |
| 231 |
char *efactorparam, *slantparam, *lspaceparam; |
| 232 |
int forceoctal = 0; |
| 233 |
int keepligs = 0; /* retain afm ligs in spite of lspace>0 */ |
| 234 |
|
| 235 |
int rboundarychar = -1; /* the (right) boundary character */ |
| 236 |
const char *boundaryname = "||"; /* name of boundarychars for liginfo specs */ |
| 237 |
struct adobeinfo *rbound, *lbound; |
| 238 |
char *boundglyph = NULL; |
| 239 |
/* glyph name of rboundarychar; non-null only if encoded */ |
| 240 |
/* track presence of r- and l boundarychar ligkerns. |
| 241 |
* we don't check whether the real chars in those ligkerns |
| 242 |
* are encoded, so we may get false positives |
| 243 |
*/ |
| 244 |
|
| 245 |
int missingchars = 0; |
| 246 |
int verbose = 0; |
| 247 |
|
| 248 |
/************************************************************** |
| 249 |
* general utility functions */ |
| 250 |
|
| 251 |
/* little hack: error message is warning unless it starts with '!' */ |
| 252 |
static void |
| 253 |
error(const char *s) |
| 254 |
{ |
| 255 |
char *parasave; |
| 256 |
parasave = param; |
| 257 |
(void) fprintf (stderr, "%s\n", s); |
| 258 |
if (obuffer[0]) { |
| 259 |
(void) fprintf (stderr, "%s\n", obuffer); |
| 260 |
while (param > buffer) { |
| 261 |
(void) fprintf (stderr, " "); |
| 262 |
param--; |
| 263 |
} |
| 264 |
(void) fprintf (stderr, "^\n"); |
| 265 |
} |
| 266 |
if (*s == '!') |
| 267 |
exit (1); |
| 268 |
param = parasave; |
| 269 |
} |
| 270 |
|
| 271 |
static char * |
| 272 |
mymalloc(unsigned long len) |
| 273 |
{ |
| 274 |
register char *p; |
| 275 |
unsigned long i; |
| 276 |
|
| 277 |
#ifdef SMALLMALLOC |
| 278 |
if (len > 65500L) |
| 279 |
error ("! can't allocate more than 64K!"); |
| 280 |
#endif |
| 281 |
p = malloc ((unsigned) len); |
| 282 |
if (p == NULL) |
| 283 |
error ("! out of memory"); |
| 284 |
for (i = 0; i < len; i++) |
| 285 |
p[i] = 0; |
| 286 |
return (p); |
| 287 |
} |
| 288 |
|
| 289 |
static char * |
| 290 |
newstring(const char *s) |
| 291 |
{ |
| 292 |
char *q = mymalloc ((unsigned long) (strlen (s) + 1)); |
| 293 |
(void) strcpy (q, s); |
| 294 |
return q; |
| 295 |
} |
| 296 |
|
| 297 |
/* find a glyph name in an adobeinfo array */ |
| 298 |
static struct adobeinfo * |
| 299 |
findname(struct adobeinfo **achars, int n, const char *p) |
| 300 |
{ |
| 301 |
register int i; |
| 302 |
for (i = 0; i < n; i++) |
| 303 |
if (achars[i] && strcmp (p, achars[i]->adobename) == 0) |
| 304 |
return achars[i]; |
| 305 |
return NULL; |
| 306 |
} |
| 307 |
|
| 308 |
/* Find glyph info by name in the original adobechars array |
| 309 |
* We don't include the boundarychars in the search but always test |
| 310 |
* separately for those. |
| 311 |
*/ |
| 312 |
static struct adobeinfo * |
| 313 |
findadobe(const char *p) |
| 314 |
{ |
| 315 |
return findname (adobechars, nglyphs, p); |
| 316 |
} |
| 317 |
|
| 318 |
/* Find glyph info by name in target encoding */ |
| 319 |
static struct adobeinfo * |
| 320 |
findtfm(const char *p) |
| 321 |
{ |
| 322 |
return findname (tfmptrs, 256, p); |
| 323 |
} |
| 324 |
|
| 325 |
/* just for adobechars, we sometimes want the index instead */ |
| 326 |
static int |
| 327 |
findindex(const char *p) |
| 328 |
{ |
| 329 |
int i; |
| 330 |
for (i = 0; i < nglyphs; i++) |
| 331 |
if (adobechars[i] && strcmp (p, adobechars[i]->adobename) == 0) |
| 332 |
return i; |
| 333 |
return -1; |
| 334 |
} |
| 335 |
|
| 336 |
/* geometrically transformed boundingbox */ |
| 337 |
static int |
| 338 |
transform(int x, int y) |
| 339 |
{ |
| 340 |
register double acc; |
| 341 |
acc = efactor * x + slant * y; |
| 342 |
return (int) (acc >= 0 ? floor (acc + 0.5) : ceil (acc - 0.5)); |
| 343 |
} |
| 344 |
|
| 345 |
/* read a line from infile into buffer and obuffer */ |
| 346 |
static int |
| 347 |
texlive_getline(void) |
| 348 |
{ |
| 349 |
register char *p; |
| 350 |
register int c; |
| 351 |
int maxline; |
| 352 |
|
| 353 |
param = buffer; |
| 354 |
p = buffer; |
| 355 |
maxline = buflen; |
| 356 |
c = 0; /* to suppress phony compiler warning */ |
| 357 |
while (((c = getc (infile)) != EOF) && (c != '\n') && (c != '\r')) |
| 358 |
/* added: test for \r. The way we do it, the DOS cr/lf convention |
| 359 |
* leads to alternating empty lines, but that is ok. |
| 360 |
*/ |
| 361 |
if (--maxline > 0) *p++ = c; |
| 362 |
*p = 0; |
| 363 |
(void) strcpy (obuffer, buffer); |
| 364 |
if (p == buffer && c == EOF) |
| 365 |
return (0); |
| 366 |
else |
| 367 |
return (1); |
| 368 |
} |
| 369 |
|
| 370 |
/******************************************************* |
| 371 |
* file handling |
| 372 |
*/ |
| 373 |
|
| 374 |
#ifndef KPATHSEA |
| 375 |
/* simple versions of concat (concatenate with allocation), |
| 376 |
* kpse_find_suffix, xbasename and an enum for kpse_file_format_type. |
| 377 |
* This is to reduce the number of #ifdef KPATHSEA sections. |
| 378 |
*/ |
| 379 |
typedef enum { |
| 380 |
kpse_afm_format, kpse_lig_format, kpse_enc_format |
| 381 |
} kpse_file_format_type; |
| 382 |
|
| 383 |
/* string concatenation with allocation */ |
| 384 |
static char * |
| 385 |
concat(const char *s1, const char *s2) |
| 386 |
{ |
| 387 |
char *answer = (char *) malloc (strlen (s1) + strlen (s2) + 1); |
| 388 |
strcpy (answer, s1); |
| 389 |
strcat (answer, s2); |
| 390 |
|
| 391 |
return answer; |
| 392 |
} |
| 393 |
|
| 394 |
/* Return pointer to first character after `.' in last directory element |
| 395 |
* of NAME. If the name is `foo' or `/foo.bar/baz', we have no extension. |
| 396 |
*/ |
| 397 |
static const char * |
| 398 |
find_suffix(const char *name) |
| 399 |
{ |
| 400 |
const char *slash_pos; |
| 401 |
const char *dot_pos = (char *) strrchr (name, '.'); |
| 402 |
|
| 403 |
if (dot_pos == NULL) |
| 404 |
return NULL; |
| 405 |
|
| 406 |
/* find last directory separator */ |
| 407 |
for (slash_pos = name + strlen (name); |
| 408 |
slash_pos > dot_pos && |
| 409 |
(*slash_pos != ':' && *slash_pos != '\\' && *slash_pos != '/'); |
| 410 |
slash_pos--); |
| 411 |
|
| 412 |
/* accept suffix only if after last path separator */ |
| 413 |
return slash_pos > dot_pos ? NULL : dot_pos + 1; |
| 414 |
} |
| 415 |
|
| 416 |
/* Return pointer to filename with leading path stripped */ |
| 417 |
static const char * |
| 418 |
xbasename(const char *name) |
| 419 |
{ |
| 420 |
const char *base = NULL; |
| 421 |
unsigned len = strlen (name); |
| 422 |
|
| 423 |
for (len = strlen (name); len > 0; len--) { |
| 424 |
if (name[len - 1] == ':' || name[len - 1] == '\\' |
| 425 |
|| name[len - 1] == '/') { |
| 426 |
base = name + len; |
| 427 |
break; |
| 428 |
} |
| 429 |
} |
| 430 |
if (!base) |
| 431 |
base = name; |
| 432 |
return base; |
| 433 |
} |
| 434 |
|
| 435 |
#define ISALNUM(c) (isascii (c) && isalnum(c)) |
| 436 |
|
| 437 |
#endif |
| 438 |
/* end of KPATHSEA replacements */ |
| 439 |
|
| 440 |
/* file open functions; abort in case of failure; return filename */ |
| 441 |
|
| 442 |
/* open file for reading |
| 443 |
* parameters: (pointer to) requested filename |
| 444 |
* return (pointer to) actual filename without dir |
| 445 |
* Since we only have one input file open at any time |
| 446 |
* we use a global file variable infile. |
| 447 |
* Note. The kpse lib fu concat itself takes care of |
| 448 |
* allocating the result string |
| 449 |
* kpse handling isn't so helpful in the enc- and lig cases, |
| 450 |
* so we add a suffix explicitly. |
| 451 |
*/ |
| 452 |
static const char * |
| 453 |
openin(const char *fname, kpse_file_format_type format, const char *ext) |
| 454 |
{ |
| 455 |
#ifdef KPATHSEA |
| 456 |
char *realfname; |
| 457 |
|
| 458 |
realfname = NULL; |
| 459 |
if (!no_prefix && (!strcmp(ext, ".enc") || !strcmp(ext, ".lig"))) { |
| 460 |
realfname = kpse_find_file (concat("afm2pl-", fname), format, false); |
| 461 |
if (!realfname) { |
| 462 |
realfname = concat (concat("afm2pl-", fname), ext); |
| 463 |
realfname = kpse_find_file (realfname, format, false); |
| 464 |
} |
| 465 |
} |
| 466 |
if (!realfname) { |
| 467 |
realfname = kpse_find_file (fname, format, false); |
| 468 |
if (!realfname) { |
| 469 |
realfname = concat (fname, ext); |
| 470 |
realfname = kpse_find_file (realfname, format, false); |
| 471 |
} |
| 472 |
} |
| 473 |
if (!realfname) |
| 474 |
FATAL1 ("%s not found", fname); |
| 475 |
infile = kpse_open_file (realfname, format); |
| 476 |
if (infile) |
| 477 |
return xbasename (realfname); |
| 478 |
else |
| 479 |
FATAL1 ("couldn't open %s", realfname); |
| 480 |
#else |
| 481 |
const char *realfname; |
| 482 |
|
| 483 |
realfname = fname; |
| 484 |
infile = fopen (realfname, R_MODE); |
| 485 |
if (!infile && !find_suffix (realfname)) { |
| 486 |
realfname = concat (fname, ext); |
| 487 |
infile = fopen (realfname, R_MODE); |
| 488 |
} |
| 489 |
if (infile) |
| 490 |
return realfname; |
| 491 |
else |
| 492 |
error (concat ("!couldn't open ", realfname)); |
| 493 |
#endif |
| 494 |
return NULL; |
| 495 |
} |
| 496 |
|
| 497 |
/* open file for writing |
| 498 |
* Parameter based_on: if non-zero, then fname was the name |
| 499 |
* of the afm file, and we have to construct a new name |
| 500 |
* based on fname: |
| 501 |
* - replace an extension ".afm" with ".pl" |
| 502 |
* - strip leading path+ |
| 503 |
* In this function, kpathsea functions don't provide better |
| 504 |
* functionality, but they do improve portability. |
| 505 |
*/ |
| 506 |
static const char * |
| 507 |
openout(const char *fname, int based_on, const char *outext) |
| 508 |
{ |
| 509 |
const char *inext = ".afm"; |
| 510 |
/* use inext+1 and outext+1 when the leading dot is not desired */ |
| 511 |
const char *realfname; |
| 512 |
const char *suf; |
| 513 |
|
| 514 |
if (based_on) { /* compute output filename */ |
| 515 |
suf = find_suffix (fname); |
| 516 |
if (suf && !strcmp ((inext + 1), suf)) { /* replace afm suffix */ |
| 517 |
char * q; |
| 518 |
q = newstring (fname); |
| 519 |
q[suf - fname] = 0; |
| 520 |
strcat (q, (outext + 1)); |
| 521 |
realfname = q; |
| 522 |
/* no allocation required: new suffix not longer than old one */ |
| 523 |
} else /* append new suffix */ |
| 524 |
realfname = concat (fname, outext); |
| 525 |
realfname = xbasename (realfname); |
| 526 |
} else { |
| 527 |
suf = find_suffix (fname); |
| 528 |
if (suf) |
| 529 |
realfname = fname; |
| 530 |
else |
| 531 |
realfname = concat (fname, outext); |
| 532 |
} |
| 533 |
outfile = fopen (realfname, W_MODE); |
| 534 |
/* afm2tfm uses WRITEBIN instead of "w" for some OS-es */ |
| 535 |
if (outfile) |
| 536 |
return realfname; |
| 537 |
else |
| 538 |
error (concat ("!", concat (realfname, " not found"))); |
| 539 |
return NULL; |
| 540 |
} |
| 541 |
|
| 542 |
/******************************************************** |
| 543 |
* reading the afm |
| 544 |
*/ |
| 545 |
|
| 546 |
const char *interesting[] = { "FontName", "ItalicAngle", "IsFixedPitch", |
| 547 |
"XHeight", "C", "KPX", "EncodingScheme", |
| 548 |
"StartCharMetrics", "CharWidth", NULL |
| 549 |
}; |
| 550 |
#define FontName (0) |
| 551 |
#define ItalicAngle (1) |
| 552 |
#define IsFixedPitch (2) |
| 553 |
#define XHeight (3) |
| 554 |
#define C (4) |
| 555 |
#define KPX (5) |
| 556 |
#define EncodingScheme (6) |
| 557 |
#define StartCharMetrics (7) |
| 558 |
#define CharWidth (8) |
| 559 |
#define NONE (-1) |
| 560 |
static int |
| 561 |
interest(char *s) |
| 562 |
{ |
| 563 |
register const char **p; |
| 564 |
register int n; |
| 565 |
|
| 566 |
for (p = interesting, n = 0; *p; p++, n++) |
| 567 |
if (strcmp (s, *p) == 0) |
| 568 |
return (n); |
| 569 |
return (NONE); |
| 570 |
} |
| 571 |
|
| 572 |
/* At function call, param points to the first char of the next |
| 573 |
* string, or to eol. |
| 574 |
* In the input buffer, a terminating space is replaced with a null char. |
| 575 |
* Before termination, param is moved to the start of the next |
| 576 |
* string, or to eol. |
| 577 |
*/ |
| 578 |
|
| 579 |
/* next (parameter) string (param is input pointer), |
| 580 |
* with allocation */ |
| 581 |
|
| 582 |
static char * |
| 583 |
paramnewstring(void) |
| 584 |
{ |
| 585 |
register char *p, *q; |
| 586 |
|
| 587 |
p = param; |
| 588 |
while (*p > ' ') |
| 589 |
p++; |
| 590 |
if (*p != 0) |
| 591 |
*p++ = 0; |
| 592 |
q = newstring (param); |
| 593 |
while (*p && *p <= ' ') |
| 594 |
p++; |
| 595 |
param = p; |
| 596 |
return (q); |
| 597 |
} |
| 598 |
|
| 599 |
/* next (parameter) string from afm file (param is input pointer), |
| 600 |
* pre-allocated */ |
| 601 |
|
| 602 |
static char * |
| 603 |
paramstring(void) |
| 604 |
{ |
| 605 |
register char *p, *q; |
| 606 |
|
| 607 |
p = param; |
| 608 |
while (*p > ' ') |
| 609 |
p++; |
| 610 |
q = param; |
| 611 |
if (*p != 0) |
| 612 |
*p++ = 0; |
| 613 |
while (*p && *p <= ' ') |
| 614 |
p++; |
| 615 |
param = p; |
| 616 |
return (q); |
| 617 |
} |
| 618 |
|
| 619 |
static int |
| 620 |
paramnum(void) |
| 621 |
{ |
| 622 |
register char *p; |
| 623 |
int i; |
| 624 |
|
| 625 |
p = paramstring (); |
| 626 |
if (sscanf (p, "%d", &i) != 1) |
| 627 |
error ("! integer expected"); |
| 628 |
return (i); |
| 629 |
} |
| 630 |
|
| 631 |
static float |
| 632 |
paramfloat(void) |
| 633 |
{ |
| 634 |
register char *p; |
| 635 |
float i; |
| 636 |
|
| 637 |
p = paramstring (); |
| 638 |
if (sscanf (p, "%f", &i) != 1) |
| 639 |
error ("! number expected"); |
| 640 |
return (i); |
| 641 |
} |
| 642 |
|
| 643 |
static void |
| 644 |
expect(const char *s) |
| 645 |
{ |
| 646 |
if (strcmp (paramstring (), s) != 0) { |
| 647 |
(void) fprintf (stderr, "%s expected: ", s); |
| 648 |
error ("! syntax error"); |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
/* allocating and initializing structs */ |
| 653 |
|
| 654 |
/* initialize afm info for one char */ |
| 655 |
static struct adobeinfo * |
| 656 |
newchar(void) |
| 657 |
{ |
| 658 |
register struct adobeinfo *ai; |
| 659 |
|
| 660 |
ai = (struct adobeinfo *) mymalloc ((unsigned long) |
| 661 |
sizeof (struct adobeinfo)); |
| 662 |
ai->adobenum = -1; |
| 663 |
ai->tfmnum = -1; |
| 664 |
/* ai->kern_as = NULL; */ |
| 665 |
ai->width = -1; |
| 666 |
ai->adobename = NULL; |
| 667 |
ai->llx = -1; |
| 668 |
ai->lly = -1; |
| 669 |
ai->urx = -1; |
| 670 |
ai->ury = -1; |
| 671 |
ai->ligs = NULL; |
| 672 |
ai->kerns = NULL; |
| 673 |
/* ai->kern_equivs = NULL ; */ |
| 674 |
return (ai); |
| 675 |
} |
| 676 |
|
| 677 |
static struct kern * |
| 678 |
newkern(void) |
| 679 |
{ |
| 680 |
register struct kern *nk; |
| 681 |
|
| 682 |
nk = (struct kern *) mymalloc ((unsigned long) sizeof (struct kern)); |
| 683 |
nk->next = NULL; |
| 684 |
nk->succ = NULL; |
| 685 |
nk->delta = 0; |
| 686 |
return (nk); |
| 687 |
} |
| 688 |
|
| 689 |
static struct lig * |
| 690 |
newlig(void) |
| 691 |
{ |
| 692 |
register struct lig *nl; |
| 693 |
|
| 694 |
nl = (struct lig *) mymalloc ((unsigned long) sizeof (struct lig)); |
| 695 |
nl->next = NULL; |
| 696 |
nl->succ = NULL; |
| 697 |
nl->sub = NULL; |
| 698 |
nl->op = 0; /* the default =: op */ |
| 699 |
nl->boundright = 0; |
| 700 |
return (nl); |
| 701 |
} |
| 702 |
|
| 703 |
/* read and interpret afm info for 1 char |
| 704 |
* adobeptrs is an array of pointers to adobeinfo structs |
| 705 |
* indexed by adobenum. |
| 706 |
* */ |
| 707 |
static void |
| 708 |
handlechar(void) |
| 709 |
{ /* an input line beginning with C */ |
| 710 |
register struct adobeinfo *ai; |
| 711 |
register struct lig *nl; |
| 712 |
|
| 713 |
if ((++iglyph) >= nglyphs) |
| 714 |
error ("!Too many glyphs in afm"); |
| 715 |
adobechars[iglyph] = newchar (); |
| 716 |
ai = adobechars[iglyph]; |
| 717 |
ai->adobenum = paramnum (); |
| 718 |
expect (";"); |
| 719 |
expect ("WX"); |
| 720 |
ai->width = paramnum (); |
| 721 |
if (fixedpitch) |
| 722 |
charwidth = ai->width; |
| 723 |
expect (";"); |
| 724 |
expect ("N"); |
| 725 |
ai->adobename = paramnewstring (); |
| 726 |
if ((ai->adobenum) >= 0) |
| 727 |
afmencoding->vec[ai->adobenum] = newstring (ai->adobename); |
| 728 |
expect (";"); |
| 729 |
expect ("B"); |
| 730 |
ai->llx = paramnum (); |
| 731 |
ai->lly = paramnum (); |
| 732 |
ai->urx = paramnum (); |
| 733 |
ai->ury = paramnum (); |
| 734 |
expect (";"); |
| 735 |
/* Now look for ligatures (which aren't present in fixedpitch fonts) */ |
| 736 |
while (*param == 'L' && !fixedpitch) { |
| 737 |
expect ("L"); |
| 738 |
nl = newlig (); |
| 739 |
nl->succ = paramnewstring (); |
| 740 |
nl->sub = paramnewstring (); |
| 741 |
nl->next = ai->ligs; |
| 742 |
ai->ligs = nl; |
| 743 |
expect (";"); |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
static void |
| 748 |
handlekern(void) |
| 749 |
{ /* an input line beginning with KPX */ |
| 750 |
register struct adobeinfo *ai; |
| 751 |
register char *p, *sc; |
| 752 |
register struct kern *nk; |
| 753 |
int dlt; |
| 754 |
|
| 755 |
p = paramstring (); |
| 756 |
ai = findadobe (p); |
| 757 |
if (!ai) |
| 758 |
error ("kern char not found"); |
| 759 |
else { |
| 760 |
sc = paramstring (); |
| 761 |
dlt = paramnum (); |
| 762 |
if (dlt) { |
| 763 |
nk = newkern (); |
| 764 |
nk->succ = newstring (sc); |
| 765 |
nk->delta = dlt; |
| 766 |
nk->next = ai->kerns; |
| 767 |
ai->kerns = nk; |
| 768 |
} |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
/* read afm file */ |
| 773 |
static void |
| 774 |
readadobe(void) |
| 775 |
{ |
| 776 |
const char *inname; |
| 777 |
int i; |
| 778 |
|
| 779 |
/* open afm file */ |
| 780 |
inname = newstring (afmname); |
| 781 |
inname = openin (inname, kpse_afm_format, ".afm"); |
| 782 |
|
| 783 |
nglyphs = -1; /* allocate adobechars at StartCharMetrics */ |
| 784 |
afmencoding = (struct encoding *) mymalloc ((unsigned long) |
| 785 |
sizeof (struct encoding)); |
| 786 |
for (i = 0; i < 256; i++) |
| 787 |
afmencoding->vec[i] = ".notdef"; |
| 788 |
afmencoding->name = "Unspecified"; |
| 789 |
|
| 790 |
while (texlive_getline ()) { |
| 791 |
switch (interest (paramstring ())) { |
| 792 |
case FontName: |
| 793 |
fontname = paramnewstring (); |
| 794 |
break; |
| 795 |
case EncodingScheme: |
| 796 |
afmencoding->name = paramnewstring (); |
| 797 |
break; |
| 798 |
case ItalicAngle: |
| 799 |
italicangle = paramfloat (); |
| 800 |
break; |
| 801 |
case IsFixedPitch: |
| 802 |
if (*param == 't' || *param == 'T') |
| 803 |
fixedpitch = 1; |
| 804 |
else |
| 805 |
fixedpitch = 0; |
| 806 |
break; |
| 807 |
case XHeight: |
| 808 |
xheight = paramnum (); |
| 809 |
break; |
| 810 |
case StartCharMetrics: |
| 811 |
nglyphs = paramnum (); |
| 812 |
nglyphsb = nglyphs + 1; |
| 813 |
iglyph = -1; |
| 814 |
/* Allocate adobechars array (just the array of pointers). |
| 815 |
* Reserve extra slot for rboundarychar |
| 816 |
*/ |
| 817 |
adobechars = |
| 818 |
(struct adobeinfo **) mymalloc ((unsigned long) (nglyphs+1) * |
| 819 |
(unsigned long) sizeof (struct |
| 820 |
adobeinfo |
| 821 |
*)); |
| 822 |
break; |
| 823 |
case C: |
| 824 |
handlechar (); |
| 825 |
break; |
| 826 |
case KPX: |
| 827 |
handlekern (); |
| 828 |
break; |
| 829 |
case CharWidth: |
| 830 |
charwidth = paramnum (); |
| 831 |
fixedpitch = 1; |
| 832 |
break; |
| 833 |
default: |
| 834 |
break; |
| 835 |
} |
| 836 |
} |
| 837 |
fclose (infile); |
| 838 |
infile = NULL; |
| 839 |
} |
| 840 |
|
| 841 |
/* now some changes to the afm info */ |
| 842 |
static void |
| 843 |
changeadobe(void) |
| 844 |
{ |
| 845 |
struct adobeinfo *ai; |
| 846 |
int i; |
| 847 |
/* float newslant; local declaration masks global one */ |
| 848 |
|
| 849 |
/* A fix: avoiding negative heights or depths. |
| 850 |
* They break accents in math mode, among other things. |
| 851 |
*/ |
| 852 |
for (i = 0; i < nglyphs; i++) { |
| 853 |
ai = adobechars[i]; |
| 854 |
if (ai->lly > 0) |
| 855 |
ai->lly = 0; |
| 856 |
if (ai->ury < 0) |
| 857 |
ai->ury = 0; |
| 858 |
} |
| 859 |
|
| 860 |
/* apply any requested geometric transforms */ |
| 861 |
if (efactor != 1.0 || slant != 0.0) { |
| 862 |
for (i = 0; i < nglyphs; i++) { |
| 863 |
ai = adobechars[i]; |
| 864 |
ai->width = transform (ai->width, 0); |
| 865 |
ai->llx = transform (ai->llx, ai->lly); |
| 866 |
ai->urx = transform (ai->urx, ai->ury); |
| 867 |
} |
| 868 |
} |
| 869 |
newslant = (double) slant - |
| 870 |
efactor * tan (italicangle * (3.1415926535 / 180.0)); |
| 871 |
|
| 872 |
/* Avoid output of '(SLANT R -0.000000)' due to floating point |
| 873 |
* rounding; neither round() nor fabs() need be defined. */ |
| 874 |
if ((newslant < 0.0) && (newslant*2000000.0 >= -1.0)) |
| 875 |
newslant = 0.0; |
| 876 |
|
| 877 |
/* if !keepligs, remove native ligatures */ |
| 878 |
if (!keepligs && lspace>0) { |
| 879 |
for (i = 0; i < nglyphs; i++) |
| 880 |
adobechars[i]->ligs = NULL; |
| 881 |
} |
| 882 |
|
| 883 |
/* create a left and right boundarychar entries - just in case, |
| 884 |
* but don't add them (yet) to adobechars */ |
| 885 |
for (i = 0; i < 2; i++) { |
| 886 |
ai = newchar (); |
| 887 |
ai->adobenum = -1; |
| 888 |
ai->width = 0; |
| 889 |
ai->llx = 0; |
| 890 |
ai->lly = 0; |
| 891 |
ai->urx = 0; |
| 892 |
ai->ury = 0; |
| 893 |
ai->adobename = boundaryname; |
| 894 |
if (i == 0) |
| 895 |
lbound = ai; |
| 896 |
else |
| 897 |
rbound = ai; |
| 898 |
} |
| 899 |
|
| 900 |
/* global font dimensions */ |
| 901 |
|
| 902 |
/* The following may depend on the -f parameter */ |
| 903 |
|
| 904 |
if (xheight == 0) { |
| 905 |
ai = findadobe ("x"); |
| 906 |
if (ai) |
| 907 |
xheight = ai->ury; |
| 908 |
else |
| 909 |
xheight = 400; |
| 910 |
} |
| 911 |
|
| 912 |
if (afm2tfm_compat) { /* -f 'afm2tfm'*/ |
| 913 |
|
| 914 |
ai = findadobe ("space"); |
| 915 |
if (ai) |
| 916 |
fontspace = ai->width; /* transform already applied */ |
| 917 |
else { |
| 918 |
if (fixedpitch) |
| 919 |
fontspace = charwidth; |
| 920 |
else |
| 921 |
transform(500, 0); |
| 922 |
} |
| 923 |
fstretch = (fixedpitch) ? 0 : transform (300, 0); |
| 924 |
fshrink = (fixedpitch) ? 0 : transform (100, 0); |
| 925 |
/* fextra = transform (111, 0); */ |
| 926 |
fquad = transform (1000, 0); |
| 927 |
|
| 928 |
} else if (!fixedpitch) { |
| 929 |
|
| 930 |
/* some may be set by a numerical -f parameter) */ |
| 931 |
|
| 932 |
if (fontspace<0) { |
| 933 |
ai = findadobe ("space"); |
| 934 |
if (ai) |
| 935 |
fontspace = ai->width; /* transform already applied */ |
| 936 |
else { |
| 937 |
fontspace = transform(500, 0); |
| 938 |
} |
| 939 |
} |
| 940 |
if (fquad<0) { |
| 941 |
ai = findadobe ("zero"); |
| 942 |
if (ai) fquad = 2 * ai->width; |
| 943 |
else if (fixedpitch) fquad = 2 * charwidth; |
| 944 |
else fquad = transform (1000, 0); |
| 945 |
} |
| 946 |
if (fstretch<0) fstretch = fontspace / 2; |
| 947 |
if (fshrink<0) fshrink = fontspace / 3; |
| 948 |
if (fextra<0) fextra = fontspace / 3; |
| 949 |
} else { /* fixedpitch && !afm2tfm_compat */ |
| 950 |
if (fontspace<0) fontspace = charwidth; |
| 951 |
if (fstretch<0) fstretch = 0; |
| 952 |
if (fshrink<0) fshrink = 0; |
| 953 |
if (fquad<0) fquad = 2 * charwidth; |
| 954 |
if (fextra<0) fextra = charwidth; |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
/************************************************** |
| 959 |
* reading encodings |
| 960 |
*/ |
| 961 |
|
| 962 |
char smbuffer[100]; /* for tokens */ |
| 963 |
|
| 964 |
/* Here we get a token from the encoding file. We parse just as |
| 965 |
* much PostScript as we expect to find in an encoding file. We |
| 966 |
* allow commented lines and names like 0, .notdef, _foo_. We do |
| 967 |
* not allow //abc. |
| 968 |
*/ |
| 969 |
static char * |
| 970 |
gettoken(void) |
| 971 |
{ |
| 972 |
char *p, *q; |
| 973 |
|
| 974 |
while (1) { |
| 975 |
while (param == 0 || *param == 0) { |
| 976 |
if (texlive_getline () == 0) |
| 977 |
error ("! premature end in encoding file"); |
| 978 |
} |
| 979 |
if (param[0] == '%') { |
| 980 |
param[0] = 0; /* be done with this line */ |
| 981 |
continue; |
| 982 |
} |
| 983 |
while (*param && *param <= ' ') |
| 984 |
param++; |
| 985 |
if (*param) { |
| 986 |
if (*param == '[' || *param == ']' || |
| 987 |
*param == '{' || *param == '}') { |
| 988 |
smbuffer[0] = *param++; |
| 989 |
smbuffer[1] = 0; |
| 990 |
return smbuffer; |
| 991 |
} else if (*param == '/' || *param == '-' || *param == '_' || |
| 992 |
*param == '.' || |
| 993 |
('0' <= *param && *param <= '9') || |
| 994 |
('a' <= *param && *param <= 'z') || |
| 995 |
('A' <= *param && *param <= 'Z')) { |
| 996 |
smbuffer[0] = *param; |
| 997 |
for (p = param + 1, q = smbuffer + 1; |
| 998 |
*p == '-' || *p == '_' || *p == '.' || |
| 999 |
('0' <= *p && *p <= '9') || |
| 1000 |
('a' <= *p && *p <= 'z') || |
| 1001 |
('A' <= *p && *p <= 'Z'); p++, q++) |
| 1002 |
*q = *p; |
| 1003 |
*q = 0; |
| 1004 |
param = p; |
| 1005 |
return smbuffer; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
/* This routine reads the encoding file. |
| 1012 |
* Return value: pointer to encoding. |
| 1013 |
* |
| 1014 |
* There is just one reason why we read the encoding vector |
| 1015 |
* before the extra ligkern information: if a (r)boundarychar is |
| 1016 |
* specified by number then we want to translate it into |
| 1017 |
* a glyph name. |
| 1018 |
* |
| 1019 |
* We also create tfmptrs as a reencoded version of adobechars, and |
| 1020 |
* tfmnext, which tracks multiple encodings of a single glyph and is |
| 1021 |
* best explained by the code creating it. |
| 1022 |
*/ |
| 1023 |
static void |
| 1024 |
readencoding(void) |
| 1025 |
{ |
| 1026 |
char *p; |
| 1027 |
int i, inx; |
| 1028 |
struct adobeinfo *ai; |
| 1029 |
|
| 1030 |
if (infile) |
| 1031 |
error ("! oops; internal infile error"); |
| 1032 |
if (encfilename) { |
| 1033 |
encfilename = |
| 1034 |
openin (encfilename, kpse_enc_format, ".enc"); |
| 1035 |
param = 0; |
| 1036 |
if (infile == 0) |
| 1037 |
error ("! couldn't open that encoding file"); |
| 1038 |
outencoding = (struct encoding *) mymalloc |
| 1039 |
((unsigned long) sizeof (struct encoding)); |
| 1040 |
for (i = 0; i < 256; i++) |
| 1041 |
outencoding->vec[i] = ".notdef"; |
| 1042 |
outencoding->name = "Unspecified"; |
| 1043 |
p = gettoken (); |
| 1044 |
if (*p != '/' || p[1] == 0) |
| 1045 |
error ("! first token in encoding must be literal encoding name"); |
| 1046 |
outencoding->name = newstring (p + 1); |
| 1047 |
p = gettoken (); |
| 1048 |
if (strcmp (p, "[")) |
| 1049 |
error ("! second token in encoding must be mark ([) token"); |
| 1050 |
for (i = 0; i < 256; i++) { |
| 1051 |
p = gettoken (); |
| 1052 |
if (*p != '/' || p[1] == 0) |
| 1053 |
error ("! tokens 3 to 257 in encoding must be literal names"); |
| 1054 |
outencoding->vec[i] = newstring (p + 1); |
| 1055 |
} |
| 1056 |
p = gettoken (); |
| 1057 |
if (strcmp (p, "]")) |
| 1058 |
error ("! token 258 in encoding must be make-array (])"); |
| 1059 |
fclose (infile); |
| 1060 |
infile = 0; |
| 1061 |
} else |
| 1062 |
outencoding = afmencoding; |
| 1063 |
|
| 1064 |
/* find adobeinfo for each encoded glyph name |
| 1065 |
* track multiple encodings (tfmnext). |
| 1066 |
* For missing glyphs, this is not necessary. |
| 1067 |
*/ |
| 1068 |
for (i = 0; i < 256; i++) |
| 1069 |
tfmnext[i] = -1; |
| 1070 |
for (i = 0; i < 256; i++) { |
| 1071 |
if (strcmp (outencoding->vec[i], ".notdef")) { |
| 1072 |
ai = findadobe (outencoding->vec[i]); |
| 1073 |
tfmptrs[i] = ai; |
| 1074 |
if (ai) { |
| 1075 |
inx = ai->tfmnum; |
| 1076 |
if (inx == -1) |
| 1077 |
ai->tfmnum = i; |
| 1078 |
else { |
| 1079 |
while (tfmnext[inx] != -1) |
| 1080 |
inx = tfmnext[inx]; |
| 1081 |
tfmnext[inx] = i; |
| 1082 |
} |
| 1083 |
} else { /* missing glyph */ |
| 1084 |
if (!missingchars && verbose) |
| 1085 |
fputs ("Missing glyphs\n", stderr); |
| 1086 |
missingchars += 1; |
| 1087 |
if (verbose) printf ("%s\n", outencoding->vec[i]); |
| 1088 |
} |
| 1089 |
} else /* empty slot */ |
| 1090 |
tfmptrs[i] = NULL; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
|
| 1094 |
/**************************************************************** |
| 1095 |
* Processing extra ligkern info |
| 1096 |
* |
| 1097 |
* When these functions are called, we have available the afm data |
| 1098 |
* and the raw encoding vector. |
| 1099 |
* changeadobe has created adobeinfos for left and right boundarychar. |
| 1100 |
* We use the encoding vector ONLY to translate an rboundarychar spec |
| 1101 |
* into an rboundarychar name. However, normally an rboundarychar will |
| 1102 |
* occupy an otherwise unused slot in the encoding, in which case |
| 1103 |
* the name is irrelevant. |
| 1104 |
* I don't see the point of a numeric rboundarychar specification: |
| 1105 |
* either one wants to use a specific character or the numeric value |
| 1106 |
* doesn't matter. But I allow it for backward compatibility. |
| 1107 |
* |
| 1108 |
* extra ligkern info can come from: |
| 1109 |
* - comments in the encoding file |
| 1110 |
* - lig files. These replace the hard-coded set in afm2tfm. |
| 1111 |
* afm2tfm applies its own set only if the enc file contains no |
| 1112 |
* ligkern instructions. This is also the default behavior of |
| 1113 |
* afm2pl. |
| 1114 |
* |
| 1115 |
* Typically, extra ligkern info may contain: |
| 1116 |
* - tex-specific hacks such as `less less =: guillemotleft' |
| 1117 |
* - deletion of space- and number kerns |
| 1118 |
* - kern accented chars as their unaccented versions |
| 1119 |
* - the f/l/i ligatures, in case they were absent from the afm. |
| 1120 |
* |
| 1121 |
* note. afm2pl allows first copying space kerns |
| 1122 |
* to boundarychar kerns and then deleting the space kerns, leaving |
| 1123 |
* the boundarychar kerns intact. |
| 1124 |
* |
| 1125 |
* There was a function for creating accented char ligatures. |
| 1126 |
* This doesn't prevent TeX from compositing accented chars |
| 1127 |
* so it is not very useful. |
| 1128 |
* In afm2tfm this function was never called and I removed it. |
| 1129 |
* I created a file accents.lig which may be loaded for these |
| 1130 |
* accent ligs but default isn't. |
| 1131 |
*/ |
| 1132 |
|
| 1133 |
/* Notation of ligkern specs: |
| 1134 |
* char1 char2 =: char3 => replace char1 char2 with char3 |
| 1135 |
* and more generally: |
| 1136 |
* char1 char2 ligop char3 => char1 char2 ligop char3 |
| 1137 |
* char1 {} char2 => delete char1 char2 kern |
| 1138 |
* char1 <> char2 => kern char1 the same as char2 |
| 1139 |
* || = char => char is right boundary char |
| 1140 |
* |
| 1141 |
* Notes. |
| 1142 |
* - cork.enc contains specs `char @{@} char' instead of `char {} char' |
| 1143 |
* - The ligkern specs use `||' for both lboundarychar and |
| 1144 |
* rboundarychar. The context must make clear which one is intended. |
| 1145 |
* I store them in separate adobechar structs. |
| 1146 |
*/ |
| 1147 |
|
| 1148 |
/* These are the eight ligature ops, in pl terms and in METAFONT terms. |
| 1149 |
*/ |
| 1150 |
const char *plligops[] = { |
| 1151 |
"LIG", "/LIG", "/LIG>", "LIG/", "LIG/>", "/LIG/", "/LIG/>", |
| 1152 |
"/LIG/>>", 0 |
| 1153 |
}; |
| 1154 |
const char *encligops[] = { |
| 1155 |
"=:", "|=:", "|=:>", "=:|", "=:|>", "|=:|", "|=:|>", "|=:|>>", 0 |
| 1156 |
}; |
| 1157 |
|
| 1158 |
/* Make the kerning for character s1 equivalent to that for s2 |
| 1159 |
* but don't replace existing kerns. |
| 1160 |
* It doesn't matter whether or not s2 is encoded. |
| 1161 |
* In the pl file, the kerning info of both s1 and s2 will be written |
| 1162 |
* out in full. |
| 1163 |
*/ |
| 1164 |
static void |
| 1165 |
copykerns(char *s1, char *s2) |
| 1166 |
{ |
| 1167 |
int i, found, delta2, found1, found2; |
| 1168 |
struct adobeinfo *ai, *ai1, *ai2; |
| 1169 |
struct kern *nk, *nk1, *nk2; |
| 1170 |
|
| 1171 |
if (!strcmp (s1, s2)) |
| 1172 |
return; |
| 1173 |
|
| 1174 |
/* kerns with s1 and s2 on the left */ |
| 1175 |
if (!strcmp (boundaryname, s1)) |
| 1176 |
ai1 = lbound; |
| 1177 |
else |
| 1178 |
ai1 = findadobe (s1); |
| 1179 |
if (!strcmp (boundaryname, s2)) |
| 1180 |
ai2 = lbound; |
| 1181 |
else |
| 1182 |
ai2 = findadobe (s2); |
| 1183 |
if (ai1 && ai2 && ai2->kerns) { |
| 1184 |
nk2 = ai2->kerns; |
| 1185 |
while (nk2) { |
| 1186 |
found = 0; |
| 1187 |
nk1 = ai1->kerns; |
| 1188 |
while (nk1) { |
| 1189 |
if (!strcmp (nk1->succ, nk2->succ)) { |
| 1190 |
found = 1; |
| 1191 |
break; |
| 1192 |
} |
| 1193 |
nk1 = nk1->next; |
| 1194 |
} |
| 1195 |
if (!found) { |
| 1196 |
nk1 = newkern (); |
| 1197 |
nk1->succ = nk2->succ; |
| 1198 |
nk1->delta = nk2->delta; |
| 1199 |
nk1->next = ai1->kerns; |
| 1200 |
ai1->kerns = nk1; |
| 1201 |
} |
| 1202 |
nk2 = nk2->next; |
| 1203 |
} |
| 1204 |
} |
| 1205 |
|
| 1206 |
/* kerns with s1 and s2 on the right. */ |
| 1207 |
if (!strcmp (boundaryname, s1) && boundglyph) |
| 1208 |
s1 = boundglyph; |
| 1209 |
if (!strcmp (boundaryname, s2) && boundglyph) |
| 1210 |
s2 = boundglyph; |
| 1211 |
/* a name '||' for s1/s2 is untouched */ |
| 1212 |
if (!strcmp (s1, s2)) |
| 1213 |
return; |
| 1214 |
delta2 = 0; /* silence 'might be used uninitialized' warning */ |
| 1215 |
for (i = 0; i < nglyphs; i++) { |
| 1216 |
ai = adobechars[i]; |
| 1217 |
found1 = 0; |
| 1218 |
found2 = 0; |
| 1219 |
nk = ai->kerns; |
| 1220 |
while (nk) { |
| 1221 |
if (!strcmp (nk->succ, s2)) { |
| 1222 |
found2 = 1; |
| 1223 |
delta2 = nk->delta; |
| 1224 |
} |
| 1225 |
if (!strcmp (nk->succ, s1)) |
| 1226 |
found1 = 1; |
| 1227 |
nk = nk->next; |
| 1228 |
} |
| 1229 |
if (found2 && !found1) { |
| 1230 |
nk1 = newkern (); |
| 1231 |
nk1->next = ai->kerns; |
| 1232 |
ai->kerns = nk1; |
| 1233 |
nk1->succ = newstring (s1); |
| 1234 |
/* can't copy s1, which is just a stack variable */ |
| 1235 |
nk1->delta = delta2; |
| 1236 |
} |
| 1237 |
} |
| 1238 |
} |
| 1239 |
|
| 1240 |
/* remove kern between ai->adobechar and s2, where s2 != "*" |
| 1241 |
*/ |
| 1242 |
static void |
| 1243 |
adobermkern(struct adobeinfo *ai, char *s2) |
| 1244 |
{ |
| 1245 |
struct kern *k, *kprev; |
| 1246 |
char *s2a; |
| 1247 |
int first; |
| 1248 |
if (!ai->kerns) |
| 1249 |
return; |
| 1250 |
k = ai->kerns; |
| 1251 |
if (!strcmp (s2, boundaryname) && boundglyph) |
| 1252 |
s2a = boundglyph; |
| 1253 |
else |
| 1254 |
s2a = s2; |
| 1255 |
kprev = k; /* silence 'might be used uninitialized' warning */ |
| 1256 |
first = 1; |
| 1257 |
while (k) { |
| 1258 |
if (!strcmp (s2a, k->succ) || !strcmp (s2, k->succ)) { |
| 1259 |
if (first) |
| 1260 |
ai->kerns = k->next; |
| 1261 |
else |
| 1262 |
kprev->next = k->next; |
| 1263 |
return; |
| 1264 |
} |
| 1265 |
first = 0; |
| 1266 |
kprev = k; |
| 1267 |
k = k->next; |
| 1268 |
} |
| 1269 |
} |
| 1270 |
|
| 1271 |
/* remove kerns between s1 and s2 (wildcards allowed) */ |
| 1272 |
static void |
| 1273 |
rmkern(char *s1, char *s2) |
| 1274 |
{ |
| 1275 |
int i; |
| 1276 |
struct adobeinfo *ai; |
| 1277 |
|
| 1278 |
if (!strcmp (s1, "*")) { |
| 1279 |
for (i = 0; i < nglyphs; i++) { |
| 1280 |
ai = adobechars[i]; |
| 1281 |
adobermkern (ai, s2); |
| 1282 |
} |
| 1283 |
adobermkern (lbound, s2); |
| 1284 |
} else if (!strcmp (s2, "*")) { |
| 1285 |
if (!strcmp (s1, boundaryname)) |
| 1286 |
ai = lbound; |
| 1287 |
else |
| 1288 |
ai = findadobe (s1); |
| 1289 |
if (ai) |
| 1290 |
ai->kerns = NULL; |
| 1291 |
} else { /* remove single pair */ |
| 1292 |
if (!strcmp (s1, boundaryname)) |
| 1293 |
ai = lbound; |
| 1294 |
else |
| 1295 |
ai = findadobe (s1); |
| 1296 |
if (!ai) |
| 1297 |
return; |
| 1298 |
adobermkern (ai, s2); |
| 1299 |
} |
| 1300 |
} |
| 1301 |
|
| 1302 |
/* With default ligkern option, need to know whether |
| 1303 |
* the enc file contains ligkern specs |
| 1304 |
*/ |
| 1305 |
int sawligkern; |
| 1306 |
|
| 1307 |
/* zero-th iteration: look out for rboundarychar spec. |
| 1308 |
* first iteration: look out for everything else. |
| 1309 |
*/ |
| 1310 |
int lig_it; |
| 1311 |
|
| 1312 |
/* set_rboundarychar is to be called after the ligkern specs have been |
| 1313 |
* scanned for a rboundarychar spec but before we know whether it |
| 1314 |
* will actually be used. |
| 1315 |
*/ |
| 1316 |
static void |
| 1317 |
set_rboundarychar(int bch) |
| 1318 |
{ |
| 1319 |
int i; |
| 1320 |
if (bch == -1) { |
| 1321 |
/* find empty slot; skip 0, just to be safe */ |
| 1322 |
for (i = 1; i < 256; i++) |
| 1323 |
if (!strcmp (outencoding->vec[i], ".notdef")) { |
| 1324 |
rboundarychar = i; |
| 1325 |
tfmptrs[i] = rbound; |
| 1326 |
rbound->tfmnum = i; |
| 1327 |
adobechars[nglyphs] = rbound; |
| 1328 |
return; |
| 1329 |
} |
| 1330 |
error ("No tfm slot available for boundarychar"); |
| 1331 |
} else { |
| 1332 |
rboundarychar = bch; |
| 1333 |
if (tfmptrs[rboundarychar]) { |
| 1334 |
rbound = tfmptrs[rboundarychar]; |
| 1335 |
boundglyph = newstring (rbound->adobename); |
| 1336 |
nglyphsb = nglyphs; /* no extra slot in adobechars needed */ |
| 1337 |
} else { |
| 1338 |
tfmptrs[bch] = rbound; |
| 1339 |
rbound->tfmnum = bch; |
| 1340 |
adobechars[nglyphs] = rbound; |
| 1341 |
} |
| 1342 |
return; |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
/* Reads a ligkern line, which may contain several ligkern specs. |
| 1347 |
* lig_it = 0: only process rboundarychar spec |
| 1348 |
* lig_it != 0: process all other ligkern specs |
| 1349 |
* lig_it = 2: post-letterspacing; only `{}' specs are allowed. |
| 1350 |
*/ |
| 1351 |
static void |
| 1352 |
checkligkern(char *s, int isencfile) |
| 1353 |
{ |
| 1354 |
char *mlist[5]; /* tokens constituting a ligkern spec */ |
| 1355 |
int n, i, bch; |
| 1356 |
struct adobeinfo *ai; |
| 1357 |
|
| 1358 |
if (s[0] == '%') |
| 1359 |
s++; /* skip optional leading `%' */ |
| 1360 |
/* Note. '%' is necessary for ligkern comments in an encoding file |
| 1361 |
* and optional otherwise. |
| 1362 |
*/ |
| 1363 |
while (*s && *s <= ' ') |
| 1364 |
s++; /* skip to first token */ |
| 1365 |
if (!s[0]) |
| 1366 |
return; /* empty line; done */ |
| 1367 |
if (isencfile && strncmp (s, "LIGKERN", 7)) /* not a ligkern line */ |
| 1368 |
return; |
| 1369 |
if (!strncmp (s, "LIGKERN", 7)) |
| 1370 |
s += 7; /* skip beyond `LIGKERN' */ |
| 1371 |
sawligkern = 1; |
| 1372 |
while (*s && *s <= ' ') |
| 1373 |
s++; |
| 1374 |
param = s; |
| 1375 |
while (*param) { |
| 1376 |
/* collect next ligkern spec */ |
| 1377 |
for (n = 0; n < 5;) { |
| 1378 |
/* collect next token for ligkern spec */ |
| 1379 |
if (*param == 0) |
| 1380 |
break; /* ligkern spec complete */ |
| 1381 |
mlist[n] = paramstring (); |
| 1382 |
if (strcmp (mlist[n], ";") == 0) |
| 1383 |
break; /* ligkern spec complete */ |
| 1384 |
n++; |
| 1385 |
} |
| 1386 |
|
| 1387 |
/* handle ligkern spec */ |
| 1388 |
if (n > 4) |
| 1389 |
error ("! too many parameters in lig kern data"); |
| 1390 |
if (n < 3) |
| 1391 |
error ("! not enough parameters in lig kern data"); |
| 1392 |
if (n == 3 && strcmp (mlist[1], "{}") == 0) { |
| 1393 |
if (!lig_it) |
| 1394 |
continue; |
| 1395 |
if (lig_it == 2 && strcmp (mlist[0], "*") != 0) { |
| 1396 |
ai = findadobe (mlist[0]); |
| 1397 |
if (ai) ai->nonstd_lk = 1; |
| 1398 |
} |
| 1399 |
rmkern (mlist[0], mlist[2]); |
| 1400 |
} else if (n == 3 && strcmp (mlist[1], "<>") == 0) { |
| 1401 |
if (!lig_it) |
| 1402 |
continue; |
| 1403 |
if (lig_it == 2) |
| 1404 |
error ("!Post-letterspacing <> kern spec not allowed"); |
| 1405 |
copykerns (mlist[0], mlist[2]); |
| 1406 |
} else if (n == 3 && strcmp (mlist[0], boundaryname) == 0 && |
| 1407 |
strcmp (mlist[1], "=") == 0) { |
| 1408 |
/* setting of rboundarychar; only during 0-th iteration */ |
| 1409 |
if (lig_it) |
| 1410 |
continue; |
| 1411 |
if (lig_it == 2) |
| 1412 |
error ("!Post-letterspacing boundarychar spec not allowed"); |
| 1413 |
if (rboundarychar != -1) |
| 1414 |
error ("! multiple boundary character commands?"); |
| 1415 |
if (sscanf (mlist[2], "%d", &bch) == 1) { |
| 1416 |
/* number for rboundarychar */ |
| 1417 |
if (bch < 0 || bch > 255) |
| 1418 |
error ("! boundary character number must be 0..255"); |
| 1419 |
else |
| 1420 |
set_rboundarychar (bch); |
| 1421 |
} else { /* named rboundarychar */ |
| 1422 |
for (bch = 0; bch < 256; bch++) |
| 1423 |
if (!strcmp (outencoding->vec[bch], mlist[2])) |
| 1424 |
break; |
| 1425 |
if (bch<256) boundglyph = newstring(mlist[2]); |
| 1426 |
else { |
| 1427 |
if (strcmp ("cwm", mlist[2])) error |
| 1428 |
("unencoded boundarychar; will use empty slot instead"); |
| 1429 |
bch = -1; |
| 1430 |
boundglyph = newstring(boundaryname); |
| 1431 |
} |
| 1432 |
set_rboundarychar (bch); |
| 1433 |
} |
| 1434 |
} else if (n == 4) { /* ligature: char succ lig_op result */ |
| 1435 |
int op = -1; |
| 1436 |
|
| 1437 |
if (!lig_it) |
| 1438 |
continue; |
| 1439 |
if (lig_it == 2) |
| 1440 |
error ("!Post-letterspacing lig spec not allowed"); |
| 1441 |
for (i = 0; encligops[i]; i++) |
| 1442 |
if (strcmp (mlist[2], encligops[i]) == 0) { |
| 1443 |
op = i; |
| 1444 |
break; |
| 1445 |
} |
| 1446 |
if (op < 0) |
| 1447 |
error ("! bad ligature op specified"); |
| 1448 |
if (!strcmp (mlist[0], boundaryname)) |
| 1449 |
ai = lbound; |
| 1450 |
else |
| 1451 |
ai = findadobe (mlist[0]); |
| 1452 |
if (ai) { |
| 1453 |
struct lig *lig; |
| 1454 |
|
| 1455 |
if (findadobe (mlist[1])) /* remove coincident kerns */ |
| 1456 |
rmkern (mlist[0], mlist[1]); |
| 1457 |
if (strcmp (mlist[3], boundaryname) == 0) |
| 1458 |
error ("! you can't lig to the boundary character!"); |
| 1459 |
for (lig = ai->ligs; lig; lig = lig->next) |
| 1460 |
if (strcmp (lig->succ, mlist[1]) == 0) |
| 1461 |
break; /* we'll re-use this structure */ |
| 1462 |
if (lig == 0) { |
| 1463 |
lig = newlig (); |
| 1464 |
lig->succ = newstring (mlist[1]); |
| 1465 |
lig->next = ai->ligs; |
| 1466 |
ai->ligs = lig; |
| 1467 |
} |
| 1468 |
lig->sub = newstring (mlist[3]); |
| 1469 |
lig->op = op; |
| 1470 |
if (strcmp (mlist[1], boundaryname) == 0) { |
| 1471 |
lig->boundright = 1; |
| 1472 |
if (strcmp (mlist[0], boundaryname) == 0) |
| 1473 |
error ("! you can't lig boundarychar boundarychar!"); |
| 1474 |
} else |
| 1475 |
lig->boundright = 0; |
| 1476 |
} |
| 1477 |
} else |
| 1478 |
error ("! bad form in LIGKERN command"); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
static void |
| 1483 |
letterspace(void) |
| 1484 |
{ |
| 1485 |
int i,j; |
| 1486 |
struct kern *k; |
| 1487 |
struct adobeinfo *ai; |
| 1488 |
int *haskern; /* which glyphs are rhs of a kerning pair? */ |
| 1489 |
|
| 1490 |
haskern = (int *) malloc (nglyphs * sizeof (int)); |
| 1491 |
for (i=0;i<nglyphs;i++) { |
| 1492 |
for (j=0;j<nglyphs;j++) haskern[j] = 0; |
| 1493 |
ai = adobechars[i]; |
| 1494 |
for (k=ai->kerns;k;k=k->next) { |
| 1495 |
j = findindex (k->succ); |
| 1496 |
if (j>0 && j<nglyphs) { |
| 1497 |
/* kern with rbound is NOT modified */ |
| 1498 |
k->delta += lspace; |
| 1499 |
haskern[j] = 1; |
| 1500 |
} |
| 1501 |
} |
| 1502 |
for (j=0;j<nglyphs;j++) if (!haskern[j]) { |
| 1503 |
k = newkern(); |
| 1504 |
k->succ = adobechars[j]->adobename; |
| 1505 |
k->delta = lspace; |
| 1506 |
k->next = ai->kerns; |
| 1507 |
ai->kerns = k; |
| 1508 |
} |
| 1509 |
} |
| 1510 |
free (haskern); |
| 1511 |
fontspace += 2 * lspace; |
| 1512 |
} |
| 1513 |
|
| 1514 |
static void |
| 1515 |
extraligkerninfo(void) |
| 1516 |
{ |
| 1517 |
int i; |
| 1518 |
char *p; |
| 1519 |
struct adobeinfo *ai; |
| 1520 |
|
| 1521 |
/* with positive letterspacing, remove native ligs unless keepligs |
| 1522 |
*/ |
| 1523 |
if (lspace>0 && !keepligs) |
| 1524 |
for (i=0;i<nglyphs;i++) adobechars[i]->ligs = NULL; |
| 1525 |
|
| 1526 |
/* Boundarychars make things a lot messier than they would be |
| 1527 |
* otherwise. A rather long summary: |
| 1528 |
* When typesetting, TeX sandwiches words between a left |
| 1529 |
* boundarychar and a right boundarychar. |
| 1530 |
* It seems sensible to translate space kerns into boundarychar |
| 1531 |
* kerns although afm2tfm doesn't do this. |
| 1532 |
* Below, we read ligkern info twice: the first time to read |
| 1533 |
* a right boundarychar spec, if any, the second time to read everything |
| 1534 |
* else. The global loop variable lig_it is consulted by checkligkern. |
| 1535 |
* more about boundarychar/boundaryname: |
| 1536 |
* rboundarychar is the index of right boundarychar in the tfm; |
| 1537 |
* initialized as -1 |
| 1538 |
* The left boundarychar doesn't need a proper tfm index |
| 1539 |
*/ |
| 1540 |
if (lspace>0 && !strcmp (ligoption, "0")) ligoption = "1"; |
| 1541 |
if (!strcmp (ligoption, "0")) |
| 1542 |
return; |
| 1543 |
if (!strcmp (ligoption, "1") && encfilename && lspace<=0) { |
| 1544 |
sawligkern = 0; |
| 1545 |
/* ligkern specs in comments in encoding file? */ |
| 1546 |
encfilename = |
| 1547 |
openin (encfilename, kpse_enc_format, ".enc"); |
| 1548 |
for (lig_it = 0; lig_it < 2; lig_it++) { |
| 1549 |
while (texlive_getline ()) { |
| 1550 |
/* search for (ligkern) comment in line */ |
| 1551 |
for (p = buffer; *p; p++) |
| 1552 |
if (*p == '%') { |
| 1553 |
checkligkern (p, 1); /* 2nd param 1: reading .enc file */ |
| 1554 |
break; |
| 1555 |
} |
| 1556 |
} |
| 1557 |
if (!sawligkern) |
| 1558 |
break; /* read default lig file instead */ |
| 1559 |
if (!lig_it) { |
| 1560 |
if (rboundarychar == -1) |
| 1561 |
set_rboundarychar (-1); |
| 1562 |
rewind (infile); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
fclose (infile); |
| 1566 |
if (sawligkern) |
| 1567 |
return; |
| 1568 |
else { |
| 1569 |
ligfilenames->n = 1; |
| 1570 |
ligfilenames->names = malloc (sizeof (char *)); |
| 1571 |
ligfilenames->names[0] = "default.lig"; |
| 1572 |
} |
| 1573 |
} else if (!strcmp (ligoption, "1")) { /* lspace>0 or no encfile */ |
| 1574 |
ligfilenames->n = 1; |
| 1575 |
ligfilenames->names = malloc (sizeof (char *)); |
| 1576 |
if (lspace<=0) ligfilenames->names[0] = "default.lig"; |
| 1577 |
else ligfilenames->names[0] = "defpre.lig"; |
| 1578 |
} |
| 1579 |
|
| 1580 |
/* process ligfilenames struct */ |
| 1581 |
for (lig_it = 0; lig_it < 2; lig_it++) { |
| 1582 |
for (i = 0; i < ligfilenames->n; i++) { |
| 1583 |
ligfilename = openin (ligfilenames->names[i], |
| 1584 |
kpse_lig_format, ".lig"); |
| 1585 |
while (texlive_getline ()) |
| 1586 |
checkligkern (buffer, 0); /* 2nd param 0: lig file */ |
| 1587 |
fclose (infile); |
| 1588 |
} |
| 1589 |
if (!lig_it && (rboundarychar == -1)) |
| 1590 |
set_rboundarychar (-1); |
| 1591 |
} |
| 1592 |
|
| 1593 |
/* optimization: identify glyphs which now have ligs or kerns. |
| 1594 |
* Boundarychars: rboundarychar won't get a label in the ligtable, |
| 1595 |
* and lboundarychar will be done separately anyhow. |
| 1596 |
*/ |
| 1597 |
for (i=0;i<nglyphs;i++) { |
| 1598 |
ai = adobechars[i]; |
| 1599 |
ai->nonstd_lk = (ai->ligs!=NULL || ai->kerns!=NULL); |
| 1600 |
} |
| 1601 |
|
| 1602 |
if (!lspace) return; |
| 1603 |
|
| 1604 |
letterspace(); |
| 1605 |
|
| 1606 |
/* process post-letterspace ligfiles */ |
| 1607 |
if (!strcmp (Ligoption, "1")) { |
| 1608 |
Ligfilenames->n = 1; |
| 1609 |
Ligfilenames->names = malloc (sizeof (char *)); |
| 1610 |
Ligfilenames->names[0] = "defpost.lig"; |
| 1611 |
} |
| 1612 |
lig_it = 2; |
| 1613 |
for (i = 0; i < Ligfilenames->n; i++) { |
| 1614 |
ligfilename = openin (Ligfilenames->names[i], |
| 1615 |
kpse_lig_format, ".lig"); |
| 1616 |
while (texlive_getline ()) |
| 1617 |
checkligkern (buffer, 0); /* 2nd param 0: lig file */ |
| 1618 |
fclose (infile); |
| 1619 |
} |
| 1620 |
} |
| 1621 |
|
| 1622 |
static void |
| 1623 |
spaceparms(void) |
| 1624 |
{ |
| 1625 |
/* afm2tfm values for fstretch, fshrink, fextra: 200, 100, 111 |
| 1626 |
* fontinst values: 0.6 * space, 0.24 * space, ? |
| 1627 |
* cmr10 values: 0.5 * space, .33 * space, .33 * space |
| 1628 |
*/ |
| 1629 |
if (!fixedpitch) { |
| 1630 |
if (fstretch==0) fstretch = fontspace / 2; |
| 1631 |
if (fshrink==0) fshrink = fontspace / 3; |
| 1632 |
if (fextra==0) fextra = fontspace / 3; |
| 1633 |
} |
| 1634 |
} |
| 1635 |
|
| 1636 |
/********************************************************* |
| 1637 |
* debug output of adobeinfo structs */ |
| 1638 |
|
| 1639 |
#ifdef AFMDEBUG |
| 1640 |
FILE *dmp; |
| 1641 |
char *dmpname = "afm2pl.dmp"; |
| 1642 |
|
| 1643 |
static void |
| 1644 |
dumpai(struct adobeinfo *ai) |
| 1645 |
{ |
| 1646 |
struct lig *lg; |
| 1647 |
struct kern *kr; |
| 1648 |
putc ('\n', dmp); |
| 1649 |
fprintf (dmp, "adobename %s\n", |
| 1650 |
ai->adobename ? ai->adobename : "undefined"); |
| 1651 |
fprintf (dmp, "adobenum %d\n", ai->adobenum); |
| 1652 |
fprintf (dmp, "tfmnum %d\n", ai->tfmnum); |
| 1653 |
fprintf (dmp, "width %d\n", ai->width); |
| 1654 |
fprintf (dmp, "bbox %d %d %d %d\n", ai->llx, ai->lly, ai->urx, |
| 1655 |
ai->ury); |
| 1656 |
fprintf (dmp, "nonstd_lk %d\n", ai->nonstd_lk); |
| 1657 |
if (!ai->ligs) |
| 1658 |
fputs ("no ligs\n", dmp); |
| 1659 |
else |
| 1660 |
for (lg = ai->ligs; lg; lg = lg->next) |
| 1661 |
fprintf (dmp, "lig %s %d %s%s\n", |
| 1662 |
lg->succ, lg->op, lg->sub, |
| 1663 |
lg->boundright ? " boundarychar" : ""); |
| 1664 |
if (!ai->kerns) |
| 1665 |
fputs ("no kerns\n", dmp); |
| 1666 |
else |
| 1667 |
for (kr = ai->kerns; kr; kr = kr->next) |
| 1668 |
fprintf (dmp, "kern %s %d\n", kr->succ, kr->delta); |
| 1669 |
} |
| 1670 |
|
| 1671 |
static void |
| 1672 |
writedump(void) |
| 1673 |
{ |
| 1674 |
int i; |
| 1675 |
dmp = fopen (dmpname, W_MODE); |
| 1676 |
if (!dmp) |
| 1677 |
error ("Cant open dump file"); |
| 1678 |
if (lbound) { |
| 1679 |
fputs ("\nleft boundarychar\n", dmp); |
| 1680 |
dumpai (lbound); |
| 1681 |
} |
| 1682 |
if (rbound) { |
| 1683 |
fputs ("\nright boundarychar\n", dmp); |
| 1684 |
dumpai (rbound); |
| 1685 |
} |
| 1686 |
for (i = 0; i < nglyphs; i++) |
| 1687 |
if (adobechars[i]) dumpai (adobechars[i]); |
| 1688 |
else fprintf (dmp, "\nNo char at slot %d\n", i); |
| 1689 |
|
| 1690 |
fputs ("\nBy tfmptrs:\n", dmp); |
| 1691 |
for (i = 0; i < 256; i++) |
| 1692 |
if (tfmptrs[i]) dumpai (tfmptrs[i]); |
| 1693 |
else fprintf (dmp, "\nNo char at slot %d\n", i); |
| 1694 |
fclose (dmp); |
| 1695 |
} |
| 1696 |
#endif |
| 1697 |
|
| 1698 |
/******************************************************************* |
| 1699 |
* the PL file. */ |
| 1700 |
|
| 1701 |
#define plout(s) fprintf(outfile, s) |
| 1702 |
int level; /* depth of parenthesis nesting in PL output file */ |
| 1703 |
|
| 1704 |
/* indent */ |
| 1705 |
static void |
| 1706 |
pllevout(void) |
| 1707 |
{ |
| 1708 |
register int l = level; |
| 1709 |
while (l--) |
| 1710 |
plout (" "); |
| 1711 |
} |
| 1712 |
|
| 1713 |
/* newline plus indent */ |
| 1714 |
static void |
| 1715 |
pllevnlout(void) |
| 1716 |
{ |
| 1717 |
plout ("\n"); |
| 1718 |
pllevout (); |
| 1719 |
} |
| 1720 |
|
| 1721 |
#define ploutln(str) {fprintf(outfile,"%s\n",str);pllevout();} |
| 1722 |
#define ploutln2(f,s) {fprintf(outfile,f,s);pllevnlout();} |
| 1723 |
#define ploutln3(f,a,b) {fprintf(outfile,f,a,b);pllevnlout();} |
| 1724 |
#define ploutln4(f,a,b,c) {fprintf(outfile,f,a,b,c);pllevnlout();} |
| 1725 |
|
| 1726 |
/* left bracket */ |
| 1727 |
static void |
| 1728 |
plleft(void) |
| 1729 |
{ |
| 1730 |
level++; |
| 1731 |
plout ("("); |
| 1732 |
} |
| 1733 |
|
| 1734 |
/* right bracket */ |
| 1735 |
static void |
| 1736 |
plright(void) |
| 1737 |
{ |
| 1738 |
level--; |
| 1739 |
ploutln (")"); |
| 1740 |
} |
| 1741 |
|
| 1742 |
/* return string representation for .pl file of tfmptrs[c] |
| 1743 |
* don't forget that TeX doesn't use glyph names. |
| 1744 |
* only, if c happens to be a printable ascii char |
| 1745 |
* then we gratefully use that fact if we are allowed to. |
| 1746 |
* If the encoding moves the printable ascii range around then |
| 1747 |
* forceoctal would be a good idea. |
| 1748 |
*/ |
| 1749 |
char plcharbuf[6]; |
| 1750 |
static char * |
| 1751 |
plchar(int c) |
| 1752 |
{ |
| 1753 |
if (forceoctal == 0 && ISALNUM (c)) |
| 1754 |
(void) sprintf (plcharbuf, "C %c", |
| 1755 |
#ifndef VMCMS |
| 1756 |
c); |
| 1757 |
#else |
| 1758 |
ascii2ebcdic[c]); |
| 1759 |
#endif |
| 1760 |
else |
| 1761 |
(void) sprintf (plcharbuf, "O %o", (unsigned) c); |
| 1762 |
return (char *) plcharbuf; |
| 1763 |
} |
| 1764 |
|
| 1765 |
/* comment string with official glyph name if useful, |
| 1766 |
* null string otherwise |
| 1767 |
*/ |
| 1768 |
char plnamebuf[100]; |
| 1769 |
static char * |
| 1770 |
plname(int c) |
| 1771 |
{ |
| 1772 |
if (!forceoctal && ISALNUM (c)) { |
| 1773 |
plnamebuf[0] = 0; |
| 1774 |
} else if (c >= 0 && c < 256) { |
| 1775 |
sprintf (plnamebuf, " (comment %s)", tfmptrs[c]->adobename); |
| 1776 |
} |
| 1777 |
return (char *) plnamebuf; |
| 1778 |
} |
| 1779 |
|
| 1780 |
|
| 1781 |
/* obuffer: originally unmodified copy of input buffer, |
| 1782 |
* now recycled as output buffer |
| 1783 |
*/ |
| 1784 |
static void |
| 1785 |
writepl(void) |
| 1786 |
{ |
| 1787 |
register int i, j, k; |
| 1788 |
int bc, ec; |
| 1789 |
register struct adobeinfo *ai; |
| 1790 |
register struct lig *nlig; |
| 1791 |
register struct kern *nkern; |
| 1792 |
struct adobeinfo *asucc, *asub; |
| 1793 |
int ht, dt; |
| 1794 |
char labeled; |
| 1795 |
const char *pp; |
| 1796 |
|
| 1797 |
outname = openout (outname, based_on, ".pl"); |
| 1798 |
|
| 1799 |
/* header */ |
| 1800 |
{ |
| 1801 |
char *outbase = newstring (xbasename (outname)); |
| 1802 |
pp = find_suffix (outbase); |
| 1803 |
if (pp) |
| 1804 |
outbase[pp - outbase - 1] = 0; |
| 1805 |
(void) sprintf (obuffer, "%s%s%s", outbase, |
| 1806 |
(efactor == 1.0 ? "" : "-E"), |
| 1807 |
(slant == 0.0 ? "" : "-S")); |
| 1808 |
free (outbase); |
| 1809 |
} |
| 1810 |
if (strlen (obuffer) > 19) { /* too long, will retain first 9 and last 10 */ |
| 1811 |
register char *p, *q; |
| 1812 |
for (p = &obuffer[9], q = &obuffer[strlen (obuffer) - 10]; |
| 1813 |
p < &obuffer[19]; p++, q++) |
| 1814 |
*p = *q; |
| 1815 |
obuffer[19] = 0; |
| 1816 |
} |
| 1817 |
|
| 1818 |
/* global parameters */ |
| 1819 |
ploutln2 ("(FAMILY %s)", obuffer); |
| 1820 |
{ |
| 1821 |
char tbuf[41]; |
| 1822 |
char *tbp; |
| 1823 |
|
| 1824 |
strncpy (tbuf, outencoding->name, 40); |
| 1825 |
tbuf[40] = 0; |
| 1826 |
|
| 1827 |
if (strlen (tbuf) > 39) { |
| 1828 |
error ("Coding scheme too long; shortening to 39 characters."); |
| 1829 |
tbuf[39] = 0; |
| 1830 |
} |
| 1831 |
tbp = tbuf; |
| 1832 |
while (*tbp) { *tbp = toupper ((unsigned char)*tbp); tbp++; } |
| 1833 |
ploutln2 ("(CODINGSCHEME %s)", tbuf); |
| 1834 |
} |
| 1835 |
ploutln ("(DESIGNSIZE R 10.0)"); |
| 1836 |
ploutln ("(DESIGNUNITS R 1000)"); |
| 1837 |
ploutln ("(COMMENT DESIGNSIZE (1 em) IS IN POINTS)"); |
| 1838 |
ploutln |
| 1839 |
("(COMMENT OTHER DIMENSIONS ARE MULTIPLES OF DESIGNSIZE/1000)"); |
| 1840 |
/* Let pltotf compute the checksum. */ |
| 1841 |
/* ploutln2("(CHECKSUM O %lo)",cksum ^ 0xffffffff) ; */ |
| 1842 |
if (rboundarychar >= 0) |
| 1843 |
ploutln2 ("(BOUNDARYCHAR O %lo)", (unsigned long) rboundarychar); |
| 1844 |
plleft (); |
| 1845 |
ploutln ("FONTDIMEN"); |
| 1846 |
ploutln2 ("(SLANT R %f)", newslant); |
| 1847 |
ploutln2 ("(SPACE D %d)", fontspace); |
| 1848 |
ploutln2 ("(STRETCH D %d)", fstretch); |
| 1849 |
ploutln2 ("(SHRINK D %d)", fshrink); |
| 1850 |
ploutln2 ("(XHEIGHT D %d)", xheight); |
| 1851 |
ploutln2 ("(QUAD D %d)", fquad); |
| 1852 |
if (!afm2tfm_compat) ploutln2 ("(EXTRASPACE D %d)", fextra); |
| 1853 |
plright (); |
| 1854 |
|
| 1855 |
/* beginning and end of char array */ |
| 1856 |
for (i = 0; i < 256 && tfmptrs[i] == NULL; i++); |
| 1857 |
bc = i; |
| 1858 |
for (i = 255; i >= 0 && tfmptrs[i] == NULL; i--); |
| 1859 |
ec = i; |
| 1860 |
|
| 1861 |
/* ligkern table */ |
| 1862 |
plleft (); |
| 1863 |
ploutln ("LIGTABLE"); |
| 1864 |
|
| 1865 |
/* (left) boundarychar ligskerns */ |
| 1866 |
ai = lbound; |
| 1867 |
labeled = 0; |
| 1868 |
for (nlig = ai->ligs; nlig; nlig = nlig->next) |
| 1869 |
if (0 != (asucc = findtfm (nlig->succ))) |
| 1870 |
if (0 != (asub = findtfm (nlig->sub))) { |
| 1871 |
if (!labeled) { |
| 1872 |
ploutln ("(LABEL BOUNDARYCHAR)"); |
| 1873 |
labeled = 1; |
| 1874 |
} |
| 1875 |
/* handle all encodings of asucc */ |
| 1876 |
for (k = asucc->tfmnum; k >= 0; k = tfmnext[k]) |
| 1877 |
ploutln4 ("(%s %s O %o)", plligops[nlig->op], |
| 1878 |
plchar (k), (unsigned) asub->tfmnum); |
| 1879 |
} |
| 1880 |
for (nkern = ai->kerns; nkern; nkern = nkern->next) |
| 1881 |
if (0 != (asucc = findtfm (nkern->succ))) { |
| 1882 |
if (!labeled) { |
| 1883 |
ploutln ("(LABEL BOUNDARYCHAR)"); |
| 1884 |
labeled = 1; |
| 1885 |
} |
| 1886 |
/* handle all encodings of asucc */ |
| 1887 |
for (k = asucc->tfmnum; k >= 0; k = tfmnext[k]) { |
| 1888 |
ploutln4 ("(KRN %s R %d)%s", plchar (k), |
| 1889 |
nkern->delta, plname (k)); |
| 1890 |
} |
| 1891 |
} |
| 1892 |
if (labeled) |
| 1893 |
ploutln ("(STOP)"); |
| 1894 |
|
| 1895 |
/* other ligs and kerns */ |
| 1896 |
|
| 1897 |
|
| 1898 |
for (i = bc; i <= ec; i++) |
| 1899 |
if ((ai = tfmptrs[i]) && ai->tfmnum == i && ai->nonstd_lk) { |
| 1900 |
/* slot i is filled, points to a not-previously-encoded |
| 1901 |
* character, and has ligs and kerns other than |
| 1902 |
* standard letterspacing kerns. Do right boundarychar |
| 1903 |
* only if it is a real glyph. |
| 1904 |
*/ |
| 1905 |
if (!strcmp (ai->adobename, "||")) |
| 1906 |
continue; |
| 1907 |
labeled = 0; |
| 1908 |
/* do ligatures for ai = tfmptrs[i] */ |
| 1909 |
for (nlig = ai->ligs; nlig; nlig = nlig->next) |
| 1910 |
if (0 != (asucc = findtfm (nlig->succ))) |
| 1911 |
if (0 != (asub = findtfm (nlig->sub))) { |
| 1912 |
/* we found a lig which really belongs in the tfm */ |
| 1913 |
if (!labeled) { |
| 1914 |
/* also take care of all other slots for this char */ |
| 1915 |
for (j = i; j >= 0; j = tfmnext[j]) { |
| 1916 |
ploutln3 ("(LABEL %s)%s", plchar (j), plname (j)); |
| 1917 |
} |
| 1918 |
labeled = 1; |
| 1919 |
} |
| 1920 |
for (k = asucc->tfmnum; k >= 0; k = tfmnext[k]) { |
| 1921 |
ploutln4 ("(%s %s O %o)", plligops[nlig->op], |
| 1922 |
plchar (k), (unsigned) asub->tfmnum); |
| 1923 |
} |
| 1924 |
} |
| 1925 |
/* do kerns for ai = tfmptrs[i] */ |
| 1926 |
for (nkern = ai->kerns; nkern; nkern = nkern->next) |
| 1927 |
if (0 != (asucc = findtfm (nkern->succ))) { |
| 1928 |
if (!labeled) { |
| 1929 |
for (j = i; j >= 0; j = tfmnext[j]) { |
| 1930 |
ploutln3 ("(LABEL %s)%s", plchar (j), plname (j)); |
| 1931 |
} |
| 1932 |
labeled = 1; |
| 1933 |
} |
| 1934 |
dt = nkern->delta; |
| 1935 |
for (k = asucc->tfmnum; k >= 0; k = tfmnext[k]) { |
| 1936 |
ploutln4 ("(KRN %s R %d)%s", plchar (k), dt, plname (k)); |
| 1937 |
} |
| 1938 |
} |
| 1939 |
if (labeled) |
| 1940 |
ploutln ("(STOP)"); |
| 1941 |
} |
| 1942 |
|
| 1943 |
if (lspace) { |
| 1944 |
for (i = bc; i <= ec; i++) |
| 1945 |
if ((ai = tfmptrs[i]) && !ai->nonstd_lk) { |
| 1946 |
/* do all 'standard' glyphs together. |
| 1947 |
* no need to check for ligatures. |
| 1948 |
* we do check for kerns, though: |
| 1949 |
* if there are none, then apparently all space kerns |
| 1950 |
* have been tossed out, and there is nothing to do. |
| 1951 |
* Either way, we break out of the loop after doing the |
| 1952 |
* first glyph with `standard' ligkerns. |
| 1953 |
*/ |
| 1954 |
if (!strcmp(ai->adobename,"||")) continue; |
| 1955 |
if (!ai->kerns) break; |
| 1956 |
for (j = i; j <= ec; j++) if (tfmptrs[j] && !tfmptrs[j]->nonstd_lk) |
| 1957 |
ploutln3 ("(LABEL %s)%s", plchar (j), plname (j)); |
| 1958 |
for (nkern = ai->kerns; nkern; nkern = nkern->next) |
| 1959 |
if (0 != (asucc = findtfm (nkern->succ))) { |
| 1960 |
dt = nkern->delta; |
| 1961 |
for (k = asucc->tfmnum; k >= 0; k = tfmnext[k]) |
| 1962 |
ploutln4 ("(KRN %s R %d)%s", plchar (k), dt, plname (k)); |
| 1963 |
} |
| 1964 |
ploutln ("(STOP)"); |
| 1965 |
break; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
|
| 1969 |
plright (); |
| 1970 |
|
| 1971 |
/* done with ligkerns; now char metrics */ |
| 1972 |
for (i = bc; i <= ec; i++) |
| 1973 |
if (0 != (ai = tfmptrs[i])) { |
| 1974 |
if (!strcmp (ai->adobename, "||")) |
| 1975 |
continue; |
| 1976 |
plleft (); |
| 1977 |
fprintf (outfile, "CHARACTER %s", plchar (i)); |
| 1978 |
if (*plcharbuf == 'C') { |
| 1979 |
ploutln (""); |
| 1980 |
} else |
| 1981 |
ploutln2 (" (comment %s)", ai->adobename); |
| 1982 |
ploutln2 ("(CHARWD R %d)", ai->width); |
| 1983 |
if (0 != (ht = ai->ury)) |
| 1984 |
ploutln2 ("(CHARHT R %d)", ht); |
| 1985 |
if (ai->lly) |
| 1986 |
ploutln2 ("(CHARDP R %d)", -ai->lly); |
| 1987 |
if (ai->urx > ai->width) |
| 1988 |
ploutln2 ("(CHARIC R %d)", ai->urx - ai->width); |
| 1989 |
plright (); |
| 1990 |
} |
| 1991 |
if (level) |
| 1992 |
error ("! I forgot to match the parentheses"); |
| 1993 |
fclose (outfile); |
| 1994 |
} |
| 1995 |
|
| 1996 |
/******************************************************************* |
| 1997 |
* (version and) usage |
| 1998 |
*/ |
| 1999 |
static void |
| 2000 |
version(FILE *f) |
| 2001 |
{ |
| 2002 |
fputs ("afm2pl(k) 0.7.1\n", f); |
| 2003 |
#ifdef KPATHSEA |
| 2004 |
fprintf (f, "%s\n", kpathsea_version_string); |
| 2005 |
#endif |
| 2006 |
fputs ("Copyright (C) 2002, 2005, 2009 Siep Kroonenberg.\n\ |
| 2007 |
This program is derived from afm2tfm, (C) 2002 Radical Eye Software.\n\ |
| 2008 |
There is NO warranty. You may redistribute this software\n\ |
| 2009 |
under the terms of the GNU General Public License.\n\ |
| 2010 |
For more information about these matters, see the files\n\ |
| 2011 |
named COPYING and afm2pl.c.\n", f); |
| 2012 |
} |
| 2013 |
|
| 2014 |
#define USAGE "\ |
| 2015 |
Convert an Adobe font metric file to a TeX font property list.\n\ |
| 2016 |
\n\ |
| 2017 |
-p ENCFILE Read/download ENCFILE for the PostScript encoding\n\ |
| 2018 |
-o Use octal for all character codes in the pl file\n\ |
| 2019 |
-e REAL Widen (extend) characters by a factor of REAL\n\ |
| 2020 |
-s REAL Oblique (slant) characters by REAL, generally <<1\n\ |
| 2021 |
-m INTEGER Letterspace by INTEGER/1000 em\n\ |
| 2022 |
-V Verbose output; i.e. report on missing glyphs\n\ |
| 2023 |
--help Print this message and exit.\n\ |
| 2024 |
--version Print version number and exit.\n\n\ |
| 2025 |
See the man page for full documentation.\n\n\ |
| 2026 |
" |
| 2027 |
|
| 2028 |
static void |
| 2029 |
afm2pl_usage(FILE *f) |
| 2030 |
{ |
| 2031 |
fputs ("Usage: afm2pl [OPTIONS]... FILE[.afm] [FILE[.pl]]\n", f); |
| 2032 |
fputs (USAGE, f); |
| 2033 |
fputc ('\n', f); |
| 2034 |
fputs ("Email bug reports to [email protected]\n", f); |
| 2035 |
} |
| 2036 |
|
| 2037 |
/************************************************************** |
| 2038 |
* parse commandline |
| 2039 |
*/ |
| 2040 |
|
| 2041 |
/* decode comma-separated list of non-negative integers. |
| 2042 |
* initialize everything to -1 i.e. undefined |
| 2043 |
*/ |
| 2044 |
static int |
| 2045 |
getnums(char *st, int *nums, int num) |
| 2046 |
{ |
| 2047 |
char *p; /* pointer into st */ |
| 2048 |
int curnum, curindex, ndigits; |
| 2049 |
/* curnum: number to be parsed |
| 2050 |
curindex: index for nums array |
| 2051 |
ndigits: n. of digits found for curnum |
| 2052 |
*/ |
| 2053 |
for (curindex=0;curindex<num;curindex++) { |
| 2054 |
nums[curindex] = -1; |
| 2055 |
} |
| 2056 |
for (curnum=0,curindex=0,ndigits=0,p=st;;p++) { |
| 2057 |
if (*p==',' || *p==0) { |
| 2058 |
/* done with this number */ |
| 2059 |
if (ndigits>0) /* we found some digits */ |
| 2060 |
nums[curindex] = curnum; |
| 2061 |
curnum = 0; |
| 2062 |
curindex++; |
| 2063 |
ndigits = 0; |
| 2064 |
if (curindex>=num || !*p) break; |
| 2065 |
} else if (*p>='0' && *p<='9') { |
| 2066 |
curnum = 10*curnum + (*p-'0'); |
| 2067 |
ndigits++; |
| 2068 |
} else { |
| 2069 |
error ("! Illegal -f parameter"); |
| 2070 |
} |
| 2071 |
} |
| 2072 |
if (!*p) return 1; /* end of string reached: no problems */ |
| 2073 |
else return 0; |
| 2074 |
} |
| 2075 |
|
| 2076 |
/* split string on commas into strings; disregard empty strings */ |
| 2077 |
static struct nstrings * |
| 2078 |
getoutnames(const char *st, struct nstrings *onames) |
| 2079 |
{ |
| 2080 |
char *argcopy; |
| 2081 |
unsigned i; |
| 2082 |
int j, inpart; |
| 2083 |
argcopy = (char *) malloc (strlen (st) + 1); |
| 2084 |
strcpy (argcopy, st); |
| 2085 |
inpart = 0; /* cursor not inside a constituing substring */ |
| 2086 |
for (i = 0, onames->n = 0; i < strlen (st); i++) { |
| 2087 |
if (argcopy[i] == ',') { |
| 2088 |
argcopy[i] = 0; |
| 2089 |
inpart = 0; |
| 2090 |
} else if (!inpart) { |
| 2091 |
inpart = 1; |
| 2092 |
onames->n++; |
| 2093 |
} |
| 2094 |
/* !=',', inpart: do nothing */ |
| 2095 |
} |
| 2096 |
onames->names = (const char **) malloc (onames->n * sizeof (char *)); |
| 2097 |
inpart = 0; |
| 2098 |
for (i = 0, j = 0; i < strlen (st); i++) { |
| 2099 |
if (argcopy[i] == 0) |
| 2100 |
inpart = 0; |
| 2101 |
else if (!inpart) { |
| 2102 |
onames->names[j++] = argcopy + i; |
| 2103 |
inpart = 1; |
| 2104 |
} |
| 2105 |
} |
| 2106 |
return onames; |
| 2107 |
} |
| 2108 |
|
| 2109 |
/* call this when an option requires an argument */ |
| 2110 |
#define CHECKARG3 if (argc < 3) { afm2pl_usage(stderr); exit(1); } |
| 2111 |
|
| 2112 |
static void |
| 2113 |
readargs(int argc, char **argv) |
| 2114 |
{ |
| 2115 |
register int i; |
| 2116 |
int fdims[5]; |
| 2117 |
|
| 2118 |
/* skip argv[0] and look at the rest. */ |
| 2119 |
argv++; |
| 2120 |
argc--; |
| 2121 |
|
| 2122 |
if (argc <= 0 || !strcmp (argv[0], "--help") || |
| 2123 |
!strcmp (argv[0], "-help") || !strcmp (argv[0], "-h")) { |
| 2124 |
afm2pl_usage (stdout); |
| 2125 |
exit (0); |
| 2126 |
} |
| 2127 |
|
| 2128 |
if (!strcmp (argv[0], "--version") || |
| 2129 |
!strcmp (argv[0], "-version") || !strcmp (argv[0], "-v")) { |
| 2130 |
version (stdout); |
| 2131 |
exit (0); |
| 2132 |
} |
| 2133 |
|
| 2134 |
/* allocate structs for ligkern filenames */ |
| 2135 |
ligfilenames = (struct nstrings *) mymalloc |
| 2136 |
((unsigned long) sizeof (struct nstrings)); |
| 2137 |
Ligfilenames = (struct nstrings *) mymalloc |
| 2138 |
((unsigned long) sizeof (struct nstrings)); |
| 2139 |
|
| 2140 |
/* looping: advance argv and decrement argc to match unprocessed |
| 2141 |
* command-line arguments. |
| 2142 |
* After the options, we need at least an afm filename, |
| 2143 |
* which will be handled AFTER this loop. |
| 2144 |
*/ |
| 2145 |
|
| 2146 |
while (argc > 0 && *argv[0] == '-') { |
| 2147 |
i = argv[0][1]; |
| 2148 |
/* I don't understand what this is about. |
| 2149 |
* The comment below suggests that it is VM/CMS-specific |
| 2150 |
* so I comment it out for other OS-es. [SK] |
| 2151 |
*/ |
| 2152 |
#ifdef VMCMS |
| 2153 |
if (i == '/') |
| 2154 |
i = argv[0][2] - 32; /* /a ==> A for VMS */ |
| 2155 |
#endif |
| 2156 |
switch (i) { |
| 2157 |
case 'e': |
| 2158 |
efactor = 1.0; |
| 2159 |
CHECKARG3 |
| 2160 |
if (sscanf (argv[1], "%f", &efactor) == 0 || efactor < 0.01) |
| 2161 |
error ("! Bad extension factor"); |
| 2162 |
efactorparam = argv[1]; |
| 2163 |
argv += 2; |
| 2164 |
argc -= 2; |
| 2165 |
break; |
| 2166 |
case 's': |
| 2167 |
CHECKARG3 if (sscanf (argv[1], "%f", &slant) == 0) |
| 2168 |
error ("! Bad slant parameter"); |
| 2169 |
slantparam = argv[1]; |
| 2170 |
argv += 2; |
| 2171 |
argc -= 2; |
| 2172 |
break; |
| 2173 |
case 'm': |
| 2174 |
CHECKARG3 if (sscanf (argv[1], "%d", &lspace) == 0) |
| 2175 |
error ("! Bad letterspacing parameter"); |
| 2176 |
lspaceparam = argv[1]; |
| 2177 |
if (lspace > 0) |
| 2178 |
keepligs = 0; |
| 2179 |
argv += 2; |
| 2180 |
argc -= 2; |
| 2181 |
break; |
| 2182 |
case 'p': |
| 2183 |
CHECKARG3 encfilename = argv[1]; |
| 2184 |
argv += 2; |
| 2185 |
argc -= 2; |
| 2186 |
break; |
| 2187 |
case 'f': |
| 2188 |
CHECKARG3 |
| 2189 |
if (!strcmp (argv[1], "afm2tfm")) { |
| 2190 |
afm2tfm_compat = 1; |
| 2191 |
} else if (!strcmp (argv[1], "afm2tfm")) { |
| 2192 |
afm2tfm_compat = 1; |
| 2193 |
} else { |
| 2194 |
if (!getnums (argv[1], fdims, 5)) |
| 2195 |
error ("!Parsing error in argument of -f"); |
| 2196 |
fstretch = fdims[0]; fshrink = fdims[1]; fextra = fdims[2]; |
| 2197 |
fquad = fdims[3]; fontspace = fdims[4]; |
| 2198 |
} |
| 2199 |
argv += 2; |
| 2200 |
argc -= 2; |
| 2201 |
break; |
| 2202 |
case 'l': |
| 2203 |
CHECKARG3 ligoption = argv[1]; |
| 2204 |
if (strcmp (ligoption, "0") && strcmp (ligoption, "1")) { |
| 2205 |
getoutnames (ligoption, ligfilenames); |
| 2206 |
} |
| 2207 |
argv += 2; |
| 2208 |
argc -= 2; |
| 2209 |
break; |
| 2210 |
case 'L': |
| 2211 |
CHECKARG3 Ligoption = argv[1]; |
| 2212 |
if (strcmp (Ligoption, "0") && strcmp (Ligoption, "1")) { |
| 2213 |
getoutnames (Ligoption, Ligfilenames); |
| 2214 |
} |
| 2215 |
argv += 2; |
| 2216 |
argc -= 2; |
| 2217 |
break; |
| 2218 |
case 'o': |
| 2219 |
forceoctal = 1; |
| 2220 |
argv += 1; |
| 2221 |
argc -= 1; |
| 2222 |
break; |
| 2223 |
case 'k': |
| 2224 |
keepligs = 1; |
| 2225 |
argv += 1; |
| 2226 |
argc -= 1; |
| 2227 |
break; |
| 2228 |
case 'n': |
| 2229 |
no_prefix = 1; |
| 2230 |
argv += 1; |
| 2231 |
argc -= 1; |
| 2232 |
break; |
| 2233 |
case 'V': |
| 2234 |
verbose = 1; |
| 2235 |
argv += 1; |
| 2236 |
argc -= 1; |
| 2237 |
break; |
| 2238 |
default: |
| 2239 |
(void) fprintf (stderr, |
| 2240 |
"Unknown option %s %s will be ignored.\n", |
| 2241 |
argv[0], argv[1]); |
| 2242 |
argv += 2; |
| 2243 |
argc -= 2; |
| 2244 |
} |
| 2245 |
} |
| 2246 |
|
| 2247 |
/* end of loop. Remainder: name of afm file and possibly pl file */ |
| 2248 |
afmname = argv[0]; |
| 2249 |
|
| 2250 |
if ((argc < 1) || (argc > 2)) { |
| 2251 |
error ("! need one or two non-option arguments"); |
| 2252 |
afm2pl_usage (stderr); |
| 2253 |
} |
| 2254 |
|
| 2255 |
if (argc == 1) { |
| 2256 |
outname = afmname; |
| 2257 |
based_on = 1; |
| 2258 |
} else { |
| 2259 |
outname = argv[1]; |
| 2260 |
based_on = 0; |
| 2261 |
} |
| 2262 |
} |
| 2263 |
|
| 2264 |
/* This routine prints out the line that needs to be added to psfonts.map. |
| 2265 |
*/ |
| 2266 |
static void |
| 2267 |
conspsfonts(void) |
| 2268 |
{ |
| 2269 |
char *p; |
| 2270 |
const char *q; |
| 2271 |
|
| 2272 |
/* TeX fontname is file basename without path or extension */ |
| 2273 |
p = newstring (xbasename (outname)); |
| 2274 |
q = find_suffix (p); |
| 2275 |
if (q) |
| 2276 |
p[q - p - 1] = 0; |
| 2277 |
openout (p, 0, ".map"); |
| 2278 |
(void) fprintf (outfile, "%s %s", p, fontname); |
| 2279 |
free (p); |
| 2280 |
if (slantparam || efactorparam || encfilename) { |
| 2281 |
(void) fprintf (outfile, " \""); |
| 2282 |
if (slantparam) |
| 2283 |
(void) fprintf (outfile, " %s SlantFont", slantparam); |
| 2284 |
if (efactorparam) |
| 2285 |
(void) fprintf (outfile, " %s ExtendFont", efactorparam); |
| 2286 |
if (encfilename) |
| 2287 |
(void) fprintf (outfile, " %s ReEncodeFont", outencoding->name); |
| 2288 |
(void) fprintf (outfile, " \""); |
| 2289 |
if (encfilename) { |
| 2290 |
const char *base = xbasename (encfilename); |
| 2291 |
(void) fprintf (outfile, " <%s", base); |
| 2292 |
} |
| 2293 |
} |
| 2294 |
p = newstring (xbasename (afmname)); |
| 2295 |
q = find_suffix (p); |
| 2296 |
if (q) |
| 2297 |
p[q - p - 1] = 0; |
| 2298 |
(void) fprintf (outfile, " <%s.pfb", p); |
| 2299 |
free (p); |
| 2300 |
(void) fprintf (outfile, "\n"); |
| 2301 |
fclose (outfile); |
| 2302 |
} |
| 2303 |
|
| 2304 |
/******************************************************** |
| 2305 |
* main program |
| 2306 |
*/ |
| 2307 |
|
| 2308 |
#ifndef VMS |
| 2309 |
int |
| 2310 |
#endif |
| 2311 |
main(int argc, char **argv) |
| 2312 |
{ |
| 2313 |
|
| 2314 |
#ifdef KPATHSEA |
| 2315 |
kpse_set_program_name (argv[0], "afm2pl"); |
| 2316 |
|
| 2317 |
if (argc == 1) { |
| 2318 |
fputs ("afm2pl: Need at least one file argument.\n", stderr); |
| 2319 |
fputs ("Try `afm2pl --help' for more information.\n", stderr); |
| 2320 |
exit (1); |
| 2321 |
} |
| 2322 |
if (argc == 2) { |
| 2323 |
if (strcmp (argv[1], "--help") == 0) { |
| 2324 |
afm2pl_usage (stdout); |
| 2325 |
exit (0); |
| 2326 |
} else if (strcmp (argv[1], "--version") == 0) { |
| 2327 |
version (stdout); |
| 2328 |
exit (0); |
| 2329 |
} |
| 2330 |
} |
| 2331 |
#endif /* KPATHSEA */ |
| 2332 |
readargs (argc, argv); |
| 2333 |
readadobe (); |
| 2334 |
changeadobe (); |
| 2335 |
readencoding (); |
| 2336 |
extraligkerninfo (); /* loop over lig files and lines in lig files */ |
| 2337 |
spaceparms (); |
| 2338 |
#ifdef AFMDEBUG |
| 2339 |
writedump (); |
| 2340 |
#endif |
| 2341 |
writepl (); |
| 2342 |
conspsfonts (); |
| 2343 |
return -missingchars; |
| 2344 |
} |