lee@uhccux.UUCP (Greg Lee) (01/29/88)
Last summer I posted some utilities for doing things with the Hershey fonts. Here is an update to make those utilities compatible with the Hershey data in volume 4 of the mod.sources archive. This was posted to comp.sources.unix in October of last year, but I've given up hope of it ever appearing there. Greg, lee@uhccux.uhcc.hawaii.edu #! /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 1 (of 1)." # Contents: Makefile Manifest README2 cnv.c dif-eplot.c dif-hplot.c # dif-vfont.c h2s.l # Wrapped by lee@uhccux on Mon Oct 12 04:59:05 1987 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f Makefile -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile\" else echo shar: Extracting \"Makefile\" \(1201 characters\) sed "s/^X//" >Makefile <<'END_OF_Makefile' X.SUFFIXES: .spec .hmp .chr X Xall: cnv h2s X Xcnv: cnv.c X cc -O -s -o cnv cnv.c X Xh2s: h2s.l X lex h2s.l X cc -o h2s lex.yy.c -ll X rm lex.yy.c X Xgreekp.spec: greekp.hmp X rm -f greekp.spec X echo "base 5" >greekp.spec X echo "ytop 14" >>greekp.spec X h2s <greekp.hmp >>greekp.spec X Xromanp.spec: romanp.hmp X rm -f romanp.spec X echo "base 5" >romanp.spec X echo "ytop 14" >>romanp.spec X h2s <romanp.hmp >>romanp.spec X Xgreekcs.spec: greekcs.hmp X rm -f greekcs.spec X echo "base 6" > greekcs.spec X echo "ytop 10" >> greekcs.spec X h2s < greekcs.hmp >> greekcs.spec X Xitaliccs.spec: italiccs.hmp X rm -f italiccs.spec X echo "base 6" > italiccs.spec X echo "ytop 10" >> italiccs.spec X h2s < italiccs.hmp >> italiccs.spec X Xromancs.spec: romancs.hmp X rm -f romancs.spec X echo "base 6" > romancs.spec X echo "ytop 10" >> romancs.spec X h2s < romancs.hmp >> romancs.spec X X.hmp.chr: X make $*.spec X rm -f $*.chr X cnv <$*.spec >$*.chr X X.hmp.spec: X rm -f $*.spec X h2s <$*.hmp >$*.spec X Xoccidental: hersh.oc1 hersh.oc2 hersh.oc3 hersh.oc4 X rm -f occidental X cat hersh.oc1 hersh.oc2 hersh.oc3 hersh.oc4 >occidental X Xoriental: hersh.or1 hersh.or2 hersh.or3 hersh.or4 X rm -f oriental X cat hersh.or1 hersh.or2 hersh.or3 hersh.or4 >oriental END_OF_Makefile if test 1201 -ne `wc -c <Makefile`; then echo shar: \"Makefile\" unpacked with wrong size! fi # end of overwriting check fi if test -f Manifest -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Manifest\" else echo shar: Extracting \"Manifest\" \(464 characters\) sed "s/^X//" >Manifest <<'END_OF_Manifest' X File Name Archive # Description X----------------------------------------------------------- X Makefile 1 X Manifest 1 this file X README2 1 X cnv.c 1 cnv <specfile >chrfile X dif-eplot.c 1 patch eplot.c dif-eplot.c X dif-hplot.c 1 patch hplot.c dif-hplot.c X dif-vfont.c 1 patch vfont.c dif-vfont.c X h2s.l 1 h2s <hmpfile >specfile END_OF_Manifest if test 464 -ne `wc -c <Manifest`; then echo shar: \"Manifest\" unpacked with wrong size! fi # end of overwriting check fi if test -f README2 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"README2\" else echo shar: Extracting \"README2\" \(1736 characters\) sed "s/^X//" >README2 <<'END_OF_README2' X XA while back I posted some Hershey utilities to edit files of Xvector data and to create from them various sorts of fonts. XHowever, the vector data is in an idiosyncratic format -- .chr Xfiles. Now here are routines to create such files from the XHershey data in the form in which it was posted in volume 4 Xof mod.sources. Rather than use the .hmp format for specifying Xa mapping from Hershey character number to ascii, I decided Xto use the .spec format of William LeFebvre's hfont package X(in volume 5 of comp.sources.unix), since it is more complete. XBut means for creating .spec files from the data in the .hmp Xfiles that come with the Hershey data are here included. X XIf these files are placed in the same directory as the Hershey Xdata, one can proceed as follows: X (1) make X (constructs programs cnv and h2s) X (2) make occidental X (occidental is hersh.oc? concatenated) X (3) make <name>.chr X OR make <name>.spec THEN make <name>.chr X (where <name>.hmp is one of the Hershey map files) X XFor oriental fonts, create (somehow) a .spec file with a Xfirst line "repertory oriental", make oriental, then X cnv <name.spec >name.chr X XHere are also 3 patch files, dif-*, which ought to be applied Xto the source files I distributed previously, to make the utilities Xeplot and hplot more compatible with the .chr files generated Xthrough the above procedure. X XThe code in cnv.c was adapted from hershey.c by James Hurt (translated Xby Pete Holzmann) and from hfont.c by William LeFebvre. X XGreg Lee, 10/12/87 XU.S.mail: 562 Moore Hall, Dept. of Linguistics, Univ. of Hawaii, HONO, HI 96822 XINTERNET: lee@uhccux.uhcc.hawaii.edu XUUCP: {ihnp4,dcdwest,ucbvax}!sdcsvax!nosc!uhccux!lee XBITNET: lee%uhccux.uhcc.hawaii.edu@rutgers.edu END_OF_README2 if test 1736 -ne `wc -c <README2`; then echo shar: \"README2\" unpacked with wrong size! fi # end of overwriting check fi if test -f cnv.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"cnv.c\" else echo shar: Extracting \"cnv.c\" \(7406 characters\) sed "s/^X//" >cnv.c <<'END_OF_cnv.c' X#include <stdio.h> X X#ifndef TRUE X#define TRUE 1 X#define FALSE 0 X#endif X X/* X * cnv.c Make a .chr file from a .spec file (LeFebvre format, X * on standard input) and Hershey data in Hurt X * format in (default) file occidental. X * This code is adapted from hershey.c by James Hurt X * (translated by Pete Holzmann) X * and from hfont.c by William LeFebvre. X * --Greg Lee, 10/12/87 X */ X X FILE *fopen(); X X /* some variables to record the largest bounding rectangle of X the displayed characters. Printed when all finished. */ X X int minx = 999; X int miny = 999; X int maxx = -999; X int maxy = -999; X X/* .. font data file name */ X char name[80]; X X/* readspec globals: */ X X# define Off 0 X# define On 1 X X# define No 0 X# define Yes 1 X X# define MAX_ORD 4000 /* maximum Hershey font number */ X Xchar input[256]; Xchar order[MAX_ORD]; Xint left_max, right_max; Xint up_max, down_max; Xint vtrans; Xdouble x_factor; Xdouble real_x_factor; Xdouble x_trans; XFILE *vecfont; X Xint left_ex; Xint map_to_char; Xint baseline; Xint hi_char = 168; X Xint ytop = 22; Xint base = 9; Xint xheight = 0; X Xchar verbose = No; X Xchar *gets(); Xchar *vgets(); Xchar *index(); Xchar *process_option(); X X X/* X * scanint: a function to scan an integer, using n characters of X * the input file, ignoring newlines. (scanf won't work X * because it also ignores blanks) X */ Xint scanint(file,n) XFILE *file; Xint n; X{ Xchar buf[20]; Xint i,c; X X for (i=0;i<n;i++){ X while ((c = fgetc(file)) == '\n') ; /* discard spare newlines */ X if (c == EOF) return(-1); X buf[i] = c; X } X X buf[i] = 0; X return(atoi(buf)); X} X X Xint skipflag = 1; /* 1 if next draw is 'pen up' */ Xint cocnt = 2; Xint oldx,oldy; X Xstatic void Xskip() X{ Xskipflag = TRUE; X printf(" Pen Up\n "); X cocnt = 0; X} X Xstatic void Xdraw(newx,newy) Xint newx,newy; X{ X if (cocnt > 8) { X printf("\n "); X cocnt = 0; X } X printf("(%d,%d)", newx, -newy); X cocnt++; X} X X/* X * The main program... X */ X Xmain(argc,argv) Xint argc; Xchar **argv; X{ X/* .. font data */ X char line[2][256]; X int x,y; X float col,row; X/* .. which data point and which character */ X int ipnt,ich,nch,i,ichar; X int letter; X X/* X if (argc != 2) { X printf("usage: cnv file\n"); X exit(1); X } X*/ X ytop = 22; X base = 9; X X readspec(); X X printf("Height(%d)\n", ytop); X if (xheight) printf("x Height(%d)\n", xheight); X if (base) printf("Base(%d)\n", base); X X/* .. loop per character */ X while (TRUE) { X X/* .. read character number and data */ X if ((ich = scanint(vecfont,5)) < 1) { X exit(0); X } X X if (ich >= MAX_ORD) { X fprintf(stderr, "Hershey data has big character number"); X exit(1); X } X X nch = scanint(vecfont,3); X X for (i=0; i<nch;i++) { X if ((i==32) ||(i==68) ||(i==104) ||(i==140)) fgetc(vecfont); /* skip newlines */ X line[0][i] = fgetc(vecfont); X line[1][i] = fgetc(vecfont); X } X fgetc(vecfont); X X if ( (letter = order[ich]) != 0) X { X/* .. identify character */ X if (letter < ' ') printf("^%c': ", letter + 64); X else if (letter >= 127) printf("\\%o: ", letter); X else printf("'%c': ", letter); X X X/* .. draw left and right lines */ X/* .. Note: this data can be used for proportional spacing */ X X x=(int)line[0][0] - (int)'R'; X y=(int)line[1][0] - (int)'R'; X X/* skip(); X draw(x,-10);draw(x,10); X skip(); X draw(y,-10);draw(y,10); X*/ X printf("Bounds(%d,%d)", x, y); X if (letter == ' ') { X draw(x,0); X draw(y,0); X } X X/* .. first data point is a move */ X/* skip();*/ X/* .. loop per line of data */ X for (ipnt=1;ipnt<nch;ipnt++) { X X/* .. process vector number ipnt */ X if (line[0][ipnt] == ' ') { X/* .. next data point is a move */ X skip(); X } else { X/* .. draw (or move) to this data point */ X x=(int)line[0][ipnt] -(int) 'R'; X y=(int)line[1][ipnt] -(int) 'R'; X if (x < minx) minx = x; X if (x >maxx) maxx = x; X if (-y < miny) miny = -y; X if (-y >maxy) maxy = -y; X/* .. Note that Hershey Font data is in TV coordinate system */ X draw(x,-y); X } X } /* for loop */ X/* .. end of this character */ X printf(" End Char\n"); X cocnt = 2; X } /* end if */ X X } /* while true */ X} X X/* X * Read a .spec file X * adapted from hfont.c, which was X * written by William LeFebvre, LCSE, Rice University X */ X Xreadspec() X X{ X int i; X int j; X int arg; X int bytecnt; X int pt_size = 0; X int char_num; X int space_char; X int filesize; X unsigned char bytemask; X unsigned char byte; X char *inp; X char *p; X static char repertory[256] = "occidental"; X static char pen_file[256] = "pen.round"; X static char buff[256]; X struct dispatch *character; X X /* read options from stdin */ X X while (vgets(input) != NULL && strcmp(input, "charset") != 0) X { X /* get the option name */ X if ((p = index(input, ' ')) != 0) X { X *p = '\0'; X } X while (*(++p) == ' '); X X /* string switch on option names */ X if (strcmp(input, "repertory") == 0) X { X strcpy(repertory, p); X } X else if (strcmp(input, "maxchar") == 0) X { X hi_char = atoi(p); X } X else if (strcmp(input, "pen") == 0) X { X strcpy(pen_file, p); X } X else if (strcmp(input, "aspect") == 0) X { X x_factor *= atof(p); X } X else if (strcmp(input, "base") == 0) X { X base = atoi(p); X } X else if (strcmp(input, "ytop") == 0) X { X ytop = atoi(p); X } X else if (strcmp(input, "xheight") == 0) X { X xheight = atoi(p); X } X else X { X fprintf(stderr, "Unknown option: `%s'\n", input); X exit(1); X } X } X X /* open the font files */ X if ((vecfont = fopen(repertory, "r")) == NULL) X { X perror(repertory); X exit(1); X } X X X /* remember what the real x factor is */ X X real_x_factor = x_factor; X X /* translate the characters */ X X while(vgets(input) != NULL) X { X /* get the character desired */ X X space_char = char_num = 0; X if (input[0] == 's') X { X /* space character of specified width */ X space_char = atoi(&(input[1])); X } X else if (input[0] == 'p') X { X /* image of the drawing pen */ X char_num = -1; X } X else X { X /* normal vector character */ X char_num = atoi(input); X } X X /* find the font character to use */ X X if ((inp = index(input, ',')) == 0) X { X fprintf(stderr, "bad character designation in `%s'\n", X input); X break; X } X if ((inp[1] == '\\') && (inp[2] != '\0')) X { X /* octal format */ X sscanf(&(inp[2]), "%o", &map_to_char); X } X else X { X /* character format */ X map_to_char = inp[1]; X } X X if (char_num < MAX_ORD) order[char_num] = map_to_char; X X /* check for extra options */ X X vtrans = 0; X inp += 2; X if ((inp = process_option(inp)) != 0) X { X process_option(inp); X } X X } /* end while */ X X} X X/* X * process_option(ptr) - process possible line option pointed to by ptr. X */ X Xchar *process_option(ptr) X Xchar *ptr; X X{ X if ((ptr = index(ptr, ',')) != 0) X { X ptr++; X if (ptr[0] == 'r') X { X /* aspect ratio */ X x_factor *= atof(&ptr[1]); X } X else X { X /* assume it's vertical translation */ X vtrans = atoi(&(ptr[0])); X } X } X return(ptr); X} X Xchar *vgets(buff) X Xregister char *buff; X X{ X register char *retval; X X if ((retval = gets(buff)) != NULL && verbose) X { X fprintf(stderr, "%s\n", buff); X } X return(retval); X} X X END_OF_cnv.c if test 7406 -ne `wc -c <cnv.c`; then echo shar: \"cnv.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f dif-eplot.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"dif-eplot.c\" else echo shar: Extracting \"dif-eplot.c\" \(1171 characters\) sed "s/^X//" >dif-eplot.c <<'END_OF_dif-eplot.c' X*** eplot.c Mon Oct 12 03:08:16 1987 X--- ../eplot.c Mon Oct 12 01:51:48 1987 X*************** X*** 106,112 X if (!(svpt = cindex[sletter])) continue; X /*if (kbhit()) return;*/ X X! if (sletter < ' ') fprintf(obuf, "^%c': ", sletter); X else fprintf(obuf, "'%c': ", sletter); X X while (!(dspc(store[svpt], store[svpt+1]))) svpt +=2; X X--- 106,113 ----- X if (!(svpt = cindex[sletter])) continue; X /*if (kbhit()) return;*/ X X! if (sletter < ' ') fprintf(obuf, "^%c': ", sletter+64); X! else if (sletter >= 127) fprintf(obuf, "\\%o: ", sletter); X else fprintf(obuf, "'%c': ", sletter); X X while (!(dspc(store[svpt], store[svpt+1]))) svpt +=2; X*************** X*** 726,731 X X if (sscanf(ins + itempt, "^%c':", &letter)) X { match(':'); letter &= 0x1F; return(2); } X X if (sscanf(ins + itempt, "Bounds(%d,%d)", &co1, &co2)) X { match(')'); return(65); } X X--- 727,735 ----- X X if (sscanf(ins + itempt, "^%c':", &letter)) X { match(':'); letter &= 0x1F; return(2); } X+ X+ if (sscanf(ins + itempt, "\\%o:", &letter)) X+ { match(':'); return(2); } X X if (sscanf(ins + itempt, "Bounds(%d,%d)", &co1, &co2)) X { match(')'); return(65); } END_OF_dif-eplot.c if test 1171 -ne `wc -c <dif-eplot.c`; then echo shar: \"dif-eplot.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f dif-hplot.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"dif-hplot.c\" else echo shar: Extracting \"dif-hplot.c\" \(582 characters\) sed "s/^X//" >dif-hplot.c <<'END_OF_dif-hplot.c' X*** hplot.c Mon Oct 12 03:24:43 1987 X--- ../hplot.c Mon Oct 12 03:27:18 1987 X*************** X*** 351,356 X if (sscanf(ins + itempt, "^%c':", &letter)) X { match(':'); letter &= 0x1F; return(2); } X X if (sscanf(ins + itempt, "Bounds(%d,%d)", &co1, &co2)) X { match(')'); return(66); } X X X--- 351,359 ----- X if (sscanf(ins + itempt, "^%c':", &letter)) X { match(':'); letter &= 0x1F; return(2); } X X+ if (sscanf(ins + itempt, "\\%o:", &letter)) X+ { match(':'); return(2); } X+ X if (sscanf(ins + itempt, "Bounds(%d,%d)", &co1, &co2)) X { match(')'); return(66); } X END_OF_dif-hplot.c if test 582 -ne `wc -c <dif-hplot.c`; then echo shar: \"dif-hplot.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f dif-vfont.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"dif-vfont.c\" else echo shar: Extracting \"dif-vfont.c\" \(627 characters\) sed "s/^X//" >dif-vfont.c <<'END_OF_dif-vfont.c' X*** vfont.c Mon Oct 12 03:08:01 1987 X--- ../vfont.c Mon Oct 12 02:00:56 1987 X*************** X*** 43,49 X character->addr = 0; X character->up = character->down = X character->left = character->right = 0; X! character->width = 12; /* ??? */ X } X else if (cindex[letter] || cvflag) X { X X--- 43,51 ----- X character->addr = 0; X character->up = character->down = X character->left = character->right = 0; X! if (cindex[letter]) X! character->width = store[cindex[letter]+2]-store[cindex[letter]]; X! else character->width = 12; /* ??? */ X } X else if (cindex[letter] || cvflag) X { END_OF_dif-vfont.c if test 627 -ne `wc -c <dif-vfont.c`; then echo shar: \"dif-vfont.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f h2s.l -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"h2s.l\" else echo shar: Extracting \"h2s.l\" \(443 characters\) sed "s/^X//" >h2s.l <<'END_OF_h2s.l' X int lowh = 0; X int hnum = 0; X int started = 0; X int ascchar = 32; X int ix; X X%% X X[0-9]+/- { lowh = atoi(yytext); X } X X[0-9]+ { if (!started) printf("charset\n"); X started = 1; X hnum = atoi(yytext); X if (lowh) ix = lowh; X else ix = hnum; X lowh = 0; X for (; ix <= hnum; ix++,ascchar++) X if (ascchar > ' ' && ascchar < 127) X printf("%d,%c\n", ix, ascchar); X else X printf("%d,\\%o\n", ix, ascchar); X } X X. ; X\n ; X END_OF_h2s.l if test 443 -ne `wc -c <h2s.l`; then echo shar: \"h2s.l\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 1 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