]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libdraw/getdefont.c
remove debug print
[plan9front.git] / sys / src / libdraw / getdefont.c
1 #include <u.h>
2 #include <libc.h>
3 #include <draw.h>
4
5 Subfont*
6 getdefont(Display *d)
7 {
8         char *hdr, *p;
9         int n;
10         Fontchar *fc;
11         Subfont *f;
12         int ld;
13         Rectangle r;
14         Image *i;
15
16         /*
17          * make sure data is word-aligned.  this is true with Plan 9 compilers
18          * but not in general.  the byte order is right because the data is
19          * declared as char*, not ulong*.
20          */
21         p = (char*)defontdata;
22         n = (int)(uvlong)p & 3;                         /* stupid ape */
23         if(n != 0){
24                 memmove(p+(4-n), p, sizeofdefont-n);
25                 p += 4-n;
26         }
27         ld = atoi(p+0*12);
28         r.min.x = atoi(p+1*12);
29         r.min.y = atoi(p+2*12);
30         r.max.x = atoi(p+3*12);
31         r.max.y = atoi(p+4*12);
32
33         i = allocimage(d, r, drawld2chan[ld], 0, 0);
34         if(i == 0)
35                 return 0;
36
37         p += 5*12;
38         n = loadimage(i, r, (uchar*)p, (defontdata+sizeofdefont)-(uchar*)p);
39         if(n < 0){
40                 freeimage(i);
41                 return 0;
42         }
43
44         hdr = p+n;
45         n = atoi(hdr);
46         p = hdr+3*12;
47         fc = malloc(sizeof(Fontchar)*(n+1));
48         if(fc == 0){
49                 freeimage(i);
50                 return 0;
51         }
52         _unpackinfo(fc, (uchar*)p, n);
53         f = allocsubfont("*default*", n, atoi(hdr+12), atoi(hdr+24), fc, i);
54         if(f == 0){
55                 freeimage(i);
56                 free(fc);
57                 return 0;
58         }
59         return f;
60 }