]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
patch for mb char wrap
authormsw <msw>
Tue, 1 Feb 2000 02:19:20 +0000 (02:19 +0000)
committermsw <msw>
Tue, 1 Feb 2000 02:19:20 +0000 (02:19 +0000)
newt.spec
textbox.c

index 3e88ecd2f2357a30fb20325c4fe9b4afbdae9926..e14b3137cca5140dca9c59e38c7ce95641bd81f8 100644 (file)
--- a/newt.spec
+++ b/newt.spec
@@ -1,6 +1,6 @@
 Summary: A development library for text mode user interfaces.
 Name: newt
-%define version 0.50.5
+%define version 0.50.6
 Version: %{version}
 Release: 1
 Copyright: LGPL
@@ -55,6 +55,10 @@ rm -rf $RPM_BUILD_ROOT
 %postun -p /sbin/ldconfig
 
 %changelog
+* Mon Jan 31 2000 Matt Wilson <msw@redhat.com>
+- added patch from Toru Hoshina <t@kondara.org> to improve multibyte
+  character wrapping
+
 * Thu Jan 20 2000 Erik Troan <ewt@redhat.com>
 - see CHANGES
 
index 2578738d71df187133a87ed1c9cb6ba53d49ef6c..11ace205e47bb74a15b83426b075fa847841871a 100644 (file)
--- a/textbox.c
+++ b/textbox.c
@@ -147,16 +147,15 @@ static char * expandTabs(const char * text) {
     return buf;
 }
 
-#define iseuckanji(c)   (0xa1 <= (unsigned char)(c&0xff) && (unsigned char)(c&0xff) <= 0xfe)
-
 static void doReflow(const char * text, char ** resultPtr, int width, 
                     int * badness, int * heightPtr) {
     char * result = NULL;
     const char * chptr, * end;
-    int i;
     int howbad = 0;
     int height = 0;
-    int kanji = 0;
+    int cl =0;
+    int len = 0;
+    int wrap = 0;
 
     if (resultPtr) {
        /* XXX I think this will work */
@@ -165,7 +164,6 @@ static void doReflow(const char * text, char ** resultPtr, int width,
     }
     
     while (*text) {
-        kanji = 0;
        end = strchr(text, '\n');
        if (!end)
            end = text + strlen(text);
@@ -183,22 +181,25 @@ static void doReflow(const char * text, char ** resultPtr, int width,
                text = end;
                if (*text) text++;
            } else {
-               chptr = text;
-               kanji = 0;
-               for ( i = 0; i < width - 1; i++ ) {
-                   if ( !iseuckanji(*chptr)) {
-                       kanji = 0;
-                   } else if ( kanji == 1 ) {
-                       kanji = 2; 
-                   } else {
-                       kanji = 1;
-                   }
-                   chptr++;
-               }
-               if (kanji == 0) {
-                   while (chptr > text && !isspace(*chptr)) chptr--;
-                   while (chptr > text && isspace(*chptr)) chptr--;
-                   chptr++;
+              chptr = text;
+              len = 0;
+              do {
+                 cl = mblen(chptr, MB_CUR_MAX * 4);
+                 if (cl == -1)
+                   cl = 1;
+                 len += cl;
+                 chptr += cl;
+              } while (len < width - 1);
+              chptr = text + width - 1;
+              if (len > width - 1) {
+                    wrap = 1;
+              } else {
+                    wrap = 0;
+              }
+              if (cl == 1) {
+                  while (chptr > text && !isspace(*chptr)) chptr--;
+                  while (chptr > text && isspace(*chptr)) chptr--;
+                  chptr++;
                }
                
                if (chptr-text == 1 && !isspace(*chptr))
@@ -207,18 +208,17 @@ static void doReflow(const char * text, char ** resultPtr, int width,
                if (chptr > text)
                    howbad += width - (chptr - text) + 1;
                if (result) {
-                 if (kanji == 1) {
-                   strncat(result, text, chptr - text + 1 );
-                   chptr++;
-                   kanji = 0;
-                 } else {
-                   strncat(result, text, chptr - text );
-                 }
+                   if (wrap == 1) {
+                      strncat(result, text, chptr - text + 1);
+                      chptr++;
+                   } else {
+                      strncat(result, text, chptr - text);
+                   }
                    strcat(result, "\n");
                    height++;
                }
 
-               if (isspace(*chptr))
+               if (isspace(*chptr))
                    text = chptr + 1;
                else
                  text = chptr;