Path: utzoo!attcan!utgpu!watmath!iuvax!mailrus!ames!uhccux!lee From: lee@uhccux.uhcc.hawaii.edu (Greg Lee) Newsgroups: comp.fonts Subject: Disassemble Fontographer fonts Message-ID: <4588@uhccux.uhcc.hawaii.edu> Date: 18 Aug 89 10:14:16 GMT Organization: University of Hawaii Lines: 319 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 '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[0-9A-F][0-9A-F] dcd(yytext[0], yytext[1]); X X">" { X if (lastnum < 1000) printf("\n % %d left\n", lastnum); X lastnum = 1000; X printf("}"); X BEGIN(0); X}; X X\n ; X\n ; X X"def" printf(" def\n"); X X" " ; X X. printf("[%s ??]\n", yytext); X. 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\%.* ; X X"/"[a-zA-Z]+ pos = yyleng; ECHO; X X"{" printf("<"); pos++; BEGIN(H); X X X"rmoveto" ienc( 0); X"rlineto" ienc( 1); X"rcurveto" ienc( 2); X"ShowExt" ienc( 3); X"] concat" ienc( 4); X"Cache" ienc( 5); X"setlinewidth" ienc( 6); X"ShowInt" ienc( 7); X"setlinecap" ienc( 8); X"setlinejoin" ienc( 9); X"gsave" ienc(10); X"[" ienc(11); X"Fill" ienc(12); X"Eofill" ienc(13); X"stroke" ienc(14); X"SetWid" ienc(15); X"100 mul add" ienc(16); X"100 mul" ienc(17); X"100 div" ienc(18); X"Cp" ienc(19); X"Sstrk" ienc(20); X"setgray" ienc(21); X X"}" { 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[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\n ; X X"def" ; X X" " ; X X. ; X. ; 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