[comp.fonts] Disassemble Fontographer fonts

lee@uhccux.uhcc.hawaii.edu (Greg Lee) (08/18/89)

I obtained a font someone had made with Fontographer and
wanted to change some things.  I don't have Fontographer,
so I wrote a lex program dcd.l to translate such a
font into editable form.  The other two programs in
the following shar file do related things -- described
briefly in the program headers.  All are lex programs,
however I've used flex for them.  Compile with:
	% flex dcd.l
	% cc -o dcd lex.yy.c
and similarly for the other two.

			Greg, lee@uhccux.uhcc.hawaii.edu

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  dcd.l dcf.l enc.l
# Wrapped by lee@uhccux on Fri Aug 18 00:01:49 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'dcd.l' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dcd.l'\"
else
echo shar: Extracting \"'dcd.l'\" \(1403 characters\)
sed "s/^X//" >'dcd.l' <<'END_OF_FILE'
X%{
X/* This unpacks into readable form a file of character procedures
X * from a font made by Fontographer 2.4.1	-- Greg, July '89
X */
Xint lastnum = 1000;
X%}
X
X%x H
X%%
X
X"/"[a-zA-Z]+	printf("%s {\n\t", yytext);
X
X"<"		BEGIN(H);
X
X<H>[0-9A-F][0-9A-F] dcd(yytext[0], yytext[1]);
X
X<H>">"  {
X		if (lastnum < 1000) printf("\n % %d left\n", lastnum);
X		lastnum = 1000;
X		printf("}");
X		BEGIN(0);
X};
X
X\n		;
X<H>\n		;
X
X"def"		printf(" def\n");
X
X" "		;
X
X.		printf("[%s ??]\n", yytext);
X<H>.		printf("{[%s ??]}\n", yytext);
X
X%%
Xmain()
X{
X	yylex();
X}
X
Xstatic
Xchar *uvec[] = {"rmoveto", "rlineto", "rcurveto", "ShowExt", "] concat",
X	"Cache", "setlinewidth",
X	"ShowInt", "setlinecap", "setlinejoin", "gsave", "[",
X	"Fill", "Eofill", "stroke", "SetWid",
X	"100 mul add", "100 mul", "100 div", "Cp", "Sstrk", "setgray" };
X
Xdcd(h,l)
Xchar h,l;
X{	int hd, ld, code, inst;
X
X	if (h >= 'A') hd = h - 'A' + 10;  else hd = h - '0';
X	if (l >= 'A') ld = l - 'A' + 10;  else ld = l - '0';
X	code = hd * 16 + ld;
X
X	if (code < 200) {
X		if (lastnum < 1000) printf("%d ", lastnum);
X		lastnum = code - 100;
X	}
X	else if (code < 233) {
X		if (lastnum < 1000) printf("%d ", lastnum + (code - 216)*100);
X		else printf("%d add ", (code - 216)*100);
X		lastnum = 1000;
X	}
X	else {
X		inst = code - 233;
X		if (lastnum < 1000) printf("%d ", lastnum);
X		lastnum = 1000;
X		if (inst == 11) printf("%s ", uvec[inst]);
X		else printf("%s\n\t", uvec[inst]);
X	}
X}
END_OF_FILE
if test 1403 -ne `wc -c <'dcd.l'`; then
    echo shar: \"'dcd.l'\" unpacked with wrong size!
fi
# end of 'dcd.l'
fi
if test -f 'dcf.l' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dcf.l'\"
else
echo shar: Extracting \"'dcf.l'\" \(1622 characters\)
sed "s/^X//" >'dcf.l' <<'END_OF_FILE'
X%{
X/* This operates on the output of dcd to put numbers in character
X * procedures into a more readable form.	-- Greg, July '89
X */
Xdouble x, y;
Xint i, j, pos;
X%}
X
X%%
X
X[0-9\-]+" "[0-9\-]+" 100 mul add"\n\t {
X	i = atoi(yytext);
X	for (pos=0; yytext[pos] != ' '; pos++) ;
X	j = atoi(yytext+pos);
X	printf("%d ", j*100 + i);
X}
X
X[0-9\-]+" "[0-9\-]+" 100 mul add"\n\t"100 div"\n\t {
X	i = atoi(yytext);
X	for (pos=0; yytext[pos] != ' '; pos++) ;
X	j = atoi(yytext+pos);
X	x = j*100 + i;
X	x = x/100;
X	printf("%g ", x);
X}
X
X[0-9\-]+" "[0-9\-]+" 100 mul add"\n\t"100 div"\n\t"100 div"\n\t {
X	i = atoi(yytext);
X	for (pos=0; yytext[pos] != ' '; pos++) ;
X	j = atoi(yytext+pos);
X	x = j*100 + i;
X	x = x/100;
X	x = x/100;
X	printf("%g ", x);
X}
X
X[0-9\-]+" "[0-9\-]+" 100 mul add"\n\t"100 div"\n\t"100 div"\n\t"100 div"\n\t {
X	i = atoi(yytext);
X	for (pos=0; yytext[pos] != ' '; pos++) ;
X	j = atoi(yytext+pos);
X	x = j*100 + i;
X	x = x/100;
X	x = x/100;
X	x = x/100;
X	printf("%g ", x);
X}
X
X[0-9\-]+" 100 div"\n\t {
X	y = atoi(yytext);
X	x = y/100;
X	printf("%g ", x);
X}
X
X[0-9\-]+" 100 div"\n\t"100 div"\n\t {
X	y = atoi(yytext);
X	x = y/100;
X	x = x/100;
X	printf("%g ", x);
X}
X
X[0-9\-]+" 100 div"\n\t"100 div"\n\t"100 div"\n\t {
X	y = atoi(yytext);
X	x = y/100;
X	x = x/100;
X	x = x/100;
X	printf("%g ", x);
X}
X
X[0-9\-]+" 100 div"\n\t"100 div"\n\t"100 div"\n\t"100 div"\n\t {
X	y = atoi(yytext);
X	x = y/100;
X	x = x/100;
X	x = x/100;
X	x = x/100;
X	printf("%g ", x);
X}
X
X[0-9\-]+" 100 div"\n\t"100 div"\n\t"100 div"\n\t"100 div"\n\t"100 div"\n\t {
X	y = atoi(yytext);
X	x = y/100;
X	x = x/100;
X	x = x/100;
X	x = x/100;
X	x = x/100;
X	printf("%g ", x);
X}
X
X%%
Xmain()
X{
X	yylex();
X}
END_OF_FILE
if test 1622 -ne `wc -c <'dcf.l'`; then
    echo shar: \"'dcf.l'\" unpacked with wrong size!
fi
# end of 'dcf.l'
fi
if test -f 'enc.l' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'enc.l'\"
else
echo shar: Extracting \"'enc.l'\" \(1582 characters\)
sed "s/^X//" >'enc.l' <<'END_OF_FILE'
X%{
X/* This packs into unreadable form a file of character procedures
X * that was unpacked by dcd.  	-- Greg, July '89
X */
Xint num, hnum, pos = 0;
X%}
X
X%x H
X%%
X
X\%.*		;
X<H>\%.*		;
X
X"/"[a-zA-Z]+	pos = yyleng; ECHO;
X
X"{"		printf("<"); pos++; BEGIN(H);
X
X
X<H>"rmoveto"		ienc( 0);
X<H>"rlineto"		ienc( 1);
X<H>"rcurveto"		ienc( 2);
X<H>"ShowExt"		ienc( 3);
X<H>"] concat"		ienc( 4);
X<H>"Cache"		ienc( 5);
X<H>"setlinewidth"	ienc( 6);
X<H>"ShowInt"		ienc( 7);
X<H>"setlinecap"		ienc( 8);
X<H>"setlinejoin"	ienc( 9);
X<H>"gsave"		ienc(10);
X<H>"["			ienc(11);
X<H>"Fill"		ienc(12);
X<H>"Eofill"		ienc(13);
X<H>"stroke"		ienc(14);
X<H>"SetWid"		ienc(15);
X<H>"100 mul add"	ienc(16);
X<H>"100 mul"		ienc(17);
X<H>"100 div"		ienc(18);
X<H>"Cp"			ienc(19);
X<H>"Sstrk"		ienc(20);
X<H>"setgray"		ienc(21);
X
X<H>"}"  {
X		printf(">"); pos++;
X		if (pos > 66) printf("\n");
X		printf("def \n"); /* extra sp to be compat. */
X		pos = 0;
X		BEGIN(0);
X};
X
X<H>[0-9\-]+  {
X		num = atoi(yytext);
X/* -100 could be encoded as 0, but for some reason it's
X   encoded as 0 and subtract 100, so we don't say:
X		if (num < -100 || num >= 100) {
X   but rather: */
X		if (num <= -100 || num >= 100) {
X			hnum = num/100;
X			num %= 100;
X		} else	hnum = 0;
X		if (num >= -100 && num < 100) prhex(num + 100);
X		else printf("#%d#", num); /* else should never happen */
X		if (hnum) prhex(hnum + 216);
X}
X
X\n		;
X<H>\n		;
X
X"def"		;
X
X" "		;
X
X.		;
X<H>.		;
X
X%%
Xmain()
X{
X	yylex();
X}
X
Xienc(n)
Xint n;
X{
X	prhex(n + 233);
X}
X
Xprhex(n)
Xint n;
X{
X	/*printf("%d [%02X]", n, n);*/
X	printf("%02X", n);
X	pos++; pos++;
X	if (pos > 70) {
X		printf("\n");
X		pos = 0;
X	}
X}
END_OF_FILE
if test 1582 -ne `wc -c <'enc.l'`; then
    echo shar: \"'enc.l'\" unpacked with wrong size!
fi
# end of 'enc.l'
fi
echo shar: End of shell archive.
exit 0