|
|
1.1 root 1:
2: /*
3: *
4: * This program was written with tabs set to every fourth column,
5: * so things will look funny unless you have your tabs set the same way.
6: * I haven't really finished the program, but it works and I doubt I'll
7: * do anything else with it.
8: *
9: */
10:
11:
12: #include <stdio.h>
13: #include <ctype.h>
14:
15: /*
16: #include "glyph.h"
17: */
18: #include "dev.h"
19:
20:
21: #define NON_FATAL 0
22: #define FATAL 1
23:
24: #define FALSE 0
25: #define TRUE 1
26:
27: #define NOT_SET -1 /* variable has not been initialized */
28:
29: #define RES 0 /* used in new_value() switch stmt */
30: #define UNIT 1
31: #define HOR 2
32: #define VERT 3
33: #define WIDTH 4
34: #define LENGTH 5
35:
36: #define BMASK 0377 /* mask for characters */
37:
38: #define CNAME 2 /* max length of special characters */
39: #define DNAME 10 /* max length of device name */
40: #define FNAME 10 /* max length of font name */
41: #define PNAME 50 /* longest allowed pathname */
42:
43: #define MAX_BUFF 30 /* input strings are put here */
44: #define LINE_LENGTH 100 /* longest allowed line */
45: #define MAX_CHARS 255 /* most allowed chars per font */
46:
47: #define SIZE_LENGTH 150 /* space allowed for new point sizes */
48: #define FONT_LENGTH 150 /* space for new default font list */
49:
50:
51:
52: int use_rast = FALSE; /* get widths from raster tables? */
53:
54: char path[PNAME+1]; /* path names built up here */
55:
56: char *srcdir = "/usr/lib/font"; /* ASCII font files are kept here */
57: char *fontdir = "/usr/lib/font"; /* binary font and device files */
58: char *bitdir = "/usr/lib/font"; /* raster tables are located here */
59: char *changes = "FONTCHANGES"; /* interpret this file */
60:
61: char mdev[DNAME+1] = ""; /* use this device's source files */
62: char tdev[DNAME+1] = ""; /* target device - for raster tables */
63: char cur_font[FNAME+1] = ""; /* font we are currently working on */
64:
65: int unitwidth = NOT_SET; /* widths hold for this point size */
66: int res = NOT_SET; /* and this target device resolution */
67: int hor = NOT_SET; /* minimum horizontal step */
68: int vert = NOT_SET; /* minimum vertical step */
69: char fonts[FONT_LENGTH] = {0}; /* new default font list */
70: char sizes[SIZE_LENGTH] = {0}; /* and point size list */
71:
72: float incr; /* add this to width after expansion */
73: float scale = NOT_SET; /* scale factor for width changes */
74: float dflt_chng = NOT_SET; /* default width change */
75: float font_chng = NOT_SET; /* width change for current font */
76: float dflt_incr = .5; /* add to width after expansion */
77:
78: int dcount; /* index into following arrays */
79: char names[MAX_CHARS][CNAME+1]; /* special character strings go here */
80: float deltas[MAX_CHARS]; /* corresponding width changes */
81: float incrs[MAX_CHARS]; /* character increments */
82:
83: struct dev dev; /* *mdev's DESC.out header goes here */
84:
85: int nchtab; /* number of special chars in chtab */
86: short *pstab; /* point size table - not needed */
87: short *chtab; /* char's index in chname array */
88: char *chname; /* special character strings */
89:
90:
91: FILE *fp_change; /* file pointer for *changes */
92: FILE *fp_rast; /* raster table used for widths */
93: FILE *fp_in; /* input file for current font */
94: FILE *fp_out; /* output file for current font */
95:
96: char **argv; /* let everyone use them */
97: int argc;
98:
99:
100:
101:
102: /*****************************************************************************/
103:
104:
105: main(agc, agv)
106:
107:
108: int agc;
109: char *agv[];
110:
111:
112: {
113:
114:
115: /********************************************************************
116: * *
117: * This program reads the file *changes in the current *
118: * directory which contains instructions on how to expand or *
119: * contract the character widths for each of the fonts mentioned *
120: * in the file. These changes will hopefully make the output for *
121: * *tdev more readable. Admittedly there's quite a bit of overkill *
122: * in this program, but I'm not going to change it. *
123: * *
124: * There are several different methods that can be used to *
125: * make the desired width changes. Probably the simplest is to *
126: * adjust the device resolution in the new DESC file up or down *
127: * an appropriate ammount and leave the widths in the font tables *
128: * unchanged. This approach results in a uniform width change for *
129: * all the characters on every available font. This type of change *
130: * can be obtained by specifying a default width change without *
131: * defining a new device resolution. *
132: * *
133: * Since a uniform expansion may not always be appropriate *
134: * you can also specify a width change for each for the new fonts. *
135: * This type of expansion will replace any default font change *
136: * that may have been specified. *
137: * *
138: ********************************************************************/
139:
140:
141:
142: argv = agv; /* global so everyone can use them */
143: argc = agc;
144:
145: get_options(); /* process any command line options */
146: startchanges(); /* start reading the *changes file */
147: checkvalues(); /* make sure everything's defined */
148: getdesc(); /* read *mdev's DESC.out file */
149: makedesc(); /* make *tdev's new DESC file */
150: finishchanges(); /* read rest of the *changes file */
151:
152: } /* End of main */
153:
154:
155: /******************************************************************************/
156:
157:
158: get_options()
159:
160:
161: {
162:
163:
164: /********************************************************************
165: * *
166: * Called from the main program to read and process any *
167: * command line options. *
168: * *
169: ********************************************************************/
170:
171:
172: while ( argc > 1 && argv[1][0] == '-' ) {
173:
174: switch ( argv[1][1] ) {
175:
176: case 'S': /* font source directory */
177: srcdir = &argv[1][2];
178: break;
179:
180: case 'F': /* binary font directory */
181: fontdir = &argv[1][2];
182: break;
183:
184: case 'R': /* raster table directory */
185: bitdir = &argv[1][2];
186: break;
187:
188: case 'm': /* get master device name */
189: if ( strlen(&argv[1][2]) > DNAME )
190: error(FATAL, "device name %s too long", &argv[1][2]);
191: strcpy(mdev, &argv[1][2]);
192: break;
193:
194: case 't': /* set target device name */
195: if ( strlen(&argv[1][2]) > DNAME )
196: error(FATAL, "device name %s too long", &argv[1][2]);
197: strcpy(tdev, &argv[1][2]);
198: break;
199:
200: default:
201: error(FATAL, "illegal option %c", argv[1][1]);
202:
203: } /* End switch */
204:
205: argv++; /* next argument */
206: argc--;
207:
208: } /* End while */
209:
210: } /* End of get_options */
211:
212:
213: /*****************************************************************************/
214:
215:
216: startchanges()
217:
218:
219: {
220:
221:
222: char buff[MAX_BUFF]; /* input buffer */
223: int ch; /* used to skip comments */
224:
225:
226: /********************************************************************
227: * *
228: * Called from the main program to read the font change file *
229: * *changes. If there's still one command line argument left when *
230: * we get here, we will use it as the name of the input file, *
231: * otherwise the default file *changes is used. *
232: * *
233: ********************************************************************/
234:
235:
236: if ( argc > 1 )
237: changes = &argv[1][0];
238:
239: if ( (fp_change = fopen(changes, "r")) == NULL )
240: error(FATAL, "can't open file %s", changes);
241:
242: while ( fscanf(fp_change, "%s", buff) != EOF ) {
243:
244: if ( strcmp(buff, "font") == 0 )
245: return;
246: else if ( strcmp(buff, "master") == 0 )
247: get_mdev();
248: else if ( strcmp(buff, "target") == 0 )
249: get_tdev();
250: else if ( strcmp(buff, "unitwidth") == 0 )
251: get_int(fp_change, &unitwidth);
252: else if ( strcmp(buff, "res") == 0 )
253: get_int(fp_change, &res);
254: else if ( strcmp(buff, "hor") == 0 )
255: get_int(fp_change, &hor);
256: else if ( strcmp(buff, "vert") == 0 )
257: get_int(fp_change, &vert);
258: else if ( strcmp(buff, "sizes") == 0 )
259: get_sizes();
260: else if ( strcmp(buff, "fonts") == 0 )
261: get_fonts();
262: else if ( strcmp(buff, "default") == 0 ) {
263: fscanf(fp_change, "%s", buff);
264: if ( strcmp(buff, "change") != 0 )
265: error(FATAL, "syntax error - bad default change statement");
266: get_float(fp_change, &dflt_chng);
267: } else if ( strcmp(buff, "round") == 0 ) {
268: fscanf(fp_change, "%s", buff);
269: if ( strcmp(buff, "up") == 0 )
270: dflt_incr = 1.0;
271: else if ( strcmp(buff, "down") == 0 )
272: dflt_incr = 0.0;
273: else error(FATAL, "syntax error - bad round statement");
274: } else if ( strcmp(buff, "use") == 0 ) {
275: fscanf(fp_change, "%s", buff);
276: if ( strcmp(buff, "raster") != 0 )
277: error(FATAL, "syntax error - bad use statement");
278: fscanf(fp_change, "%s", buff);
279: if ( strcmp(buff, "tables") == 0 )
280: error(FATAL, "syntax error - bad use statement");
281: use_rast = TRUE;
282: } else if ( buff[0] == '#' )
283: while ( (ch = getc(fp_change)) != EOF && ch != '\n' ) ;
284: else error(FATAL, "don't know command %s", buff);
285:
286: } /* End while */
287:
288: error(FATAL, "no font commands in file %s", changes);
289:
290: } /* End of startchanges */
291:
292:
293: /*****************************************************************************/
294:
295:
296: checkvalues()
297:
298:
299: {
300:
301:
302:
303: /********************************************************************
304: * *
305: * Called from the main program to make sure all the required *
306: * parameters have been properly defined. *
307: * *
308: ********************************************************************/
309:
310:
311: if ( *mdev == '\0' )
312: error(FATAL, "missing master device name");
313:
314: if ( use_rast == TRUE )
315: if ( *tdev == '\0' )
316: error(FATAL, "missing target device name");
317: else if ( res == NOT_SET )
318: error(FATAL, "missing target device resolution");
319:
320: } /* End of checkvalues */
321:
322:
323: /*****************************************************************************/
324:
325:
326: get_mdev()
327:
328:
329: {
330:
331:
332: char buff[MAX_BUFF]; /* put the device name here */
333:
334:
335: /********************************************************************
336: * *
337: * Read the name of the master device from *fp_change, and *
338: * save the name in array mdev[]. If *mdev has already been set, *
339: * possibly by an option, it won't be changed again. *
340: * *
341: ********************************************************************/
342:
343:
344: if ( fscanf(fp_change, " device %s", buff) != 1 )
345: error(FATAL, "missing master device name");
346:
347: if ( strlen(buff) > DNAME )
348: error(FATAL, "master device name %s too long", buff);
349:
350: if ( *mdev == '\0' )
351: strcpy(mdev, buff);
352:
353: } /* End of get_mdev */
354:
355:
356: /*****************************************************************************/
357:
358:
359: get_tdev()
360:
361:
362: {
363:
364:
365: char buff[MAX_BUFF]; /* target device name put here */
366:
367:
368: /********************************************************************
369: * *
370: * Called from startchanges() to read the name of the target *
371: * typesetter from *fp_change, and store the result in the array *
372: * tdev[]. If the device has already been specified nothing is *
373: * done. *
374: * *
375: ********************************************************************/
376:
377:
378: if ( fscanf(fp_change, " device %s", buff) != 1 )
379: error(FATAL, "missing target device name");
380:
381: if ( strlen(buff) > DNAME )
382: error(FATAL, "target device name %s too long", buff);
383:
384: if ( *tdev != '\0' )
385: strcpy(tdev, buff);
386:
387: } /* End of get_tdev */
388:
389:
390: /*****************************************************************************/
391:
392:
393: get_int(fp, num)
394:
395:
396: FILE *fp; /* read an integer from this file */
397: int *num; /* and store it here */
398:
399:
400: {
401:
402:
403: /********************************************************************
404: * *
405: * Called to read an integer from the input file and store the *
406: * result in num - this routine and get_float() really should be *
407: * macros. *
408: * *
409: ********************************************************************/
410:
411:
412: if ( fscanf(fp, "%d", num) != 1 )
413: error(FATAL, "syntax error - integer not found");
414:
415: } /* End of get_int */
416:
417:
418: /*****************************************************************************/
419:
420:
421: get_float(fp, num)
422:
423:
424: FILE *fp; /* read a float from this file */
425: float *num; /* and store it here */
426:
427:
428: {
429:
430:
431: /********************************************************************
432: * *
433: * Called to read a floating point number from *fp_change and *
434: * store the result in num. *
435: * *
436: ********************************************************************/
437:
438:
439: if ( fscanf(fp, "%f", num) != 1 )
440: error(FATAL, "syntax error - floating point number not found");
441:
442: } /* End of get_float */
443:
444:
445: /*****************************************************************************/
446:
447:
448: get_sizes()
449:
450:
451: {
452:
453:
454: int i; /* index into sizes[] array */
455:
456:
457: /********************************************************************
458: * *
459: * Called from startchanges() to read the new default point *
460: * size list for the DESC file. The format expected for the size *
461: * list in the *fp_change file is the same as in the ASCII DESC *
462: * file. *
463: * *
464: ********************************************************************/
465:
466:
467: i = 0;
468:
469: while ( i < SIZE_LENGTH ) {
470:
471: while ( isspace(sizes[i++] = getc(fp_change)) ) ;
472:
473: if ( !isdigit(sizes[i-1]) )
474: error(FATAL, "syntax error - bad point size list");
475:
476: if ( sizes[i-1] == '0' && (isspace(sizes[i++] = getc(fp_change))) ) {
477: sizes[i-1] = '\0';
478: return;
479: } /* End if */
480:
481: while ( isdigit(sizes[i++] = getc(fp_change)) ) ;
482:
483: } /* End while */
484:
485: error(FATAL, "point size list too long"); /* shouldn't get here */
486:
487: } /* End of get_sizes */
488:
489:
490: /*****************************************************************************/
491:
492:
493: get_fonts()
494:
495:
496: {
497:
498:
499: int count; /* number of default fonts */
500: int i; /* index used for fonts[] array */
501:
502:
503: /********************************************************************
504: * *
505: * Called from startchanges() to read a new default font list *
506: * for the new DESC file. Again the format expected for the font *
507: * list is the same as in the ASCII DESC file. *
508: * *
509: ********************************************************************/
510:
511:
512: count = -1; /* real value is the first string */
513: i = 0; /* next character goes here */
514:
515: do {
516:
517: while ( isspace(fonts[i++] = getc(fp_changes)) ) ;
518:
519: while ( !isspace(fonts[i++] = getc(fp_changes)) ) ;
520:
521: if ( count < 0 ) /* string is the default font count */
522: count = atoi(fonts);
523:
524: } while ( count-- > 0 );
525:
526: fonts[i-1] = '\0';
527:
528: } /* End of get_fonts */
529:
530:
531: /*****************************************************************************/
532:
533:
534: getdesc()
535:
536:
537: {
538:
539:
540: int fin; /* DESC.out's file descriptor */
541: char *filebase; /* memory block for DESC.out file */
542: char *malloc(); /* memory allocation routine */
543:
544:
545: /********************************************************************
546: * *
547: * Called from the main program to read the DESC.out file for *
548: * *mdev. Most of the file is only needed if we are going to do *
549: * the width lookups in the raster tables, but anyway we'll read *
550: * the whole thing in. *
551: * *
552: ********************************************************************/
553:
554:
555: sprintf(path, "%s/dev%s/DESC.out", fontdir, mdev);
556: if ( (fin = open(path, 0)) < 0 )
557: error(FATAL, "can't open file %s", path);
558:
559: read(fin, &dev, sizeof(struct dev)); /* struct dev comes first */
560:
561: nchtab = dev.nchtab;
562:
563: if ( (filebase = malloc(dev.filesize)) == NULL )
564: error(FATAL, "no memory available");
565:
566: read(fin, filebase, dev.filesize); /* get rest of the DESC.out file */
567: pstab = (short *) filebase; /* this table is never used */
568: chtab = pstab + dev.nsizes + 1;
569: chname = (char *) (chtab + dev.nchtab);
570:
571: close(fin); /* won't need this guy again */
572:
573: } /* End of getdesc */
574:
575:
576: /*****************************************************************************/
577:
578:
579: makedesc()
580:
581:
582: {
583:
584:
585: char buff[MAX_BUFF]; /* input strings are put here */
586: int ch; /* used in skipping over comments */
587: int temp; /* used to skip font and point sizes */
588:
589:
590: /********************************************************************
591: * *
592: * Called from the main program to make the new ASCII DESC *
593: * file for *tdev. *
594: * *
595: ********************************************************************/
596:
597:
598: sprintf(path, "%s/dev%s/DESC", srcdir, mdev);
599: if ( (fp_in = fopen(path, "r")) == NULL )
600: error(FATAL, "can't read file %s", path);
601:
602: if ( (fp_out = fopen("DESC", "w")) == NULL )
603: error(FATAL, "can't write new DESC file");
604:
605: while ( fscanf(fp_in, "%s", buff) != EOF ) {
606:
607: fprintf(fp_out, "%s", buff);
608: if ( strcmp(buff, "res") == 0 )
609: new_value(RES);
610: else if ( strcmp(buff, "hor") == 0 )
611: new_value(HOR);
612: else if ( strcmp(buff, "vert") == 0 )
613: new_value(VERT);
614: else if ( strcmp(buff, "unitwidth") == 0 )
615: new_value(UNIT);
616: else if ( strcmp(buff, "paperwidth") == 0 )
617: new_value(WIDTH);
618: else if ( strcmp(buff, "paperlength") == 0 )
619: new_value(LENGTH);
620: else if ( strcmp(buff, "fonts") == 0 && fonts[0] ) {
621: fprintf(fp_out, "%s\n", fonts);
622: get_int(fp_in, &temp);
623: while ( temp-- > 0 )
624: fscanf(fp_in, "%s", buff);
625: } else if ( strcmp(buff, "sizes") == 0 && sizes[0] ) {
626: fprintf(fp_out, "%s\n", sizes);
627: do {
628: get_int(fp_in, &temp);
629: } while ( temp != 0 );
630: } else if ( strcmp(buff, "charset") == 0 )
631: while ( (ch = getc(fp_in)) != EOF ) putc(ch, fp_out);
632: else copy_line();
633:
634: } /* End while */
635:
636: fclose(fp_in);
637: fclose(fp_out);
638:
639: } /* End of makedesc */
640:
641:
642: /*****************************************************************************/
643:
644:
645: new_value(value)
646:
647:
648: int value; /* used in the switch statement */
649:
650:
651: {
652:
653:
654: int temp; /* next number read from *fp_in */
655:
656:
657: /********************************************************************
658: * *
659: * Called from makedesc() to write a new value out to the DESC *
660: * file for the parameter specified by value. *
661: * *
662: ********************************************************************/
663:
664:
665: get_int(fp_in, &temp);
666:
667: switch ( value ) {
668:
669: case RES:
670: if ( res == NOT_SET )
671: if ( dflt_chng == NOT_SET ) {
672: res = temp;
673: dflt_chng = 0.0;
674: } else res = temp / (1 + dflt_chng);
675: temp = res;
676: break;
677:
678: case UNIT:
679: if ( unitwidth == NOT_SET )
680: unitwidth = temp;
681: temp = unitwidth;
682: break;
683:
684: case HOR:
685: if ( hor == NOT_SET )
686: hor = temp;
687: temp = hor;
688: break;
689:
690: case VERT:
691: if ( vert == NOT_SET )
692: vert = temp;
693: temp = vert;
694: break;
695:
696: case WIDTH:
697: case LENGTH:
698: temp = (temp * res) / dev.res;
699: break;
700:
701: } /* End switch */
702:
703: fprintf(fp_out, " %d\n", temp);
704:
705: } /* End of new_value */
706:
707:
708: /*****************************************************************************/
709:
710:
711: finishchanges()
712:
713:
714: {
715:
716:
717: char buff[MAX_BUFF];
718: int ch;
719: int i;
720:
721:
722: /********************************************************************
723: * *
724: * Called from startchanges() to process all the new font *
725: * commands. *
726: * *
727: ********************************************************************/
728:
729:
730: nextfont(); /* do initialization for next font */
731:
732: while ( fscanf(fp_change, "%s", buff ) != EOF ) {
733:
734: if ( strcmp(buff, "font") == 0 ) {
735: makefont();
736: nextfont();
737: } else if ( strcmp(buff, "increment") == 0 ) {
738: if ( fscanf(fp_change, "%s by ", buff) != 1 )
739: error(FATAL, "syntax error - bad file format");
740: if ( strlen(buff) > CNAME )
741: error(FATAL, "special char %s too long", buff);
742: i = lookup(buff);
743: get_float(fp_change, &incrs[i]);
744: if ( i == dcount ) {
745: deltas[dcount] = NOT_SET;
746: strcpy(&names[dcount++][0], buff);
747: } /* End if */
748: } else if ( strcmp(buff, "change") == 0 ) {
749: if ( fscanf(fp_change, "%s by ", buff) != 1 )
750: error(FATAL, "syntax error - bad file format");
751: if ( strcmp(buff, "widths") == 0 )
752: get_float(fp_change, &font_chng);
753: else {
754: if ( strlen(buff) > CNAME )
755: error(FATAL, "special char %s too long", buff);
756: i = lookup(buff);
757: get_float(fp_change, &deltas[i]);
758: if ( i == dcount ) {
759: incrs[dcount] = 0;
760: strcpy(&names[dcount++][0], buff);
761: } /* End if */
762: } /* End else */
763: } else if ( buff[0] == '#' )
764: while ( (ch = getc(fp_change)) != '\n' && ch != EOF ) ;
765:
766: } /* End while */
767:
768: makefont();
769:
770: } /* End of finishchanges */
771:
772:
773: /*****************************************************************************/
774:
775:
776: nextfont()
777:
778:
779: {
780:
781:
782: /********************************************************************
783: * *
784: * Called from finishchanges() to get the name of the next *
785: * font and do any other initialization that may be required. *
786: * *
787: ********************************************************************/
788:
789:
790: fscanf(fp_change, "%s", cur_font); /* name of the next font */
791:
792: font_chng = NOT_SET;
793: incr = dflt_incr;
794: dcount = 0;
795:
796: if ( scale == NOT_SET )
797: if ( use_rast == TRUE )
798: scale = 1.0;
799: else scale = ( float )(res * unitwidth) / (dev.res * dev.unitwidth);
800:
801: } /* End of nextfont */
802:
803:
804: /*****************************************************************************/
805:
806:
807: makefont()
808:
809:
810: {
811:
812:
813: char buff[MAX_BUFF]; /* temp buffer for *fp_change reads */
814:
815:
816: /********************************************************************
817: * *
818: * This routine makes all the new ASCII font files. *
819: * *
820: ********************************************************************/
821:
822:
823: sprintf(path, "%s/dev%s/%s", srcdir, mdev, cur_font);
824: if ( (fp_in = fopen(path, "r")) == NULL )
825: error(FATAL, "can't open font file %s", path);
826:
827: if ( (fp_out = fopen(cur_font, "w")) == NULL )
828: error(FATAL, "can't open output font file %s", cur_font);
829:
830: while ( fscanf(fp_in, "%s", buff) != EOF ) {
831:
832: fprintf(fp_out, "%s", buff); /* echo what we just read in */
833: if ( strcmp(buff, "charset") == 0 )
834: copy_chars();
835: else copy_line();
836:
837: } /* End while */
838:
839: fclose(fp_in); /* done with these files for now */
840: fclose(fp_out);
841:
842: } /* End of makefont */
843:
844:
845: /*****************************************************************************/
846:
847:
848: copy_chars()
849:
850:
851: {
852:
853:
854: char ch[10]; /* standard stuff from makedev */
855: char width[10];
856: char kern[10];
857: char code[10];
858: char buff[LINE_LENGTH]; /* next line from charset part */
859:
860:
861: /********************************************************************
862: * *
863: * Called from makefont() to copy the charset portion of the *
864: * current font file to the output file. The width entry for each *
865: * character will be adjusted by routine newwidth(). *
866: * *
867: ********************************************************************/
868:
869:
870: putc('\n', fp_out);
871:
872: while ( fgets(buff, sizeof(buff), fp_in) != NULL ) {
873:
874: if ( sscanf(buff, "%s %s %s %s", ch, width, kern, code) < 2 )
875: continue;
876:
877: if ( width[0] == '"' ) { /* it's a synonym */
878: fprintf(fp_out, "%s", buff);
879: continue;
880: } /* End if */
881:
882: newwidth(ch, width); /* calculate *ch's new width */
883:
884: fprintf(fp_out, "%s\t%s\t%s\t%s\n", ch, width, kern, code);
885:
886: } /* End while */
887:
888: } /* End of copy_chars */
889:
890:
891: /*****************************************************************************/
892:
893:
894: copy_line()
895:
896:
897: {
898:
899:
900: int ch;
901:
902:
903: /********************************************************************
904: * *
905: * Called from makefont() to copy the current line from fp_in *
906: * to fp_out. *
907: * *
908: ********************************************************************/
909:
910:
911: while ( (ch = putc(getc(fp_in), fp_out)) != '\n' && ch != EOF ) ;
912:
913: } /* End of copy_line */
914:
915:
916: /*****************************************************************************/
917:
918:
919: newwidth(ch, width)
920:
921:
922: char *ch; /* get the width for this character */
923: char *width; /* and store it here */
924:
925:
926: {
927:
928:
929: int newwidth; /* character's new width */
930: float cwidth; /* char's current width */
931: float delta; /* width change for the character */
932:
933: float getdelta();
934: float atof();
935:
936:
937: /********************************************************************
938: * *
939: * Called from copy_chars() to get the new width for character *
940: * ch, and store the ASCII representation for it in array width[]. *
941: * If we are supposed to be getting the character widths from the *
942: * raster tables we call getwidth() to do the work, otherwise we *
943: * use the value obtained from the ASCII font file. *
944: * *
945: ********************************************************************/
946:
947:
948: if ( use_rast == TRUE )
949: cwidth = getwidth(ch);
950: else cwidth = atof(width);
951:
952: delta = getdelta(ch);
953:
954: if ( (newwidth = cwidth * (1 + delta) * scale + incr) < 0 || newwidth > BMASK )
955: error(FATAL, "bad width %d for char %s", newwidth, ch);
956:
957: sprintf(width, "%d", newwidth);
958:
959: } /* End of newwidth */
960:
961:
962: /*****************************************************************************/
963:
964:
965: getwidth(ch)
966:
967:
968: char *ch; /* get raster width for this char */
969:
970:
971: {
972:
973:
974: /********************************************************************
975: * *
976: * Called from newwidth() to get the raster table width for *
977: * character ch form the raster table for the current font and in *
978: * size unitwidth. *
979: * *
980: ********************************************************************/
981:
982:
983: return(1);
984:
985: } /* End of getwidth */
986:
987:
988: /*****************************************************************************/
989:
990:
991: float getdelta(ch)
992:
993:
994: char *ch; /* get change for this char */
995:
996:
997: {
998:
999:
1000: int i;
1001: float change;
1002:
1003:
1004: /********************************************************************
1005: * *
1006: * This routine gets the appropriate change in width that we *
1007: * should use for character ch in the new font table. *
1008: * *
1009: ********************************************************************/
1010:
1011:
1012: change = font_chng == NOT_SET ? dflt_chng : font_chng;
1013: incr = dflt_incr;
1014:
1015: if ( (i = lookup(ch)) < dcount ) {
1016: change = ( deltas[i] == NOT_SET ) ? change : deltas[i];
1017: incr += incrs[i];
1018: } /* End if */
1019:
1020: return(change);
1021:
1022: } /* End of getdelta */
1023:
1024:
1025: /*****************************************************************************/
1026:
1027:
1028: lookup(ch)
1029:
1030:
1031: char *ch; /* look this character string up */
1032:
1033:
1034: {
1035:
1036:
1037: int i;
1038:
1039:
1040: /********************************************************************
1041: * *
1042: * Called from finishchanges() to find the character string *
1043: * *ch in array names[]. If it isn't found dcount is returnd. *
1044: * *
1045: ********************************************************************/
1046:
1047:
1048: for ( i = 0; i < dcount; i++ )
1049: if ( strcmp(ch, &names[i][0]) == 0 )
1050: break;
1051:
1052: return(i);
1053:
1054: } /* End of lookup */
1055:
1056:
1057: /*****************************************************************************/
1058:
1059:
1060: error(kind, mesg, arg1, arg2)
1061:
1062:
1063: int kind; /* FATAL or NON_FATAL error */
1064: char *mesg; /* error message to be printed */
1065:
1066:
1067: {
1068:
1069:
1070: /********************************************************************
1071: * *
1072: * Write out the error message *mesg, and quit the program if *
1073: * kind is FATAL. *
1074: * *
1075: ********************************************************************/
1076:
1077:
1078: fprintf(stderr, "makefonts: ");
1079: fprintf(stderr, mesg, arg1, arg2);
1080: fprintf(stderr, "\n");
1081:
1082: if ( kind == FATAL )
1083: exit(1);
1084:
1085: } /* End of error */
1086:
1087:
1088: /*****************************************************************************/
1089:
1090:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.