[comp.sources.x] v12i005: bdftools -- tools for working with BDF fonts, Part02/02

mleisher@NMSU.Edu (03/02/91)

Submitted-by: mleisher@NMSU.Edu
Posting-number: Volume 12, Issue 5
Archive-name: bdftools/part02

Submitted-by: mleisher@nmsu.edu
Archive-name: bdftools/part02

---- Cut Here and feed the following to sh ----
#!/bin/sh
# this is bdftools.02 (part 2 of bdftools/part)
# do not concatenate these parts, unpack them in order with /bin/sh
# file bdftools/snftobdf-1.4/MANIFEST continued
#
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 2; then
	echo Please unpack part "$Scheck" next!
	exit 1
 else
	exit 0
 fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
	echo 'x - still skipping bdftools/snftobdf-1.4/MANIFEST'
else
echo 'x - continuing file bdftools/snftobdf-1.4/MANIFEST'
sed 's/^X//' << 'SHAR_EOF' >> 'bdftools/snftobdf-1.4/MANIFEST' &&
X
These are the files that are part of snftobdf.
----------------------------------------------
Makefile
input.c
output.c
patchlevel.h
snftobdf.c
snftobdf.h
snftobdf.man
SHAR_EOF
echo 'File bdftools/snftobdf-1.4/MANIFEST is complete' &&
chmod 0664 bdftools/snftobdf-1.4/MANIFEST ||
echo 'restore of bdftools/snftobdf-1.4/MANIFEST failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/MANIFEST'`"
test 178 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/MANIFEST: original size 178, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/Makefile ==============
if test -f 'bdftools/snftobdf-1.4/Makefile' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/Makefile (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/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.a16110>
# $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 SNF to BDF font compiler
#
# 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  = snftobdf.c input.c output.c
X      OBJS  = snftobdf.o input.o output.o
X   INCLUDES = -I. -I$(SERVERSRC)/include -I$(SERVERSRC)/ddx/snf \
X              -I$(BDFTOSNFSRC)
X   PROGRAM  = snftobdf
X
X PROGRAM = snftobdf
X
all:: snftobdf
X
snftobdf: $(OBJS)
X	$(RM) $@
X	$(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
X
saber_snftobdf:
X	#load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
osaber_snftobdf:
X	#load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
install:: snftobdf
X	$(INSTALL) -c $(INSTPGMFLAGS)   snftobdf $(BINDIR)
X
install.man:: snftobdf.man
X	$(INSTALL) -c $(INSTMANFLAGS) snftobdf.man $(MANDIR)/snftobdf.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 bdftools/snftobdf-1.4/Makefile ||
echo 'restore of bdftools/snftobdf-1.4/Makefile failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/Makefile'`"
test 9230 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/Makefile: original size 9230, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/README ==============
if test -f 'bdftools/snftobdf-1.4/README' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/README (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/README' &&
/*
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
Created:  Mon Sep 17 11:10:12 MDT 1990 M. Leisher
Modified: Sat Oct 13 20:21:22 MDT 1990 M. Leisher
/* */
Modified: Mon Oct 15 15:58:38 MDT 1990 M. Leisher
/* */
Modified: Thu Oct 18 18:20:08 MDT 1990 M. Leisher
/* Fixed include problem with stat.h & time.h for Sun OS 4.0.3
X   Added missing include path in Imakefile */
Modified: Sat Nov 17 10:15:00 MDT 1990 M. Leisher
/* Added pointSize for correct point size value in SIZE, fixed
X   FONTBOUNDINGBOX calculation
X   Pointed out by: jjl%miata.esd.sgi.com%SGI.COM (Jim Lee) */
Modified: Tue Nov 20 03:04:42 MDT 1990 M. Leisher
/* Fixed pixelSize calculation
X   Pointed out by: jjl%miata.esd.sgi.com%SGI.COM (Jim Lee)
X   Added GNU GPL copyright notice */
Modified: Sun Feb 24 21:36:43 MDT 1991 M. Leisher
/* Added fixes sent by asami@is.s.u-tokyo.ac.jp (Satoshi Asami) and
X   take@is.s.u-tokyo.ac.jp (Taketo Tsukioka) */
X
COMPILATION
X
snftobdf is pretty much self contained except for some header files it
needs from the X11 source.  The Imakefile should generate the correct
Makefile, but some sites seem to have their toplevel distribution
source define incorrect.  If you don't have access to the site.def
file for imake, simply uncomment the line containing TOPDIR in the
Imakefile and set it to the location of the X11 distribution on your
system.
X
NOTES
X
Due to some TeX font wierdnesses, some gf/pk/pxl files that are
converted to X11 format have characters of width 0, particularly the
music16.85.snf font, generated from the MuTeX .pk font.  snftobdf will
fill in the width value.
X
X
BUGS
X
I have only tested this code on Big Endian architectures, so I'm not
completely sure the bit and byte swapping works as it should.
X
Thanks to "der Mouse" for the SWIDTH calculation.
X
Thanks to Satoshi Asami and Taketo Tsukioka of University of Tokyo for
bug fix for Kanji fonts and fix for missing font names.
X
Please send fixes or bugs to: mleisher@nmsu.edu
SHAR_EOF
chmod 0664 bdftools/snftobdf-1.4/README ||
echo 'restore of bdftools/snftobdf-1.4/README failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/README'`"
test 2716 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/README: original size 2716, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/input.c ==============
if test -f 'bdftools/snftobdf-1.4/input.c' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/input.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/input.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/input.c' &&
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "snftobdf.h"
X
extern char *program;
X
void
invertbits(buf, count)
unsigned char *buf;
int count;
{
X    int i, n, m;
X    unsigned char c, oc;
X
X    for ( i = 0; i < count; i++ ) {
X        c = buf[i];
X        oc = 0;
X        for (n=0, m=7; n < 8; n++, m--) {
X            oc |= ((c >> n) & 1) << m;
X        }
X        buf[i] = oc;
X    }
}
X
void
invert2(buf, count)
unsigned char *buf;
int count;
{
X    int i;
X    unsigned char c;
X
X    for ( i = 0; i < count; i += 2) {
X        c = buf[i];
X        buf[i] = buf[i+1];
X        buf[i+1] = c;
X    }
}
X
void
invert4(buf, count)
unsigned char *buf;
int count;
{
X    int i;
X    unsigned char c;
X
X    for (i = 0; i < count; i += 4) {
X        c = buf[i];
X        buf[i] = buf[i+3];
X        buf[i+3] = c;
X        c = buf[i+1];
X        buf[i+1] = buf[i+2];
X        buf[i+2] = c;
X    }
}
X
TempFont *
GetSNFInfo(name, bitOrder, byteOrder, scanUnit)
char *name;
int bitOrder, byteOrder, scanUnit;
{
X    int fd, tot, strings, i, glyphbytes;
X    char *buf;
X    struct stat st;
X    TempFont *tf;
X
X    if (stat(name, &st) < 0) {
X        fprintf(stderr, "%s: problem with file %s\n", program, name);
X        exit(1);
X    }
X
X    if ((fd = open(name, O_RDONLY)) < 0) {
X        fprintf(stderr, "%s: can't open file %s\n", program, name);
X        exit(1);
X    }
X
X    if (!(tf = (TempFont *)malloc(sizeof(TempFont)))) {
X        fprintf(stderr, "BAD MALLOC\n");
X        close(fd);
X        exit(1);
X    }
X
X    if (!(buf = (char *)malloc(st.st_size))) {
X        fprintf(stderr, "BAD MALLOC\n");
X        close(fd);
X        exit(1);
X    }
X
X    if ((tot = read(fd, buf, st.st_size)) < st.st_size) {
X        fprintf(stderr, "%s: read problem on font %s\n", program, name);
X        close(fd);
X        exit(1);
X    }
X    close(fd);
X
X    tf->pFI = (FontInfoPtr)buf;
X    if (tf->pFI->version1 != FONT_FILE_VERSION ||
X        tf->pFI->version2 != FONT_FILE_VERSION)
X      fprintf(stderr, "%s: %s is old style BDF\n", program, name);
X    i = BYTESOFFONTINFO(tf->pFI);
X    tf->pCI = (CharInfoPtr)(buf + i);
X    i = BYTESOFCHARINFO(tf->pFI);
X    tf->pGlyphs = ((unsigned char *)(tf->pCI)) + i;
X    glyphbytes = BYTESOFGLYPHINFO(tf->pFI);
X    tf->pFP = (FontPropPtr)(tf->pGlyphs + glyphbytes);
X    strings = (int)tf->pFP + BYTESOFPROPINFO(tf->pFI);
X    if (tf->pFI->inkMetrics) {
X        tf->pInkMin = (CharInfoPtr)(strings + BYTESOFSTRINGINFO(tf->pFI));
X        tf->pInkMax = tf->pInkMin + 1;
X        tf->pInkCI  = tf->pInkMax + 1;
X    }
X    for (i = 0; i < tf->pFI->nProps; i++) {
X        tf->pFP[i].name += strings;
X        if (tf->pFP[i].indirect)
X          tf->pFP[i].value += strings;
X    }
X
X    if (bitOrder == LSBFirst)
X      invertbits(tf->pGlyphs, glyphbytes);
X    if (bitOrder != byteOrder) {
X        if (scanUnit == 2)
X          invert2(tf->pGlyphs, glyphbytes);
X        else if (scanUnit == 4)
X          invert4(tf->pGlyphs, glyphbytes);
X    }
X        
X    return(tf);
}
X
unsigned char *
GetSNFBitmap(tf, charnum, glyphPad)
TempFont *tf;
unsigned int charnum;
int glyphPad;
{
X    CharInfoPtr pCI = tf->pCI;
X    int ht = pCI[charnum].metrics.descent +
X             pCI[charnum].metrics.ascent;
X
X    int wd = pCI[charnum].metrics.rightSideBearing -
X             pCI[charnum].metrics.leftSideBearing;
X
X    int gbp = GLWIDTHBYTESPADDED(wd, glyphPad);
X    int wid = ((wd / 8) + ((wd % 8) ? 1 : 0));
X    int bytes = ht * wid;
X    int i, j = 0, count = 0;
X    unsigned char *bitmaps = (unsigned char *)tf->pGlyphs +
X                             pCI[charnum].byteOffset;
X    unsigned char *bmap =
X      (unsigned char *)malloc(sizeof(unsigned char) * bytes);
X
X    unsigned char *ptr = bitmaps;
X
X    if (!pCI[charnum].exists || ReallyNonExistent(pCI[charnum]))
X      return(NULL);
X
X    for (i = 0; i < ht; i++) {
X        for (j = 0; j < wid; j++)
X          bmap[count++] = *ptr++;
X        ptr += (gbp - wid);
X    }
X    return(bmap);
}
SHAR_EOF
chmod 0664 bdftools/snftobdf-1.4/input.c ||
echo 'restore of bdftools/snftobdf-1.4/input.c failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/input.c'`"
test 3915 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/input.c: original size 3915, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/output.c ==============
if test -f 'bdftools/snftobdf-1.4/output.c' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/output.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/output.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/output.c' &&
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include "snftobdf.h"
#include "patchlevel.h"
X
extern char *program;
X
static int pointSize, pixelSize, resX, resY;
X
void
SetSizeAndRes(tf)
TempFont *tf;
{
X    int i, res = 0,
X        res_found   = 0,
X        res_x_found = 0,
X        res_y_found = 0;
X
X    resX = resY = pointSize = pixelSize = 0;
X    for (i = 0; i < tf->pFI->nProps; i++) {
X        if (!strcmp(tf->pFP[i].name, "POINT_SIZE"))
X          pointSize = tf->pFP[i].value / 10;
X        else if (!strcmp(tf->pFP[i].name, "PIXEL_SIZE"))
X          pixelSize = tf->pFP[i].value;
X        else if (!strcmp(tf->pFP[i].name, "RESOLUTION"))
X          res = tf->pFP[i].value;
X        else if (!strcmp(tf->pFP[i].name, "RESOLUTION_X"))
X          resX = tf->pFP[i].value;
X        else if (!strcmp(tf->pFP[i].name, "RESOLUTION_Y"))
X          resY = tf->pFP[i].value;
X    }
X
X    if (res)
X      resX = resY = (res * 73) / 100;
}
X
int
nonexistChars(tf)
TempFont *tf;
{
X    int i, count = 0, tot_chars = n2dChars(tf->pFI);
X    CharInfoPtr pCI = tf->pCI;
X
X    for (i = 0; i < tot_chars; i++) {
X        if (!pCI[i].exists || ReallyNonExistent(pCI[i]))
X          count++;
X    }
X    return(count);
}
X
void
BDFHeader(tf, name)
TempFont *tf;
char *name;
{
X    FontInfoPtr pFI = tf->pFI;
X    CharInfoPtr minBounds = &(pFI->minbounds);
X    CharInfoPtr maxBounds = &(pFI->maxbounds);
X    int props;
X    int b1, b2, b3, b4;
X    time_t clock;
X
X    int i = 0;
X
X    time(&clock);
X    printf("STARTFONT %s\n", BDF_VERSION);
X    printf("COMMENT\n");
X    printf("COMMENT GENERATED BY \"snftobdf %d.%d\"\n",
X           SNFTOBDF_VERSION, patchlevel);
X    printf("COMMENT AUTHOR %s\n", AUTHOR_STRING);
X    printf("COMMENT DATE %s", ctime(&clock));
X    printf("COMMENT\n");
X
X    /* Add three for DEFAULT_CHAR, FONT_ASCENT, FONT_DESCENT */
X    props = pFI->nProps + 3;
X    while(i < pFI->nProps &&
X          strcmp(tf->pFP[i].name, "FONT"))
X      i++;
X    if (i < pFI->nProps) {
X        printf("FONT %s\n", tf->pFP[i].value);
X        props--;
X    } else {
X        fprintf(stderr, "Warning: missing font name. Using file name instead.\n");
X        fprintf(stderr, "Please modify FONT field in BDF file if necessary.\n");
X        printf("FONT %s\n", name);
X    }
X
X    SetSizeAndRes(tf);
X
X    if (pixelSize == 0)
X      pixelSize = maxBounds->metrics.ascent +
X                  maxBounds->metrics.descent;
X    if (pointSize == 0)
X      pointSize = pixelSize;
X
X    printf("SIZE %d %d %d\n", pointSize, resX, resY);
X
X    b1 = maxBounds->metrics.rightSideBearing +
X         maxBounds->metrics.leftSideBearing;
X    b2 = maxBounds->metrics.ascent +
X         maxBounds->metrics.descent;
X    b3 = -(maxBounds->metrics.leftSideBearing);
X    b4 = -(maxBounds->metrics.descent);
X
X    printf("FONTBOUNDINGBOX %d %d %d %d\n", b1, b2, b3, b4);
X
X    printf("STARTPROPERTIES %d\n", props);
X    for (i = 0; i < pFI->nProps; i++) {
X        if (strcmp(tf->pFP[i].name, "FONT")) {
X            printf("%s ", tf->pFP[i].name);
X            if (tf->pFP[i].indirect)
X              printf("\"%s\"\n", tf->pFP[i].value);
X            else
X              printf("%d\n", tf->pFP[i].value);
X        }
X    }
X    printf("DEFAULT_CHAR %d\n", pFI->chDefault);
X    printf("FONT_ASCENT %d\n", pFI->fontAscent);
X    printf("FONT_DESCENT %d\n", pFI->fontDescent);
X    printf("ENDPROPERTIES\n");
X    printf("CHARS %d\n", n2dChars(pFI) - nonexistChars(tf));
}
X
void
BDFBitmaps(tf, glyphPad)
TempFont *tf;
int glyphPad;
{
X    CharInfoPtr pCI = tf->pCI;
X    FontInfoPtr pFI = tf->pFI;
X    CharInfoPtr minBounds = &(pFI->minbounds);
X    CharInfoPtr maxBounds = &(pFI->maxbounds);
X
X    int height, width, wd, bytes,
X        i, j, k, nrows, ncols,
X        nchars, dwidth, swidth = 0,
X        b1, b2, b3, b4, rownum, colnum;
X
X    unsigned char *bitmap;
X
X
X    ncols = (pFI->lastCol - pFI->firstCol) + 1;
X    if (IsLinear(pFI)) {
X        nchars = n1dChars(pFI);
X        nrows = 0;
X    } else {
X        nchars = n2dChars(pFI);
X        nrows = (pFI->lastRow - pFI->firstRow) + 1;
X    }
X
X    colnum = pFI->firstCol;
X    rownum = pFI->firstRow;
X    for( i = 0; i < nchars; i++ ) {
X        if (pCI[i].exists && !ReallyNonExistent(pCI[i])) {
X
X            dwidth = pCI[i].metrics.characterWidth;
X            if (dwidth == 0)
X                dwidth = pCI[i].metrics.leftSideBearing +
X                         pCI[i].metrics.rightSideBearing;
X
X            if (IsLinear(pFI)) {
X                printf("STARTCHAR C%03o\n", colnum);
X                printf("ENCODING %d\n", colnum);
X            } else {
X                colnum = i % ncols + pFI->firstCol;
X                rownum = i / ncols + pFI->firstRow;
X                printf("STARTCHAR %02x%02x\n",
X                       (rownum & 0xff), (colnum & 0xff));
X                printf("ENCODING %d\n",
X                       ((rownum << 8) & 0xff00)|(colnum & 0xff));
X            }
X                
X            swidth = (dwidth * 72270)/(pointSize * resX);
X            printf("SWIDTH %d 0\n", swidth);
X            printf("DWIDTH %d 0\n", dwidth);
X
X            b1 = pCI[i].metrics.rightSideBearing -
X                 pCI[i].metrics.leftSideBearing;
X            b2 = pCI[i].metrics.descent +
X                 pCI[i].metrics.ascent;
X            b3 = pCI[i].metrics.leftSideBearing;
X            b4 = -(pCI[i].metrics.descent);
X            printf("BBX %d %d %d %d\n", b1, b2, b3, b4);
X
X            printf("BITMAP\n");
X            bitmap = GetSNFBitmap(tf, i, glyphPad);
X
X            wd = b1;
X            height = b2;
X            width = ((wd / 8) + ((wd % 8) ? 1 : 0)),
X            bytes = height * width;
X
X            k = 0;
X            for (j = 0; j < bytes; j++) {
X                if (k == width) {
X                    putchar(10);
X                    k = 0;
X                }
X                printf("%02x", (bitmap[j] & 0xff));
X                k++;
X            }
X            putchar(10);
X            printf("ENDCHAR\n");
X        }
X        colnum++;
X    }
}
X
void
BDFTrailer(tf)
TempFont *tf;
{
X    printf("ENDFONT\n");
}
X
SHAR_EOF
chmod 0664 bdftools/snftobdf-1.4/output.c ||
echo 'restore of bdftools/snftobdf-1.4/output.c failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/output.c'`"
test 5991 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/output.c: original size 5991, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/snftobdf.c ==============
if test -f 'bdftools/snftobdf-1.4/snftobdf.c' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/snftobdf.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/snftobdf.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/snftobdf.c' &&
/*
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 <sys/types.h>
#include <sys/stat.h> 
#include "snftobdf.h"
X
char *program;
X
void
usage()
{
X    fprintf (stderr, "usage:  %s [-options ...] snffile ...\n\n", program);
X    fprintf (stderr, "where options include:\n");
X    fprintf (stderr, "\t-m\t\tset bit order to Most Significant Bit First\n");
X    fprintf (stderr, "\t-l\t\tset bit order to Least Significant Bit First\n");
X    fprintf (stderr, "\t-M\t\tset byte order to Most Significant Byte First\n");
X    fprintf (stderr, "\t-L\t\tset byte order to Least Significant Byte First\n");
X    fprintf (stderr, "\t-p#\t\tset glyph padding to #\n");
X    fprintf (stderr, "\t-u#\t\tset scanline unit to #\n\n");
X    exit (1);
}
X
main(argc, argv)
int argc;
char **argv;
{
X    char *name;
X    TempFont *tf;
X    int glyphPad  = DEFAULTGLPAD,
X        bitOrder  = DEFAULTBITORDER,
X        byteOrder = DEFAULTBYTEORDER,
X        scanUnit  = DEFAULTSCANUNIT;
X
X    program = argv[0];
X
X    argc--;
X    *argv++;
X    while(argc) {
X        if (argv[0][0] == '-') {
X            switch(argv[0][1]) {
X              case 'm': bitOrder = MSBFirst; break;
X              case 'l': bitOrder = LSBFirst; break;
X              case 'M': byteOrder = MSBFirst; break;
X              case 'L': byteOrder = LSBFirst; break;
X              case 'p': glyphPad = atoi(argv[0] + 2); break;
X              case 'u': scanUnit = atoi(argv[0] + 2); break;
X              default: usage(); break;
X            }
X        } else if (!argv[0][0])
X          usage();
X        else {
X            tf = GetSNFInfo(argv[0], bitOrder, byteOrder, scanUnit);
X            BDFHeader(tf, argv[0]);
X            BDFBitmaps(tf, glyphPad);
X            BDFTrailer(tf);
X        }
X        argc--;
X        *argv++;
X    }
}
SHAR_EOF
chmod 0664 bdftools/snftobdf-1.4/snftobdf.c ||
echo 'restore of bdftools/snftobdf-1.4/snftobdf.c failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/snftobdf.c'`"
test 2543 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/snftobdf.c: original size 2543, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/patchlevel.h ==============
if test -f 'bdftools/snftobdf-1.4/patchlevel.h' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/patchlevel.h (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/patchlevel.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/patchlevel.h' &&
#define patchlevel 4
SHAR_EOF
chmod 0664 bdftools/snftobdf-1.4/patchlevel.h ||
echo 'restore of bdftools/snftobdf-1.4/patchlevel.h failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/patchlevel.h'`"
test 21 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/patchlevel.h: original size 21, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/snftobdf.h ==============
if test -f 'bdftools/snftobdf-1.4/snftobdf.h' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/snftobdf.h (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/snftobdf.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/snftobdf.h' &&
#ifndef _snftobdf_h
#define _snftobdf_h
X
/* Note: n2dChars is a macro defined in
X         mit/server/include/font.h
X
X         the file fontutil.c only used for
X         bit and byte ordering functions   */
X
#include <X11/Xos.h>
#include <X11/Xmd.h>
#include <X11/X.h>
#include <X11/Xproto.h>
X
#include "misc.h"
#include "fontstruct.h"
#include "snfstruct.h"
#include "font.h"
#include "bdftosnf.h"
X
#define AUTHOR_STRING "mleisher@nmsu.edu (Mark Leisher)"
#define SNFTOBDF_VERSION 1
X
#define BDF_VERSION "2.1"
X
#define IsLinear(pfi) (((pfi)->firstRow == 0) && ((pfi)->lastRow == 0))
X
#define ReallyNonExistent(pci) \
X  ((((pci).metrics.leftSideBearing + (pci).metrics.rightSideBearing) == 0) && \
X   (((pci).metrics.ascent + (pci).metrics.descent) == 0))
X
X
TempFont *
GetSNFInfo();
/*
char *path;
int bitOrder, byteOrder, scanUnit;
*/
X
unsigned char *
GetSNFBitmap();
/*
TempFont *tf;
unsigned int charnum;
int glyphPad;
*/
X
void
BDFHeader();
/*
TempFont *tf;
*/
X
void
BDFBitmaps();
/*
TempFont *tf;
int glyphPad;
*/
X
void
BDFTrailer();
/*
TempFont *tf;
*/
X
#endif /* _snftobdf_h */
SHAR_EOF
chmod 0664 bdftools/snftobdf-1.4/snftobdf.h ||
echo 'restore of bdftools/snftobdf-1.4/snftobdf.h failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/snftobdf.h'`"
test 1083 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/snftobdf.h: original size 1083, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= bdftools/snftobdf-1.4/snftobdf.man ==============
if test -f 'bdftools/snftobdf-1.4/snftobdf.man' -a X"$1" != X"-c"; then
	echo 'x - skipping bdftools/snftobdf-1.4/snftobdf.man (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bdftools/snftobdf-1.4/snftobdf.man (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bdftools/snftobdf-1.4/snftobdf.man' &&
.TH SNFTOBDF 1 "Release 4" "X Version 11"
.SH NAME
snftobdf - SNF to BDF font decompiler for X11
.SH SYNOPSIS
.B "snftobdf"
[-p#] [-u#] [-m] [-l] [-M] [-L] [snf-file]
.SH DESCRIPTION
.PP
.B snftobdf
reads a Server Normal Format (SNF) font from the
specified file and writes an X11 Bitmap Distribution Format (BDF) to
standard output.
.SH OPTIONS
.TP 8
.B \-p#
Force the glyph padding to a specific number.  The legal
values are 1, 2, 4, and 8.
.B \-u#
Force the scanline unit padding to a specific number.  The legal
values are 1, 2, and 4.
.TP 8
.B \-m
Force the bit order to most significant bit first.
.TP 8
.B \-l
Force the bit order to least significant bit first.
.TP 8
.B \-M
Force the byte order to most significant bit first.
.TP 8
.B \-L
Force the byte order to least significant bit first.
.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 bdftools/snftobdf-1.4/snftobdf.man ||
echo 'restore of bdftools/snftobdf-1.4/snftobdf.man failed'
Wc_c="`wc -c < 'bdftools/snftobdf-1.4/snftobdf.man'`"
test 1074 -eq "$Wc_c" ||
	echo 'bdftools/snftobdf-1.4/snftobdf.man: original size 1074, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
rm -f _shar_seq_.tmp
echo You have unpacked the last part
exit 0