[comp.sources.x] REPOST: v10i076: BDF to Postscript program, Part01/01

mleisher@NMSU.Edu (01/27/91)

Submitted-by: mleisher@NMSU.Edu
Posting-number: Volume 10, Issue 76
Archive-name: bdf2ps/part01

This program makes a Postscript font out from a BDF font.  It will not
work with large, two byte BDF fonts such as Chinese or Japanese BDF
fonts.  It also ignores any entries that have an ENCODING value less
than zero.

You might want to tune some of the Postscript parameters by hand to
get the output closer to what you want.  There is a short description
of this in the man page.

This program depends heavily on the SWIDTH entry for each character.
Please see the "Bitmaps Distribution Format 2.1" document for details
on SWIDTH.  You can also send me email for a copy of this document.

Please send bug reports, enhancements, etc. to:
Internet: mleisher@nmsu.edu
Bitnet  : mleisher@nmsu.bitnet

#!/bin/sh
# This is bdftops-1.0/part, a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 11/19/1990 17:54 UTC by mleisher@nmsu.edu
# Source directory /tmp_mnt/home/nikita1/X11R4/contrib/fonts/bdftops-1.0
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    337 -rw-rw-r-- Imakefile
#   9117 -rw-rw-r-- Makefile
#   1587 -rw-rw-r-- README
#   7704 -rw-rw-r-- bdftops.c
#   2082 -rw-rw-r-- bdftops.man
#     22 -rw-rw-r-- patchlevel.h
#
# ============= Imakefile ==============
if test -f 'Imakefile' -a X"$1" != X"-c"; then
	echo 'x - skipping Imakefile (File already exists)'
else
echo 'x - extracting Imakefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Imakefile' &&
#
# Make file for the BDF font to Postscript font converter
#
# If TOP is incorrectly defined, uncomment and change the following
# line to point at the X11 distribution source.
X
#        TOP = /usr/local/src/X11/mit
X
X      SRCS  = bdftops.c
X      OBJS  = bdftops.o
X   INCLUDES = -I.
X   PROGRAM  = bdftops
X
ComplexProgramTarget(bdftops)
SHAR_EOF
chmod 0664 Imakefile ||
echo 'restore of Imakefile failed'
Wc_c="`wc -c < 'Imakefile'`"
test 337 -eq "$Wc_c" ||
	echo 'Imakefile: original size 337, current size' "$Wc_c"
fi
# ============= Makefile ==============
if test -f 'Makefile' -a X"$1" != X"-c"; then
	echo 'x - skipping Makefile (File already exists)'
else
echo 'x - extracting Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
# Makefile generated by imake - do not edit!
# $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
#
# The cpp used on this machine replaces all newlines and multiple tabs and
# spaces in a macro expansion with a single space.  Imake tries to compensate
# for this, but is not always successful.
#
X
###########################################################################
# Makefile generated from "Imake.tmpl" and </tmp/IIf.a09492>
# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
#
# Platform-specific parameters may be set in the appropriate .cf
# configuration files.  Site-wide parameters may be set in the file
# site.def.  Full rebuilds are recommended if any parameters are changed.
#
# If your C preprocessor doesn't define any unique symbols, you'll need
# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
# "make Makefile", "make Makefiles", or "make World").
#
# If you absolutely can't get imake to work, you'll need to set the
# variables at the top of each Makefile as well as the dependencies at the
# bottom (makedepend will do this automatically).
#
X
###########################################################################
# platform-specific configuration parameters - edit sun.cf to change
X
# platform:  $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
# operating system:  SunOS 4.1
X
###########################################################################
# site-specific configuration parameters - edit site.def to change
X
# site:  $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
X
X            SHELL = /bin/sh
X
X              TOP = /usr/local/src/X11/mit
X      CURRENT_DIR = .
X
X               AR = ar clq
X  BOOTSTRAPCFLAGS =
X               CC = cc
X
X         COMPRESS = compress
X              CPP = /lib/cpp $(STD_CPP_DEFINES)
X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
X          INSTALL = install
X               LD = ld
X             LINT = lint
X      LINTLIBFLAG = -C
X         LINTOPTS = -axz
X               LN = ln -s
X             MAKE = make
X               MV = mv
X               CP = cp
X           RANLIB = ranlib
X  RANLIBINSTFLAGS =
X               RM = rm -f
X     STD_INCLUDES =
X  STD_CPP_DEFINES =
X      STD_DEFINES =
X EXTRA_LOAD_FLAGS =
X  EXTRA_LIBRARIES =
X             TAGS = ctags
X
X    SHAREDCODEDEF = -DSHAREDCODE
X         SHLIBDEF = -DSUNSHLIB
X
X    PROTO_DEFINES =
X
X     INSTPGMFLAGS =
X
X     INSTBINFLAGS = -m 0755
X     INSTUIDFLAGS = -m 4755
X     INSTLIBFLAGS = -m 0664
X     INSTINCFLAGS = -m 0444
X     INSTMANFLAGS = -m 0444
X     INSTDATFLAGS = -m 0444
X    INSTKMEMFLAGS = -m 4755
X
X          DESTDIR =
X
X     TOP_INCLUDES = -I$(INCROOT)
X
X      CDEBUGFLAGS = -O
X        CCOPTIONS =
X      COMPATFLAGS = -DXAW_BC
X
X      ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
X   LDCOMBINEFLAGS = -X -r
X
X        MACROFILE = sun.cf
X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
X
X    IMAKE_DEFINES =
X
X         IRULESRC = $(CONFIGDIR)
X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
X
X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
X			$(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
X			$(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
X
###########################################################################
# X Window System Build Parameters
# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
###########################################################################
# X Window System make variables; this need to be coordinated with rules
# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X          PATHSEP = /
X        USRLIBDIR = /usr/local/lib/X11R4
X           BINDIR = /usr/local/bin/X11R4
X          INCROOT = /usr/include/X11
X     BUILDINCROOT = $(TOP)
X      BUILDINCDIR = $(BUILDINCROOT)/X11
X      BUILDINCTOP = ..
X           INCDIR = $(INCROOT)/X11
X           ADMDIR = $(DESTDIR)/usr/adm
X           LIBDIR = /usr/local/lib/X11R4
X        CONFIGDIR = $(LIBDIR)/config
X       LINTLIBDIR = $(USRLIBDIR)/lint
X
X          FONTDIR = /usr/local/lib/X11R4/fonts
X         XINITDIR = $(LIBDIR)/xinit
X           XDMDIR = $(LIBDIR)/xdm
X           AWMDIR = $(LIBDIR)/awm
X           TWMDIR = $(LIBDIR)/twm
X           GWMDIR = $(LIBDIR)/gwm
X          MANPATH = $(DESTDIR)/usr/local/man
X    MANSOURCEPATH = $(MANPATH)/man
X           MANDIR = /usr/local/man/man1
X        LIBMANDIR = $(MANSOURCEPATH)3X
X      XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X        SOXLIBREV = 4.2
X          SOXTREV = 4.0
X         SOXAWREV = 4.0
X        SOOLDXREV = 4.0
X         SOXMUREV = 4.0
X        SOXEXTREV = 4.0
X
X       FONTCFLAGS = -t
X
X     INSTAPPFLAGS = $(INSTDATFLAGS)
X
X            IMAKE = imake
X           DEPEND = makedepend
X              RGB = rgb
X            FONTC = bdftosnf
X        MKFONTDIR = mkfontdir
X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh
X
X        CONFIGSRC = $(TOP)/config
X        CLIENTSRC = $(TOP)/clients
X          DEMOSRC = $(TOP)/demos
X           LIBSRC = $(TOP)/lib
X          FONTSRC = $(TOP)/fonts
X       INCLUDESRC = $(TOP)/X11
X        SERVERSRC = $(TOP)/server
X          UTILSRC = $(TOP)/util
X        SCRIPTSRC = $(UTILSRC)/scripts
X       EXAMPLESRC = $(TOP)/examples
X       CONTRIBSRC = $(TOP)/../contrib
X           DOCSRC = $(TOP)/doc
X           RGBSRC = $(TOP)/rgb
X        DEPENDSRC = $(UTILSRC)/makedepend
X         IMAKESRC = $(CONFIGSRC)
X         XAUTHSRC = $(LIBSRC)/Xau
X          XLIBSRC = $(LIBSRC)/X
X           XMUSRC = $(LIBSRC)/Xmu
X       TOOLKITSRC = $(LIBSRC)/Xt
X       AWIDGETSRC = $(LIBSRC)/Xaw
X       OLDXLIBSRC = $(LIBSRC)/oldX
X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
X     MKFONTDIRSRC = $(FONTSRC)/mkfontdir
X     EXTENSIONSRC = $(TOP)/extensions
X
X  DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a
X     EXTENSIONLIB =  -lXext
X
X          DEPXLIB = $(DEPEXTENSIONLIB)
X             XLIB = $(EXTENSIONLIB) -lX11
X
X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
X         XAUTHLIB =  -lXau
X
X        DEPXMULIB =
X           XMULIB = -lXmu
X
X       DEPOLDXLIB =
X          OLDXLIB = -loldX
X
X      DEPXTOOLLIB =
X         XTOOLLIB = -lXt
X
X        DEPXAWLIB =
X           XAWLIB = -lXaw
X
X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln
X         LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
X          LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
X        LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
X          LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
X
X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
X
X         DEPLIBS1 = $(DEPLIBS)
X         DEPLIBS2 = $(DEPLIBS)
X         DEPLIBS3 = $(DEPLIBS)
X
###########################################################################
# Imake rules for building libraries, programs, scripts, and data files
# rules:  $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
X
###########################################################################
# start of Imakefile
X
#
# Make file for the BDF font to Postscript font converter
#
# If TOP is incorrectly defined, uncomment and change the following
# line to point at the X11 distribution source.
X
#        TOP = /usr/local/src/X11/mit
X
X      SRCS  = bdftops.c
X      OBJS  = bdftops.o
X   INCLUDES = -I.
X   PROGRAM  = bdftops
X
X PROGRAM = bdftops
X
all:: bdftops
X
bdftops: $(OBJS)
X	$(RM) $@
X	$(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
X
saber_bdftops:
X	#load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
osaber_bdftops:
X	#load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
install:: bdftops
X	$(INSTALL) -c $(INSTPGMFLAGS)   bdftops $(BINDIR)
X
install.man:: bdftops.man
X	$(INSTALL) -c $(INSTMANFLAGS) bdftops.man $(MANDIR)/bdftops.1
X
depend::
X	$(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
X
lint:
X	$(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
lint1:
X	$(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
X
clean::
X	$(RM) $(PROGRAM)
X
###########################################################################
# common rules for all Makefiles - do not edit
X
emptyrule::
X
clean::
X	$(RM_CMD) \#*
X
Makefile::
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) -DCURDIR=$(CURRENT_DIR)
X
tags::
X	$(TAGS) -w *.[ch]
X	$(TAGS) -xw *.[ch] > TAGS
X
saber:
X	#load $(ALLDEFINES) $(SRCS)
X
osaber:
X	#load $(ALLDEFINES) $(OBJS)
X
###########################################################################
# empty rules for directories that do not have SUBDIRS - do not edit
X
install::
X	@echo "install in $(CURRENT_DIR) done"
X
install.man::
X	@echo "install.man in $(CURRENT_DIR) done"
X
Makefiles::
X
includes::
X
###########################################################################
# dependencies generated by makedepend
X
SHAR_EOF
chmod 0664 Makefile ||
echo 'restore of Makefile failed'
Wc_c="`wc -c < 'Makefile'`"
test 9117 -eq "$Wc_c" ||
	echo 'Makefile: original size 9117, current size' "$Wc_c"
fi
# ============= README ==============
if test -f 'README' -a X"$1" != X"-c"; then
	echo 'x - skipping README (File already exists)'
else
echo 'x - extracting README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'README' &&
--------------------------------------------------------------------
Copyright (C) 1990 Mark Leisher.
X
Author: Mark Leisher (mleisher@nmsu.edu)
X
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
X
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
X
A copy of the GNU General Public License can be obtained from this
program's author (send electronic mail to mleisher@nmsu.edu) or from
the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
02139, USA.
--------------------------------------------------------------------
X
This program makes a Postscript font out from a BDF font.  It will not
work with large, two byte BDF fonts such as Chinese or Japanese BDF
fonts.  It also ignores any entries that have an ENCODING value less
than zero.
X
You might want to tune some of the Postscript parameters by hand to
get the output closer to what you want.  There is a short description
of this in the man page.
X
This program depends heavily on the SWIDTH entry for each character.
Please see the "Bitmaps Distribution Format 2.1" document for details
on SWIDTH.  You can also send me email for a copy of this document.
X
Please send bug reports, enhancements, etc. to:
Internet: mleisher@nmsu.edu
Bitnet  : mleisher@nmsu.bitnet
SHAR_EOF
chmod 0664 README ||
echo 'restore of README failed'
Wc_c="`wc -c < 'README'`"
test 1587 -eq "$Wc_c" ||
	echo 'README: original size 1587, current size' "$Wc_c"
fi
# ============= bdftops.c ==============
if test -f 'bdftops.c' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftops.c (File already exists)'
else
echo 'x - extracting bdftops.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftops.c' &&
/*
X *
X * File:         bdftops.c
X * Description:  Make a Postscript font from a BDF font
X * Author:       Mark Leisher
X * Created:      Mon Nov 19 10:27:38 1990
X * Modified:     Mon Nov 19 10:27:42 1990
X *
X */
X
/*
X * Copyright (C) 1990 Mark Leisher.
X *
X * Author: Mark Leisher (mleisher@nmsu.edu)
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 1, or (at your option)
X * any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * A copy of the GNU General Public License can be obtained from this
X * program's author (send electronic mail to mleisher@nmsu.edu) or from
X * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
X * 02139, USA.
X *
X */
X
#include <stdio.h>
#include <X11/Xos.h>
#include "patchlevel.h"
X
#define BDFTOPS_VERSION 1
#define AUTHOR_STRING "mleisher@nmsu.edu (Mark Leisher)"
#define BDF_VERSION "2.1"
X
char *program, *fontname;
char buff[128];
int fontno = 1;
X
int w, h, psize, resX, resY;
double width_scale;
X
char *
get_fontname(str)
char *str;
{
X    int len;
X    char *ptr, *tmp_name;
X
X    if (str == NULL) {
X        tmp_name = (char *)malloc(20 * sizeof(char));
X        sprintf(tmp_name, "BDF FONT %d", fontno++);
X        return(tmp_name);
X    }
X    len = strlen(str);
X    ptr = str + (len - 1);
X    while(ptr > str && *ptr != '.')
X      ptr--;
X    if (ptr == str)
X      return(str);
X    ptr++;
X    if (!strncmp(ptr, "bdf", 3)) {
X        ptr--;
X        tmp_name = (char *)malloc(((ptr-str) + 1) * sizeof(char));
X        strncpy(tmp_name, str, (ptr-str));
X        tmp_name[ptr-str] = '\0';
X        return(tmp_name);
X    }
X    return(str);
}
X
void
header(in)
FILE *in;
{
X    int dx, dy;
X    int i, count, ndx, ndy;
X    double llx, lly, urx, ury;
X    time_t clock;
X
X    printf("%%!PS-Adobe-2.0\n");
X    printf("%%%% GENERATED BY \"bdftops %d.%d\"\n", BDFTOPS_VERSION,
X           patchlevel);
X    printf("%%%% AUTHOR %s\n", AUTHOR_STRING);
X
X    time(&clock);
X    printf("%%%% DATE %s\n", ctime(&clock));
X
X    printf("10 dict dup begin\n");
X    printf("/FontType 3 def\n");
X    printf("/FontMatrix [1 0 0 1 0 0] def\n");
X
X    fscanf(in, "%[^\n]\n", buff);
X
X    if (strcmp(buff, "STARTFONT 2.1")) {
X        fprintf(stderr, "%s: incorrect BDF format \"%s\"\n", program,
X                buff);
X        exit(1);
X    }
X
X    while(!feof(in) && strncmp(buff, "SIZE", 4))
X      fscanf(in, "%[^\n]\n", buff);
X    if (strncmp(buff, "SIZE", 4)) {
X        fprintf(stderr, "%s: missing SIZE\n", program);
X        exit(1);
X    }
X    sscanf(buff, "SIZE %d %d %d", &psize, &resX, &resY);
X
X    width_scale = (((double)psize)/1000.0) * (((double)resX)/72.27);
X
X    while(!feof(in) && strncmp(buff, "FONTBOUNDINGBOX", 15))
X      fscanf(in, "%[^\n]\n", buff);
X    if (strncmp(buff, "FONTBOUNDINGBOX", 15)) {
X        fprintf(stderr, "%s: missing FONTBOUNDINGBOX\n", program);
X        exit(1);
X    }
X    sscanf(buff, "FONTBOUNDINGBOX %d %d %d %d", &w, &h, &dx, &dy);
X
X    ndx = (dx < 0) ? -(dx) : dx;
X    ndy = (dy < 0) ? -(dy) : dy;
X    if (w == 0)
X      llx = urx = 0.0;
X    else {
X        llx = ((double)(w + ndx)) / ((double) w);
X        urx = ((double) dx) / ((double) w);
X    }
X    if (h == 0)
X      lly = ury = 0.0;
X    else {
X        lly = ((double)(h + ndy)) / ((double) h);
X        ury = ((double) dy) / ((double) h);
X    }
X    printf("/FontBBox [%g %g %g %g] def\n", llx, lly, urx, ury);
X    printf("/Encoding 256 array def\n");
X    printf("0 1 255 {Encoding exch /.notdef put} for\n");
X    printf("Encoding\n");
X    count = 0;
X    for (i = 32; i < 255; i++) {
X        printf("dup %d /char%d put\t", i, i);
X        count++;
X        if (count % 3 == 0) {
X            count = 0;
X            printf("\n");
X        }
X    }
X    printf("255 /char255 put\n");
X    printf("/BuildChar\n{0 begin\n/char exch def\n/fontdict exch def\n");
X    printf("/charname fontdict /Encoding get char get def\n");
X    printf("/charinfo fontdict /CharData get charname get def\n");
X    printf("/wx charinfo 0 get def\n");
X    printf("/charbbox charinfo 1 4 getinterval def\n");
X    printf("wx 0 charbbox aload pop setcachedevice\n");
X    printf("charinfo 5 get charinfo 6 get true\n");
X    printf("fontdict /imagemaskmatrix get\n");
X    printf("dup 4 charinfo 7 get put\n");
X    printf("dup 5 charinfo 8 get put\n");
X    printf("charinfo 9 1 getinterval cvx imagemask\n");
X    printf("end } def\n");
X    printf("/BuildChar load 0 6 dict put\n");
X    printf("/imagemaskmatrix [%d 0 0 -%d 0 0] def\n", w, h);
X    printf("/CharData 224 dict def\nCharData begin\n");
}
X
void
gen_chars(in)
FILE *in;
{
X    int cw, ch, dx, dy, dx1, dy1, encoding, i;
X    int sw, dummy;
X    double wx, llx, lly, urx, ury, ndx, ndy, tdx;
X
X    fscanf(in, "%[^\n]\n", buff);
X    while(!feof(in)) {
X        while(!feof(in) && strncmp(buff, "ENCODING", 8))
X          fscanf(in, "%[^\n]\n", buff);
X        if (feof(in))
X          break;
X        sscanf(buff, "ENCODING %d", &encoding);
X
X        while(!feof(in) && strncmp(buff, "SWIDTH", 6))
X          fscanf(in, "%[^\n]\n", buff);
X        if (feof(in))
X          break;
X        sscanf(buff, "SWIDTH %d %d", &sw, &dummy);
X
X        sw = (int)(((double)sw) * width_scale);
X        sw++;
X
X        if (!feof(in) && encoding >= 32) {
X            while(!feof(in) && strncmp(buff, "BBX", 3))
X              fscanf(in, "%[^\n]\n", buff);
X            if (feof(in))
X              break;
X            sscanf(buff, "BBX %d %d %d %d", &cw, &ch, &dx, &dy);
X            dx1 = (dx < 0) ? -(dx) : dx;
X            dy1 = (dy < 0) ? -(dy) : dy;
X            ndx = 2.0 * (((double) dx1) - 0.5);
X            wx = (((double) sw) + ndx) / ((double) w);
X            if (wx == 0)
X              wx = ((double)w) * 0.01;
X            if (w == 0)
X              llx = urx = 0.0;
X            else {
X                urx = ((double)(sw + dx1)) / ((double) sw);
X                llx = ((double) dx) / ((double) sw);
X            }
X            if (h == 0)
X              lly = ury = 0.0;
X            else {
X                ury = ((double)(ch + dy1)) / ((double) ch);
X                lly = ((double) dy) / ((double) ch);
X            }
X            ndx = ((double)dx1) - 0.5;
X            ndy = ((double)ch) - 0.5;
X            printf("/char%d [%g %g %g %g %g %d %d %g %g\n<", encoding, wx, llx,
X                   lly, urx, ury, cw, ch, ndx, ndy);
X
X            fscanf(in, "%[^\n]\n", buff);
X            while(!feof(in) && strncmp(buff, "BITMAP", 6))
X              fscanf(in, "%[^\n]\n", buff);
X            if (feof(in))
X              break;
X            for (i = 0; i < ch; i++) {
X                fscanf(in, "%[^\n]", buff);
X                printf("%s", buff);
X                getc(in);  /* kill the EOL */
X            }
X            printf(">] def\n");
X        } else
X          fscanf(in, "%[^\n]\n", buff);
X    }
X    printf("/.notdef [%g 0 0 0 0 1 0 0 <>] def\n", ((double) w) * .01);
X    printf("end\nend\n/%s exch definefont pop\n", fontname);
}
X
X
main(argc, argv)
int argc;
char **argv;
{
X    FILE *in = stdin;
X
X    program = argv[0];
X
X    argc--;
X    *argv++;
X    while(argc) {
X        if (!(in = fopen(argv[0], "r")))
X          fprintf(stderr, "%s: problem with %s\n", program, argv[0]);
X        else {
X            fontname = get_fontname(argv[0]);
X            header(in);
X            gen_chars(in);
X            fclose(in);
X            in = NULL;
X        }
X        argc--;
X        *argv++;
X    }
X    if (in != NULL) {
X        header(in);
X        gen_chars(in);
X    }
}
SHAR_EOF
chmod 0664 bdftops.c ||
echo 'restore of bdftops.c failed'
Wc_c="`wc -c < 'bdftops.c'`"
test 7704 -eq "$Wc_c" ||
	echo 'bdftops.c: original size 7704, current size' "$Wc_c"
fi
# ============= bdftops.man ==============
if test -f 'bdftops.man' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftops.man (File already exists)'
else
echo 'x - extracting bdftops.man (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftops.man' &&
.TH BDFTOPS 1 "Release 4" "X Version 11"
.SH NAME
bdftops - BDF font to Postscript font generator
.SH SYNOPSIS
.B "bdftops"
[bdf-file(s)]
.SH DESCRIPTION
.PP
.B bdftops
reads a Bitmap Distribution Format (BDF) file (or from standard input
if no file is specified on the command line) and produces a
Postscript font on standard output.
.sp
.B bdftops
will use the font filename minus the \fI.bdf\fP extension as
the name of the font, the full font filename if the \fI.bdf\fP extension is
not there, or a font name of "\fBBDF-FONT-\fIn\fP", where \fIn\fP is a
number, when a font file is read from standard input.
.SH "TUNING FONTS"
.B bdftops
depends on the SWIDTH (scalable width) x value heavily.  If this value
is not correct, then the horizontal offsets will be a little too
small, especially with variable width fonts.  Details of the SWIDTH
entry are described in the "Bitmap Distribution Format 2.1" document.
.sp
Variable width fonts will probably need a small amount of hand tuning
to get correct kerning.
.sp
An example of a Postscript character definition from the Adobe
Times-Roman 24(timR24.bdf) font:
.nf
\f(CW/char116 [0.230769 0 0 1 1 7 15 -0.5 14.5
<103070FE303030303030303030321C>] def\fP
.fi
.sp
The first number is the horziontal offset of the character that
follows this one, the next four numbers are the character's bounding
box for the font cacheing mechanism, the next two numbers are the
bitmap's width and height, and the last two numbers are horizontal and
vertical translations of the bitmap with .5 subtracted to handle
Postscript rounding errors.
.sp
This example in particular is a lower case ``t''.  The horizontal
offset of the next character is not quite right.  So the 0.230769
needs to be increased a little so that the character following the
``t'' is kerned correctly.
.SH "SEE ALSO"
XX(1), Xserver(1), bdftosnf(1)
.br
"Bitmap Distribution Format 2.1"
.SH AUTHOR
Internet: mleisher@nmsu.edu     Bitnet: mleisher@nmsu.bitnet
.br
Mark Leisher
.br
Computing Research Lab
.br
New Mexico State University
.br
Las Cruces, NM 88003
.br
(505) 646-5711
X
SHAR_EOF
chmod 0664 bdftops.man ||
echo 'restore of bdftops.man failed'
Wc_c="`wc -c < 'bdftops.man'`"
test 2082 -eq "$Wc_c" ||
	echo 'bdftops.man: original size 2082, current size' "$Wc_c"
fi
# ============= patchlevel.h ==============
if test -f 'patchlevel.h' -a X"$1" != X"-c"; then
	echo 'x - skipping patchlevel.h (File already exists)'
else
echo 'x - extracting patchlevel.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
#define patchlevel 0
X
SHAR_EOF
chmod 0664 patchlevel.h ||
echo 'restore of patchlevel.h failed'
Wc_c="`wc -c < 'patchlevel.h'`"
test 22 -eq "$Wc_c" ||
	echo 'patchlevel.h: original size 22, current size' "$Wc_c"
fi
exit 0

--
dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.