diff options
author | Russ Cox <rsc@swtch.com> | 2018-11-15 23:52:05 -0500 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2018-11-16 00:03:24 -0500 |
commit | 16d00819899260085ee10949012b07bf1c203db6 (patch) | |
tree | 540151e0f43ef7e08255d31f5c68b4100c783b93 /src/libdraw/init.c | |
parent | 3ebbb99ce3b13357f4dfb0156877c6e5892de5aa (diff) | |
download | plan9port-16d00819899260085ee10949012b07bf1c203db6.tar.gz plan9port-16d00819899260085ee10949012b07bf1c203db6.tar.bz2 plan9port-16d00819899260085ee10949012b07bf1c203db6.zip |
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.
Diffstat (limited to 'src/libdraw/init.c')
-rw-r--r-- | src/libdraw/init.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/libdraw/init.c b/src/libdraw/init.c index e5a367f3..350365fe 100644 --- a/src/libdraw/init.c +++ b/src/libdraw/init.c @@ -8,7 +8,6 @@ Font *font; Image *screen; int _drawdebug; -static char deffontname[] = "*default*"; Screen *_screen; int debuglockdisplay = 1; @@ -41,8 +40,7 @@ drawshutdown(void) int geninitdraw(char *devdir, void(*error)(Display*, char*), char *fontname, char *label, char *windir, int ref) { - Subfont *df; - char buf[128], *p; + char *p; if(label == nil) label = argv0; @@ -53,9 +51,7 @@ geninitdraw(char *devdir, void(*error)(Display*, char*), char *fontname, char *l /* * Set up default font */ - df = getdefont(display); - display->defaultsubfont = df; - if(df == nil){ + if(openfont(display, "*default*") == 0) { fprint(2, "imageinit: can't open default subfont: %r\n"); Error: closedisplay(display); @@ -69,21 +65,13 @@ geninitdraw(char *devdir, void(*error)(Display*, char*), char *fontname, char *l * Build fonts with caches==depth of screen, for speed. * If conversion were faster, we'd use 0 and save memory. */ - if(fontname == nil){ - snprint(buf, sizeof buf, "%d %d\n0 %d\t%s\n", df->height, df->ascent, - df->n-1, deffontname); -//BUG: Need something better for this installsubfont("*default*", df); - font = buildfont(display, buf, deffontname); - if(font == nil){ - fprint(2, "imageinit: can't open default font: %r\n"); - goto Error; - } - }else{ - font = openfont(display, fontname); /* BUG: grey fonts */ - if(font == nil){ - fprint(2, "imageinit: can't open font %s: %r\n", fontname); - goto Error; - } + if(fontname == nil) + fontname = strdup("*default*"); + + font = openfont(display, fontname); + if(font == nil){ + fprint(2, "imageinit: can't open font %s: %r\n", fontname); + goto Error; } display->defaultfont = font; @@ -306,7 +294,7 @@ _initdisplay(void (*error)(Display*, char*), char *label) /* * Call with d unlocked. - * Note that disp->defaultfont and defaultsubfont are not freed here. + * Note that disp->defaultfont is not freed here. */ void closedisplay(Display *disp) |