From: Teemu Toivola Date: Sat, 4 Apr 2015 20:32:05 +0000 (+0300) Subject: fix image output field padding when using UTF-8 locale, document found restriction... X-Git-Tag: v1.14~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=602d9890e9742ef9e89e1e862d68cc566dad9141;p=vnstat fix image output field padding when using UTF-8 locale, document found restriction related to gd library --- diff --git a/man/vnstati.1 b/man/vnstati.1 index b275db1..0715d23 100644 --- a/man/vnstati.1 +++ b/man/vnstati.1 @@ -262,6 +262,11 @@ for default interface to standard output (stdout). Output monthly traffic statistics for default interface specified in configuration file /home/me/vnstat.cfg to standard output (stdout). +.SH RESTRICTIONS + +Depending on the font provided by the GD library, not all characters may end up shown +correctly when a UTF-8 locale is used. + .SH AUTHOR Teemu Toivola diff --git a/src/image.c b/src/image.c index 2d51c08..b70f39e 100644 --- a/src/image.c +++ b/src/image.c @@ -475,7 +475,7 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate) strncpy_nt(daytemp, "today", 32); } - snprintf(buffer, 32, "%12s", daytemp); + snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp); gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext); if (cfg.summaryrate) { @@ -540,7 +540,7 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate) strncpy_nt(daytemp, "yesterday", 32); } - snprintf(buffer, 32, "%12s", daytemp); + snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp); gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext); if (cfg.summaryrate) { @@ -601,7 +601,7 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate) d = localtime(&data.month[0].month); strftime(daytemp, 16, cfg.mformat, d); - snprintf(buffer, 32, "%12s", daytemp); + snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp); gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext); if (cfg.summaryrate) { @@ -655,7 +655,7 @@ void drawsummary(IMAGECONTENT *ic, int type, int rate) d = localtime(&data.month[1].month); strftime(daytemp, 16, cfg.mformat, d); - snprintf(buffer, 32, "%12s", daytemp); + snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp); gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext); if (cfg.summaryrate) { @@ -843,7 +843,7 @@ void drawoldsummary(IMAGECONTENT *ic, int type, int rate) gdImageLine(ic->im, textx+218, texty+4, textx+218, texty+64, ic->cline); if (data.day[1].date!=0) { - snprintf(buffer, 32, "%9s ", daytemp); + snprintf(buffer, 32, "%*s ", getpadding(9, daytemp), daytemp); strncat(buffer, getvalue(data.day[1].rx, data.day[1].rxk, 10, 1), 32); strcat(buffer, " "); strncat(buffer, getvalue(data.day[1].tx, data.day[1].txk, 10, 1), 32); @@ -852,7 +852,7 @@ void drawoldsummary(IMAGECONTENT *ic, int type, int rate) gdImageString(ic->im, gdFontGetSmall(), textx, texty+20, (unsigned char*)buffer, ic->ctext); } - snprintf(buffer, 32, "%9s ", daytemp2); + snprintf(buffer, 32, "%*s ", getpadding(9, daytemp2), daytemp2); strncat(buffer, getvalue(data.day[0].rx, data.day[0].rxk, 10, 1), 32); strcat(buffer, " "); strncat(buffer, getvalue(data.day[0].tx, data.day[0].txk, 10, 1), 32); @@ -1022,9 +1022,9 @@ void drawdaily(IMAGECONTENT *ic) d = localtime(&data.day[i].date); if (strftime(datebuff, 16, cfg.dformat, d)<=8) { - snprintf(buffer, 32, " %8s ", datebuff); + snprintf(buffer, 32, " %*s ", getpadding(8, datebuff), datebuff); } else { - snprintf(buffer, 32, " %-11s ", datebuff); + snprintf(buffer, 32, " %-*s ", getpadding(11, datebuff), datebuff); } strncat(buffer, getvalue(data.day[i].rx, data.day[i].rxk, 10, 1), 32); strcat(buffer, " "); @@ -1173,9 +1173,9 @@ void drawmonthly(IMAGECONTENT *ic) d = localtime(&data.month[i].month); if (strftime(datebuff, 16, cfg.mformat, d)<=9) { - snprintf(buffer, 32, " %9s ", datebuff); + snprintf(buffer, 32, " %*s ", getpadding(9, datebuff), datebuff); } else { - snprintf(buffer, 32, " %-11s ", datebuff); + snprintf(buffer, 32, " %-*s ", getpadding(11, datebuff), datebuff); } strncat(buffer, getvalue(data.month[i].rx, data.month[i].rxk, 10, 1), 32); strcat(buffer, " "); @@ -1316,9 +1316,9 @@ void drawtop(IMAGECONTENT *ic) d = localtime(&data.top10[i].date); if (strftime(datebuff, 16, cfg.tformat, d)<=8) { - snprintf(buffer, 32, " %2d %8s ", i+1, datebuff); + snprintf(buffer, 32, " %2d %*s ", i+1, getpadding(8, datebuff), datebuff); } else { - snprintf(buffer, 32, " %2d %-11s ", i+1, datebuff); + snprintf(buffer, 32, " %2d %-*s ", i+1, getpadding(11, datebuff), datebuff); } strncat(buffer, getvalue(data.top10[i].rx, data.top10[i].rxk, 10, 1), 32); strcat(buffer, " ");