home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
pastex13.lha
/
DVIPS
/
dvips5519.lha
/
dvips
/
afm2tfm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-12
|
53KB
|
1,886 lines
/*
* This program converts AFM files to TeX TFM files, and optionally
* to TeX VPL files that retain all kerning and ligature information.
* Both files make the characters not normally encoded by TeX available
* by character codes greater than 127.
*/
/* (Modified by Don Knuth from Tom Rokicki's pre-VPL version.) */
/* VM/CMS port by J. Hafner (hafner@almaden.ibm.com), based on
* the port by Alessio Guglielmi (guglielmi@ipisnsib.bitnet)
* and Marco Prevedelli (prevedelli@ipisnsva.bitnet).
* This port is still in test state. No guarantees.
* 11/3/92: more corrections to VM/CMS port. Now it looks correct
* and will be supported by J. Hafner.
*
*/
#include <stdio.h>
#if defined(SYSV) || defined(VMS) || defined(__THINK__) || defined(MSDOS)
#include <string.h>
#else
#include <strings.h>
#endif
#include <math.h>
/* JLH: added these to make the code easier to read and remove some
ascii<->ebcdic dependencies */
#define ASCII_A 65
#define ASCII_Z 90
#define ASCII_a 97
#define ASCII_z 122
#define ASCII_0 48
#define ASCII_9 57
#ifdef VMCMS
#define interesting lookstr /* for 8 character truncation conflicts */
#include "dvipscms.h"
extern FILE *cmsfopen() ;
extern char ebcdic2ascii[] ;
extern char ascii2ebcdic[] ;
#ifdef fopen
#undef fopen
#endif
#define fopen cmsfopen
#endif
#if defined MSDOS || defined OS2
#define WRITEBIN "wb"
#else
#ifdef VMCMS
#define WRITEBIN "wb, lrecl=1024, recfm=f"
#else
#define WRITEBIN "w"
#endif
#endif
#ifdef __TURBOC__
#define SMALLMALLOC
#endif
struct encoding {
char *name ;
char *vec[256] ;
} ;
struct encoding staticencoding = {
"TeX text",
{"Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma",
"Upsilon", "Phi", "Psi", "Omega", "arrowup", "arrowdown", "quotesingle",
"exclamdown", "questiondown", "dotlessi", "dotlessj", "grave", "acute",
"caron", "breve", "macron", "ring", "cedilla", "germandbls", "ae", "oe",
"oslash", "AE", "OE", "Oslash", "space", "exclam", "quotedbl", "numbersign",
"dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright",
"asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one",
"two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
"semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
"bracketright", "circumflex", "underscore", "quoteleft", "a", "b", "c", "d",
"e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
"t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright",
"tilde", "dieresis", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "" } } ;
/*
* It's easier to put this in static storage and parse it as we go
* than to build the structures ourselves.
*/
char *staticligkern[] = {
"% LIGKERN space l =: lslash ; space L =: Lslash ;",
"% LIGKERN question quoteleft =: questiondown ;",
"% LIGKERN exclam quoteleft =: exclamdown ;",
"% LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;",
"% LIGKERN quoteleft quoteleft =: quotedblleft ;",
"% LIGKERN quoteright quoteright =: quotedblright ;",
"% LIGKERN space {} * ; * {} space ; zero {} * ; * {} zero ;",
"% LIGKERN one {} * ; * {} one ; two {} * ; * {} two ;",
"% LIGKERN three {} * ; * {} three ; four {} * ; * {} four ;",
"% LIGKERN five {} * ; * {} five ; six {} * ; * {} six ;",
"% LIGKERN seven {} * ; * {} seven ; eight {} * ; * {} eight ;",
"% LIGKERN nine {} * ; * {} nine ;",
/*
* These next are only included for deficient afm files that
* have the lig characters but not the lig commands.
*/
"% LIGKERN f i =: fi ; f l =: fl ; f f =: ff ; ff i =: ffi ;",
"% LIGKERN ff l =: ffl ;",
0 } ;
/*
* The above layout corresponds to TeX Typewriter Type and is compatible
* with TeX Text because the position of ligatures is immaterial.
*/
struct encoding *outencoding = 0 ;
struct encoding *inencoding = 0 ;
char *outenname, *inenname ;/* the file names for input and output encodings */
int boundarychar = -1 ; /* the boundary character */
int ignoreligkern ; /* do we look at ligkern info in the encoding? */
/*
* This is what we store Adobe data in.
*/
struct adobeinfo {
struct adobeinfo *next ;
int adobenum, texnum, width ;
char *adobename ;
int llx, lly, urx, ury ;
struct lig *ligs ;
struct kern *kerns ;
struct pcc *pccs ;
int wptr, hptr, dptr, iptr ;
} *adobechars, *adobeptrs[256], *texptrs[256],
*uppercase[256], *lowercase[256] ;
int nexttex[256] ; /* for characters encoded multiple times in output */
/*
* These are the eight ligature ops, in VPL terms and in METAFONT terms.
*/
char *vplligops[] = {
"LIG", "/LIG", "/LIG>", "LIG/", "LIG/>", "/LIG/", "/LIG/>", "/LIG/>>", 0
} ;
char *encligops[] = {
"=:", "|=:", "|=:>", "=:|", "=:|>", "|=:|", "|=:|>", "|=:|>>", 0
} ;
struct lig {
struct lig *next ;
char *succ, *sub ;
short op, boundleft ;
} ;
struct kern {
struct kern *next ;
char *succ ;
int delta ;
} ;
struct pcc {
struct pcc *next ;
char * partname ;
int xoffset, yoffset ;
} ;
FILE *afmin, *vplout, *tfmout ;
char inname[200], outname[200] ; /* names of input and output files */
char buffer[255]; /* input buffer (modified while parsing) */
char obuffer[255] ; /* unmodified copy of input buffer */
char *param ; /* current position in input buffer */
char *fontname = "Unknown" ;
char *codingscheme = "Unspecified" ;
#ifdef VMCMS
char *ebfontname ;
char *ebcodingscheme ;
#endif
float italicangle = 0.0 ;
char fixedpitch ;
char makevpl ;
char pedantic ;
int xheight = 400 ;
int fontspace ;
int bc, ec ;
long cksum ;
float efactor = 1.0, slant = 0.0 ;
float capheight = 0.8 ;
char *efactorparam, *slantparam ;
double newslant ;
char titlebuf[500] ;
void
error(s)
register char *s ;
{
extern void exit() ;
(void)fprintf(stderr, "%s\n", s) ;
if (obuffer[0]) {
(void)fprintf(stderr, "%s\n", obuffer) ;
while (param > buffer) {
(void)fprintf(stderr, " ") ;
param-- ;
}
(void)fprintf(stderr, "^\n") ;
}
if (*s == '!')
exit(1) ;
}
int
transform(x,y)
register int x,y ;
{
register double acc ;
acc = efactor * x + slant *y ;
return (int)(acc>=0? acc+0.5 : acc-0.5 ) ;
}
int
getline() {
register char *p ;
register int c ;
param = buffer ;
for (p=buffer; (c=getc(afmin)) != EOF && c != '\n';)/* changed 10 to '\n' */
*p++ = c ;
*p = 0 ;
(void)strcpy(obuffer, buffer) ;
if (p == buffer && c == EOF)
return(0) ;
else
return(1) ;
}
char *interesting[] = { "FontName", "ItalicAngle", "IsFixedPitch",
"XHeight", "C", "KPX", "CC", "EncodingScheme", NULL} ;
#define FontName (0)
#define ItalicAngle (1)
#define IsFixedPitch (2)
#define XHeight (3)
#define C (4)
#define KPX (5)
#define CC (6)
#define EncodingScheme (7)
#define NONE (-1)
int
interest(s)
char *s ;
{
register char **p ;
register int n ;
for (p=interesting, n=0; *p; p++, n++)
if (strcmp(s, *p)==0)
return(n) ;
return(NONE) ;
}
char *
mymalloc(len)
unsigned long len ;
{
register char *p ;
int i ;
#ifndef IBM6000
#if defined MSDOS || defined OS2
extern void *malloc() ;
#else
extern char *malloc() ;
#endif
#endif
#ifdef SMALLMALLOC
if (len > 65500L)
error("! can't allocate more than 64K!") ;
#endif
p = malloc((unsigned)len) ;
if (p==NULL)
error("! out of memory") ;
for (i=0; i<len; i++)
p[i] = 0 ;
return(p) ;
}
char *
newstring(s)
char *s ;
{
char *q = mymalloc((unsigned lon