[comp.graphics] Vector Fonts

jonnyg@umd5.umd.edu (Jon Greenblatt) (09/17/88)

	I have seen this question asked a lot but I have never seen an
answer posted. Does any one have a free public domain definition of a
vector font I can use in an academic application. Some format that uses
lines, arcs, and ellipses or some subset will do. If I do not get an answer
I will have to write my own which I will post since netters are so kind.
I will be using this under Microsoft Windows because their vector fonts are
too limited. It will be used in the Actor language and I will set up a
postscript type font system for them.

	BTW my apologies again to the poster if the usa map, James Peterson,
I printed your map with linewidth 0 and it worked great, good work!

						JonnyG.
					(jonnyg@rover.umd.edu)
					(jonnyg@umd5.umd.edu)

jonnyg@umd5.umd.edu (Jon Greenblatt) (09/21/88)

	Thank you all for the numerous responses to my request for vectorized
fonts. The answer was to look at the uunet archives in volume4. In keeping
with my tradition of asking questions I am going to post some useful
code I have developed to deal with Hershey fonts.

	The following program will take a font description and print it out
in unix plot format. The font descriptions are in the .hmp files. The fonts
need to be concatenated in a file hersh.c, see the comments in the code. This
should help people isolate fonts into ascii order.

	I hope I am not repeating work already done but this code is not
long. Thanks again for the responses.

					JonnyG.
					(jonnyg@rover.umd.edu)
					(jonnyg@umd5.umd.edu)

-----------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>

#define FONTFILE "hersh.oc"

/*
 * Hersh.c Display the hershy fonts based on the .hmp definitions.
 *
 * This program has been converted to work with the unix plot library.
 * The .hmp discriptions are used to read the occidental fonts only.
 * All the occidental fonts hersh.oc1-hersh.oc4 need to be concatenated
 * into hersh.oc.
 *
 *   Translated to Unix Plot by Jonathan Greenblatt.
 *				(jonnyg@rover.umd.edu)
 *				(jonnyg@umd5.umd.edu)
 *
 * Note: This only prints fonts in the .hmp definitions, make the file
 * "all.hmp" and place the following line in it:
 *    1-3926
 * To print all the characters type "hersh all".
 *
 * The oriental characters can be printed by changing the FONTFILE definition.
 */

/*
 *
 *** This is the old comment from the hershey.c program. (Jon Greenblatt) **
 *
 * hershey.c   Display all of the Hershey font data in a font file
 *
 * This sample program is intended more so the user can see how the
 * font data is read and used in an (admittedly minimal) application,
 * than as a useable program.
 *
 * Its function is to display all of the hershey font characters on-screen,
 * in a format 8 characters across and 8 vertical.
 *
 * usage:
 *    hershey <fontname>
 *
 *       where <fontname> is the name of a hershey name, e.g.
 *                      romancs
 *			italict
 *			scripts
 *
 * Translated from Fortran to C and GKS (that's why it looks wierd!)
 *    (PRIOR Data Sciences non-ANSI GKS binding used here. Sorry!
 *     Somebody else is welcome to translate to the ANSI binding)
 *
 *
 */

/*
     Translated by Pete Holzmann
         Octopus Enterprises
         19611 La Mar Court
         Cupertino, CA 95014

      Original...  
     .. By James Hurt when with
     ..    Deere and Company
     ..    John Deere Road
     ..    Moline, IL 61265

     .. now with Cognition, Inc.
     ..          900 Technology Park Drive
     ..          Billerica, MA 01821
*/

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

float deltac = 12.5, deltar = 12.5, colmax = 100.0;
FILE	*INfile,*OUTfile,*fopen(); /* some files */
int minx = 999,miny = 999,maxx=-999,maxy=-999;

char name[80];

/*
 * scanint: a function to scan an integer, using n characters of
 *          the input file, ignoring newlines. (scanf won't work
 *          because it also ignores blanks)
 */
int scanint(file,n)
FILE *file;
int n;
{
char buf[20];
int i,c;

   for (i=0;i<n;i++){
      while ((c = fgetc(file)) == '\n') ; /* discard spare newlines */
      if (c == EOF) return(-1);
       buf[i] = c;
   }
   
   buf[i] = 0;
   return(atoi(buf));
}

typedef struct achar {
	int code, len;
	char *data;
	} Achar;

#define MAXCHARS 4000
int nchars = 0;
Achar chars[MAXCHARS];


int skipflag = 1; /* 1 if next draw is 'pen up' */
int oldx,oldy;

static void
skip()
{
skipflag = TRUE;
}

static void
draw(newx,newy)
int newx,newy;
   {
   if (!skipflag) {
      cont(newx,newy);
      }
   else move(newx,newy);
   skipflag = FALSE;
   oldx = newx;
   oldy = newy;
   }

readdat(name)
char *name;
	{
	FILE *f;
	char fname[80];
	int n;

	nchars = 0;
	strcat(strcpy(fname,name),".hmp");
	if ((f = fopen(fname,"r")) == NULL)
		{
		printf("Could not open %s\n",fname);
		exit(1);
		}
	while (fscanf(f,"%d",&n) > 0) {
		if (n < 0) {
			int t;
			t = chars[nchars-1].code;
			while (t < -n)
				chars[nchars++].code = ++t;
			}
		else
			chars[nchars++].code = n;
		}
	fclose(f);
	}

main(argc,argv)
int argc;
char **argv;
{
  FILE *kfile;
  char line[2][256];
  int x,y;
  float col,row;
  int     ipnt,ich,nch,i;

  for (x = 0; x < MAXCHARS; x++)
	chars[x].len = 0;
  if (argc != 2) {
     printf("usage: hershey file\n");
     exit(1);
     }


  if (!(kfile = fopen(FONTFILE,"r"))) {
     fprintf(stderr,"Can't open font file '%s'\n",FONTFILE);
     exit(1);
     }

  readdat(argv[1]);

  while ((ich = scanint(kfile,5)) > 0) {
	Achar *achar;
	char *s;
	char *malloc();
	int j;

	for (i = 0; i < nchars; i++)
		if (chars[i].code == ich) break;
	if (i < nchars) {
	 	achar = &chars[i];
		achar->len = scanint(kfile,3);
		s = achar->data = malloc(achar->len * 2);
		for (i = 0; i < achar->len; i++) {
        		if ((i==32) ||(i==68) ||(i==104) ||(i==140)) fgetc(kfile); /* skip newlines */
			*s++ = fgetc(kfile);
			*s++ = fgetc(kfile);
			}
		}
	else
		{
		j = scanint(kfile,3);
		for (i = 0; i < j; i++) {
        		if ((i==32) ||(i==68) ||(i==104) ||(i==140)) fgetc(kfile); /* skip newlines */
				fgetc(kfile); fgetc(kfile);
			}
		}
	fgetc(kfile);
	}

  fclose(kfile);

  col = 0.0;
  row = 100.0;
  openpl();
  erase();

  for (ich = 0; ich < nchars; ich++) {
    if ((nch = chars[ich].len) == 0) continue;
    for (i=0; i<nch;i++) {
      if ((i==32) ||(i==68) ||(i==104) ||(i==140)) fgetc(kfile); /* skip newlines */
         line[0][i] = chars[ich].data[i*2];
         line[1][i] = chars[ich].data[i*2+1];
      }

    space((int)(-col)*3-16,(int)(-row)*3+16,
          316-(int)col*3-16,316-(int)row*3+16);

    jnumbr(ich+32,3,-10.0,-16.0,6.0);

/*		     .. draw left and right lines */
/*		     .. Note: this data can be used for proportional spacing */

    x=(int)line[0][0] - (int)'R';
    y=(int)line[1][0] - (int)'R';

    skip();
    draw(x,-10);draw(x,10);
    skip();
    draw(y,-10);draw(y,10);

    skip();
    for (ipnt=1;ipnt<nch;ipnt++) {
      if (line[0][ipnt] == ' ') {
         skip();
         }
      else {
         x=(int)line[0][ipnt] -(int) 'R';
         y=(int)line[1][ipnt] -(int) 'R';
         if (x < minx) minx = x;
         if (x >maxx) maxx = x;
         if (-y < miny) miny = -y;
         if (-y >maxy) maxy = -y;
           draw(x,-y);
         }
      } /* for loop */

    if( (col += deltac) < colmax )
         continue;
    col = 0.0;
    if( (row -= deltar) >= deltar ) 
         continue;

    fflush(stdout);
    if (getchar() == 'q') exit(0);
    erase();
    col = 0.0;
    row = 100.0;
    } /* while true */
    fflush(stdout);
    getchar();
  }


      long power[] ={ 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
          100000000, 1000000000 };
      int  start[] ={0,11,14,22,36,42,55,68,73,91,104};
    char linedat[]={'R','M','P','N','O','P','O','S','P','U','R','V','T','U',
      'U','S','U','P','T','N','R','M','P','O','R','M','R',
        'V','O','N','Q','M','S','M','U','N','U','P','T','R','O',
      'V','U','V','O','N','Q','M','S','M','U','N','U','P','S','Q',
        ' ','R','R','Q','S','Q','U','R','U','U','S','V','Q','V','O','U',
      'S','M','S','V',' ','R','S','M','N','S','V','S','P',
        'M','O','Q','Q','P','R','P','T','Q','U','S','T','U','R','V','Q',
      'V','O','U',' ','R','P','M','T','M','T','M','R','M','P','N',
        'O','P','O','S','P','U','R','V','T','U','U','S','T','Q','R','P',
      'P','Q','O','S','U','M','Q','V',' ','R','O','M','U','M',
      'Q','M','O','N','O','P','Q','Q','S','Q','U','P','U','N','S',
      'M','Q','M',' ','R','Q','Q','O','R','O','U','Q','V','S','V','U','U',
        'U','R','S','Q','U','P','T','R','R','S','P','R','O','P',
      'P','N','R','M','T','N','U','P','U','S','T','U','R','V','P','V'};
 
#define line(a,b) linedat[(b*2+a)]
jnumbr( number, iwidth, x0, y0, height )
      int number, iwidth;
      float x0, y0, height;

{
      int ipnt, ipos, ival, idigit;
      float x, y, scale;
      float xleft, ylower;
      scale = height/10.0;
      xleft = x0;
      ylower = y0;
      ival = number;

      for (ipos = iwidth;ipos>=1;ipos--) {
         idigit = (ival/power[ipos-1])% 10;

         skip();

         for ( ipnt=start[idigit]; ipnt < start[idigit+1];ipnt++) {
            if(((char)line(0,ipnt)) == ' ') {
               skip();   /* next data point is a move */
            } else {
               x=(int)line(0,ipnt) -(int) 'N';
               y=(int)line(1,ipnt) -(int) 'V';

         		draw((int)(xleft+scale*x),(int)(ylower-scale*y));
            }
          } /* data for this digit */
         xleft += height;
       } /* whole string */
}

bmott@garfield.catt.ncsu.edu (Bradford Mott) (04/16/91)

	I'm trying to find some information on vector fonts.  I'm
interested in implementing a system to take a vector outline of a font
and create a bitmap version of the font at a given point size.  I want
to keep a cache of the most recently created bitmap fonts, to speed
things up some.
	What I'm looking for is a good book on the subject, some code,
and some sample font files.  Are there any ftp sites that have this
information?
	Any help will be very appreciated.

Bradford Mott


--------------------------------------------------------------------------
    Bradford W. Mott                     Internet: bmott@catt.ncsu.edu
                                         GEnie:    B.MOTT
    North Carolina State University