update draw.c
f7cbe710
2 file(s) · +14 −14
| 120 | 120 | ||
| 121 | 121 | Bool |
|
| 122 | 122 | loadfont(DC *dc, const char *fontstr) { |
|
| 123 | - | char *def, **missing; |
|
| 124 | - | int i, n; |
|
| 123 | + | char *def, **missing, **names; |
|
| 124 | + | int i, n = 1; |
|
| 125 | + | XFontStruct **xfonts; |
|
| 125 | 126 | ||
| 126 | 127 | if(!*fontstr) |
|
| 127 | 128 | return False; |
|
| 128 | - | if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) { |
|
| 129 | - | char **names; |
|
| 130 | - | XFontStruct **xfonts; |
|
| 129 | + | if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) |
|
| 130 | + | n = XFontsOfFontSet(dc->font.set, &xfonts, &names); |
|
| 131 | + | else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) |
|
| 132 | + | xfonts = &dc->font.xfont; |
|
| 133 | + | else |
|
| 134 | + | n = 0; |
|
| 131 | 135 | ||
| 132 | - | n = XFontsOfFontSet(dc->font.set, &xfonts, &names); |
|
| 133 | - | for(i = dc->font.ascent = dc->font.descent = 0; i < n; i++) { |
|
| 134 | - | dc->font.ascent = MAX(dc->font.ascent, xfonts[i]->ascent); |
|
| 135 | - | dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent); |
|
| 136 | - | } |
|
| 137 | - | } |
|
| 138 | - | else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) { |
|
| 139 | - | dc->font.ascent = dc->font.xfont->ascent; |
|
| 140 | - | dc->font.descent = dc->font.xfont->descent; |
|
| 136 | + | for(i = 0; i < n; i++) { |
|
| 137 | + | dc->font.ascent = MAX(dc->font.ascent, xfonts[i]->ascent); |
|
| 138 | + | dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent); |
|
| 139 | + | dc->font.width = MAX(dc->font.width, xfonts[i]->max_bounds.width); |
|
| 141 | 140 | } |
|
| 142 | 141 | if(missing) |
|
| 143 | 142 | XFreeStringList(missing); |
| 15 | 15 | int ascent; |
|
| 16 | 16 | int descent; |
|
| 17 | 17 | int height; |
|
| 18 | + | int width; |
|
| 18 | 19 | XFontSet set; |
|
| 19 | 20 | XFontStruct *xfont; |
|
| 20 | 21 | } font; |