summaryrefslogtreecommitdiff
path: root/sys/src/libdraw/mkfont.c
blob: 56b0aea4e933c1dc36c4a71c4d2dfe7be2743200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <u.h>
#include <libc.h>
#include <draw.h>

/*
 * Cobble fake font using existing subfont
 */
Font*
mkfont(Subfont *subfont, Rune min)
{
	Font *font;
	Cachefont *c;

	font = malloc(sizeof(Font));
	if(font == nil)
		return nil;
	memset(font, 0, sizeof(Font));
	font->display = subfont->bits->display;
	font->name = strdup("<synthetic>");
	font->ncache = NFCACHE+NFLOOK;
	font->nsubf = NFSUBF;
	font->cache = malloc(font->ncache * sizeof(font->cache[0]));
	font->subf = malloc(font->nsubf * sizeof(font->subf[0]));
	if(font->name==nil || font->cache==nil || font->subf==nil){
    Err:
		free(font->name);
		free(font->cache);
		free(font->subf);
		free(font->sub);
		free(font);
		return 0;
	}
	memset(font->cache, 0, font->ncache*sizeof(font->cache[0]));
	memset(font->subf, 0, font->nsubf*sizeof(font->subf[0]));
	font->height = subfont->height;
	font->ascent = subfont->ascent;
	font->age = 1;
	font->sub = malloc(sizeof(Cachefont*));
	if(font->sub == nil)
		goto Err;
	c = malloc(sizeof(Cachefont));
	if(c == nil)
		goto Err;
	font->nsub = 1;
	font->sub[0] = c;
	c->min = min;
	c->max = min+subfont->n-1;
	c->offset = 0;
	c->name = nil;	/* noticed by agefont() */
	c->subfontname = nil;
	font->subf[0].age = 0;
	font->subf[0].cf = c;
	font->subf[0].f = subfont;
	return font;
}