make it possible to access fonts without a display.

This commit is contained in:
rsc 2004-04-25 20:26:27 +00:00
parent a2c2caaafe
commit 4e20688042
7 changed files with 78 additions and 48 deletions

View file

@ -161,7 +161,8 @@ cf2subfont(Cachefont *cf, Font *f)
if(f->display){
if(f->display->screenimage)
depth = f->display->screenimage->depth;
}
}else
depth = 8;
name = subfontname(cf->name, f->name, depth);
if(name == nil)
return nil;
@ -244,7 +245,7 @@ loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
}
subf->cf = cf;
if(subf->f->ascent > f->ascent){
if(subf->f->ascent > f->ascent && f->display){
/* should print something? this is a mistake in the font file */
/* must prevent c->top from going negative when loading cache */
Image *b;
@ -297,6 +298,8 @@ loadchar(Font *f, Rune r, Cacheinfo *c, int h, int noflush, char **subfontname)
c->width = fi->width;
c->x = h*f->width;
c->left = fi->left;
if(f->display == nil)
return 1;
flushimage(f->display, 0); /* flush any pending errors */
b = bufimage(f->display, 37);
if(b == 0)
@ -355,10 +358,13 @@ fontresize(Font *f, int wid, int ncache, int depth)
Display *d;
ret = 0;
d = f->display;
if(depth <= 0)
depth = 1;
d = f->display;
if(d == nil)
goto Nodisplay;
new = allocimage(d, Rect(0, 0, ncache*wid, f->height), CHAN1(CGrey, depth), 0, 0);
if(new == nil){
fprint(2, "font cache resize failed: %r\n");
@ -382,6 +388,7 @@ fontresize(Font *f, int wid, int ncache, int depth)
}
freeimage(f->cacheimage);
f->cacheimage = new;
Nodisplay:
f->width = wid;
f->maxdepth = depth;
ret = 1;