summaryrefslogtreecommitdiff
path: root/bk_info.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2004-04-22 17:47:28 +0000
committerSimon Tatham <anakin@pobox.com>2004-04-22 17:47:28 +0000
commit3e7ac03ca71c9b93c73fa58fd1de9a2042ec13d7 (patch)
tree6e01e5ddf83e8430bf84daa7a1af625a1c44e274 /bk_info.c
parentc097d194c02212f642af2b2be68a0b8aa3ee17c0 (diff)
downloadhalibut-3e7ac03ca71c9b93c73fa58fd1de9a2042ec13d7.zip
halibut-3e7ac03ca71c9b93c73fa58fd1de9a2042ec13d7.tar.gz
halibut-3e7ac03ca71c9b93c73fa58fd1de9a2042ec13d7.tar.bz2
halibut-3e7ac03ca71c9b93c73fa58fd1de9a2042ec13d7.tar.xz
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]
Diffstat (limited to 'bk_info.c')
-rw-r--r--bk_info.c23
1 files changed, 7 insertions, 16 deletions
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 <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -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;
}