fix font width calculations

This commit is contained in:
Markus Teich 2015-10-31 18:07:07 +01:00
parent 4a114392bb
commit a9ca2473fd
2 changed files with 5 additions and 4 deletions

2
drw.c
View File

@ -379,7 +379,7 @@ unsigned int
drw_fontset_getwidth(Drw *drw, const char *text) {
if (!drw || !drw->fonts || !text)
return 0;
return drw_text(drw, 0, 0, 0, 0, text, 0) + drw->fonts->h;
return drw_text(drw, 0, 0, 0, 0, text, 0);
}
void

7
sent.c
View File

@ -312,17 +312,18 @@ void pngdraw(Image *img)
void getfontsize(char *str, unsigned int *width, unsigned int *height)
{
size_t i;
size_t len = strlen(str);
for (i = 0; i < NUMFONTSCALES; i++) {
drw_setfontset(d, fonts[i]);
drw_font_getexts(fonts[i], str, len, width, height);
*height = fonts[i]->h;
*width = drw_fontset_getwidth(d, str);
if (*width > xw.uw || *height > xw.uh)
break;
}
if (i > 0) {
drw_setfontset(d, fonts[i-1]);
drw_font_getexts(fonts[i-1], str, len, width, height);
*height = fonts[i-1]->h;
*width = drw_fontset_getwidth(d, str);
}
*width += d->fonts->h;
}