|
|
1.1 root 1: #include <stdio.h>
2: #include "jerq.h"
3: #include "commands.h"
4: #include "io.h"
5:
6: #define ISIZE(n) ((n+1)*sizeof(Fontchar))
7:
8: #define FNTsize 20
9: Font *fntab[FNTsize];
10: FILE *inf;
11: extern int Jin, Jout;
12:
13: int lookUpFont(f) Font *f;
14: { int i;
15: for (i=0; i<FNTsize && fntab[i]!=(Font *)NULL && fntab[i]!=f; i++) ;
16: if (i >= FNTsize) {
17: fprintf(stderr,"out of room in font table\n");
18: exit();
19: }
20: else if (fntab[i] == (Font *) NULL) {
21: fprintf(stderr,"unknown font referenced. DEFONT substituted.\n");
22: return(0);
23: }
24: else return(i);
25: }
26:
27: void ffree(f) Font *f;
28: { int i,j;
29: sendCommand(CCFFREE);
30: i = lookUpFont(f);
31: sendInt(i);
32: /*close the hole*/
33: for (j=i+1; j<FNTsize; j++) fntab[j-1] = fntab[j];
34: fntab[FNTsize] = (Font *) NULL;
35: }
36:
37: static ngetc(n, base) int n; char **base;
38: { int x, i;
39:
40: i = 0;
41: do {
42: x = getc(inf);
43: (*base)[i++] = x;
44: if(x == -1)
45: return(1);
46: } while (--n > 0);
47: return(0);
48: }
49:
50:
51: Font *loadFont(fname) char *fname;
52: { short n, in;
53: Font *f;
54: char *temp;
55:
56: if((inf = fopen(fname, "r")) == (FILE *)NULL) return((Font *) NULL);
57:
58: temp = (char *)∈
59: if (ngetc(2, &temp)) f = (Font *) NULL;
60: else {
61: swab(temp, (char*)&n, 2);
62: if ((f = (Font *) malloc(sizeof(Font)+ISIZE(n)))!=(Font *)NULL) {
63: f->n = n;
64: temp = 2 + (char *)f;
65: if (ngetc(6, &temp)) {
66: free(f);
67: f = (Font *) NULL;
68: }
69: else {
70: temp = (char *)f->info;
71: if (ngetc(ISIZE(n), &temp)) {
72: free(f);
73: f = (Font *) NULL;
74: }
75: }
76: }
77: }
78:
79: fclose(inf);
80: return(f);
81: }
82:
83: Font *getfont(fname) char *fname;
84: { int i, j, n;
85: FILE *fp;
86: char fbuf[4096];
87:
88: if ((fp=fopen(fname,"r"))==(FILE *)NULL) {
89: fprintf(stderr,"font not found: %s\n",fname);
90: return((Font *)NULL);
91: }
92: sendCommand(CCGETFONT);
93: for (i=0; i<FNTsize && fntab[i]!=(Font *) NULL; i++) ;
94: if (i>=FNTsize) i=1;
95: sendInt(i);
96: flush();
97: while((n=fread(fbuf,sizeof(char),sizeof(fbuf),fp)) > 0)
98: /* for (j=0; j<n; j++) put(fbuf[j]); */
99: write(Jout,fbuf,n);
100: fclose(fp);
101: fntab[i] = loadFont(fname);
102: return(fntab[i]);
103: }
104:
105: strwidth(f,s) Font *f; unsigned char *s;
106: {
107: int wid=0;
108: int n = f->n;
109: Fontchar *info;
110:
111: info = f->info;
112: for(; *s; s++)
113: if(*s < n) wid+=info[*s].width;
114: return(wid);
115: }
116:
117: jstrwidth(s)
118: char *s;
119: {
120: return(strwidth(&defont,s));
121: }
122:
123:
124:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.