5 extern vlong _drawflength(int);
9 parsefontscale(char *name, char **base)
16 while('0' <= *p && *p <= '9') {
17 scale = scale*10 + *p - '0';
20 if(*p == '*' && scale > 0)
29 extern char _defontfile[];
32 openfont1(Display *d, char *name)
36 char *buf, *nambuf, *nambuf0, *fname, *freename;
40 scale = parsefontscale(name, &fname);
42 if(strcmp(fname, "*default*") == 0) {
43 buf = strdup(_defontfile);
46 fd = open(fname, OREAD);
47 if(fd < 0 && strncmp(fname, "/lib/font/bit/", 14) == 0){
48 nambuf = smprint("#9/font/%s", fname+14);
51 nambuf0 = unsharp(nambuf);
57 if((fd = open(nambuf, OREAD)) < 0){
62 name = smprint("%d*%s", scale, nambuf);
70 if(fd < 0 && strncmp(fname, "/mnt/font/", 10) == 0) {
71 fd = _fontpipe(fname+10);
87 i = readn(fd, buf, n);
97 fnt = buildfont(d, buf, name);
103 fnt->height *= scale;
104 fnt->ascent *= scale;
111 swapfont(Font *targ, Font **oldp, Font **newp)
116 sysfatal("bad swapfont %p %p %p", targ, *oldp, *newp);
122 f.display = old->display;
123 f.height = old->height;
124 f.ascent = old->ascent;
125 f.width = old->width;
128 f.maxdepth = old->maxdepth;
129 f.ncache = old->ncache;
130 f.nsubf = old->nsubf;
131 f.scale = old->scale;
132 f.cache = old->cache;
135 f.cacheimage = old->cacheimage;
137 old->name = new->name;
138 old->display = new->display;
139 old->height = new->height;
140 old->ascent = new->ascent;
141 old->width = new->width;
142 old->nsub = new->nsub;
144 old->maxdepth = new->maxdepth;
145 old->ncache = new->ncache;
146 old->nsubf = new->nsubf;
147 old->scale = new->scale;
148 old->cache = new->cache;
149 old->subf = new->subf;
151 old->cacheimage = new->cacheimage;
154 new->display = f.display;
155 new->height = f.height;
156 new->ascent = f.ascent;
157 new->width = f.width;
160 new->maxdepth = f.maxdepth;
161 new->ncache = f.ncache;
162 new->nsubf = f.nsubf;
163 new->scale = f.scale;
164 new->cache = f.cache;
167 new->cacheimage = f.cacheimage;
179 // If font name has form x,y return y.
180 p = strchr(f->namespec, ',');
184 // If font name is /mnt/font/Name/Size/font, scale Size.
185 if(strncmp(f->name, "/mnt/font/", 10) == 0) {
186 p = strchr(f->name+10, '/');
187 if(p == nil || *++p < '0' || *p > '9')
191 while('0' <= *q && *q <= '9')
192 size = size*10 + *q++ - '0';
193 return smprint("%.*s%d%s", utfnlen(f->name, p-f->name), f->name, size*2, q);
196 // Otherwise use pixel doubling.
198 return smprint("%d*%s", f->scale*2, f->name);
209 if(f->hidpi != nil) {
210 swapfont(f, &f->lodpi, &f->hidpi);
215 fnew = openfont1(f->display, name);
221 swapfont(f, &f->lodpi, &f->hidpi);
225 openfont(Display *d, char *name)
231 // If font name has form x,y use x for lodpi, y for hidpi.
233 namespec = strdup(name);
234 if((p = strchr(name, ',')) != nil)
237 f = openfont1(d, name);
242 f->namespec = namespec;
244 /* add to display list for when dpi changes */
245 /* d can be nil when invoked from mc. */
247 f->ondisplaylist = 1;
248 f->prev = d->lastfont;
256 /* if this is a hi-dpi display, find hi-dpi version and swap */
257 if(d->dpi >= DefaultDPI*3/2)
267 _fontpipe(char *name)
271 char buf[1024], *argv[10];
276 pid = rfork(RFNOWAIT|RFFDG|RFPROC);
292 execvp("fontsrv", argv);
293 print("exec fontsrv: %r\n");
298 // success marked with leading \001.
299 // otherwise an error happened.
300 for(nbuf=0; nbuf<sizeof buf-1; nbuf++) {
301 if(read(p[0], &c, 1) < 1 || c == '\n') {