1 #include "../lib9.h" 2 3 #include "../libdraw/draw.h" 4 #include "../libmemdraw/memdraw.h" 5 6 Memsubfont* 7 getmemdefont(void) 8 { 9 char *hdr, *p; 10 int n; 11 Fontchar *fc; 12 Memsubfont *f; 13 int ld; 14 Rectangle r; 15 Memimage *i; 16 17 /* 18 * make sure data is word-aligned. this is true with Plan 9 compilers 19 * but not in general. the byte order is right because the data is 20 * declared as char*, not ulong*. 21 */ 22 p = (char*)defontdata; 23 n = (ulong)p & 3; 24 if(n != 0){ 25 memmove(p+(4-n), p, sizeofdefont-n); 26 p += 4-n; 27 } 28 ld = atoi(p+0*12); 29 r.min.x = atoi(p+1*12); 30 r.min.y = atoi(p+2*12); 31 r.max.x = atoi(p+3*12); 32 r.max.y = atoi(p+4*12); 33 34 p += 5*12; 35 36 i = allocmemimage(r, drawld2chan[ld]); 37 if(i == nil) 38 return nil; 39 40 loadmemimage(i, i->r, (uchar*)p, Dy(r)*i->width*sizeof(ulong)); 41 42 hdr = p+Dy(r)*i->width*sizeof(ulong); 43 n = atoi(hdr); 44 p = hdr+3*12; 45 fc = malloc(sizeof(Fontchar)*(n+1)); 46 if(fc == 0){ 47 freememimage(i); 48 return 0; 49 } 50 _unpackinfo(fc, (uchar*)p, n); 51 f = allocmemsubfont("*default*", n, atoi(hdr+12), atoi(hdr+24), fc, i); 52 if(f == 0){ 53 freememimage(i); 54 free(fc); 55 return 0; 56 } 57 return f; 58 } 59