subfont.c (806B)
1 #include <u.h> 2 #include <libc.h> 3 #include <draw.h> 4 5 Subfont* 6 allocsubfont(char *name, int n, int height, int ascent, Fontchar *info, Image *i) 7 { 8 Subfont *f, *cf; 9 10 assert(height != 0 /* allocsubfont */); 11 12 f = malloc(sizeof(Subfont)); 13 if(f == 0) 14 return 0; 15 f->n = n; 16 f->height = height; 17 f->ascent = ascent; 18 f->info = info; 19 f->bits = i; 20 f->ref = 1; 21 if(name){ 22 /* 23 * if already caching this subfont, leave older 24 * (and hopefully more widely used) copy in cache. 25 * this case should not happen -- we got called 26 * because cachechars needed this subfont and it 27 * wasn't in the cache. 28 */ 29 f->name = strdup(name); 30 if((cf=lookupsubfont(i->display, name)) == 0) 31 installsubfont(name, f); 32 else 33 freesubfont(cf); /* drop ref we just picked up */ 34 }else 35 f->name = 0; 36 return f; 37 }