plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

mkfont.c (1342B)


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