elwell@osu-eddie.UUCP (01/30/87)
Here is a little C program I hacked up to convert Adobe AFM files to TeX PL
files (which can then be touched up by hand if necessary), which can be
converted into TFM files by the standard TeX utility PLTOTF.
Using this program, I can take any font I have an AFM file for and produce
a TeX TFM file almost completely automatically. It even takes care of most
of the kerning information, and fakes the italic correction (close enough
for me). Cut at the dashed line, remove my signature, and compile.
------------------------ CUT HERE ------------------------
/**
Program: aftopl -- convert Adobe AFM files into TeX PL files
Author: Clayton M. Elwell, Ohio State University
Disclaimer: This program seems to work, but it was cobbled up in
an afternoon. Its operation should be readily apparent
to any C programmer.
**/
#include <stdio.h>
#include <ctype.h>
#define max(a,b) ((a) > (b) ? (a) : (b))
char line[BUFSIZ];
char *strupr(s)
register char *s;
{
register char *s1;
s1 = s;
while (*s) {
if (islower(*s)) *s = toupper(*s);
s++;
}
return s1;
}
starts(s1, s2)
register char *s1;
register char *s2;
{
return !strncmp(s1, s2, strlen(s2));
}
float hscale;
float scale(i)
int i;
{
return (hscale * (((float) i) / 1000.0));
}
int number, width, left, bottom, right, top;
char name[64];
main(argc, argv)
int argc;
char *argv[];
{
double atof();
if (argc == 2) hscale = atof(argv[1]); else hscale = 1.0;
puts("(COMMENT THIS PL FILE WAS GENERATED FROM AN AFM FILE BY AFTOPL)");
puts("(COMMENT AFTOPL WAS WRITTEN BY CLAYTON M. ELWELL, OHIO STATE UNIVERSITY)");
puts("(DESIGNSIZE D 1)");
puts("(SEVENBITSAFEFLAG FALSE)");
while (gets(line)) {
if (starts(line, "Comment"))
printf("(COMMENT %s)\n", strupr(line+8));
else if (starts(line, "EncodingScheme"))
printf("(CODINGSCHEME %s)\n", strupr(line+15));
else if (starts(line, "ItalicAngle")) {
printf("(FONTDIMEN\n (SLANT R %s)\n", line+12);
puts(" (STRETCH R 0.300)\n (SHRINK R 0.100)\n )");
}
else if (starts(line, "CapHeight"))
printf("(FONTDIMEN\n (QUAD R %f)\n )\n", scale(atoi(line+10)));
else if (starts(line, "XHeight"))
printf("(FONTDIMEN\n (XHEIGHT R %f)\n )\n", scale(atoi(line+8)));
else if (starts(line, "C ")) {
sscanf(line, "C %d ; WX %d ; N %s ; B %d %d %d %d ;",
&number, &width, name, &left, &bottom, &right, &top);
if (number < 32) { /* do nothing */
} else if (number == 32) {
printf("(FONTDIMEN\n (SPACE R %f)\n )\n", scale(width));
} else {
printf("(COMMENT %s)\n(CHARACTER D %d\n", name, number);
printf(" (CHARWD R %f)\n (CHARHT R %f)\n",
scale(width), scale(top));
if (max(0, -bottom))
printf(" (CHARDP R %f)\n", scale(-bottom));
if (right > width)
printf(" (CHARIC R %f)\n", scale(right - width));
puts(" )");
}
} else if (starts(line, "StartKernPairs"))
puts("(LIGTABLE");
else if (starts(line, "EndKernPairs"))
puts(" )");
else if (starts(line, "KPX ")) {
if ((line[5] != ' ') || (line[7] != ' ')) {
} else {
printf(" (LABEL C %c)\n", line[4]);
while (starts(line, "KPX ")) {
if ((line[5] == ' ') && (line[7] == ' ')) {
sscanf(line, "KPX %c %c %d", name, name+1, &width);
printf(" (KRN C %c R %f)\n", name[1], scale(width));
}
gets(line);
}
puts(" (STOP)");
}
}
}
}
------------------------ CUT HERE ------------------------
--
====================
Total Nuclear Annihilation: Clayton Elwell
The Ultimate Error Message. Elwell@Ohio-State.ARPA
...!cbosgd!osu-eddie!elwell
====================