From 3e7ac03ca71c9b93c73fa58fd1de9a2042ec13d7 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 22 Apr 2004 17:47:28 +0000 Subject: bk_text and bk_info both need to know the on-screen width of characters in order to wrap and align them properly. Therefore, they should be using wcwidth(). So here are a couple of wrappers on wcwidth(), one which filters out the Unicode characters not representable in the target charset, and one which converts _from_ a charset to Unicode before calling wcwidth(). bk_text and bk_info should now align correctly even in the face of unsupported characters and Japanese. [originally from svn r4116] --- bk_info.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'bk_info.c') diff --git a/bk_info.c b/bk_info.c index f7efbf5..d513587 100644 --- a/bk_info.c +++ b/bk_info.c @@ -25,17 +25,6 @@ * - might be helpful to diagnose duplicate node names! */ -/* - * FIXME: - * - * - alignment in the index is broken when a non-representable - * character appears with no alternative. More generally, I - * fear, this is the fault of the info_rdadd* functions failing - * to return correct width figures in this circumstance (so it - * will affect list paragraph prefixes and paragraph wrapping as - * well). - */ - #include #include #include @@ -767,7 +756,7 @@ static int info_width_internal(word *words, int xrefs, int charset) { attraux(words->aux) == attr_Always ? 0 : 1) : 0) + (cvt_ok(charset, words->text) || !words->alt ? - ustrlen(words->text) : + ustrwid(words->text, charset) : info_width_internal_list(words->alt, xrefs, charset))); case word_WhiteSpace: @@ -790,7 +779,7 @@ static int info_width_internal(word *words, int xrefs, int charset) { case word_LowerXref: if (xrefs && words->private_data) { /* "*Note " plus "::" comes to 8 characters */ - return 8 + strlen(((node *)words->private_data)->name); + return 8 + strwid(((node *)words->private_data)->name, charset); } break; } @@ -995,9 +984,11 @@ static int info_rdadds(info_data *d, wchar_t const *wcs) if (wcs) { char buf[256]; - int len, origlen, ret; + int len, width, ret; + + width = ustrwid(wcs, d->charset); - origlen = len = ustrlen(wcs); + len = ustrlen(wcs); while (len > 0) { int prevlen = len; @@ -1012,7 +1003,7 @@ static int info_rdadds(info_data *d, wchar_t const *wcs) } } - return origlen; + return width; } else return 0; } -- cgit v1.1