v09i099: snftobdf, Part01/01
mleisher at NMSU.Edu
mleisher at NMSU.Edu
Wed Oct 17 06:50:20 AEST 1990
Submitted-by: mleisher at NMSU.Edu
Posting-number: Volume 9, Issue 99
Archive-name: snftobdf/part01
My profuse apologies for being a Space Cadet. Full shar file ahead.
Submitted-by: mleisher at nmsu.edu
Archive-name: snftobdf/part01
---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is snftobdf, 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 10/16/1990 20:46 UTC by mleisher at nmsu.edu
# Source directory /tmp_mnt/home/thrinakia1/mleisher/x_stuff/snftobdf
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 261 -rw-rw-r-- Imakefile
# 71 -rw-rw-r-- MANIFEST
# 9724 -rw-rw-r-- Makefile
# 892 -rw-rw-r-- README
# 3881 -rw-rw-r-- input.c
# 5580 -rw-rw-r-- output.c
# 21 -rw-rw-r-- patchlevel.h
# 2278 -rw-rw-r-- snftobdf.c
# 1087 -rw-rw-r-- snftobdf.h
# 1123 -rw-rw-r-- snftobdf.man
#
# ============= 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 SNF to BDF font compiler
#
X SRCS = snftobdf.c input.c output.c
X OBJS1 = snftobdf.o input.o output.o
X INCLUDES = -I. -I$(TOP) -I$(SERVERSRC)/include -I$(SERVERSRC)/ddx/snf
X PROGRAM = snftobdf
X
ComplexProgramTarget(snftobdf)
SHAR_EOF
chmod 0664 Imakefile ||
echo 'restore of Imakefile failed'
Wc_c="`wc -c < 'Imakefile'`"
test 261 -eq "$Wc_c" ||
echo 'Imakefile: original size 261, current size' "$Wc_c"
fi
# ============= MANIFEST ==============
if test -f 'MANIFEST' -a X"$1" != X"-c"; then
echo 'x - skipping MANIFEST (File already exists)'
else
echo 'x - extracting MANIFEST (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'MANIFEST' &&
MANIFEST
X
Makefile
input.c
output.c
snftobdf.c
snftobdf.h
snftobdf.man
SHAR_EOF
chmod 0664 MANIFEST ||
echo 'restore of MANIFEST failed'
Wc_c="`wc -c < 'MANIFEST'`"
test 71 -eq "$Wc_c" ||
echo 'MANIFEST: original size 71, 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.a06881>
# $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$(TOP)
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 = $(CONFIGSRC)
X IMAKE_CMD = $(NEWTOP)$(IMAKE) -I$(NEWTOP)$(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/local/include/X11R4
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 = $(IMAKESRC)/imake
X DEPEND = $(DEPENDSRC)/makedepend
X RGB = $(RGBSRC)/rgb
X FONTC = $(BDFTOSNFSRC)/bdftosnf
X MKFONTDIR = $(MKFONTDIRSRC)/mkfontdir
X MKDIRHIER = /bin/sh $(SCRIPTSRC)/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 = $(EXTENSIONSRC)/lib/libXext.a
X EXTENSIONLIB = $(DEPEXTENSIONLIB)
X
X DEPXLIB = $(DEPEXTENSIONLIB)
X XLIB = $(EXTENSIONLIB) -L$(XLIBSRC) -lX11
X
X DEPXAUTHLIB = $(XAUTHSRC)/libXau.a
X XAUTHLIB = $(DEPXAUTHLIB)
X
X DEPXMULIB =
X XMULIB = -L$(XMUSRC) -lXmu
X
X DEPOLDXLIB =
X OLDXLIB = -L$(OLDXLIBSRC) -loldX
X
X DEPXTOOLLIB =
X XTOOLLIB = -L$(TOOLKITSRC) -lXt
X
X DEPXAWLIB =
X XAWLIB = -L$(AWIDGETSRC) -lXaw
X
X LINTEXTENSIONLIB = $(EXTENSIONSRC)/lib/llib-lXext.ln
X LINTXLIB = $(XLIBSRC)/llib-lX11.ln
X LINTXMU = $(XMUSRC)/llib-lXmu.ln
X LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
X LINTXAW = $(AWIDGETSRC)/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
#
X SRCS = snftobdf.c input.c output.c
X OBJS1 = snftobdf.o input.o output.o
X INCLUDES = -I. -I$(TOP) -I$(SERVERSRC)/include -I$(SERVERSRC)/ddx/snf
X PROGRAM = snftobdf
X
X PROGRAM = snftobdf
X
all:: snftobdf
X
snftobdf: $(OBJS) $(DEPLIBS)
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:: $(DEPEND)
X
$(DEPEND):
X @echo "checking $@ over in $(DEPENDSRC) first..."; \
X cd $(DEPENDSRC); $(MAKE); \
X echo "okay, continuing in $(CURRENT_DIR)"
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:: $(IMAKE)
X
$(IMAKE):
X @(cd $(IMAKESRC); if [ -f Makefile ]; then \
X echo "checking $@ in $(IMAKESRC) first..."; $(MAKE) all; else \
X echo "bootstrapping $@ from Makefile.ini in $(IMAKESRC) first..."; \
X $(MAKE) -f Makefile.ini BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS); fi; \
X echo "okay, continuing in $(CURRENT_DIR)")
X
Makefile::
X - at 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 9724 -eq "$Wc_c" ||
echo 'Makefile: original size 9724, 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' &&
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
X
COMPILATION
X
snftobdf is pretty much self contained except for some header files it
needs from the X11 source. Just change the XSRC variable in Makefile
to point to the location of the mit/ subdirectory in your X11 sources,
and it should compile without problems.
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
Please send fixes or bugs to: mleisher at nmsu.edu
SHAR_EOF
chmod 0664 README ||
echo 'restore of README failed'
Wc_c="`wc -c < 'README'`"
test 892 -eq "$Wc_c" ||
echo 'README: original size 892, current size' "$Wc_c"
fi
# ============= input.c ==============
if test -f 'input.c' -a X"$1" != X"-c"; then
echo 'x - skipping input.c (File already exists)'
else
echo 'x - extracting input.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'input.c' &&
#include <stdio.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;
{
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 input.c ||
echo 'restore of input.c failed'
Wc_c="`wc -c < 'input.c'`"
test 3881 -eq "$Wc_c" ||
echo 'input.c: original size 3881, current size' "$Wc_c"
fi
# ============= output.c ==============
if test -f 'output.c' -a X"$1" != X"-c"; then
echo 'x - skipping output.c (File already exists)'
else
echo 'x - extracting output.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'output.c' &&
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include "snftobdf.h"
X
extern char *program;
X
static int 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 = pixelSize = 0;
X for (i = 0; i < tf->pFI->nProps; i++) {
X 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)
TempFont *tf;
{
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 \"%s %s\"\n", program, SNFTOBDF_VERSION);
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 }
X
X SetSizeAndRes(tf);
X
X if (pixelSize == 0)
X pixelSize = maxBounds->metrics.rightSideBearing +
X maxBounds->metrics.leftSideBearing;
X
X printf("SIZE %d %d %d\n", pixelSize, resX, resY);
X
X b1 = maxBounds->metrics.rightSideBearing -
X minBounds->metrics.leftSideBearing;
X b2 = maxBounds->metrics.ascent +
X maxBounds->metrics.descent;
X b3 = minBounds->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 if (colnum > pFI->lastCol) {
X colnum = pFI->firstCol;
X rownum++;
X }
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)/(pixelSize * 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 output.c ||
echo 'restore of output.c failed'
Wc_c="`wc -c < 'output.c'`"
test 5580 -eq "$Wc_c" ||
echo 'output.c: original size 5580, 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
SHAR_EOF
chmod 0664 patchlevel.h ||
echo 'restore of patchlevel.h failed'
Wc_c="`wc -c < 'patchlevel.h'`"
test 21 -eq "$Wc_c" ||
echo 'patchlevel.h: original size 21, current size' "$Wc_c"
fi
# ============= snftobdf.c ==============
if test -f 'snftobdf.c' -a X"$1" != X"-c"; then
echo 'x - skipping snftobdf.c (File already exists)'
else
echo 'x - extracting snftobdf.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'snftobdf.c' &&
/*
X * Copyright (c) 1990, New Mexico State University
X * Computing Research Lab, Mark Leisher mleisher at nmsu.edu
X *
X * Permission is granted to copy and distribute this file in modified
X * or unmodified form, for noncommercial use, provided (a) this copyright
X * notice is preserved, (b) no attempt is made to restrict redistribution
X * of this file, and (c) this file is not distributed as part of any
X * collection whose redistribution is restricted by a compilation copyright.
X *
X *
X * 'snftobdf' was written using 'showsnf' by RWS of the X Consortium as an
X * example.
X */
X
#include <stdio.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);
X BDFBitmaps(tf, glyphPad);
X BDFTrailer(tf);
X }
X argc--;
X *argv++;
X }
}
SHAR_EOF
chmod 0664 snftobdf.c ||
echo 'restore of snftobdf.c failed'
Wc_c="`wc -c < 'snftobdf.c'`"
test 2278 -eq "$Wc_c" ||
echo 'snftobdf.c: original size 2278, current size' "$Wc_c"
fi
# ============= snftobdf.h ==============
if test -f 'snftobdf.h' -a X"$1" != X"-c"; then
echo 'x - skipping snftobdf.h (File already exists)'
else
echo 'x - extracting snftobdf.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > '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 at nmsu.edu (Mark Leisher)"
#define SNFTOBDF_VERSION "1.0"
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 snftobdf.h ||
echo 'restore of snftobdf.h failed'
Wc_c="`wc -c < 'snftobdf.h'`"
test 1087 -eq "$Wc_c" ||
echo 'snftobdf.h: original size 1087, current size' "$Wc_c"
fi
# ============= snftobdf.man ==============
if test -f 'snftobdf.man' -a X"$1" != X"-c"; then
echo 'x - skipping snftobdf.man (File already exists)'
else
echo 'x - extracting snftobdf.man (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'snftobdf.man' &&
.TH SNFTOBDF 1 "Release 4" "X Version 11"
.SH NAME
sbftobdf - 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 (or from standard input if no file is specified)
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 at nmsu.edu Bitnet: mleisher at 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 snftobdf.man ||
echo 'restore of snftobdf.man failed'
Wc_c="`wc -c < 'snftobdf.man'`"
test 1123 -eq "$Wc_c" ||
echo 'snftobdf.man: original size 1123, current size' "$Wc_c"
fi
exit 0
dan
----------------------------------------------------
O'Reilly && Associates argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list