Blob
- Date:
- Message:
- libdraw: redo default font construction to be hidpi-safe If $font is not set, the default font is constructed from font data linked into every libdraw binary. That process was different from the usual openfont code, and so it was not hidpi-aware, resulting in very tiny fonts out of the box on hidpi systems, until users set $font. Fix this by using openfont to construct the default font, by recognizing the name *default* when looking for font and subfont file contents. Then all the hidpi scaling applies automatically. As a side effect, the concept of a 'default subfont' is gone, as are display->defaultsubfont, getdefont, and memgetdefont.
- Actions:
- History | Blame | Raw File
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>5 Subfont*6 readsubfonti(Display*d, char *name, int fd, Image *ai, int dolock)7 {8 char hdr[3*12+4+1];9 int n;10 uchar *p;11 Fontchar *fc;12 Subfont *f;13 Image *i;15 i = ai;16 if(i == nil){17 i = readimage(d, fd, dolock);18 if(i == nil)19 return nil;20 }21 if(read(fd, hdr, 3*12) != 3*12){22 if(ai == nil)23 freeimage(i);24 werrstr("rdsubfonfile: header read error: %r");25 return nil;26 }27 n = atoi(hdr);28 p = malloc(6*(n+1));29 if(p == nil)30 goto Err;31 if(read(fd, p, 6*(n+1)) != 6*(n+1)){32 werrstr("rdsubfonfile: fontchar read error: %r");33 Err:34 if(ai == nil)35 freeimage(i);36 free(p);37 return nil;38 }39 fc = malloc(sizeof(Fontchar)*(n+1));40 if(fc == nil)41 goto Err;42 _unpackinfo(fc, p, n);43 if(dolock)44 lockdisplay(d);45 f = allocsubfont(name, n, atoi(hdr+12), atoi(hdr+24), fc, i);46 if(dolock)47 unlockdisplay(d);48 if(f == nil){49 free(fc);50 goto Err;51 }52 free(p);53 return f;54 }56 Subfont*57 readsubfont(Display*d, char *name, int fd, int dolock)58 {59 return readsubfonti(d, name, fd, nil, dolock);60 }62 void63 _unpackinfo(Fontchar *fc, uchar *p, int n)64 {65 int j;67 for(j=0; j<=n; j++){68 fc->x = p[0]|(p[1]<<8);69 fc->top = p[2];70 fc->bottom = p[3];71 fc->left = p[4];72 fc->width = p[5];73 fc++;74 p += 6;75 }76 }