]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
use full textbox width when reflowing
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 23 Sep 2009 13:22:23 +0000 (15:22 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 23 Sep 2009 13:22:23 +0000 (15:22 +0200)
textbox.c

index ec75446e0229a545d160016ab4afa06fe3b562d5..f6f89d9b0457313ff3ee4967e248a8540597e831 100644 (file)
--- a/textbox.c
+++ b/textbox.c
@@ -174,7 +174,7 @@ static void doReflow(const char * text, char ** resultPtr, int width,
     mbstate_t ps;
 
     if (resultPtr) {
-       /* XXX I think this will work */
+       /* use width - 1 for double width characters that won't fit at end of line */
        result = malloc(strlen(text) + (strlen(text) / (width - 1)) + 2);
        *result = '\0';
     }
@@ -189,7 +189,7 @@ static void doReflow(const char * text, char ** resultPtr, int width,
            int len;
                
            len = wstrlen(text, end - text);
-           if (len < width) {
+           if (len <= width) {
                if (result) {
                    strncat(result, text, end - text);
                    strcat(result, "\n");
@@ -206,11 +206,11 @@ static void doReflow(const char * text, char ** resultPtr, int width,
                if (*text) text++;
            } else {
                const char *spcptr = NULL;
-               int spc =0,w2, x;
+               int spc = 0, w2 = 0, x, w;
 
                chptr = text;
-               w2 = 0;
-               for (i = 0; i < width - 1;) {
+               i = 0;
+               while (1) {
                        if ((x=mbrtowc(&tmp,chptr,end-chptr,&ps))<=0)
                                break;
                        if (spc && !iswspace(tmp))
@@ -220,10 +220,13 @@ static void doReflow(const char * text, char ** resultPtr, int width,
                                spcptr = chptr;
                                w2 = i;
                        }
+                       w = wcwidth(tmp);
+                       if (w < 0)
+                               w = 0;
+                       if (i && w + i > width)
+                               break;
                        chptr += x;
-                       x = wcwidth(tmp);
-                       if (x>0)
-                           i+=x;
+                       i += w;
                }
                howbad += width - w2 + 1;
 #ifdef DEBUG_WRAP