[comp.sources.mac] pktor.c - convert PK font file to RMaker source

gae@osupyr.UUCP (Gerald Edgar) (01/30/88)

[pktor.c - convert PK font file to RMaker source]

pktor.c   A program that runs under UNIX, and converts a (Rokicki-type)
PK font file to the RMaker source for the corresponding Macintosh font.

  Gerald A. Edgar                               TS1871@OHSTVMA.bitnet
  Department of Mathematics                     gae@osupyr.UUCP
  The Ohio State University  ...{akgua,gatech,ihnp4,ulysses}!cbosgd!osupyr!gae
  Columbus, OH 43210                            70715,1324  CompuServe

---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	read.me
#	pktor.c
# This archive created: Tue Dec 22 08:07:50 1987
export PATH; PATH=/bin:$PATH
if test -f 'read.me'
then
	echo shar: will not over-write existing file "'read.me'"
else
sed 's/^X//' << \SHAR_EOF > 'read.me'
XSome comments on the TeX to Macintosh font converter
X
Xpktor.c is the source for a program that runs on a UNIX machine.  It takes
Xas input a PK font file, and produces as output an RMaker source file
Xfor the corresponding Macintosh font.  It should work in other UNIX-like
Xenvironments, such as the MPW shell.
X
XSample usage:
X
X          pktor cmr10.144pk cmr10.r cmr10 190
X
XThis will take a PK file cmr10.144pk and convert it to an RMaker
Xsource file cmr10.r containing the source for (one size of) a font
Xcmr10 with font number 190.  (The PK file can be made using gftopk or
Xpxtopk, both of which should come with the standard TeX distribution.)
XThen RMaker can be used to produce a font file (a "suitcase" file).
XWhen Font/DA Mover puts this font into another file, a FOND resource
Xwill be created for it.
X
XMacintosh fonts are of limited size: some of the pointers involved are
X16 bits only.  So if you try to convert a big font you may get nonsense.
XI tried to produce a 144 dpi version of cminch; no good.  So I have to content
Xmyself with a 72 dpi version.
X
XTo produce a 144 dpi font using METAFONT, I have used the following mode
Xdefinition.  With this small size, it will probably take a bit of
Xtouching-up by hand.  The worst cases seem to be the smaller italic fonts,
Xlike cmti5 and cmmi5.
X
X% mode for Imagewriter (144 dots per inch)
Xmode_def imagewriter =
X  pixels_per_inch := 144;
X  blacker := 0;
X  o_correction := .2;
X  fillin := 0;
X  proofing := 0;
X  fontmaking := 1;
X  tracingtitles := 1; enddef;
Xmode=imagewriter;
X
XThe character with hex code $20 (the ASCII space) is repeated as the
X"undefined" character.  I have done this since I have not yet figured
Xout how to make QuickDraw actually draw character $20.  So I can ask
XQuickDraw to draw character $80 instead.
SHAR_EOF
fi # end of overwriting check
if test -f 'pktor.c'
then
	echo shar: will not over-write existing file "'pktor.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pktor.c'
X
X/* pktor.c by G. Edgar [ based on pktype.c by tomas rokicki ] */
X#define VERSION "1.1  9/9/86"
X
X/*
Xsample usage:
X          pktor cmr10.144pk cmr10.r cmr10 190
XThis will take a PK file cmr10.155pk and convert it to an RMaker
Xsource file cmr10.r containing the source for (one size of) a font
Xcmr10 with font number 190.  The PK file can be made using gftopk or
Xpxtopk, both of which should come with the standard TeX distribution.
X*/
X
X#include <stdio.h>
X#define namelength 80 
X#define terminallinelength 132 
X#define incr(a) a++
X#define decr(a) a--
X#define true (1)
X#define false (0)
X#define round(a) ((integer)(a+.5))
X#define sendout(a,b) zsendout((boolean)(a),(int)(b))
X#define max(a,b) (((a)>(b))?(a):(b))
X
Xchar * malloc(), * strcpy();
X  typedef long integer ;
X  typedef unsigned char quarterword ;
X  typedef char boolean ;
X  typedef double real ;
X  typedef quarterword ASCIIcode ; 
X  typedef FILE *textfile ; 
X  typedef quarterword eightbits ; 
X  typedef FILE *bytefile ; 
X  ASCIIcode xord[128] ; 
X  char xchr[256] ; 
X  textfile outfile ; 
X  bytefile pkfile ; 
X  char pkname[81] ;
X  char outname[81];
X  integer pkloc ; 
X  integer termpos ; 
X  integer magnification ; 
X  integer designsize ; 
X  integer checksum ; 
X  integer hppp, vppp ; 
X  integer i, j ; 
X  int flagbyte ; 
X  integer endofpacket ; 
X  integer width, height ; 
X  integer xoff, yoff ; 
X  integer tfmwidth ; 
X  integer dx, dy ; 
X  integer dynf ; 
X  integer car ; 
X  integer packetlength ; 
X  eightbits inputbyte ; 
X  eightbits bitweight ; 
X  integer repeatcount ; 
X  integer rowsleft ; 
X  boolean turnon ; 
X  integer hbit ; 
X  integer count ; 
X  integer gargc ;
X  char **gargv ;
X  int hp,wp;
X  int xcount;
X  int firstchar,lastchar,widmax,kernmax,frectwidth,frectheight,ascent;
X  int descent,leading,charwid,charoff,charas,chardes;
X  int loctable[131];
X  int owtable[131];
X  char fname[100];
X  int fsize,fnumber,owtloc,rowwords,column,showplus,rowbits;
X  char nyb[] = "0123456789ABCDEF";
X  int pass2 = 0;
X  int hbitx,vbit;
X/* short bitimage[MAXROWS][MAXROWWORDS]; */
X  short * pbitim;
X#define bitimage(x,y) pbitim[(long)(x) * rowwords + (long)(y)]
X
X  initialize () { int i ;
X    for ( i = 0 ; i < 131 ; i++)
X	  {
X	  loctable[i] = 0;
X	  owtable[i] = -1;
X	  }
X    for ( i = 0 ; i <= 31 ; i ++ ) xchr [ i ] = '?' ; 
X      xchr [ 32 ] = ' ' ; 
X    xchr [ 33 ] = '!' ; 
X    xchr [ 34 ] = '"' ; 
X    xchr [ 35 ] = '#' ; 
X    xchr [ 36 ] = '$' ; 
X    xchr [ 37 ] = '%' ; 
X    xchr [ 38 ] = '&' ; 
X    xchr [ 39 ] = '\'' ; 
X    xchr [ 40 ] = '(' ; 
X    xchr [ 41 ] = ')' ; 
X    xchr [ 42 ] = '*' ; 
X    xchr [ 43 ] = '+' ; 
X    xchr [ 44 ] = ',' ; 
X    xchr [ 45 ] = '-' ; 
X    xchr [ 46 ] = '.' ; 
X    xchr [ 47 ] = '/' ; 
X    xchr [ 48 ] = '0' ; 
X    xchr [ 49 ] = '1' ; 
X    xchr [ 50 ] = '2' ; 
X    xchr [ 51 ] = '3' ; 
X    xchr [ 52 ] = '4' ; 
X    xchr [ 53 ] = '5' ; 
X    xchr [ 54 ] = '6' ; 
X    xchr [ 55 ] = '7' ; 
X    xchr [ 56 ] = '8' ; 
X    xchr [ 57 ] = '9' ; 
X    xchr [ 58 ] = ':' ; 
X    xchr [ 59 ] = ';' ; 
X    xchr [ 60 ] = '<' ; 
X    xchr [ 61 ] = '=' ; 
X    xchr [ 62 ] = '>' ; 
X    xchr [ 63 ] = '?' ; 
X    xchr [ 64 ] = '@' ; 
X    xchr [ 65 ] = 'A' ; 
X    xchr [ 66 ] = 'B' ; 
X    xchr [ 67 ] = 'C' ; 
X    xchr [ 68 ] = 'D' ; 
X    xchr [ 69 ] = 'E' ; 
X    xchr [ 70 ] = 'F' ; 
X    xchr [ 71 ] = 'G' ; 
X    xchr [ 72 ] = 'H' ; 
X    xchr [ 73 ] = 'I' ; 
X    xchr [ 74 ] = 'J' ; 
X    xchr [ 75 ] = 'K' ; 
X    xchr [ 76 ] = 'L' ; 
X    xchr [ 77 ] = 'M' ; 
X    xchr [ 78 ] = 'N' ; 
X    xchr [ 79 ] = 'O' ; 
X    xchr [ 80 ] = 'P' ; 
X    xchr [ 81 ] = 'Q' ; 
X    xchr [ 82 ] = 'R' ; 
X    xchr [ 83 ] = 'S' ; 
X    xchr [ 84 ] = 'T' ; 
X    xchr [ 85 ] = 'U' ; 
X    xchr [ 86 ] = 'V' ; 
X    xchr [ 87 ] = 'W' ; 
X    xchr [ 88 ] = 'X' ; 
X    xchr [ 89 ] = 'Y' ; 
X    xchr [ 90 ] = 'Z' ; 
X    xchr [ 91 ] = '[' ; 
X    xchr [ 92 ] = '\\' ; 
X    xchr [ 93 ] = ']' ; 
X    xchr [ 94 ] = '^' ; 
X    xchr [ 95 ] = '_' ; 
X    xchr [ 96 ] = '`' ; 
X    xchr [ 97 ] = 'a' ; 
X    xchr [ 98 ] = 'b' ; 
X    xchr [ 99 ] = 'c' ; 
X    xchr [ 100 ] = 'd' ; 
X    xchr [ 101 ] = 'e' ; 
X    xchr [ 102 ] = 'f' ; 
X    xchr [ 103 ] = 'g' ; 
X    xchr [ 104 ] = 'h' ; 
X    xchr [ 105 ] = 'i' ; 
X    xchr [ 106 ] = 'j' ; 
X    xchr [ 107 ] = 'k' ; 
X    xchr [ 108 ] = 'l' ; 
X    xchr [ 109 ] = 'm' ; 
X    xchr [ 110 ] = 'n' ; 
X    xchr [ 111 ] = 'o' ; 
X    xchr [ 112 ] = 'p' ; 
X    xchr [ 113 ] = 'q' ; 
X    xchr [ 114 ] = 'r' ; 
X    xchr [ 115 ] = 's' ; 
X    xchr [ 116 ] = 't' ; 
X    xchr [ 117 ] = 'u' ; 
X    xchr [ 118 ] = 'v' ; 
X    xchr [ 119 ] = 'w' ; 
X    xchr [ 120 ] = 'x' ; 
X    xchr [ 121 ] = 'y' ; 
X    xchr [ 122 ] = 'z' ; 
X    xchr [ 123 ] = '{' ; 
X    xchr [ 124 ] = '|' ; 
X    xchr [ 125 ] = '}' ; 
X    xchr [ 126 ] = '~' ; 
X    for ( i = 127 ; i <= 255 ; i ++ ) xchr [ i ] = '?' ; 
X      for ( i = 0 ; i <= 127 ; i ++ ) xord [ ( i ) ] = 32 ; 
X      for ( i = 32 ; i <= 126 ; i ++ ) xord [ xchr [ i ] ] = i ;
X	firstchar = 256;
X	lastchar = 0;
X	widmax = 0;
X	kernmax = 0;
X	frectwidth = 0;
X	frectheight = 0;
X	ascent = 0;
X	descent = 0;
X	leading = 0;
X      }
X	  
X  jumpout () {
X    (void)fclose(pkfile);
X    (void)fclose(outfile);
X    exit ( 1 ) ; 
X    }
X	
X  openoutfile () { 
X    outfile = fopen (outname, "w"); 
X    }
X	
X  openpkfile () {
X    pkfile = fopen ( pkname , "r" ) ; 
X    pkloc = 0 ; 
X    }
X	
X  integer pkbyte () {
X    incr ( pkloc ) ; 
X    return ( 255L & getc ( pkfile ) ) ; 
X    } 
X  integer get16 () { integer a ; 
X    a = pkbyte () ; 
X    return ( a * 256L + pkbyte () ) ; 
X    } 
X  integer get32 () { integer a ; 
X    a = get16 () ; 
X    if ( a > 32767L ) a = a - 65536L ; 
X    return ( a * 65536L + get16 () ) ; 
X    } 
X  integer getnyb () { eightbits temp ; 
X    if ( bitweight == 0 ) 
X    { inputbyte = pkbyte () ; 
X      bitweight = 16 ; 
X      } 
X    temp = inputbyte / bitweight ; 
X    inputbyte = inputbyte - temp * bitweight ; 
X    bitweight = bitweight / 16 ; 
X    return ( temp ) ; 
X    } 
X  boolean getbit () { boolean temp ; 
X    bitweight = bitweight / 2 ; 
X    if ( bitweight == 0 ) 
X    { inputbyte = pkbyte () ; 
X      bitweight = 128 ; 
X      } 
X    temp = inputbyte >= bitweight ; 
X    if ( temp ) inputbyte = inputbyte - bitweight ; 
X    return ( temp ) ; 
X    }
X
X  zsendout ( repeatcount , value ) 
X  boolean repeatcount ; 
X  int value ; 
X  { 
X	if ( repeatcount )
X	  xcount = value;
X    else if ( turnon )
X	  for ( ; value > 0 ; value--)
X	    xout(1); 
X    else
X	  for ( ; value > 0 ; value--)
X	    xout(0) ; 
X    }
X
Xxout(x)
X  int x;
X  {
X  xx(wp,hp,x);
X  wp++;
X  if (wp >= width)
X    {
X	hp++;
X	while (xcount)
X	  {
X	  for (wp = 0 ; wp < width ; wp++)
X	    xx(wp,hp,xy(wp,hp-1));
X	  hp++;
X	  xcount--;
X	  }
X	wp = 0;
X	}
X/*
X  if (hp >= height)
X    {
X	for (hp = 0 ; hp < height ; hp++)
X	  {
X	  printf(" |");
X	  for (wp = 0 ; wp < width ; wp++)
X	    {
X		if (xy(wp,hp) == 1)
X		  printf("<>");
X		else if (xy(wp,hp) == 0)
X		  printf("  ");
X		else
X		  printf("??");
X		}
X	  printf("|\n");
X	  }
X	}
X*/
X  }
X
Xxx(w,h,x)
X  int w,h,x;
X  {
X  w += hbitx;
X  h += vbit;
X  bitimage(h,w/16) |= (x << (15-w%16)) ;
X  }
X
Xxy(w,h)
X  int w,h;
X  {
X  int x;
X  w += hbitx;
X  h += vbit;
X  x = ((bitimage(h,w/16) & 1<<(15-w%16)) != 0) ;
X  return x;
X  }
X  
X  integer pkpackednum () { integer i, j; 
X    i = getnyb () ; 
X    if ( i == 0 ) 
X    { do { j = getnyb () ; 
X        incr ( i ) ; 
X        } while ( ! ( j != 0 ) ) ; 
X      while ( i > 0 ) 
X        { j = j * 16 + getnyb () ; 
X          decr ( i ) ; 
X          } 
X        return ( j - 15 + ( 13 - dynf ) * 16 + dynf ) ; 
X      } 
X    else if ( i <= dynf ) return ( i ) ; 
X    else if ( i < 14 ) return ( ( i - dynf - 1 ) * 16 + getnyb () + dynf + 1 
X    ) ; 
X    else 
X    { if ( repeatcount != 0 ) 
X      { ; 
X        printf ( " Second repeat count for this row!\n" ) ; 
X        jumpout () ; 
X        } 
X      if ( i == 14 ) repeatcount = pkpackednum () ; 
X      else repeatcount = 1 ; 
X      sendout ( true , repeatcount ) ; 
X      return ( pkpackednum () ) ; 
X      } 
X    }
X	
X  skipspecials () { integer i, j; int cc; 
X    do { flagbyte = pkbyte () ; 
X      if ( flagbyte >= 240 ) switch ( flagbyte ) 
X      { case 240 : 
X        case 241 : 
X        case 242 : 
X        case 243 : 
X        
X        { 
X		  if (!pass2) printf ( "%ld:  Special: '" , pkloc - 1 ) ; 
X          i = 0 ; 
X          for ( j = 240 ; j <= flagbyte ; j ++ ) i = 256 * i + pkbyte () ; 
X            for ( j = 1 ; j <= i ; j ++ )
X			  {
X			  cc = xchr [ pkbyte () ] ;
X			  if (!pass2) (void)putchar ( cc ) ;
X			  }
X            if (!pass2 ) printf ( "'\n" ) ; 
X          } 
X        break ; 
X        case 244 :
X		i = get32();
X        if (!pass2) printf ( "%ld:  Num special: %ld\n" , pkloc - 1 ,i ) ; 
X        break ; 
X        case 245 : 
X        if (!pass2) printf ( "%ld:  Postamble\n" , pkloc - 1 ) ; 
X        break ; 
X        case 246 : 
X        if (!pass2) printf ( "%ld:  No op\n" , pkloc - 1 ) ; 
X        break ; 
X        case 247 : 
X        case 248 : 
X        case 249 : 
X        case 250 : 
X        case 251 : 
X        case 252 : 
X        case 253 : 
X        case 254 : 
X        case 255 : 
X        
X        { ; 
X          printf ( " Unexpected %d!\n" , flagbyte ) ; 
X          jumpout () ; 
X          } 
X        break ; 
X        } } while ( ! ( ( flagbyte < 240 ) || ( flagbyte == 245 ) ) ) ; 
X    }
X	
X  dialog () { if ( gargc < 2 ) 
X    { ; 
X      printf (" Usage: %s <pkfile> <rfile> <name> <font_number>\n",gargv[0]); 
X      exit(1); 
X      } 
X    (void) strcpy ( pkname , gargv [ 1 ] ) ;
X	if (gargc > 2)
X	  (void) strcpy(outname, gargv[2]);
X	else
X      (void) strcpy(outname, "font.r");
X	if (gargc > 3)
X	  (void) strcpy(fname,gargv[3]);
X	else
X	  (void) strcpy(fname,"Font");
X	if (gargc > 4)
X	  fnumber = atoi(gargv[4]);
X	else
X	  fnumber = 201;
X    }
X	
X#define gonyb(y) fprintf(outfile,"%c",nyb[(y)&15])
X  
Xgoout(x)
X  int x;
X  {
X  if (column >= 16)
X    {
X	fprintf(outfile,"\n");
X	column = 0;
X	if (showplus >= 5)
X	  {
X	  printf("+");(void)fflush(stdout);
X	  showplus = 0;
X	  }
X	showplus++;
X	}
X  gonyb(x>>12);
X  gonyb(x>>8);
X  gonyb(x>>4);
X  gonyb(x);
X  column++;
X  }
X
Xp1()
X  {
X  printf ( "This is pktor, ver. %s\n" ,VERSION) ; 
X  printf ( "  Input file:   %s\n" , pkname ) ; 
X  printf ( "  Output file:  %s\n" , outname ) ; 
X  if ( (j = pkbyte ()) != 247 ) 
X  { ; 
X    printf ( " Bad pk file!  pre command missing.(%ld)\n",j ) ; 
X    jumpout () ; 
X    } 
X  if ( pkbyte () != 89 ) 
X  { ; 
X    printf ( " Wrong version of packed file!.\n" ) ; 
X    jumpout () ; 
X    } 
X  j = pkbyte () ; 
X  printf ( "'" ) ; 
X  for ( i = 1 ; i <= j ; i ++ ) (void)putchar ( xchr [ pkbyte () ] ) ; 
X    printf ( "'\n" ) ; 
X  designsize = get32 () ; 
X  printf ( "Design size = %ld (%f points)\n" ,
X            designsize ,(double)designsize/(double)1048576L) ; 
X  checksum = get32 () ; 
X  printf ( "Checksum = %ld\n" , checksum ) ; 
X  hppp = get32 () ; 
X  vppp = get32 () ; 
X  printf ( "Resolution: horizontal = %ld  vertical = %ld" , hppp , vppp ) ; 
X  magnification = round ( hppp * 72.27 / 65536L ) ; 
X  printf ( "  (%ld dpi)\n" , magnification ) ;
X  fsize = round(((double)magnification * (double)designsize)/
X            (72.0 * (double)1048576L));
X  if (fsize > 127)
X    {
X	printf("WARNING: Font size would be %d, changed to 127 (the maximum).\n",fsize);
X    fsize = 127;
X    }
X  if ( hppp != vppp ) ; 
X  skipspecials () ; 
X  while ( flagbyte != 245 ) 
X    {
X	/* printf ( "%ld:  Flag byte = %d" , pkloc - 1 , flagbyte ) ; */
X      dynf = flagbyte / 16 ; 
X      flagbyte = flagbyte % 16 ; 
X      turnon = flagbyte >= 8 ; 
X      if ( turnon ) flagbyte = flagbyte - 8 ; 
X      if ( flagbyte == 7 ) 
X      { packetlength = get32 () ; 
X        car = get32 () ; 
X        endofpacket = packetlength + pkloc ; 
X        packetlength = packetlength + 9 ; 
X        tfmwidth = get32 () ; 
X        dx = get32 () ; 
X        dy = get32 () ; 
X        width = get32 () ; 
X        height = get32 () ; 
X        xoff = get32 () ; 
X        yoff = get32 () ; 
X        } 
X      else if ( flagbyte > 3 ) 
X      { packetlength = ( flagbyte - 4 ) * 65536L + get16 () ; 
X        car = pkbyte () ; 
X        endofpacket = packetlength + pkloc ; 
X        packetlength = packetlength + 4 ; 
X        i = pkbyte () ; 
X        tfmwidth = i * 65536L + get16 () ; 
X        dx = get16 () * 65536L ; 
X        dy = 0 ; 
X        width = get16 () ; 
X        height = get16 () ; 
X        xoff = get16 () ; 
X        yoff = get16 () ; 
X        if ( xoff > 32767L ) xoff = xoff - 65536L ; 
X        if ( yoff > 32767L ) yoff = yoff - 65536L ; 
X        } 
X      else 
X      { packetlength = flagbyte * 256 + pkbyte () ; 
X        car = pkbyte () ; 
X        endofpacket = packetlength + pkloc ; 
X        packetlength = packetlength + 3 ; 
X        i = pkbyte () ; 
X        tfmwidth = i * 65536L + get16 () ; 
X        dx = pkbyte () * 65536L ; 
X        dy = 0 ; 
X        width = pkbyte () ; 
X        height = pkbyte () ; 
X        xoff = pkbyte () ; 
X        yoff = pkbyte () ; 
X        if ( xoff > 127 ) xoff = xoff - 256 ; 
X        if ( yoff > 127 ) yoff = yoff - 256 ; 
X        } 
X/*
X      printf ( "  Character = %ld  Packet length = %ld\n",car,packetlength); 
X      printf ( "  Dynamic packing variable = %ld\n" , dynf ) ; 
X      printf ( "  TFM width = %ld  dx = %ld" , tfmwidth , dx ) ;
X      if ( dy != 0 ) printf ( "  dy = %ld\n" , dy ) ; 
X      else printf ( "\n" ) ; 
X      printf ( "  Height = %ld  Width = %ld  X-offset = %ld  Y-offset = %ld\n" ,
X      height , width , xoff , yoff ) ;
X*/
X	  charwid = round((double)dx / 65536L);
X	  charas = max(yoff,0);
X	  chardes = max(height-yoff,0);
X	  charoff = max(-xoff,0);
X	  if (car < firstchar) firstchar = car;
X	  if (car > lastchar) lastchar = car;
X	  if (charwid > widmax) widmax = charwid;
X	  if (xoff > kernmax) kernmax = xoff;
X	  if (charwid > frectwidth) frectwidth = charwid;
X	  if (charas > ascent) ascent = charas;
X	  if (chardes > descent) descent = chardes;
X	  frectheight = ascent + descent;
X	  hp = 0 ; wp = 0; xcount = 0;
X	  loctable[(int)car + 1] = width;  /* first widths, sum later */
X	  owtable[(int)car] = (((int)(charoff) ) << 8) + (int)charwid;
X      bitweight = 0 ; 
X      if ( dynf == 14 ) 
X      { for ( i = 1 ; i <= height ; i ++ ) 
X          {
X            for ( j = 1 ; j <= width ; j ++ )
X			   (void)getbit (); 
X            } 
X          } 
X      else 
X      { rowsleft = height ; 
X        hbit = width ; 
X        repeatcount = 0 ; 
X        while ( rowsleft > 0 ) 
X          { count = pkpackednum () ; 
X            if ( count >= hbit ) 
X            { rowsleft = rowsleft - repeatcount - 1 ; 
X              repeatcount = 0 ; 
X              count = count - hbit ; 
X              hbit = width ; 
X              rowsleft = rowsleft - count / width ; 
X              count = count % width ; 
X              } 
X            hbit = hbit - count ; 
X            turnon = ! turnon ; 
X            } 
X        if ( ( rowsleft != 0 ) || ( hbit != width ) ) 
X        { ; 
X          printf ( " Bad pk file---more bits than required!\n" ) ; 
X          jumpout () ; 
X          } 
X        } 
X      if ( endofpacket != pkloc ) 
X      { ; 
X        printf ( " Bad pk file!  Bad packet length.\n" ) ; 
X        jumpout () ; 
X        } 
X      skipspecials () ; 
X      } 
X    j = 0 ; 
X    i = pkbyte () ;
X  while ( ! feof ( pkfile ) ) 
X    { if ( i != 246 ) 
X      { ; 
X        printf ( " Bad byte at end of file: %ld\n" , i ) ; 
X        jumpout () ; 
X        } 
X      incr(j) ;
X      printf ( "%ld:  No op\n" , pkloc - 1 ) ; 
X      i = pkbyte () ;
X      } 
X    if ( j > 4 ) 
X  { ; 
X    printf ( " Too many no-ops at end of file\n" ) ; 
X    jumpout () ; 
X    } 
X  pkloc -- ;
X  printf ( "%ld bytes read from packed file on first pass.\n" , pkloc ) ; 
X  printf("**************************************************\n");
X  printf("FONT: %s   SIZE:%d    NUMBER:%d\n",fname,fsize,fnumber);
X  printf("firstchar=%d  lastchar=%d  widmax=%d  kernmax=%d\n",
X        firstchar,lastchar,widmax,kernmax);
X		printf("frectwidth=%d  frectheight=%d  ascent=%d  descent=%d\n",
X		      frectwidth,frectheight,ascent,descent);
X  loctable[lastchar+2] = loctable[' '+1];  /* missing char = ' ' */
X  owtable[lastchar+1] = owtable[' '];
X  owtable[lastchar+2] = -1;
X  for (i = firstchar ; i <= lastchar+1 ; i++)
X    {
X	loctable[i+1] = loctable[i] + loctable[i+1];
X	}
X/*
Xprintf("%10s %9s   %6s %6s\n",
X      "character","location","offset","width");
X  for (i = firstchar ; i <= lastchar+2 ; i++)
X    {
X	printf("%9ld %9d   %6d %6d\n",
X	      i,loctable[i],255 & (owtable[i] >> 8),255 & owtable[i]);
X	}
X*/
X  leading = 6;
X  rowbits = loctable[lastchar+2];
X  rowwords = (rowbits+15)/16;
X  printf("rows (frectheight) %d   rowwords %d\n",frectheight,rowwords);
X  if ((long)frectheight * (long)rowwords >= 16384L)
X    {
X	printf("Too big.  Product must be < 16K\n");
X	jumpout();
X	}
X  j = (long)frectheight * (long)rowwords;
X  printf("Allocate %ld words...",j);
X  pbitim = (short *)malloc(sizeof(short) * (unsigned)j);
X  if (pbitim == (short *)0)
X    {
X	printf("Too little memory left...\n");
X	jumpout();
X	}
X  for (i = 0 ; i < j ; i++)
X    {
X    pbitim[i] = 0;
X	}
X  printf(" Ready.\n");
X  owtloc = 8 + rowwords*frectheight + lastchar - firstchar;
X  
X  }
X  
Xp2()
X  {
X  if ( (j = pkbyte ()) != 247 ) 
X  { ; 
X    jumpout () ; 
X    } 
X  if ( pkbyte () != 89 ) 
X  { ; 
X    jumpout () ; 
X    } 
X  j = pkbyte () ; 
X  for ( i = 1 ; i <= j ; i ++ ) (void)pkbyte(); 
X
X  designsize = get32 () ; 
X  checksum = get32 () ; 
X  hppp = get32 () ; 
X  vppp = get32 () ; 
X 
X  skipspecials () ; 
X  while ( flagbyte != 245 ) 
X    {      dynf = flagbyte / 16 ; 
X      flagbyte = flagbyte % 16 ; 
X      turnon = flagbyte >= 8 ; 
X      if ( turnon ) flagbyte = flagbyte - 8 ; 
X      if ( flagbyte == 7 ) 
X      { packetlength = get32 () ; 
X        car = get32 () ; 
X        endofpacket = packetlength + pkloc ; 
X        packetlength = packetlength + 9 ; 
X        tfmwidth = get32 () ; 
X        dx = get32 () ; 
X        dy = get32 () ; 
X        width = get32 () ; 
X        height = get32 () ; 
X        xoff = get32 () ; 
X        yoff = get32 () ; 
X        } 
X      else if ( flagbyte > 3 ) 
X      { packetlength = ( flagbyte - 4 ) * 65536L + get16 () ; 
X        car = pkbyte () ; 
X        endofpacket = packetlength + pkloc ; 
X        packetlength = packetlength + 4 ; 
X        i = pkbyte () ; 
X        tfmwidth = i * 65536L + get16 () ; 
X        dx = get16 () * 65536L ; 
X        dy = 0 ; 
X        width = get16 () ; 
X        height = get16 () ; 
X        xoff = get16 () ; 
X        yoff = get16 () ; 
X        if ( xoff > 32767L ) xoff = xoff - 65536L ; 
X        if ( yoff > 32767L ) yoff = yoff - 65536L ; 
X        } 
X      else 
X      { packetlength = flagbyte * 256 + pkbyte () ; 
X        car = pkbyte () ; 
X        endofpacket = packetlength + pkloc ; 
X        packetlength = packetlength + 3 ; 
X        i = pkbyte () ; 
X        tfmwidth = i * 65536L + get16 () ; 
X        dx = pkbyte () * 65536L ; 
X        dy = 0 ; 
X        width = pkbyte () ; 
X        height = pkbyte () ; 
X        xoff = pkbyte () ; 
X        yoff = pkbyte () ; 
X        if ( xoff > 127 ) xoff = xoff - 256 ; 
X        if ( yoff > 127 ) yoff = yoff - 256 ; 
X        } 
X/*	printf("character %ld\n",car); */
X      if (car == 0x20)
X	    car = lastchar+1;      /* missing char is space: for QuickDraw */
X	  charwid = round((double)dx / 65536L);
X	  charas = max(yoff,0);
X	  chardes = max(height-yoff,0);
X	  charoff = -xoff;
X	  hp = 0 ; wp = 0; xcount = 0;
X	  hbitx = loctable[car];
X	  vbit = ascent-charas;
X      bitweight = 0 ; 
X      if ( dynf == 14 ) 
X      { for ( i = 1 ; i <= height ; i ++ ) 
X          {
X            for ( j = 1 ; j <= width ; j ++ )
X			  if ( getbit () ) 
X			    xout(1) ; 
X              else 
X			    xout(0) ; 
X            } 
X          } 
X      else 
X      { termpos = 2 ; 
X        rowsleft = height ; 
X        hbit = width ; 
X        repeatcount = 0 ; 
X        while ( rowsleft > 0 ) 
X          { count = pkpackednum () ; 
X            sendout ( false , count ) ; 
X            if ( count >= hbit ) 
X            { rowsleft = rowsleft - repeatcount - 1 ; 
X              repeatcount = 0 ; 
X              count = count - hbit ; 
X              hbit = width ; 
X              rowsleft = rowsleft - count / width ; 
X              count = count % width ; 
X              } 
X            hbit = hbit - count ; 
X            turnon = ! turnon ; 
X            } 
X          printf ( "." ) ; (void)fflush(stdout); 
X        if ( ( rowsleft != 0 ) || ( hbit != width ) ) 
X        { ; 
X          jumpout () ; 
X          } 
X        } 
X      if ( endofpacket != pkloc ) 
X      { ; 
X        jumpout () ; 
X        } 
X      skipspecials () ; 
X      } 
X    j = 0 ; 
X    i = pkbyte () ;
X  while ( ! feof ( pkfile ) ) 
X    { if ( i != 246 ) 
X      { ; 
X        jumpout () ; 
X        } 
X      incr(j) ;
X      i = pkbyte () ;
X      } 
X    if ( j > 4 ) 
X  { ; 
X    jumpout () ; 
X    } 
X  pkloc -- ;
X  printf ( "\n%ld bytes read from packed file on second pass.\n" , pkloc ) ; 
X  openoutfile () ;
X  printf("Writing file %s...\n",outname);
X  fprintf(outfile,"* RMaker font source\n");
X  fprintf(outfile,"*  created by pktor (ver. %s) from %s\n",VERSION,pkname);
X  fprintf(outfile,"%s\n",fname);
X  fprintf(outfile,"FFILDMOV\n\n");  /* Font/DA Mover file */
X
X  fprintf(outfile,"TYPE FONT=GNRL\n");
X  fprintf(outfile,"%s,%d (32)\n",fname,fnumber*128);
X  fprintf(outfile,".H\n");
X  fprintf(outfile,"0000000000000000000000000000000000000000000000000000\n");
X  
X  fprintf(outfile,"\nTYPE FONT=GNRL\n");
X  fprintf(outfile,",%d (32)\n",fnumber*128+fsize);
X  fprintf(outfile,".H\n9000\n");   /* proportional */
X  fprintf(outfile,".I\n%d\n",firstchar);
X  fprintf(outfile,".I\n%d\n",lastchar);
X  fprintf(outfile,".I\n%d\n",widmax);
X  fprintf(outfile,".I\n%d\n",kernmax);
X  fprintf(outfile,".I\n%d\n",-descent);
X  fprintf(outfile,".I\n%d\n",frectwidth);
X  fprintf(outfile,".I\n%d\n",frectheight);
X  fprintf(outfile,".I\n%d\n",owtloc);
X  fprintf(outfile,".I\n%d\n",ascent);
X  fprintf(outfile,".I\n%d\n",descent);
X  fprintf(outfile,".I\n%d\n",leading);
X  fprintf(outfile,".I\n%d\n",rowwords);
X  
X  fprintf(outfile,"* bitImage\n.H\n");
X  column = 0;
X  showplus = 0;
X  for (j = 0 ; j < frectheight ; j++)
X    for (i = 0 ; i < rowwords ; i++)
X	  goout(bitimage(j,i));
X  printf("\n");
X  fprintf(outfile,"\n* locTable\n");
X  for (i = firstchar ; i <= lastchar+2 ; i++)
X    fprintf(outfile,".I\n%d\n",loctable[i]);
X  fprintf(outfile,"* owTable\n");
X  for (i = firstchar ; i <= lastchar+2 ; i++)
X    fprintf(outfile,".I\n%d\n",owtable[i]);
X  fprintf(outfile,"\n* END *\n");
X  (void)fclose(outfile);
X  }
X  
Xmain (argc, argv) 
Xint argc ;
Xchar *argv[] ;
X{ gargc = argc ;
X  gargv = argv ;
X  initialize () ; 
X  dialog () ; 
X  openpkfile () ;
X  pass2 = 0;
X  p1();
X  (void)fclose(pkfile);
X  openpkfile();
X  pass2 = 1;
X  p2();
X  (void)fclose(pkfile);
X  exit(0);
X  } 
X
X/* end */
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0
---