mikew@wyse.wyse.com (Mike Wexler) (03/08/89)
Submitted-by: ken@cs.rochester.edu (Ken Yap) Posting-number: Volume 3, Issue 36 Archive-name: bdftools/part01 [These compile and run. I haven't tested to see if the output is reasonable. -mcw] #! /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 archive 1 (of 1)." # Contents: README AUTHOR Imakefile Makefile bdf.h bdf2gf.1 bdf2gf.c # bdf2vf.1 dumpgf.c dumpvfont.c gf.h patchlevel.h # Wrapped by mikew@wyse on Tue Mar 7 10:18:44 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(122 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' XThese are updated version of the bdf to gf and bdf to vfont converters Xin the R3 tape. X X ken@cs.rochester.edu X march 1989 END_OF_FILE if test 122 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'AUTHOR' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'AUTHOR'\" else echo shar: Extracting \"'AUTHOR'\" \(1464 characters\) sed "s/^X//" >'AUTHOR' <<'END_OF_FILE' X(Message inbox:1032) XReturn-Path: ken@cs.rochester.edu XReceived: by wyse.wyse.com (5.58/Wyse master/5-13-88) X id AA18789; Thu, 2 Mar 89 03:52:03 PST XReceived: from cayuga.cs.rochester.edu by uunet.UU.NET (5.61/1.14) with SMTP X id AA16598; Thu, 2 Mar 89 00:45:10 -0500 XReceived: from cursa.cs.rochester.edu by cayuga.cs.rochester.edu (5.59/l) id AA10061; Thu, 2 Mar 89 00:43:27 EST XReceived: from loopback by cursa.cs.rochester.edu (3.2/l) id AA04602; Thu, 2 Mar 89 00:43:07 EST XMessage-Id: <8903020543.AA04602@cursa.cs.rochester.edu> XTo: mikew@wyse.com (Mike Wexler) XSubject: Re: bdftools XIn-Reply-To: Your message of Wed, 01 Mar 89 12:25:25 -0800. X <8903012025.AA19680@wyse.wyse.com> XX-Uucp: ..!rochester!ken Internet: ken@cs.rochester.edu XX-Snail: CS Dept., U of Roch., NY 14627. Voice: Ken! XX-Phone: (716) 275-1448 (office) XDate: Thu, 02 Mar 89 00:43:05 -0500 XFrom: Ken Yap <ken@cs.rochester.edu> X XHi, I think this is a complete distribution. I hope this is Xsufficient. Sorry I wasn't very helpful in providing a complete set Xbefore. I was not the one who tossed the sources on the tape. Somebody Xtook the sources from expo:/pub/contrib and added them to the tape. I Xthought I'd just send you an update of the only file affected and leave Xit at that, but since you have taken the trouble to make an Imakefile, XI've added a man page for bdf2vf, the only thing really missing. Casey XLeedom posted one to the net but I forgot to save that one. X END_OF_FILE if test 1464 -ne `wc -c <'AUTHOR'`; then echo shar: \"'AUTHOR'\" unpacked with wrong size! fi # end of 'AUTHOR' fi if test -f 'Imakefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Imakefile'\" else echo shar: Extracting \"'Imakefile'\" \(215 characters\) sed "s/^X//" >'Imakefile' <<'END_OF_FILE' X SYS_LIBRARIES = -ll -lm $(XMULIB) $(XLIB) X XSRCS= bdf2gf.c dumpgf.c XOBJS= bdf2gf.o dumpgf.o XPROGRAMS= bdftogf bdftovf X XComplexProgramTarget(bdftogf) XComplexProgramTarget(bdftovf) XNormalLintTarget($(SRCS)) X END_OF_FILE if test 215 -ne `wc -c <'Imakefile'`; then echo shar: \"'Imakefile'\" unpacked with wrong size! fi # end of 'Imakefile' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(7124 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# Makefile generated by imake - do not edit! X# $XConsortium: imake.c,v 1.37 88/10/08 20:08:30 jim Exp $ X# X# The cpp used on this machine replaces all newlines and multiple tabs and X# spaces in a macro expansion with a single space. Imake tries to compensate X# for this, but is not always successful. X# X X########################################################################### X# X Window System Makefile generated from template file Imake.tmpl X# $XConsortium: Imake.tmpl,v 1.91 88/10/23 22:37:10 jim Exp $ X# X# Do not change the body of the imake template file. Server-specific X# parameters may be set in the appropriate .macros file; site-specific X# parameters (but shared by all servers) may be set in site.def. If you X# make any changes, you'll need to rebuild the makefiles using X# "make World" (at best) or "make Makefile; make Makefiles" (at least) in X# the top level directory. X# X# If your C preprocessor doesn't define any unique symbols, you'll need X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing X# "make Makefile", "make Makefiles", or "make World"). X# X# If you absolutely can't get imake to work, you'll need to set the X# variables at the top of each Makefile as well as the dependencies at the X# bottom (makedepend will do this automatically). X# X X########################################################################### X# platform-specific configuration parameters - edit Sun.macros to change X X# platform: $XConsortium: Sun.macros,v 1.52 88/10/23 11:00:55 jim Exp $ X# operating system: SunOS 3.4 X XBOOTSTRAPCFLAGS = X AS = as X CC = cc X CPP = /lib/cpp X LD = ld X LINT = lint X INSTALL = install X TAGS = ctags X RM = rm -f X MV = mv X LN = ln -s X RANLIB = ranlib XRANLIBINSTFLAGS = -t X AR = ar clq X LS = ls X LINTOPTS = -xz X LINTLIBFLAG = -C X MAKE = make XSTD_CPP_DEFINES = X STD_DEFINES = X X########################################################################### X# site-specific configuration parameters - edit site.def to change X X# site: $XConsortium: site.def,v 1.16 88/10/12 10:30:24 jim Exp $ X X########################################################################### X# definitions common to all Makefiles - do not edit X X SHELL = /bin/sh X X DESTDIR = /global X USRLIBDIR = $(DESTDIR)/lib X BINDIR = $(DESTDIR)/bin/X11 X INCDIR = $(DESTDIR)/include X ADMDIR = $(DESTDIR)/usr/adm X LIBDIR = $(USRLIBDIR)/X11 X LINTLIBDIR = $(USRLIBDIR)/lint X FONTDIR = $(LIBDIR)/fonts X XINITDIR = $(LIBDIR)/xinit X XDMDIR = $(LIBDIR)/xdm X UWMDIR = $(LIBDIR)/uwm X AWMDIR = $(LIBDIR)/awm X TWMDIR = $(LIBDIR)/twm X DTDIR = $(LIBDIR)/dt X MANPATH = /usr/man X MANSOURCEPATH = $(MANPATH)/man X MANDIR = $(MANSOURCEPATH)n X LIBMANDIR = $(MANSOURCEPATH)n3 X XAPPLOADDIR = $(LIBDIR)/app-defaults X X INSTBINFLAGS = -m 0755 X INSTUIDFLAGS = -m 4755 X INSTLIBFLAGS = -m 0664 X INSTINCFLAGS = -m 0444 X INSTMANFLAGS = -m 0444 X INSTAPPFLAGS = -m 0444 X INSTKMEMFLAGS = -m 4755 X FCFLAGS = -t X CDEBUGFLAGS = -O X X PATHSEP = / X DEPEND = $(BINDIR)/makedepend X IMAKE = $(BINDIR)/imake X RGB = $(LIBDIR)/rgb X FC = $(BINDIR)/bdftosnf X MKFONTDIR = $(BINDIR)/mkfontdir X MKDIRHIER = $(BINDIR)/mkdirhier.sh X X CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) X LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT X LDFLAGS = $(CDEBUGFLAGS) -L$(USRLIBDIR) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES) X X IRULESRC = $(LIBDIR)/imake.includes X X EXTENSIONLIB = $(USRLIBDIR)/libext.a X XLIB = $(USRLIBDIR)/libX11.a X XMULIB = $(USRLIBDIR)/libXmu.a X OLDXLIB = $(USRLIBDIR)/liboldX.a X XTOOLLIB = $(USRLIBDIR)/libXt.a X XAWLIB = $(USRLIBDIR)/libXaw.a X LINTXLIB = $(USRLIBDIR)/lint/llib-lX11.ln X LINTXMU = $(USRLIBDIR)/lint/llib-lXmu.ln X LINTXTOOL = $(USRLIBDIR)/lint/llib-lXt.ln X LINTXAW = $(USRLIBDIR)/lint/llib-lXaw.ln X INCLUDES = -I$(INCDIR) X MACROFILE = Sun.macros X ICONFIGFILES = $(IRULESRC)/Imake.tmpl \ X $(IRULESRC)/$(MACROFILE) $(IRULESRC)/site.def X IMAKE_DEFINES = X IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl -I$(NEWTOP)$(IRULESRC) \ X -s Makefile $(IMAKE_DEFINES) X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \ X .emacs_* tags TAGS make.log MakeOut X X########################################################################### X# rules: $XConsortium: Imake.rules,v 1.71 88/10/23 22:46:34 jim Exp $ X X########################################################################### X# start of Imakefile X X SYS_LIBRARIES = -ll -lm $(XMULIB) $(XLIB) X XSRCS= bdf2gf.c dumpgf.c XOBJS= bdf2gf.o dumpgf.o XPROGRAMS= bdftogf bdftovf X X PROGRAM = bdftogf X Xall:: bdftogf X Xbdftogf: $(OBJS) $(LOCAL_LIBRARIES) X $(RM) $@ X $(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS) $(SYSLAST_LIBRARIES) X Xrelink:: X $(RM) $(PROGRAM) X $(MAKE) $(MFLAGS) $(PROGRAM) X Xinstall:: bdftogf X $(INSTALL) -c $(INSTALLFLAGS) bdftogf $(BINDIR) X Xinstall.man:: bdftogf.man X $(INSTALL) -c $(INSTMANFLAGS) bdftogf.man $(MANDIR)/bdftogf.n X Xdepend:: $(DEPEND) X Xdepend:: X $(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS) X X$(DEPEND): X @echo "making $@"; \ X cd $(DEPENDSRC); $(MAKE) X Xclean:: X $(RM) $(PROGRAM) X X PROGRAM = bdftovf X Xall:: bdftovf X Xbdftovf: $(OBJS) $(LOCAL_LIBRARIES) X $(RM) $@ X $(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS) $(SYSLAST_LIBRARIES) X Xrelink:: X $(RM) $(PROGRAM) X $(MAKE) $(MFLAGS) $(PROGRAM) X Xinstall:: bdftovf X $(INSTALL) -c $(INSTALLFLAGS) bdftovf $(BINDIR) X Xinstall.man:: bdftovf.man X $(INSTALL) -c $(INSTMANFLAGS) bdftovf.man $(MANDIR)/bdftovf.n X Xdepend:: $(DEPEND) X Xdepend:: X $(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS) X X$(DEPEND): X @echo "making $@"; \ X cd $(DEPENDSRC); $(MAKE) X Xclean:: X $(RM) $(PROGRAM) X Xlint: X $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS) Xlint1: X $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS) X X########################################################################### X# Imake.tmpl common rules for all Makefiles - do not edit X Xemptyrule:: X Xclean:: X $(RM_CMD) \#* X XMakefile:: $(IMAKE) X XMakefile:: Imakefile \ X $(IRULESRC)/Imake.tmpl \ X $(IRULESRC)/Imake.rules \ X $(IRULESRC)/site.def \ X $(IRULESRC)/$(MACROFILE) X -@if [ -f Makefile ]; then \ X echo "$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \ X $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \ X else exit 0; fi X $(IMAKE_CMD) -DTOPDIR=$(TOP) X X$(IMAKE): X @echo "making $@"; \ X cd $(IMAKESRC); $(MAKE) BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS) X Xtags:: X $(TAGS) -w *.[ch] X $(TAGS) -xw *.[ch] > TAGS X X########################################################################### X# empty rules for directories that do not have SUBDIRS - do not edit X Xinstall:: X @echo "install done" X Xinstall.man:: X @echo "install.man done" X XMakefiles:: X X########################################################################### X# dependencies generated by makedepend X END_OF_FILE if test 7124 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'bdf.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'bdf.h'\" else echo shar: Extracting \"'bdf.h'\" \(203 characters\) sed "s/^X//" >'bdf.h' <<'END_OF_FILE' X/* X** Everything that is saved up from the bdf file X*/ X Xextern char fontname[100]; Xextern int pointsize, xres, yres; Xextern int bbx, bby, offx, offy; Xextern int nchars; Xextern u_char *bitmaps[256]; END_OF_FILE if test 203 -ne `wc -c <'bdf.h'`; then echo shar: \"'bdf.h'\" unpacked with wrong size! fi # end of 'bdf.h' fi if test -f 'bdf2gf.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'bdf2gf.1'\" else echo shar: Extracting \"'bdf2gf.1'\" \(362 characters\) sed "s/^X//" >'bdf2gf.1' <<'END_OF_FILE' X.TH BDF2GF 1 "1st March 1988" X.AT 3 X.SH NAME Xbdf2gf \- convert BDF format to GF (TeX generic font) format X.SH SYNOPSIS X.B bdf2gf Xgffile [plfile] < bdffile X.SH DESCRIPTION X.I Bdf2gf Xconverts the BDF file on stdin to a TeX GF (generic font) Xfile and optionally a PL (property list) file. X.SH DIAGNOSTICS XNo error recovery in parser, just quits. X.SH AUTHOR XKen Yap END_OF_FILE if test 362 -ne `wc -c <'bdf2gf.1'`; then echo shar: \"'bdf2gf.1'\" unpacked with wrong size! fi # end of 'bdf2gf.1' fi if test -f 'bdf2gf.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'bdf2gf.c'\" else echo shar: Extracting \"'bdf2gf.c'\" \(3710 characters\) sed "s/^X//" >'bdf2gf.c' <<'END_OF_FILE' X#include <stdio.h> X#include <sys/types.h> X Xchar fontname[100]; Xint pointsize, xres, yres; Xint bbx, bby, offx, offy; Xint nchars; Xu_char *bitmaps[256] = { 0 }; X Xfatal(m) X char *m; X{ X (void)fprintf(stderr, "%s\n", m); X exit(1); X} X Xchar *xfgets(s, max, f) X char *s; X int max; X FILE *f; X{ X register char *r; X X do X { X if ((r = fgets(s, max, f)) == NULL) X break; X } while (strncmp("COMMENT ", s, 8) == 0); X return (r); X} X X/* X** Read line in and match against s. X** If mustmatch and none found, exit. X** If !mustmatch and none found, return 0. X** Else return 1. X*/ Xint match(s, line, max, mustmatch) X char *s, *line; X int max, mustmatch; X{ X int len = strlen(s); X X if (xfgets(line, max, stdin) == NULL) X fatal("Unexpected EOF on input"); X if (strncmp(line, s, len) != 0) X { X if (mustmatch) X { X (void)fprintf(stderr, "Expected %s, got %s", s, line); X exit(1); X } X else X return (0); X } X return (1); X} X Xreadproperties(line, max) X char *line; X int max; X{ X int nprops; X X if (sscanf(line, "STARTPROPERTIES %d", &nprops) != 1) X fatal("No property count"); X while (nprops-- > 0) X if (xfgets(line, max, stdin) == NULL) X fatal("Unexpected EOF on input reading properties"); X (void)match("ENDPROPERTIES", line, max, 1); X} X Xu_char *readbitmap(line, max, width, height) X char *line; X int max; X int width, height; X{ X register int i, j, bytewidth; X register u_char *p, *q; X unsigned byte; X char *malloc(); X X (void)match("BITMAP", line, max, 1); X bytewidth = (width + 7) / 8; X if ((q = p = (u_char *)malloc(bytewidth * height)) == NULL) X fatal("Cannot allocate bitmap storage"); X for (i = 0; i < height; ++i) X { X if (xfgets(line, max, stdin) == NULL) X fatal("Unexpected EOF on input reading bitmap"); X for (j = 0; j < bytewidth; ++j) X { X if (sscanf(&line[j*2], "%02x", &byte) != 1) X fatal("Cannot read hex pair"); X *q++ = byte & 0xff; X } X } X (void)match("ENDCHAR", line, max, 1); X return (p); X} X Xread1char(line, max) X char *line; X int max; X{ X int charnum; X int width, bbx, bby, offx, offy; X float dx, dy; X X (void)match("STARTCHAR", line, max, 1); X (void)match("ENCODING", line, max, 1); X if (sscanf(line, "ENCODING %d", &charnum) != 1) X fatal("No position number for character"); X (void)match("SWIDTH", line, max, 1); X if (sscanf(line, "SWIDTH %g %g", &dx, &dy) != 2) X fatal("No scalable width info for character"); X (void)match("DWIDTH", line, max, 1); X if (sscanf(line, "DWIDTH %d", &width) != 1) X fatal("No width info for character"); X (void)match("BBX", line, max, 1); X if (sscanf(line, "BBX %d %d %d %d", &bbx, &bby, &offx, &offy) != 4) X fatal("Insufficient bounding box info for character"); X bitmaps[charnum % 0x100] = readbitmap(line, max, bbx, bby); X storeglyph(charnum, bbx, bby, offx, offy, dx, dy); X} X Xreadchars(line, max) X char *line; X int max; X{ X (void)match("CHARS", line, max, 1); X if (sscanf(line, "CHARS %d", &nchars) != 1) X fatal("No count of chars"); X while (nchars-- > 0) X read1char(line, max); X} X Xmain(argc, argv) X int argc; X char *argv[]; X{ X char line[512]; X X initialize(argc, argv); X X (void)match("STARTFONT 2.1", line, sizeof(line), 1); X while (!match("FONT", line, sizeof(line), 0)) X ; X if (sscanf(line, "FONT %s", fontname) != 1) X fatal("No font name"); X (void)match("SIZE", line, sizeof(line), 1); X if (sscanf(line, "SIZE %d %d %d", &pointsize, &xres, &yres) != 3) X fatal("Insufficient size info"); X (void)match("FONTBOUNDINGBOX", line, sizeof(line), 1); X if (sscanf(line, "FONTBOUNDINGBOX %d %d %d %d", &bbx, &bby, X &offx, &offy) != 4) X fatal("Insufficient bounding box info"); X if (match("STARTPROPERTIES", line, sizeof(line), 0)) X readproperties(line, sizeof(line)); X readchars(line, sizeof(line)); X dumpfont(bitmaps); X exit(0); X} END_OF_FILE if test 3710 -ne `wc -c <'bdf2gf.c'`; then echo shar: \"'bdf2gf.c'\" unpacked with wrong size! fi # end of 'bdf2gf.c' fi if test -f 'bdf2vf.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'bdf2vf.1'\" else echo shar: Extracting \"'bdf2vf.1'\" \(440 characters\) sed "s/^X//" >'bdf2vf.1' <<'END_OF_FILE' X.TH BDF2VF 1 "1st March 1988" X.AT 3 X.SH NAME Xbdf2vf \- convert BDF format to vfont format X.SH SYNOPSIS X.B bdf2vf Xvffile < bdffile X.SH DESCRIPTION X.I Bdf2vf Xconverts the BDF file on stdin to vfont format. X.SH DIAGNOSTICS XNo error recovery in parser, just quits. X.SH BUGS XVfont format can only handle glyphs smaller than 127 per side. XSun vfont glyphs is 16-bit word aligned. I haven't provided Xfor this. Hack it yourself. X.SH AUTHOR XKen Yap END_OF_FILE if test 440 -ne `wc -c <'bdf2vf.1'`; then echo shar: \"'bdf2vf.1'\" unpacked with wrong size! fi # end of 'bdf2vf.1' fi if test -f 'dumpgf.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dumpgf.c'\" else echo shar: Extracting \"'dumpgf.c'\" \(8985 characters\) sed "s/^X//" >'dumpgf.c' <<'END_OF_FILE' X#include <stdio.h> X#include <sys/types.h> X#include "bdf.h" X#include "gf.h" X X#define NCHARS 256 X Xstatic charinfo ci[NCHARS]; X Xstatic int filepos = 0; /* position in gf output */ X Xstatic FILE *plfile = NULL; /* property list output */ X X/* X** The parameters to these routines follow the order X** they are described in gftopk.web. X*/ X Xstatic out(c) X int c; X{ X putchar(c); X filepos++; X} X Xstatic out2(c) X int c; X{ X out((c >> 8) & 0xff); X out(c & 0xff); X} X Xstatic out3(c) X int c; X{ X out((c >> 16) & 0xff); X out((c >> 8) & 0xff); X out(c & 0xff); X} X Xstatic out4(c) X int c; X{ X out((c >> 24) & 0xff); X out((c >> 16) & 0xff); X out((c >> 8) & 0xff); X out(c & 0xff); X} X Xstatic paint(n) X register int n; X{ X if (0 <= n && n < 64) X out(PAINT0 + n); X else if (64 <= n && n < 256) X { X out(PAINT1); X out(n); X } X else if (256 <= n && n < 65536) X { X out(PAINT2); X out2(n); X } X else if (65536 <= n && n < (1 << 24)) X { X out(PAINT3); X out3(n); X } X else X fatal("Impossibly large value for paint(n)"); X} X Xstatic boc(c, p, minm, maxm, minn, maxn) X int c, p, minm, maxm, minn, maxn; X{ X if (p == -1 && X 0 <= maxm && maxm < 256 && X (maxm - minm) < 256 && X 0 <= maxn && maxn < 256 && X (maxn - minn) < 256) X { X out(BOC1); X out(c); X out(maxm-minm); X out(maxm); X out(maxn-minn); X out(maxn); X } X else X { X out(BOC); X out4(c); X out4(p); X out4(minm); X out4(maxm); X out4(minn); X out4(maxn); X } X} X Xstatic eoc() X{ X out(EOC); X} X Xstatic skip(n) X int n; X{ X if (n <= 0) X out(SKIP0); X else if (1 <= n && n <= 256) X { X out(SKIP1); X out(n-1); X } X else if (256 < n && n < 65536) X { X out(SKIP2); X out2(n); X } X else if (65536 <= n && n < (1 << 24)) X { X out(SKIP3); X out3(n); X } X else X fatal("Impossibly large value for skip(n)"); X} X Xstatic newrow(m) X int m; X{ X if (m <= 0) X out(NEWROW0); X else if (1 <= m && m <= 164) X out(NEWROW1+m-1); X else X fatal("Too large a value for newrow(m)"); X} X Xstatic xxx(k, x) X int k; X char *x; X{ X if (0 <= k && k < 256) X { X out(XXX1); X out(k); X } X else if (256 <= k && k < 65536) X { X out(XXX2); X out2(k); X } X else if (65536 <= k && k < (1 << 24)) X { X out(XXX3); X out3(k); X } X else X { X out(XXX4); X out4(k); X } X while (k-- > 0) X out(*x++); X} X Xstatic yyy(n) X int n; X{ X out(YYY); X out4(n); X} X Xstatic noop() X{ X out(NOOP); X} X Xstatic charloc(c, dx, dy, w, p) X int c, dx, dy, w, p; X{ X if (dy == 0 && (dx & 0xffff) == 0 && (dx >> 16) < 256) X { X out(CHARLOC0); X out(c); X out(dx >> 16); X out4(w); X out4(p); X } X else X { X out(CHARLOC); X out(c); X out4(dx); X out4(dy); X out4(w); X out4(p); X } X} X Xstatic pre(i, k, x) X int i, k; X char *x; X{ X out(PRE); X out(i); X out(k); X while (k-- > 0) X out(*x++); X} X Xstatic post(p) X int p; X{ X out(POST); X out4(p); X out4(pointsize * FIX); X out4(0); /* checksum */ X out4((xres * (1 << 16))/72); /* hppp */ X out4((yres * (1 << 16))/72); /* vppp */ X out4(offx); /* global */ X out4(bbx + offx); X out4(offy); X out4(bby + offy - 1); X} X Xstatic postpost(q, i) X int q, i; X{ X register int n; X X out(POSTPOST); X out4(q); X out(i); X for (n = 0; n < 4; ++n) X out(223); X while (filepos & 0x3) /* round off to 4 bytes */ X out(223); X} X Xinitialize(argc, argv) X int argc; X char *argv[]; X{ X register int i; X X if (argc < 2) X fatal("Usage: bdf2gf gf [pl]"); X X if (freopen(argv[1], "w", stdout) == NULL) X fatal("Cannot open gf file"); X X if (argc >= 3) X { X if ((plfile = fopen(argv[2], "w")) == NULL) X fatal("Cannot open pl file"); X } X X for (i = 0; i < NCHARS; ++i) X ci[i].p = -1; X} X Xstoreglyph(n, bbx, bby, offx, offy, dx, dy) X int n, bbx, bby, offx, offy; X float dx, dy; X{ X register charinfo *cp; X X n %= NCHARS; X cp = &ci[n]; X if (cp->p != -1) X (void)fprintf(stderr, "Warning, redefinition of char %d\n", n); X cp->bbx = bbx; X cp->bby = bby; X cp->offx = offx; X cp->offy = offy; X cp->w = dx * (float)FIX / 1000.0; X/* X** Conversion from BDF swidths to pixels: X** pixels = swidth * (pointsize / 72) * resolution / 1000; X** i.e. swidths are dimensionless and 1000x the true width. X** Swidths normally range in the high hundreds, as you would expect. X** X** To convert to GF escapements we round and multiply by 2^16. X*/ X dx *= (float)(pointsize * xres) / 72000.0; X cp->dx = (int)(dx + 0.5) * (1 << 16); X dy *= (float)(pointsize * yres) / 72000.0; X cp->dy = (int)(dy + 0.5) * (1 << 16); X} X X/* X** We can save white_pixels until a black_pixel forces us X** to output them. X** If end_of_row == 0, then white_pixels are row trailing counts, X** otherwise they are row leading counts. X*/ Xstatic int white_pixels = 0; Xstatic int end_of_row = 0; X Xstatic run(color, length) X int color, length; X{ X register int leading_white; X X if (length <= 0) X return; X if (color == WHITE_PIXEL) X white_pixels += length; X else /* BLACK_PIXEL */ X { X if (end_of_row <= 0) X paint(white_pixels); X else X { X/* X** This is how we dispose of most of the blank rows. X*/ X if (end_of_row > 1) X skip(end_of_row - 1); X if ((leading_white = white_pixels) > 164) X leading_white = 164; X newrow(leading_white); X/* X** It is very unlikely that we will have more than 164 X** leading columns of white but in case, we output a paint(0) X** followed by as many more white pixels as we need. X*/ X if ((white_pixels - leading_white) > 0) X { X paint(0); X paint(white_pixels); X } X } X white_pixels = end_of_row = 0; /* reset counts */ X paint(length); /* and automatically reverse color */ X } X} X Xstatic endrow() X{ X/* X** If we have white pixels here they are trailing pixels and X** we can just throw them away because we will output X** a newrow command next. X*/ X white_pixels = 0; X ++end_of_row; X} X Xstatic dump1map(n, bitmap) X int n; X u_char *bitmap; X{ X register int i, j, save, paintswitch, bitpos; X register u_char *p; X register int bytewidth; X register charinfo *cp; X X if (bitmap == 0) /* no bitmap? */ X return; X cp = &ci[n]; X i = filepos; /* save position */ X /* any xxx's come here */ X boc(n, cp->p, cp->offx, cp->bbx + cp->offx, X cp->offy, cp->bby + cp->offy - 1); X cp->p = i; /* set backpointer */ X /* dump bitmap here */ X bytewidth = (cp->bbx + 7) / 8; X white_pixels = end_of_row = 0; X for (i = 0; i < cp->bby; ++i) X { X p = &bitmap[i * bytewidth]; X bitpos = 7; X paintswitch = WHITE_PIXEL; X for (save = j = 0; j < cp->bbx; ++j) X { X if (((*p >> bitpos) & 0x1) != paintswitch) X { X run(paintswitch, j - save); X save = j; X paintswitch ^= 0x1; X } X if (--bitpos < 0) X { X ++p; X bitpos = 7; X } X } X run(paintswitch, j - save); X endrow(); X } X eoc(); X} X Xstatic dump1loc(n, bitmap) X int n; X u_char *bitmap; X{ X register charinfo *cp; X X if (bitmap == 0) X return; X cp = &ci[n]; X charloc(n, cp->dx, cp->dy, cp->w, cp->p); X} X Xstatic fontdimens(scale, bitmaps) X float scale; X u_char *bitmaps[NCHARS]; X{ X register int ch; X register charinfo *cp; X X (void)fprintf(plfile, "(FONTDIMEN\n"); X ch = bitmaps[' '] != 0 ? ' ' : 'x'; X if (bitmaps[ch] != 0) X { X cp = &ci[ch]; X (void)fprintf(plfile, " (SPACE D %d)\n", cp->bbx); X (void)fprintf(plfile, " (STRETCH R %.9f)\n", (float)cp->bbx * 0.5); X (void)fprintf(plfile, " (SHRINK R %.9f)\n", (float)cp->bbx * 0.3); X (void)fprintf(plfile, " (EXTRASPACE R %.9f)\n", (float)cp->bbx * 0.3); X (void)fprintf(plfile, " (QUAD D %d)\n", cp->bbx * 2); X (void)fprintf(plfile, " (XHEIGHT D %d)\n", cp->bby); X } X else X { X (void)fprintf(plfile, " (SPACE R %.9f)\n", scale * 0.75); X (void)fprintf(plfile, " (STRETCH R %.9f)\n", scale * 0.375); X (void)fprintf(plfile, " (SHRINK R %.9f)\n", scale * 0.225); X (void)fprintf(plfile, " (EXTRASPACE R %.9f)\n", scale * 0.225); X (void)fprintf(plfile, " (QUAD R %.9f)\n", scale * 1.5); X (void)fprintf(plfile, " (XHEIGHT R %.9f)\n", scale * 0.75); X } X (void)fprintf(plfile, " )\n"); X} X Xstatic dump1pl(n, bitmap) X int n; X u_char *bitmap; X{ X register charinfo *cp; X X if (bitmap == 0) X return; X cp = &ci[n]; X if (' ' < n && n <= '~' && n != '(' && n != ')') X (void)fprintf(plfile, "(CHARACTER C %c\n", n); X else X (void)fprintf(plfile, "(CHARACTER D %d\n", n); X (void)fprintf(plfile, " (CHARWD D %d)\n", cp->bbx); X (void)fprintf(plfile, " (CHARHT D %d)\n", cp->bby + cp->offy); X (void)fprintf(plfile, " (CHARDP D %d)\n", -cp->offy); X (void)fprintf(plfile, " )\n"); X} X Xstatic dumppl(bitmaps) X u_char *bitmaps[NCHARS]; X{ X register int i; X register float du; X X (void)fprintf(plfile, "(DESIGNSIZE D %d)\n", pointsize); X du = (float)xres * (float)pointsize / 72.0; X (void)fprintf(plfile, "(DESIGNUNITS R %.9f)\n", du); X (void)fprintf(plfile, "(COMMENT Units are in pixels)\n"); X fontdimens(du, bitmaps); X for (i = 0; i < NCHARS; ++i) X dump1pl(i, bitmaps[i]); X (void)fclose(plfile); X} X Xdumpfont(bitmaps) X u_char *bitmaps[NCHARS]; X{ X register int i, lastboc, pos; X X pre(131, 0, ""); X for (i = 0; i < NCHARS; ++i) X dump1map(i, bitmaps[i]); X lastboc = filepos; /* save position of lastboc */ X /* xxx's for the postamble go here */ X pos = filepos; /* save position of post */ X /* beginning of postamble */ X post(lastboc); X for (i = 0; i < NCHARS; ++i) X dump1loc(i, bitmaps[i]); X postpost(pos, 131); X if (plfile != NULL) X dumppl(bitmaps); X} END_OF_FILE if test 8985 -ne `wc -c <'dumpgf.c'`; then echo shar: \"'dumpgf.c'\" unpacked with wrong size! fi # end of 'dumpgf.c' fi if test -f 'dumpvfont.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dumpvfont.c'\" else echo shar: Extracting \"'dumpvfont.c'\" \(1402 characters\) sed "s/^X//" >'dumpvfont.c' <<'END_OF_FILE' X#include <stdio.h> X#include <vfont.h> X#include <sys/types.h> X X#define NCHARS 256 X Xstruct header vhdr; Xstruct dispatch vd[NCHARS]; X Xinitialize(argc, argv) X int argc; X char *argv[]; X{ X if (argc < 2) X fatal("Usage: bdf2vf vf"); X X if (freopen(argv[1], "w", stdout) == NULL) X fatal("Cannot open output file"); X} X Xstoreglyph(n, bbx, bby, offx, offy) X int n, bbx, bby, offx, offy; X{ X register struct dispatch *d; X X d = &vd[n]; X d->nbytes = (bbx + 7) / 8 * bby; X d->right = bbx + offx; X d->left = -offx; X d->up = bby + offy; X d->down = -offy; X d->width = bbx; X if (bbx > vhdr.maxx) X vhdr.maxx = bbx; X if (bby > vhdr.maxy) X vhdr.maxy = bby; X} X Xdumpfont(bitmaps) X u_char *bitmaps[NCHARS]; X{ X register int c, bitbytes = 0; X register struct dispatch *d; X X if (fseek(stdout, (long)(sizeof(vhdr) + sizeof(vd)), 0) < 0) X fatal("Cannot seek on output"); X for (c = 0; c < NCHARS; ++c) X { X if (bitmaps[c] != NULL && (d = &vd[c])->nbytes > 0) X { X d->addr = bitbytes; X if (fwrite((char *)bitmaps[c], d->nbytes, 1, stdout) != 1) X fatal("Cannot write glyph"); X bitbytes += d->nbytes; X } X } X vhdr.magic = VFONT_MAGIC; X vhdr.size = bitbytes; X if (fseek(stdout, 0L, 0) < 0) X fatal("Cannot seek to beginning on output"); X if (fwrite((char *)&vhdr, sizeof(vhdr), 1, stdout) != 1) X fatal("Cannot write header"); X if (fwrite((char *)vd, sizeof(vd), 1, stdout) != 1) X fatal("Cannot write dispatch table"); X} END_OF_FILE if test 1402 -ne `wc -c <'dumpvfont.c'`; then echo shar: \"'dumpvfont.c'\" unpacked with wrong size! fi # end of 'dumpvfont.c' fi if test -f 'gf.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'gf.h'\" else echo shar: Extracting \"'gf.h'\" \(769 characters\) sed "s/^X//" >'gf.h' <<'END_OF_FILE' X#define WHITE_PIXEL 0 X#define BLACK_PIXEL 1 X X#define PAINT0 0 X#define PAINT1 64 X#define PAINT2 65 X#define PAINT3 66 X#define BOC 67 X#define BOC1 68 X#define EOC 69 X#define SKIP0 70 X#define SKIP1 71 X#define SKIP2 72 X#define SKIP3 73 X#define NEWROW0 74 X#define NEWROW1 75 X#define XXX1 239 X#define XXX2 240 X#define XXX3 241 X#define XXX4 242 X#define YYY 243 X#define NOOP 244 X#define CHARLOC 245 X#define CHARLOC0 246 X#define PRE 247 X#define POST 248 X#define POSTPOST 249 X X#define FIX (1 << 20) X X/* X** Information about a character X*/ X Xtypedef struct { X int bbx, bby; /* bounding box */ X int offx, offy; /* coords of left bottom corner from origin */ X int dx, dy; /* escapements */ X int w; /* width in FIXes */ X int p; /* backpointer */ X} charinfo; END_OF_FILE if test 769 -ne `wc -c <'gf.h'`; then echo shar: \"'gf.h'\" unpacked with wrong size! fi # end of 'gf.h' fi if test -f 'patchlevel.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'patchlevel.h'\" else echo shar: Extracting \"'patchlevel.h'\" \(21 characters\) sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE' X#define PATCHLEVEL 0 END_OF_FILE if test 21 -ne `wc -c <'patchlevel.h'`; then echo shar: \"'patchlevel.h'\" unpacked with wrong size! fi # end of 'patchlevel.h' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330 Moderator of comp.sources.x