Article View: comp.text
Article #3341Adobe Font Metric File to TeX Font Metric File Converter
From: elwell
Date: Thu, 29 Jan 1987 23:21
Date: Thu, 29 Jan 1987 23:21
126 lines
4292 bytes
4292 bytes
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
====================
Technical Details
Message-ID:
<3007@osu-eddie.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!osu-eddie!elwellShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!osu-eddie!elwell From: elwell@osu-eddie.UUCP Newsgroups: comp.text Subject: Adobe Font Metric File to TeX Font Metric File Converter Message-ID: <3007@osu-eddie.UUCP> Date: Thu, 29-Jan-87 18:21:23 EST Article-I.D.: osu-eddi.3007 Posted: Thu Jan 29 18:21:23 1987 Date-Received: Sat, 31-Jan-87 07:51:12 EST Reply-To: elwell@osu-eddie.UUCP (Clayton M. Elwell) Organization: The Ohio State University, CIS Dept. Lines: 126