v04i075: JetRoff Source Code (06 of 7)
root2 at pcrat.UUCP
root2 at pcrat.UUCP
Sun Sep 18 09:11:06 AEST 1988
Posting-number: Volume 4, Issue 75
Submitted-by: "A. Nonymous" <root2 at pcrat.UUCP>
Archive-name: jetroff/src/Part06
#! /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 6 (of 7)."
# Contents: bm/map.c bm/pcpaint.c djet/jetbackup.c
# font/devjet/sfp2pk.c
# Wrapped by rick at pcroe on Sat Aug 27 13:01:13 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'bm/map.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'bm/map.c'\"
else
echo shar: Extracting \"'bm/map.c'\" \(10542 characters\)
sed "s/^X//" >'bm/map.c' <<'END_OF_FILE'
X/*c
X * JetRoff - DWB 2.0 postprocessor for HP LaserJet Series II
X *
X * Copyright (c) 1988 PC Research, Inc. All Rights Reserved.
X *
X * This source code is supplied to you under the terms of the
X * contents of the "License" agreement found with this source
X * distribution. You must read the "License" before you use
X * this source code in any way.
X *
Xc*/
X
Xstatic char Copyright[] =
X"@(#) JetRoff (c) Copyright 1988 PC Research, Inc. All Rights Reserved.";
X
X/*
X * Common main routine for processing bitmap images.
X *
X * This routine should be linked with error.o and a user supplied
X * file containing bitmap specific subroutines and data
X *
X * The user supplied subroutines and data are:
X *
X * map_open(filename, p_xpixels, p_ypixels)
X * char *filename;
X * int *p_xpixels, *p_ypixels);
X * Open "filename", and set *p_xpixels to the number
X * of horizontal pixels in the picture. Set *p_ypixels
X * to the number of vertical scan lines in the picture.
X *
X * map_read(buffer)
X * unsigned char *buffer;
X * "buffer" is an area of memory large enough to
X * hold a two dimensional array with the following
X * dimensions: buffer[ypixels][(xpixels+7)/8].
X * Place the picture into this buffer, scanline by
X * scanline, with 8 pixels per byte. Leftmost pixel
X * is most significant bit in each byte.
X * map_close()
X * do any necessary cleanup (close file, etc.)
X * map_usage()
X * Print any user specific usage information to
X * standard error.
X * map_option(letter, arg)
X * char letter;
X * char *arg;
X * Process option 'letter', with optional argument 'arg'.
X *
X * char map_opts[] = "<whatever>";
X * A "getopt(3)" format string of user specific options
X * which map_option() will accept.
X *
X * The global flag:
X * int debug;
X * will be non-zero if the '-D' option has been listed. The user supplied
X * routines may use this flag for debugging purposes.
X */
X
X/*
X * $Id: map.c,v 1.1 88/08/26 23:26:23 rick Exp $
X *
X * $Log: map.c,v $
X * Revision 1.1 88/08/26 23:26:23 rick
X * Initial revision
X *
X */
X#ifndef lint
Xstatic char rcsid[] = "$Id: map.c,v 1.1 88/08/26 23:26:23 rick Exp $";
X#endif
X
X#include <stdio.h>
X#include <string.h>
X#include <memory.h>
X#include <values.h>
X
Xextern map_open();
Xextern map_read();
Xextern map_close();
Xextern map_usage();
Xextern map_option();
Xextern char map_opts[];
X
X#define Printf (void) printf
X#define Fprintf (void) fprintf
X#define Putchar (void) putchar
X
Xint debug = 0;
Xint hp_flag = 0;
X
X/*
X * rotation, mirroring, and clipping is done in the
X * order specified on the command line. Multiple
X * appearances of the options are allowed, so
X *
X * pcpaint -a90 -i -a270 -i
X * pcpaint -a180
X * do the same thing
X */
Xint complement = 0; /* -c */
Xint angle = 0; /* -a */
Xint mirror = 0; /* -i */
Xint rclip = 0; /* -r */
Xint lclip = 0; /* -l */
Xint tclip = 0; /* -t */
Xint bclip = 0; /* -b */
X
Xchar map_comopts[] = "?cHDSia:r:l:t:b:";
X
Xchar *argv0;
X
Xmain(argc, argv)
Xchar *argv[];
X{
X register int i;
X extern char *optarg;
X extern int optind;
X int c;
X int size_flag = 0;
X char *optbuf;
X
X char *malloc();
X void exit();
X void free();
X int xpixels;
X int xbytes;
X int ypixels;
X long xybytes;
X int cxpixels;
X int cypixels;
X unsigned char *pic;
X
X argv0 = argv[0];
X
X optbuf = (char *) malloc( (unsigned)
X strlen(map_comopts) + strlen(map_opts) + 1);
X (void) strcpy(optbuf, map_comopts);
X (void) strcat(optbuf, map_opts);
X
X while ((c = getopt(argc, argv, optbuf)) != EOF)
X switch (c)
X {
X case 'S':
X size_flag = 1;
X break;
X case 'D':
X debug = 1;
X break;
X case 'H':
X hp_flag = 1;
X break;
X case 'c':
X complement = !complement;
X break;
X case 'i':
X add_mirror(mirror ? 0 : 1);
X break;
X case 'a':
X i = atoi(optarg);
X if (i < 0) i += 360;
X if (i != 0 && i != 270 && i != 90 && i != 180)
X error(1,
X "angle must be 0, 90, 180, or 270");
X add_angle(i);
X break;
X case 'r':
X i = atoi(optarg);
X add_clip(i, 0, 0, 0);
X break;
X case 'l':
X i = atoi(optarg);
X add_clip(0, i, 0, 0);
X break;
X case 't':
X i = atoi(optarg);
X add_clip(0, 0, i, 0);
X break;
X case 'b':
X i = atoi(optarg);
X add_clip(0, 0, 0, i);
X break;
X case '?':
X map_comusage();
X map_usage();
X (void) exit(0);
X default:
X (void) map_option(c, optarg);
X break;
X }
X (void) free(optbuf);
X
X if (optind >= argc)
X {
X map_comusage();
X map_usage();
X error(1, "Missing bitmap file name");
X }
X
X (void) map_open(argv[optind], &xpixels, &ypixels);
X
X if (debug)
X Fprintf(stderr, "Picture is %d X %d pixels\n",
X xpixels, ypixels);
X
X if (angle == 90 || angle == 270)
X {
X cxpixels = ypixels - lclip - rclip;
X cypixels = xpixels - tclip - bclip;
X }
X else
X {
X cxpixels = xpixels - lclip - rclip;
X cypixels = ypixels - tclip - bclip;
X }
X
X if (!hp_flag)
X {
X (void) putw(cxpixels, stdout);
X (void) putw(cypixels, stdout);
X }
X else if (debug)
X {
X Fprintf(stderr, "Final Picture is %d X %d pixels\n",
X cxpixels, cypixels);
X }
X
X if (size_flag)
X {
X map_close();
X (void) exit(0);
X }
X
X xbytes = (xpixels+7)/8;
X xybytes = (long) xbytes * (long) ypixels;
X i = MAXINT;
X if (xybytes > i)
X error(1, "%ld byte bitmap exceeds machine limitation of %d",
X xybytes, i);
X pic = (unsigned char *) malloc( (unsigned int) xybytes );
X (void) memset((char *) pic, 0, (int) xybytes);
X if (!pic)
X error(1, "couldn't get %ld bytes to hold bitmap", xybytes);
X
X (void) map_read(pic);
X
X map_out(pic, xpixels, ypixels);
X
X map_close();
X
X (void) exit(0);
X /* NOTREACHED */
X}
X
Xadd_clip(r, l, t, b)
X{
X rclip += r;
X lclip += l;
X tclip += t;
X bclip += b;
X}
X
Xadd_angle(a)
X{
X register int tl = lclip;
X register int tr = rclip;
X register int tt = tclip;
X register int tb = bclip;
X
X if (debug)
X Fprintf(stderr, "l=%3d r=%3d t=%3d b=%3d a=%3d ",
X lclip, rclip, tclip, bclip, angle);
X
X switch (a + mirror)
X {
X case 0:
X case 1:
X break;
X case 91:
X a = 360 - a;
X case 90:
X tclip = tr;
X lclip = tt;
X bclip = tl;
X rclip = tb;
X break;
X case 181:
X case 180:
X tclip = tb;
X lclip = tr;
X bclip = tt;
X rclip = tl;
X break;
X case 271:
X a = 360 - a;
X case 270:
X tclip = tl;
X lclip = tb;
X bclip = tr;
X rclip = tt;
X break;
X }
X angle += a;
X if (angle >= 360) angle -= 360;
X if (debug)
X Fprintf(stderr, "l=%3d r=%3d t=%3d b=%3d a=%3d\n",
X lclip, rclip, tclip, bclip, angle);
X}
X
Xadd_mirror(m)
X{
X register int t;
X
X t = rclip;
X rclip = lclip;
X lclip = t;
X mirror = m;
X}
X
Xmap_out(pic, xpixels, ypixels)
Xunsigned char *pic;
Xint xpixels;
Xint ypixels;
X{
X register int x, y;
X register int xbytes = (xpixels+7)/8;
X int v;
X int b;
X int t;
X int xs, xe;
X int ys, ye;
X static char setbit[8] = {128, 64, 32, 16, 8, 4, 2, 1};
X# define getbit(x, y) (pic[(y)*xbytes+((x)>>3)]&setbit[(x)&7])
X
X if (hp_flag) Printf("\033*t150R\033*r1A");
X /*
X * Four angles, two mirrors, two complements
X * Enumerate the cases for efficiency
X */
X switch (angle)
X {
X case 0:
X xs = lclip; xe = xpixels - rclip;
X ys = tclip; ye = ypixels - bclip;
X if (!mirror)
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(x, y);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X else /* mirror */
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(xpixels-x-1, y);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X break;
X case 90:
X xs = lclip; xe = ypixels - rclip;
X ys = tclip; ye = xpixels - bclip;
X if (!mirror)
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(xpixels-y-1, x);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X else /* mirror */
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(xpixels-y-1, ypixels-x-1);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X break;
X case 180:
X xs = lclip; xe = xpixels - rclip;
X ys = tclip; ye = ypixels - bclip;
X if (!mirror)
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(xpixels-x-1, ypixels-y-1);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X else /* mirror */
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(x, ypixels-y-1);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X break;
X case 270:
X xs = lclip; xe = ypixels - rclip;
X ys = tclip; ye = xpixels - bclip;
X if (!mirror)
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(y, ypixels-x-1);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X else /* mirror */
X for (y = ys; y < ye; ++y)
X {
X if (hp_flag) Printf("\033*b%dW", (xe-xs+7)/8);
X for (v=b=0, x = xs; x < xe; ++x)
X {
X t = getbit(y, x);
X if ( (complement && !t)
X || (!complement && t) )
X v |= setbit[b];
X if (++b == 8) { Putchar(v); b=v=0; }
X }
X if (b) Putchar(v);
X }
X break;
X }
X
X if (hp_flag) Printf("\033*rB");
X}
X
Xstatic char *use[] =
X{
X "Generic Options:",
X " -aANGLE Rotate bitmap counterclockwise ANGLE degrees",
X " -c Complement bitmap",
X " -i Flip left-right (mirror image) bitmap",
X " -rPIXELS Clip PIXELS off right edge",
X " -lPIXELS Clip PIXELS off left edge",
X " -tLINES Clip LINES off top edge",
X " -bLINES Clip LINES off bottom edge",
X " -H HP PCL to standard output (for testing)",
X " -S Size information only",
X " -D Debugging mode",
X "Format Specific Options:",
X NULL
X};
X
Xmap_comusage()
X{
X register int i;
X
X Fprintf(stderr, "\nUsage: %s [options] file\n\n", argv0);
X for (i = 0; use[i]; ++i)
X Fprintf(stderr, "%s\n", use[i]);
X}
END_OF_FILE
if test 10542 -ne `wc -c <'bm/map.c'`; then
echo shar: \"'bm/map.c'\" unpacked with wrong size!
fi
# end of 'bm/map.c'
fi
if test -f 'bm/pcpaint.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'bm/pcpaint.c'\"
else
echo shar: Extracting \"'bm/pcpaint.c'\" \(11092 characters\)
sed "s/^X//" >'bm/pcpaint.c' <<'END_OF_FILE'
X/*c
X * JetRoff - DWB 2.0 postprocessor for HP LaserJet Series II
X *
X * Copyright (c) 1988 PC Research, Inc. All Rights Reserved.
X *
X * This source code is supplied to you under the terms of the
X * contents of the "License" agreement found with this source
X * distribution. You must read the "License" before you use
X * this source code in any way.
X *
Xc*/
X
X/*
X * PC Paint Plus v 2.0 bitmap reader
X */
X
X/*
X * $Id: pcpaint.c,v 1.1 88/08/26 23:26:25 rick Exp $
X *
X * $Log: pcpaint.c,v $
X * Revision 1.1 88/08/26 23:26:25 rick
X * Initial revision
X *
X */
X#ifndef lint
Xstatic char rcsid[] = "$Id: pcpaint.c,v 1.1 88/08/26 23:26:25 rick Exp $";
X#endif
X
X#include <stdio.h>
X#include <string.h>
X
Xextern int debug;
X
X#define Fread (void) fread
X#define Fprintf (void) fprintf
X
Xtypedef unsigned char uchar;
Xtypedef unsigned short ushort;
X
Xunsigned short getushort()
X{
X register int v;
X
X v = (unsigned short) getchar();
X v += (unsigned short) getchar()<<8;
X return v;
X}
X
Xushort magic;
Xushort xpixels;
Xushort xbytes;
Xushort ypixels;
Xushort xoffset;
Xushort yoffset;
Xuchar bits_per_pixel;
Xuchar extra_bit_planes;
Xuchar extra_info;
Xuchar video_mode;
Xchar *modes[] =
X{
X "320 x 200 x 4",
X "320 x 200 x 16",
X "640 x 200 x 2",
X "640 x 200 x 16",
X "640 x 350 x 2",
X "640 x 350 x 4",
X "640 x 350 x 16",
X "720 x 200 x 2",
X};
Xushort descriptor;
Xushort extra_count;
Xuchar palette;
Xuchar background;
Xuchar color_regs[16];
Xushort packed_blocks;
Xint clipping_bytes;
X
Xshort x, y;
Xchar lookup[256] =
X{
X 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
X};
X
Xchar *filename;
Xuchar *pic;
X
Xmap_open(fname, p_xpixels, p_ypixels)
Xchar *fname;
Xint *p_xpixels;
Xint *p_ypixels;
X{
X uchar byte1, byte2;
X char *p;
X extern FILE *myreopen();
X
X if ( myreopen(filename = fname, "r", stdin,
X "JETMAPS", STD) == NULL)
X {
X error(1, "Couldn't find bitmap file '%s'", filename);
X }
X
X p = strchr(fname, '.');
X
X byte1 = getchar();
X byte2 = getchar();
X if (p && strncmp(p, ".clp", 4) == 0)
X { /* Clipping file */
X magic = 0;
X clipping_bytes = byte1 + (byte2<<8);
X xpixels = getushort();
X ypixels = getushort();
X }
X else if (byte1 == 0x34 && byte2 == 0x12)
X {
X if (debug)
X Fprintf(stderr, ".pic is a packed page file\n");
X magic = 0x1234; /* 2.0 packed page file */
X xpixels = getushort();
X ypixels = getushort();
X }
X else if (byte1 == 0xfd)
X {
X xpixels = 320;
X ypixels = 200;
X bits_per_pixel = 2;
X magic = 0xfd;
X byte1 = getchar();
X }
X else if (byte1 == 0xfe)
X error(1, "Can't handle pcpaint 1.5 format");
X else
X error(1, "Can't handle unknown format");
X if (debug)
X Fprintf(stderr, ".pic is %d x %d pixels\n", xpixels, ypixels);
X *p_xpixels = xpixels;
X *p_ypixels = ypixels;
X return (0);
X}
X
Xmap_read(picbuf)
Xunsigned char *picbuf;
X{
X pic = picbuf;
X xbytes = (xpixels+7)/8;
X switch (magic)
X {
X case 0: return map_read_clipping();
X case 0xfd: return map_read_bsave();
X case 0x1234: return map_read_1234();
X }
X return (0);
X}
X
X# ifdef ERR_SEG_OVERWRITE
X# define PIC_OR(X,Y) { register int _b; \
X _b = map[X&7]; \
X pic[ Y*xbytes + (X>>3) ] |= _b; }
X# else
X# define PIC_OR(X,Y) pic[ Y*xbytes + (X>>3) ] |= map[X&7]
X# endif
X
Xmap_read_bsave()
X{
X short buffer_size;
X uchar c;
X int pixels_per_byte = 8/bits_per_pixel;
X static uchar bmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
X static uchar map[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
X int mask = bmask[bits_per_pixel];
X register int xx;
X
X xoffset = getushort();
X buffer_size = getushort();
X# ifdef lint
X x = buffer_size;
X# endif
X for (y = 0; y < ypixels; y += 2)
X {
X for (xx = 0; xx < xpixels; xx += pixels_per_byte)
X {
X register int pn;
X c = getchar();
X for (pn = (pixels_per_byte-1)*bits_per_pixel;
X pn >= 0; pn -= bits_per_pixel)
X if (lookup[ (c>>pn) & mask ])
X PIC_OR(xx, y);
X }
X }
X (void) fseek(stdin, 8199L, 0);
X for (y = 1; y < ypixels; y += 2)
X {
X for (xx = 0; xx < xpixels; xx += pixels_per_byte)
X {
X register int pn;
X c = getchar();
X for (pn = (pixels_per_byte-1)*bits_per_pixel;
X pn >= 0; pn -= bits_per_pixel)
X if (lookup[ (c>>pn) & mask ])
X PIC_OR(xx, y);
X }
X }
X return 0;
X}
X
Xmap_read_1234()
X{
X xoffset = getushort();
X yoffset = getushort();
X if (debug)
X Fprintf(stderr,".pic is offset by (%d, %d)\n",xoffset, yoffset);
X bits_per_pixel = getchar();
X extra_bit_planes = (bits_per_pixel >> 4) & 0x0f;
X bits_per_pixel &= 0x0f;
X if (debug)
X Fprintf(stderr,".pic has %d bits/pixel, %d additional planes\n",
X bits_per_pixel, extra_bit_planes);
X extra_info = getchar();
X if (extra_info != 0xff)
X error(1, "'%s' is not a PC Paint Plus 2.0 picture", filename);
X video_mode = getchar();
X if (debug)
X Fprintf(stderr, ".pic video mode is %s\n",
X modes[video_mode - 'A']);
X descriptor = getushort();
X switch (descriptor)
X {
X case 0:
X extra_count = getushort();
X break;
X case 1:
X extra_count = getushort();
X palette = getchar();
X background = getchar();
X if (debug)
X Fprintf(stderr, ".pic palette = %d, background = %d\n",
X palette, background);
X extra_count -= 2;
X break;
X case 2:
X case 3:
X extra_count = getushort();
X Fread((char *) color_regs, sizeof(color_regs), 1, stdin);
X extra_count -= sizeof(color_regs);
X if (debug)
X {
X Fprintf(stderr,".pic colors: %2d %2d %2d %2d %2d %2d %2d %2d\n",
X color_regs[0], color_regs[1], color_regs[2],
X color_regs[3], color_regs[4], color_regs[5],
X color_regs[6], color_regs[7]);
X Fprintf(stderr," %2d %2d %2d %2d %2d %2d %2d %2d\n",
X color_regs[8], color_regs[9], color_regs[10],
X color_regs[11], color_regs[12], color_regs[13],
X color_regs[14], color_regs[15]);
X }
X break;
X }
X (void) fseek(stdin, (long) extra_count, 1);
X packed_blocks = getushort();
X if (debug)
X Fprintf(stderr,".pic %d packed blocks\n", packed_blocks);
X
X if (packed_blocks)
X {
X x = 0;
X y = ypixels - 1; /* Picture is packed upside down */
X while (packed_blocks--)
X unpack();
X }
X else
X { /* Unpacked format */
X uchar c;
X int pixels_per_byte = 8/bits_per_pixel;
X static uchar bmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
X static uchar map[8] =
X {0x80,0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
X int mask = bmask[bits_per_pixel];
X for (y = ypixels - 1; y >= 0; --y)
X for (x = 0; x < xbytes; ++x)
X {
X register int pn;
X c = getchar();
X for (pn = (pixels_per_byte-1)*bits_per_pixel;
X pn >= 0; pn -= bits_per_pixel)
X if (lookup[ (c>>pn) & mask ])
X PIC_OR(x, y);
X }
X }
X
X return(0);
X}
X
Xmap_read_clipping()
X{
X xoffset = getushort();
X yoffset = getushort();
X bits_per_pixel = getchar();
X if (bits_per_pixel == 0xff)
X { /* packed */
X bits_per_pixel = getchar();
X if (debug)
X Fprintf(stderr,".clp packed, %d bits per pixel\n",
X bits_per_pixel);
X x = 0;
X y = ypixels - 1; /* Picture is packed upside down */
X clipping_bytes -= 12;
X unpack_clipping();
X }
X else
X { /* unpacked */
X Fprintf(stderr,".clp unpacked, %d bits per pixel\n",
X bits_per_pixel);
X error(1, "Can't handle unpacked clippings");
X }
X return 0;
X}
Xunpack_clipping()
X{
X uchar marker;
X int pixels_per_byte = 8/bits_per_pixel;
X static uchar bmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
X int mask = bmask[bits_per_pixel];
X
X marker = getchar(); --clipping_bytes;
X if (debug) Fprintf(stderr, ".clp marker %d\n", marker);
X/* clipping_bytes -=100;*/
X while (clipping_bytes > 0)
X {
X uchar c;
X uchar n;
X ushort nn;
X
X c = getchar(); --clipping_bytes;
X if (c == marker)
X {
X n = getchar(); --clipping_bytes;
X if (n == 0)
X {
X nn = getushort(); clipping_bytes -= 2;
X }
X else
X nn = n;
X c = getchar(); -- clipping_bytes;
X }
X else
X nn = 1;
X while (nn--)
X {
X register int pn;
X for (pn = (pixels_per_byte-1)*bits_per_pixel;
X pn >= 0; pn -= bits_per_pixel)
X {
X /* Fprintf(stderr, "%02x ", p); */
X bit(lookup[ (c>>pn) & mask ]);
X }
X }
X }
X if (clipping_bytes)
X {
X error(1, "Short bytes unpacking '%s'. Got %d\n",
X filename, clipping_bytes);
X }
X}
X
Xmap_close()
X{
X}
X
Xchar map_opts[] = "p:";
X
Xmap_option(letter, optarg)
Xchar letter;
Xchar *optarg;
X{
X switch (letter)
X {
X case 'p':
X do_palette(optarg);
X break;
X default:
X return (1);
X }
X return (0);
X}
X
Xmap_usage()
X{
X Fprintf(stderr,
X" -pPLIST (for color pics) pixel values in PLIST are black\n");
X Fprintf(stderr,
X" PLIST format is 1,2,3 or 1-15 or 1,7-15\n");
X}
X
Xunpack()
X{
X ushort PackedSize;
X ushort unPackedSize;
X uchar marker;
X register int bytes = 0;
X int pixels_per_byte = 8/bits_per_pixel;
X static uchar bmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
X int mask = bmask[bits_per_pixel];
X
X PackedSize = getushort();
X unPackedSize = getushort();
X marker = getchar();
X if (debug)
X Fprintf(stderr,
X ".pic packed size %d, unpacked size %d, marker %d\n",
X PackedSize, unPackedSize, marker);
X PackedSize -= 5;
X while (PackedSize != 0)
X {
X uchar c;
X uchar n;
X ushort nn;
X
X c = getchar();
X PackedSize -= sizeof(c);
X if (c == marker)
X {
X n = getchar();
X PackedSize -= sizeof(n);
X if (n == 0)
X {
X nn = getushort();
X PackedSize -= sizeof(nn);
X }
X else
X nn = n;
X c = getchar();
X PackedSize -= sizeof(c);
X }
X else
X nn = 1;
X while (nn--)
X {
X register int pn;
X ++bytes;
X for (pn = (pixels_per_byte-1)*bits_per_pixel;
X pn >= 0; pn -= bits_per_pixel)
X {
X /* Fprintf(stderr, "%02x ", p); */
X bit(lookup[ (c>>pn) & mask ]);
X/*
X if (pflag)
X {
X color( (c>>pn) & mask );
X point(x, ypixels-1-y);
X }
X*/
X }
X }
X }
X if (bytes != unPackedSize)
X {
X error(1, "Short bytes unpacking '%s'. Got %d wanted %d\n",
X filename, bytes, unPackedSize);
X }
X /* (void) fseek(stdin, (long) PackedSize, 1); */
X}
X
X
Xbit(on)
X{
X static uchar map[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
X
X if (y < 0)
X error(1, "Y tried to go negative in '%s'", filename);
X if (on)
X PIC_OR(x, y);
X ++x;
X if (x >= (xbytes<<3) )
X {
X x = 0;
X --y;
X }
X}
X
X/*
X * convert list like 1,2,3-15 into on values for pallete
X */
Xdo_palette(s)
Xchar *s;
X{
X char *n1, *n2;
X int dash;
X register int i, f, l;
X
X if (s == NULL) return;
X for (i = 0; i < sizeof(lookup)/sizeof(lookup[0]); ++i)
X lookup[i] = 0;
X n1 = n2 = NULL; dash = 0;
X for(;;)
X switch (*s++)
X {
X case '0': case '1': case '2': case '3': case '4':
X case '5': case '6': case '7': case '8': case '9':
X if (!n1) n1 = &s[-1];
X else if (!n2) n2 = &s[-1];
X break;
X case '-':
X dash = 1; n2 = NULL;
X break;
X case ',':
X case '\0':
X if (dash)
X {
X if (n2 == NULL)
X l = 255;
X else
X l = atoi(n2) & 255;
X f = atoi(n1) & 255;
X for (i = f; i <= l; ++i)
X lookup[i] = 1;
X }
X else if (*n1)
X {
X i = atoi(n1) & 255;
X lookup[i] = 1;
X }
X n1 = n2 = NULL; dash = 0;
X if (!s[-1]) goto out;
X break;
X }
Xout:
X return;
X}
END_OF_FILE
if test 11092 -ne `wc -c <'bm/pcpaint.c'`; then
echo shar: \"'bm/pcpaint.c'\" unpacked with wrong size!
fi
# end of 'bm/pcpaint.c'
fi
if test -f 'djet/jetbackup.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'djet/jetbackup.c'\"
else
echo shar: Extracting \"'djet/jetbackup.c'\" \(9205 characters\)
sed "s/^X//" >'djet/jetbackup.c' <<'END_OF_FILE'
X/*c
X * JetRoff - DWB 2.0 postprocessor for HP LaserJet Series II
X *
X * Copyright (c) 1988 PC Research, Inc. All Rights Reserved.
X *
X * This source code is supplied to you under the terms of the
X * contents of the "License" agreement found with this source
X * distribution. You must read the "License" before you use
X * this source code in any way.
X *
Xc*/
X
Xstatic char Copyright[] =
X"@(#) JetRoff (c) Copyright 1988 PC Research, Inc. All Rights Reserved.";
X
X/*
X *
X * ljbackup [-wWIDTH] [-b]
X *
X * read standard input and repaginate
X * for two-on-one and backed up landscape output
X * That is, output:
X * page 1, xoffset 0
X * page 3, xoffset WIDTH/2
X * page 4, xoffset 0
X * page 2, xoffset WIDTH/2
X *
X * -b makes last sheet say "this page intentionally left blank"
X *
X * This program is at best a kludge!
X */
X
X/*
X * $Id: jetbackup.c,v 1.1 88/08/26 23:10:57 rick Exp $
X *
X * $Log: jetbackup.c,v $
X * Revision 1.1 88/08/26 23:10:57 rick
X * Initial revision
X *
X */
X#ifndef lint
Xstatic char rcsid[] = "@(#) $Id: jetbackup.c,v 1.1 88/08/26 23:10:57 rick Exp $";
X#endif
X
X#include <stdio.h>
X#include <string.h>
X
X#define Printf (void) printf
X#define Fprintf (void) fprintf
X#define Putchar (void) putchar
X#define Fputc (void) fputc
X#define Fputs (void) fputs
X
Xint PageWidth = 14*300;
Xint Blank = 0;
XFILE *page2fp;
Xchar *page2name;
X
Xmain(argc, argv)
Xchar *argv[];
X{
X register int c;
X extern char *optarg;
X extern int optind;
X double w;
X extern double atof();
X extern char *tmpnam();
X extern void exit();
X
X while ((c = getopt(argc, argv, "bw:")) != EOF)
X switch (c)
X {
X case 'w':
X w = atof(optarg);
X if (strchr(optarg, 'd')) PageWidth = w*300/720;
X else if (strchr(optarg, 'p')) PageWidth = w*300/72;
X else PageWidth = w * 300;
X break;
X case 'b':
X Blank = 1;
X break;
X }
X
X page2name = tmpnam( (char *) NULL);
X
X backup(stdin);
X exit(0);
X /* NOTREACHED */
X}
X
Xbackup(fp)
XFILE *fp;
X{
X for (;;)
X {
X if (page_one(fp) == EOF)
X {
X if (Blank)
X {
X Putchar('\f');
X intentional(2);
X }
X return;
X }
X
X if (page_two(fp) == EOF)
X {
X Putchar('\f');
X dump_two();
X return;
X }
X
X if (page_three(fp) == EOF)
X {
X Putchar('\f');
X dump_two();
X if (Blank) intentional(4);
X return;
X }
X Putchar('\f');
X
X if (page_four(fp) == EOF)
X {
X dump_two();
X return;
X }
X dump_two();
X Putchar('\f');
X }
X}
X
Xpage_one(fp)
XFILE *fp;
X{
X register int c;
X register int state = 0;
X
X while ( (c = fgetc(fp)) != EOF)
X {
X switch (state)
X {
X case 0:
X if (c == '\f') return (1);
X if (c == '\033') state = '\033';
X else
X Putchar(c);
X break;
X case '\033':
X if (c >= 48 && c <= 126)
X {
X Putchar('\033');
X Putchar(c);
X }
X else if (c >= 33 && c <= 47)
X {
X if (do_esc(stdout, fp, c, 0) == EOF)
X return EOF;
X }
X else
X burp(state, c);
X state = 0;
X break;
X }
X }
X return EOF;
X}
X
Xdo_esc(outfp, infp, intro, shift)
XFILE *outfp;
XFILE *infp;
Xchar intro;
Xint shift;
X{
X register int c;
X register int i;
X char groupc;
X int nparms;
X char parms[16][64];
X char *parmp[16];
X char parmc[16];
X register int state = 'g';
X int x;
X double atof();
X int sbincount = 0;
X int obincount = 0;
X int oany = 0;
X int sany = 0;
X
X/* Fprintf(stderr, "do_esc %c\n", intro); */
X while ( (c = fgetc(infp)) != EOF)
X {
X/* Fprintf(stderr, "%c %d\n", c, c); */
X switch (state)
X {
X case 'g':
X state = 'v';
X nparms = 0;
X parmp[nparms] = parms[nparms];
X *parmp[nparms] = 0;
X if (c < 96 || c > 126)
X groupc = 0;
X else
X {
X groupc = c;
X break;
X }
X /* FALL THRU */
X case 'v':
X if ( (c >= 48 && c <= 57)
X || c == '+' || c == '-' || c == '.')
X {
X *parmp[nparms]++ = c;
X *parmp[nparms] = 0;
X }
X else if (c >= 96 && c <= 126)
X {
X parmc[nparms] = c;
X ++nparms;
X parmp[nparms] = parms[nparms];
X *parmp[nparms] = 0;
X }
X else if (c >= 64 && c <= 94)
X {
X parmc[nparms] = c;
X ++nparms;
X goto wade;
X }
X else
X burp(state, c);
X break;
X }
X }
X return EOF;
X
Xwade:
X for (i = 0; i < nparms; ++i)
X {
X switch (parmc[i])
X {
X case 'w': case 'W':
X if (groupc == 's' && (intro == '(' || intro == ')') )
X { /* Font desc or character */
X sbincount += atoi(parms[i]);
X /* Make sure font is available */
X if (!sany)
X {
X Fputc('\033', stdout);
X Fputc(intro, stdout);
X if (groupc) Fputc(groupc, stdout);
X sany = 1;
X }
X Fputs(parms[i], stdout);
X Fputc(parmc[i], stdout);
X }
X else if (groupc == 'b' && intro == '*')
X { /* Raster transfer */
X obincount += atoi(parms[i]);
X goto dull;
X }
X else
X goto dull;
X break;
X case 'd': case 'D':
X case 'f': case 'F':
X case 'e': case 'E':
X if (intro == '*' && groupc == 'c')
X { /* Font manangement */
X /* Make sure font is available */
X if (!sany)
X {
X Fputc('\033', stdout);
X Fputc(intro, stdout);
X if (groupc) Fputc(groupc, stdout);
X sany = 1;
X }
X Fputs(parms[i], stdout);
X Fputc(parmc[i], stdout);
X }
X else
X goto dull;
X break;
X case 'h': case 'H':
X if (intro == '&' && groupc == 'l')
X {
X if (parms[i][0] != '0')
X {
X parms[i][0] = '2';
X parms[i][1] = 0;
X }
X }
X else if (intro == '&' && groupc == 'a' && shift)
X { /* Must be series 1, decipoint pos */
X if (parms[i][0] == '+' || parms[i][0] == '-')
X goto dull; /* Relative motion boring */
X x = PageWidth*6;
X x /= 5;
X x += atoi(parms[i]);
X if (!oany)
X {
X Fputc('\033', outfp);
X Fputc(intro, outfp);
X if (groupc) Fputc(groupc, outfp);
X oany = 1;
X }
X Fprintf(outfp, "%d%c", x, parmc[i]);
X/*
XFprintf(stderr, "Motion %s changed to %d%c\n", parms[i], x, parmc[i]);
X*/
X }
X goto dull;
X case 'x': case 'X':
X if (intro != '*' || groupc != 'p')
X goto dull;
X if (!shift) goto dull;
X if (parms[i][0] == '+' || parms[i][0] == '-')
X goto dull; /* Relative motion boring */
X /* Must be series 2, dot pos */
X x = atoi(parms[i]) + PageWidth/2;
X if (!oany)
X {
X Fputc('\033', outfp);
X Fputc(intro, outfp);
X if (groupc) Fputc(groupc, outfp);
X oany = 1;
X }
X Fprintf(outfp, "%d%c", x, parmc[i]);
X/*
XFprintf(stderr, "Motion %s changed to %d%c\n", parms[i], x, parmc[i]);
X*/
X break;
X default:
Xdull:
X if (!oany)
X {
X Fputc('\033', outfp);
X Fputc(intro, outfp);
X if (groupc) Fputc(groupc, outfp);
X oany = 1;
X }
X Fputs(parms[i], outfp);
X Fputc(parmc[i], outfp);
X break;
X }
X }
X while (sbincount--)
X {
X c = fgetc(infp);
X if (c == EOF)
X burp(state, c);
X else
X Fputc(c, stdout);
X }
X while (obincount--)
X {
X c = fgetc(infp);
X if (c == EOF)
X burp(state, c);
X else
X Fputc(c, outfp);
X }
X return (1);
X}
X
Xpage_two(fp)
XFILE *fp;
X{
X register int c;
X register int state = 0;
X
X page2fp = fopen(page2name, "w");
X while ( (c = fgetc(fp)) != EOF)
X {
X switch (state)
X {
X case 0:
X if (c == '\f')
X {
X (void) fclose(page2fp);
X return (1);
X }
X if (c == '\033') state = '\033';
X else Fputc(c, page2fp);
X break;
X case '\033':
X if (c >= 48 && c <= 126)
X {
X Fputc('\033', page2fp);
X Fputc(c, page2fp);
X }
X else if (c >= 33 && c <= 47)
X {
X if (do_esc(page2fp, fp, c, 1) == EOF)
X goto eof;
X }
X else
X burp(state, c);
X state = 0;
X break;
X }
X }
Xeof:
X (void) fclose(page2fp);
X return (EOF);
X}
X
Xdump_two()
X{
X register int c;
X
X if (page2fp == NULL) return;
X page2fp = fopen(page2name, "r");
X while ( (c = fgetc(page2fp)) != EOF)
X Putchar(c);
X (void) fclose(page2fp);
X (void) unlink(page2name);
X page2fp = NULL;
X}
X
Xpage_three(fp)
XFILE *fp;
X{
X register int c;
X register int state = 0;
X
X while ( (c = fgetc(fp)) != EOF)
X {
X switch (state)
X {
X case 0:
X if (c == '\f') return (1);
X if (c == '\033') state = '\033';
X else Putchar(c);
X break;
X case '\033':
X if (c >= 48 && c <= 126)
X {
X Putchar('\033');
X Putchar(c);
X }
X else if (c >= 33 && c <= 47)
X {
X if (do_esc(stdout, fp, c, 1) == EOF)
X return EOF;
X }
X else
X burp(state, c);
X state = 0;
X break;
X }
X }
X return EOF;
X}
X
Xpage_four(fp)
XFILE *fp;
X{
X register int c;
X register int state = 0;
X
X while ( (c = fgetc(fp)) != EOF)
X {
X switch (state)
X {
X case 0:
X if (c == '\f') return (1);
X if (c == '\033') state = '\033';
X else Putchar(c);
X break;
X case '\033':
X if (c >= 48 && c <= 126)
X {
X Putchar('\033');
X Putchar(c);
X }
X else if (c >= 33 && c <= 47)
X {
X if (do_esc(stdout, fp, c, 0) == EOF)
X return EOF;
X }
X else
X burp(state, c);
X state = 0;
X break;
X }
X }
X return EOF;
X}
X
Xburp(state, c)
X{
X Fprintf(stderr, "Burp state=%c %d, char=%c %d\n",
X state, state, c, c);
X exit(1);
X /* NOTREACHED */
X}
X
X/*
X * Page two or four is blank!
X */
Xintentional(page)
X{
X static char msg[] = "This Page Intentionally Left Blank";
X register int mdots;
X
X# if SERIES == 1
X Printf("\033*p%dV", 4*720);
X# else
X Printf("\033*p%dY", 4*300);
X# endif
X mdots = strlen(msg) * 300;
X mdots /= 17;
X# if SERIES == 1
X {
X register int x;
X if (page == 4)
X x = (PageWidth/4) - mdots/2;
X else
X x = (PageWidth*3/4) - mdots/2;
X x *= 12; x /= 5;
X Printf("\033*p%dH", x);
X }
X# else
X if (page == 4)
X Printf("\033*p%dX", (PageWidth/4) - mdots/2 );
X else
X Printf("\033*p%dX", (PageWidth*3/4) - mdots/2 );
X# endif
X Printf("\033(s0t17H%c", 15);
X Printf("%s", msg);
X}
END_OF_FILE
if test 9205 -ne `wc -c <'djet/jetbackup.c'`; then
echo shar: \"'djet/jetbackup.c'\" unpacked with wrong size!
fi
# end of 'djet/jetbackup.c'
fi
if test -f 'font/devjet/sfp2pk.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'font/devjet/sfp2pk.c'\"
else
echo shar: Extracting \"'font/devjet/sfp2pk.c'\" \(15857 characters\)
sed "s/^X//" >'font/devjet/sfp2pk.c' <<'END_OF_FILE'
X/*c
X * JetRoff - DWB 2.0 postprocessor for HP LaserJet Series II
X *
X * Copyright (c) 1988 PC Research, Inc. All Rights Reserved.
X *
X * This source code is supplied to you under the terms of the
X * contents of the "License" agreement found with this source
X * distribution. You must read the "License" before you use
X * this source code in any way.
X *
Xc*/
X
X#ifndef lint
Xstatic char Copyright[] =
X"@(#) JetRoff (c) Copyright 1988 PC Research, Inc. All Rights Reserved.";
X#endif
X
X/*
X * sfp2pk:
X * Convert hp soft font to TeX pk format
X *
X * WARNING: THIS ROUTINE HASN'T PASSED LINT YET, AND
X * PROBABLY WON'T WORK ON ANY 16 BIT CPU OR CPU WITH
X * BYTE ORDERING DIFFERENT FROM THE 80386.
X */
X
X/*
X * $Id: sfp2pk.c,v 1.1 88/08/27 00:00:09 rick Exp $
X *
X * $Log: sfp2pk.c,v $
X * Revision 1.1 88/08/27 00:00:09 rick
X * Initial revision
X *
X */
X#ifndef lint
Xstatic char rcsid[] = "@(#) $Id: sfp2pk.c,v 1.1 88/08/27 00:00:09 rick Exp $";
X#endif
X
X#include <stdio.h>
X
X#define Fprintf (void) fprintf
Xextern char *malloc();
Xextern void free();
Xextern void exit();
X
Xtypedef unsigned char uchar;
Xtypedef unsigned short ushort;
X
X#include "lj.h"
X
XLJ_FONT_DESC *fd = NULL;
Xchar *FontName;
Xchar *FontExtra;
XLJ_CHAR_DESC *cd = NULL;
Xuchar *CharData;
Xint CurCode;
Xint NumCodes = 0;
Xint Swap;
X
Xextern long pk_loc;
Xint only_code = 0;
Xint force_bitmap = 0;
X
Xusage()
X{
X Fprintf(stderr,
X "Usage: sfp2pk [-b -oN] <HP_Soft_Font >PackedPixelFont\n");
X Fprintf(stderr,
X "\n -b Force bitmap only output (no compression)\n");
X Fprintf(stderr,
X "\n -oNN Output only character code NN\n");
X exit(1);
X}
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X register int state = 0;
X register int c = 0;
X extern int optind;
X extern char *optarg;
X
X Swap = need_swap();
X
X while ((c = getopt(argc, argv, "h?o:bc")) != EOF)
X switch (c)
X {
X case 'o': only_code = atoi(optarg);
X break;
X case 'b':
X force_bitmap = 1;
X break;
X case 'c':
X force_bitmap = 0;
X break;
X default:
X usage();
X break;
X }
X
X while ( (c = getchar()) != EOF)
X {
X switch (state)
X {
X case 0:
X if (c == '\033') state = 1;
X break;
X case 1:
X switch (c)
X {
X case ')':
X font_desc();
X break;
X case '*':
X char_code();
X break;
X case '(':
X char_desc();
X break;
X default:
X burp("", c);
X break;
X }
X state = 0;
X break;
X }
X }
X
X postamble();
X Fprintf(stderr, "%d codes converted\n", NumCodes);
X Fprintf(stderr, "%ld bytes written\n", pk_loc);
X exit(0);
X /* NOTREACHED */
X}
X
Xneed_swap()
X{
X ushort x = 0x1122;
X uchar *xl = (uchar *) &x;
X if (*xl == 0x22) return 1;
X else return 0;
X}
X
Xswap(sp)
Xushort *sp;
X{
X register uchar t;
X register uchar *p = (uchar *) sp;
X
X if (Swap) { t = p[0]; p[0] = p[1]; p[1] = t; }
X}
X
Xburp(sofar, bad)
Xchar *sofar;
X{
X Fprintf(stderr, "Something in there I don't like: '%s_", sofar);
X if (bad >= ' ' && bad <= 126)
X Fprintf(stderr, "%c'\n", bad);
X else
X Fprintf(stderr, "%02x'\n", bad);
X exit(1);
X /* NOTREACHED */
X}
X
Xfont_desc()
X{
X register int c;
X int len;
X
X if ((c = getchar()) != 's') burp(")", c);
X if (scanf("%d", &len) != 1) burp(")s", len);
X if ((c = getchar()) != 'W') burp(")s#", c);
X
X if (fd) free(fd);
X fd = (LJ_FONT_DESC *) malloc( (unsigned) len);
X (void) fread(fd, len, 1, stdin);
X
X swap(&fd->font_desc_size);
X swap(&fd->r2);
X swap(&fd->baseline_dist);
X swap(&fd->cell_width);
X swap(&fd->cell_height);
X swap(&fd->symbol_set);
X swap(&fd->pitch);
X swap(&fd->height);
X swap(&fd->xheight);
X if (fd->font_desc_size >= FONT_DESC_SIZE)
X { /* Newer format */
X swap(&fd->r4);
X swap(&fd->text_height);
X swap(&fd->text_width);
X swap(&fd->r5);
X swap(&fd->r6);
X swap(&fd->r7);
X swap(&fd->r8);
X swap(&fd->r9);
X FontName = ( (char *) fd) + 48;
X }
X else
X FontName = ( (char *) fd) + 26;
X FontExtra = ( (char *) fd) + fd->font_desc_size;
X
X write_preamble();
X}
X
Xchar_code()
X{
X register int c;
X
X if ((c = getchar()) != 'c') burp("*", c);
X if (scanf("%d", &CurCode) != 1) burp("*c", CurCode);
X if ((c = getchar()) != 'E') burp("*c#", c);
X}
X
Xchar_desc()
X{
X int c;
X int len;
X
X if ((c = getchar()) != 's') burp("(", c);
X if (scanf("%d", &len) != 1) burp("(s", len);
X if ((c = getchar()) != 'W') burp("(s#", c);
X
X if (cd) free(cd);
X cd = (LJ_CHAR_DESC *) malloc( (unsigned) len);
X (void) fread(cd, len, 1, stdin);
X swap( (ushort *) &cd->left_offset);
X swap( (ushort *) &cd->top_offset);
X swap(&cd->char_width);
X swap(&cd->char_height);
X swap( (ushort *) &cd->delta_x);
X
X CharData = ( (uchar *) cd) + cd->char_desc_size + 2;
X
X if (!only_code || CurCode == only_code)
X {
X ship_character();
X ++NumCodes;
X }
X}
X
X/*************************************************************************
XThe rest of this was lifted from PASCAL.
XDon't complain to me about the crudeness of the data structures.
XSomeday, I'll make a decent algorithm here.
X*************************************************************************/
X
X
X#define MAX_MEM_SIZE 8000
X#define ONE_FOURTH 1073741824
X
Xlong pk_loc;
X
Xpk_byte(b)
Xint b;
X{
X (void) putchar(b); ++pk_loc;
X}
X
Xpk_halfword(h)
Xint h;
X{
X pk_byte(h>>8);
X pk_byte(h);
X}
X
Xpk_three_bytes(l)
Xlong l;
X{
X pk_byte( (int) (l>>16));
X pk_byte( (int) (l>>8));
X pk_byte( (int) (l));
X}
X
Xpk_word(l)
Xlong l;
X{
X pk_byte( (int) (l>>24));
X pk_byte( (int) (l>>16));
X pk_byte( (int) (l>>8));
X pk_byte( (int) (l));
X}
X
Xlong bit_weight;
Xlong output_byte;
X
Xpk_nyb(n)
X{
X if (bit_weight == 16)
X {
X output_byte = n * 16;
X bit_weight = 1;
X }
X else
X {
X pk_byte( (int) (output_byte + n));
X bit_weight = 16;
X }
X}
X
Xlong mem[MAX_MEM_SIZE];
Xint next_mem_free;
X
Xwrite_preamble()
X{
X long l;
X int i, n;
X
X pk_loc = 0;
X
X pk_byte(247);
X pk_byte(89);
X n = strlen(FontName); if (n > 16) n = 16;
X pk_byte(n);
X for (i = 0; i < n; ++i)
X pk_byte(FontName[i]);
X
X l = fd->height*72;
X l /= 4;
X l = (l+150)/300; /* Rounded points */
X pk_word( (long) l << 20); /* Design size */
X pk_word(0L); /* Checksum */
X l = 300L;
X l <<= 16;
X l = ((double) l) / 72.27;
X pk_word( (long) l); /* Pixels per point */
X pk_word( (long) l);
X
X}
X
Xint car;
Xlong width;
Xlong height;
Xlong c_x_off;
Xlong c_y_off;
X
X
Xequal(row1, row2)
X{
X register int i;
X
X for (i = width; i > 0; ++row1, ++row2, i -= 32)
X {
X if (mem[row1] != mem[row2])
X return 0;
X }
X return 1;
X}
X
Xmove_char()
X{
X register int i;
X register int j;
X register int row;
X register int words = ((cd->char_width+31)/32);
X register int bytes = ((cd->char_width+7)/8);
X
X next_mem_free = 0;
X for (row = 0; row < cd->char_height; ++row)
X {
X for (i = 0, j = 0; i < words; ++i, j += 4)
X {
X mem[row*words+i] = 0;
X if (j < bytes)
X mem[row*words+i] += CharData[row*bytes+j];
X mem[row*words+i] <<= 8;
X if (j+1 < bytes)
X mem[row*words+i] += CharData[row*bytes+j+1];
X mem[row*words+i] <<= 8;
X if (j+2 < bytes)
X mem[row*words+i] += CharData[row*bytes+j+2];
X mem[row*words+i] <<= 8;
X if (j+3 < bytes)
X mem[row*words+i] += CharData[row*bytes+j+3];
X }
X next_mem_free += words;
X }
X}
X
Xlong power[32] =
X{
X 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
X 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000,
X 0x00010000, 0x00020000, 0x00040000, 0x00080000,
X 0x00100000, 0x00200000, 0x00400000, 0x00800000,
X 0x01000000, 0x02000000, 0x04000000, 0x08000000,
X 0x10000000, 0x20000000, 0x40000000, 0x80000000
X};
X
X#define black 1
X#define white 0
X#define end_of_glyph 2
X
Xship_character()
X{
X int c_raster;
X int word_width;
X long comp_size;
X int hor_esc;
X long tfm_width;
X
X int i, j, k;
X int zero_row;
X int ones_row;
X int repeat_pointer;
X int bit_counts;
X
X int count;
X int test;
X int cur_ptr;
X int bit;
X int repeat_flag;
X long word;
X int bit_ptr;
X int bit_mod_32;
X int cur_repeat;
X int end_raster;
X
X int dyn_f;
X long deriv[14];
X long b_comp_size;
X int first_on;
X int flag_byte;
X int state;
X int on;
X
X int h_bit;
X int p_bit;
X int r_on;
X int s_on;
X int r_count;
X int s_count;
X int r_i;
X int s_i;
X int max_2;
X int pred_pk_loc;
X int buff;
X
X /*
X * Move character data into mem array for algorithm simulation
X */
X move_char();
X power[0] = 1;
X for (i = 1; i <= 30; ++i)
X power[i] = power[i-1] * 2;
X power[31] = -power[i-1] - power[i-1];
X
X tfm_width = 0;
X hor_esc = cd->delta_x/4;
X width = cd->char_width;
X height = cd->char_height;
X car = CurCode;
X c_x_off = - cd->left_offset;
X c_y_off = cd->top_offset;
X
X c_raster = 0;
X word_width = (width+31)/32;
X
X /* Create repeat list */
X zero_row = next_mem_free;
X ones_row = next_mem_free + word_width;
X repeat_pointer = ones_row + word_width;
X bit_counts = repeat_pointer + height + 1;
X
X for (i = zero_row; i < ones_row; ++i) mem[i] = 0;
X for (i = ones_row; i <= (repeat_pointer-2); ++i) mem[i] = -1;
X i = width % 32;
X if (i == 0)
X mem[repeat_pointer - 1] = -1;
X else if (i == 1)
X mem[repeat_pointer - 1] = -ONE_FOURTH - ONE_FOURTH;
X else
X mem[repeat_pointer - 1] = -power[32 - i];
X
X for (i = 0, j = height; i < j; ++i)
X {
X if (equal(i*word_width+c_raster, zero_row))
X mem[repeat_pointer + i] = 0;
X else if (equal(i*word_width+c_raster, ones_row))
X mem[repeat_pointer + i] = 0;
X else if ( (i+1) == j)
X mem[repeat_pointer + i] = 0;
X else if (equal(i*word_width+c_raster,(i+1)*word_width+c_raster))
X mem[repeat_pointer + i] = 1;
X else
X mem[repeat_pointer + i] = 0;
X }
X for (i = 0, j = height; i < j; )
X {
X k = i;
X while (mem[repeat_pointer + k] == 1) ++k;
X mem[repeat_pointer + i] = k - i;
X i = k + 1;
X }
X mem[repeat_pointer + i] = 0;
X /* END Create repeat list */
X
X /* Create bit counts */
X repeat_flag = 0;
X bit_ptr = width - 1;
X cur_repeat = repeat_pointer;
X end_raster = c_raster + height * word_width;
X cur_ptr = bit_counts;
X count = 0;
X test = white;
X do
X {
X /* Get a bit, skipping repeated rows */
X ++bit_ptr;
X if (bit_ptr == width)
X {
X bit_mod_32 = 0;
X bit_ptr = 0;
X if (mem[cur_repeat] > 0)
X {
X repeat_flag = mem[cur_repeat];
X cur_repeat += repeat_flag;
X c_raster += word_width * repeat_flag;
X }
X ++cur_repeat;
X }
X --bit_mod_32;
X if (bit_mod_32 == -1)
X {
X bit_mod_32 = 31;
X word = mem[c_raster++];
X }
X if (c_raster > end_raster) bit = end_of_glyph;
X else if (bit_mod_32 == 31)
X {
X if (word < 0)
X {
X bit = black;
X word += ONE_FOURTH + ONE_FOURTH;
X }
X else
X bit = white;
X }
X else
X {
X if (word >= power[bit_mod_32])
X {
X word -= power[bit_mod_32];
X bit = black;
X }
X else
X bit = white;
X }
X /* END Get a bit, skipping repeated rows */
X
X if (bit == test) ++count;
X else
X {
X mem[cur_ptr++] = count;
X if (cur_ptr +3 > MAX_MEM_SIZE) (void) abort();
X count = 1;
X test = bit;
X if (repeat_flag > 0)
X {
X mem[cur_ptr++] = -repeat_flag;
X repeat_flag = 0;
X }
X }
X } while (test != end_of_glyph);
X mem[cur_ptr] = 0;
X mem[cur_ptr+1] = 0;
X /* END Create bit counts */
X
X /* Calc dynf and packed size and write character */
X for (i = 1; i <= 13; ++i) deriv[i] = 0;
X first_on = mem[bit_counts] == 0;
X if (first_on) ++bit_counts;
X i = bit_counts;
X comp_size = 0;
X while (mem[i])
X {
X /* Process count for best dyn_f value */
X j = mem[i];
X if (j == -1) ++comp_size;
X else
X {
X if (j < 0)
X {
X ++comp_size;
X j = -j;
X }
X if (j < 209) comp_size += 2;
X else
X {
X k = j - 193;
X while (k >= 16)
X {
X k /= 16;
X comp_size += 2;
X }
X comp_size++;
X }
X if (j < 14) --deriv[j];
X else if (j < 209) ++deriv[(223-j)/15];
X else
X {
X k = 16;
X while ( (k*16) < (j+3) ) k *= 16;
X if ( (j-k) <= 192)
X deriv[(207-j+k)/15] += 2;
X }
X }
X ++i;
X /* END Process count for best dyn_f value */
X }
X b_comp_size = comp_size;
X dyn_f = 0;
X for (i = 1; i <= 13; ++i)
X {
X comp_size += deriv[i];
X if (comp_size <= b_comp_size)
X {
X b_comp_size = comp_size;
X dyn_f = i;
X }
X }
X comp_size = (b_comp_size + 1) / 2;
X if (force_bitmap)
X comp_size = 99999999;
X if (comp_size > ((height*width + 7)/8) || (height*width) == 0)
X {
X comp_size = (height * width + 7) / 8;
X dyn_f = 14;
X }
X
X /* Write character preamble */
X flag_byte = dyn_f * 16;
X if (first_on) flag_byte += 8;
X if (tfm_width > 16777215L || tfm_width < 0
X || hor_esc < 0 || comp_size > 196579L || width > 65536L ||
X height > 65535L || c_x_off > 32767 || c_y_off > 32767 ||
X c_x_off < -32768 || c_y_off < -32768)
X {
X /* Write Long Preamble */
X flag_byte += 7;
X pk_byte(flag_byte);
X comp_size += 28;
X pk_word( (long) comp_size);
X pk_word( (long) car);
X pred_pk_loc = pk_loc + comp_size;
X pk_word( (long) tfm_width);
X pk_word( (long) hor_esc * 65536L);
X pk_word(0L);
X pk_word( (long) width);
X pk_word( (long) height);
X pk_word( (long) c_x_off);
X pk_word( (long) c_y_off);
X /* END Write Long Preamble */
X }
X else if (hor_esc > 255 || width > 255 || height > 255 ||
X c_x_off > 127 || c_x_off < -128 || c_y_off > 127 ||
X c_y_off < -128 || comp_size > 1016)
X {
X /* Write two-byte short Preamble */
X comp_size += 13;
X flag_byte += comp_size/65536L + 4;
X pk_byte(flag_byte);
X pk_halfword( (int) (comp_size & 65535L));
X pk_byte(car);
X pred_pk_loc = pk_loc + comp_size;
X pk_three_bytes(tfm_width);
X pk_halfword( (int) hor_esc);
X pk_halfword( (int) width);
X pk_halfword( (int) height);
X pk_halfword( (int) c_x_off);
X pk_halfword( (int) c_y_off);
X
X /* END Write two-byte short Preamble */
X }
X else
X {
X /* Write one-byte short Preamble */
X comp_size += 8;
X flag_byte += comp_size/256;
X pk_byte(flag_byte);
X pk_byte( (int) (comp_size & 255));
X pk_byte(car);
X pred_pk_loc = pk_loc + comp_size;
X pk_three_bytes(tfm_width);
X pk_byte( (int) hor_esc);
X pk_byte( (int) width);
X pk_byte( (int) height);
X pk_byte( (int) c_x_off);
X pk_byte( (int) c_y_off);
X /* END Write one-byte short Preamble */
X }
X /* END Write character preamble */
X
X if (dyn_f != 14)
X {
X /* Send compressed format */
X bit_weight = 16;
X max_2 = 208 - 15 * dyn_f;
X i = bit_counts;
X while (mem[i])
X {
X j = mem[i];
X if (j == -1) pk_nyb(15);
X else
X {
X if (j < 0)
X {
X pk_nyb(14);
X j = -j;
X }
X if (j <= dyn_f) pk_nyb(j);
X else if (j <= max_2)
X {
X j = j - dyn_f - 1;
X pk_nyb(j/16 + dyn_f + 1);
X pk_nyb(j % 16);
X }
X else
X {
X j = j - max_2 + 15;
X k = 16;
X while (k <= j)
X {
X k *= 16;
X pk_nyb(0);
X }
X while (k > 1)
X {
X k /= 16;
X pk_nyb(j/k);
X j %= k;
X }
X }
X }
X ++i;
X }
X if (bit_weight != 16) pk_byte( (int) output_byte);
X /* END Send compressed format */
X }
X else
X {
X /* Send bit map */
X buff = 0;
X p_bit = 8;
X i = bit_counts;
X h_bit = width;
X on = !first_on;
X state = 0;
X count = 0;
X repeat_flag = 0;
X while (mem[i] != 0 || state || count > 0)
X {
X if (state)
X {
X count = r_count; i = r_i; on = r_on;
X --repeat_flag;
X }
X else
X {
X r_count = count; r_i = i; r_on = on;
X }
X /* Send one row by bits */
X do
X {
X if (count == 0)
X {
X if (mem[i] < 0)
X {
X if (!state)
X repeat_flag = -mem[i];
X ++i;
X }
X count = mem[i++];
X on = !on;
X }
X if (count >= p_bit && p_bit < h_bit)
X {
X if (on)
X buff = buff + power[p_bit] - 1;
X pk_byte(buff); buff = 0;
X h_bit -= p_bit;
X count -= p_bit;
X p_bit = 8;
X }
X else if (count < p_bit && count < h_bit)
X {
X if (on)
X buff = buff + power[p_bit] -
X power[p_bit-count];
X p_bit -= count;
X h_bit -= count;
X count = 0;
X }
X else
X {
X if (on)
X buff = buff + power[p_bit] -
X power[p_bit-h_bit];
X count -= h_bit;
X p_bit -= h_bit;
X h_bit = width;
X if (p_bit == 0)
X {
X pk_byte(buff);
X buff = 0;
X p_bit = 8;
X }
X }
X } while (h_bit != width);
X /* END Send one row by bits */
X if (state && repeat_flag == 0)
X {
X count = s_count; i = s_i; on = s_on;
X state = 0;
X }
X else if (!state && repeat_flag > 0)
X {
X s_count = count; s_i = i; s_on = on;
X state = 1;
X }
X }
X if (p_bit != 8) pk_byte(buff);
X /* END Send bit map */
X }
X if (pred_pk_loc != pk_loc) (void) abort();
X /* END Calc dynf and packed size and write character */
X}
X
X
Xpostamble()
X{
X pk_byte(245);
X while (pk_loc & 3)
X pk_byte(246);
X}
END_OF_FILE
if test 15857 -ne `wc -c <'font/devjet/sfp2pk.c'`; then
echo shar: \"'font/devjet/sfp2pk.c'\" unpacked with wrong size!
fi
# end of 'font/devjet/sfp2pk.c'
fi
echo shar: End of archive 6 \(of 7\).
cp /dev/null ark6isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 7 archives.
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
More information about the Comp.sources.misc
mailing list