1 #include <u.h> 2 #include <libc.h> 3 #include <draw.h> 4 5 /* 6 * Cobble fake font using existing subfont 7 */ 8 Font* mkfont(Subfont * subfont,Rune min)9mkfont(Subfont *subfont, Rune min) 10 { 11 Font *font; 12 Cachefont *c; 13 14 font = malloc(sizeof(Font)); 15 if(font == 0) 16 return 0; 17 memset(font, 0, sizeof(Font)); 18 font->display = subfont->bits->display; 19 font->name = strdup("<synthetic>"); 20 font->ncache = NFCACHE+NFLOOK; 21 font->nsubf = NFSUBF; 22 font->cache = malloc(font->ncache * sizeof(font->cache[0])); 23 font->subf = malloc(font->nsubf * sizeof(font->subf[0])); 24 if(font->name==0 || font->cache==0 || font->subf==0){ 25 Err: 26 free(font->name); 27 free(font->cache); 28 free(font->subf); 29 free(font->sub); 30 free(font); 31 return 0; 32 } 33 memset(font->cache, 0, font->ncache*sizeof(font->cache[0])); 34 memset(font->subf, 0, font->nsubf*sizeof(font->subf[0])); 35 font->height = subfont->height; 36 font->ascent = subfont->ascent; 37 font->age = 1; 38 font->sub = malloc(sizeof(Cachefont*)); 39 if(font->sub == 0) 40 goto Err; 41 c = malloc(sizeof(Cachefont)); 42 if(c == 0) 43 goto Err; 44 font->nsub = 1; 45 font->sub[0] = c; 46 c->min = min; 47 c->max = min+subfont->n-1; 48 c->offset = 0; 49 c->name = 0; /* noticed by freeup() and agefont() */ 50 c->subfontname = 0; 51 font->subf[0].age = 0; 52 font->subf[0].cf = c; 53 font->subf[0].f = subfont; 54 return font; 55 } 56