Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2016-02-01 12:14:47 -0500
committerAllan McRae <allan@archlinux.org>2016-02-20 14:01:52 +1000
commitc1bb41a0378736e0fdd535541daa8cd7d09a4cc6 (patch)
treedecb94668a0f374cd996fdbbb227cee82a09f8f8 /src
parent252183b4093b8c82ad19159d23bdd2cf0e2d574e (diff)
dump_pkg_info: fix wide character title alignment
The padding added to the end of the title was based on the return value of mbstowcs which is the number of characters. This caused alignment issues for languages with characters that span multiple columns. Instead, base the padding on the number of columns needed by the translated string as returned by wcswidth. Fixes #47980 Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/package.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c
index ac474939..3ab9abc0 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -89,10 +89,12 @@ static char titles[_T_MAX][TITLE_MAXLEN * sizeof(wchar_t)];
static void make_aligned_titles(void)
{
unsigned int i;
- size_t max = 0;
+ size_t maxlen = 0;
+ int maxcol = 0;
static const wchar_t title_suffix[] = L" :";
wchar_t wbuf[ARRAYSIZE(titles)][TITLE_MAXLEN + ARRAYSIZE(title_suffix)];
size_t wlen[ARRAYSIZE(wbuf)];
+ int wcol[ARRAYSIZE(wbuf)];
char *buf[ARRAYSIZE(wbuf)];
buf[T_ARCHITECTURE] = _("Architecture");
buf[T_BACKUP_FILES] = _("Backup Files");
@@ -125,14 +127,19 @@ static void make_aligned_titles(void)
for(i = 0; i < ARRAYSIZE(wbuf); i++) {
wlen[i] = mbstowcs(wbuf[i], buf[i], strlen(buf[i]) + 1);
- if(wlen[i] > max) {
- max = wlen[i];
+ wcol[i] = wcswidth(wbuf[i], wlen[i]);
+ if(wcol[i] > maxcol) {
+ maxcol = wcol[i];
+ }
+ if(wlen[i] > maxlen) {
+ maxlen = wlen[i];
}
}
for(i = 0; i < ARRAYSIZE(wbuf); i++) {
- wmemset(wbuf[i] + wlen[i], L' ', max - wlen[i]);
- wmemcpy(wbuf[i] + max, title_suffix, ARRAYSIZE(title_suffix));
+ size_t padlen = maxcol - wcol[i];
+ wmemset(wbuf[i] + wlen[i], L' ', padlen);
+ wmemcpy(wbuf[i] + wlen[i] + padlen, title_suffix, ARRAYSIZE(title_suffix));
wcstombs(titles[i], wbuf[i], sizeof(wbuf[i]));
}
}