diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /libdraw/getdefont.c | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'libdraw/getdefont.c')
| -rw-r--r-- | libdraw/getdefont.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/libdraw/getdefont.c b/libdraw/getdefont.c new file mode 100644 index 00000000..8a9e6355 --- /dev/null +++ b/libdraw/getdefont.c @@ -0,0 +1,59 @@ +#include "lib9.h" +#include "draw.h" + +Subfont* +getdefont(Display *d) +{ + char *hdr, *p; + int n; + Fontchar *fc; + Subfont *f; + int ld; + Rectangle r; + Image *i; + + /* + * make sure data is word-aligned. this is true with Plan 9 compilers + * but not in general. the byte order is right because the data is + * declared as char*, not ulong*. + */ + p = (char*)defontdata; + n = (ulong)p & 3; + if(n != 0){ + memmove(p+(4-n), p, sizeofdefont-n); + p += 4-n; + } + ld = atoi(p+0*12); + r.min.x = atoi(p+1*12); + r.min.y = atoi(p+2*12); + r.max.x = atoi(p+3*12); + r.max.y = atoi(p+4*12); + + i = allocimage(d, r, drawld2chan[ld], 0, 0); + if(i == 0) + return 0; + + p += 5*12; + n = loadimage(i, r, (uchar*)p, (defontdata+sizeofdefont)-(uchar*)p); + if(n < 0){ + freeimage(i); + return 0; + } + + hdr = p+n; + n = atoi(hdr); + p = hdr+3*12; + fc = malloc(sizeof(Fontchar)*(n+1)); + if(fc == 0){ + freeimage(i); + return 0; + } + _unpackinfo(fc, (uchar*)p, n); + f = allocsubfont("*default*", n, atoi(hdr+12), atoi(hdr+24), fc, i); + if(f == 0){ + freeimage(i); + free(fc); + return 0; + } + return f; +} |
