]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libdraw/mkfont.c
remove debug print
[plan9front.git] / sys / src / libdraw / mkfont.c
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 == nil)
16                 return nil;
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==nil || font->cache==nil || font->subf==nil){
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 == nil)
40                 goto Err;
41         c = malloc(sizeof(Cachefont));
42         if(c == nil)
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 = nil;  /* noticed by agefont() */
50         c->subfontname = nil;
51         font->subf[0].age = 0;
52         font->subf[0].cf = c;
53         font->subf[0].f = subfont;
54         return font;
55 }