diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt
index 22edb2004..f43a383cd 100644
--- a/docs/CHANGES.txt
+++ b/docs/CHANGES.txt
@@ -7,7 +7,7 @@ bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
-2003.March.14 (0.9.11) [cvs]
+2003.April.5 (0.9.11) [cvs]
* Set $OUTPUT_CHARSET for Japanese locale, to fix Win32 issue.
TOYAMA Shin-ichi
@@ -33,6 +33,9 @@ http://www.newbreedsoftware.com/tuxpaint/
* Fixed a few typos in the manpage.
Robert Glowczynski
+ * Fixed UTF-8 word-wrapping bug when there were no spaces
+ (e.g., in some Japanese strings)
+
2003.February.22 (0.9.10)
* UTF-8 stamp descriptions word-wrap around spaces.
diff --git a/docs/README.txt b/docs/README.txt
index 1121b3993..d18bfbad9 100644
--- a/docs/README.txt
+++ b/docs/README.txt
@@ -9,7 +9,7 @@
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
- June 14, 2002 - February 28, 2003
+ June 14, 2002 - April 5, 2003
----------------------------------------------------------------------
diff --git a/docs/html/README.html b/docs/html/README.html
index 226d0f8f2..f2a20b90f 100644
--- a/docs/html/README.html
+++ b/docs/html/README.html
@@ -21,7 +21,7 @@ New Breed Software
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
-June 14, 2002 - February 28, 2003
+June 14, 2002 - April 5, 2003
diff --git a/src/manpage/tuxpaint.1 b/src/manpage/tuxpaint.1
index 39a9c91e9..704601c18 100644
--- a/src/manpage/tuxpaint.1
+++ b/src/manpage/tuxpaint.1
@@ -1,5 +1,5 @@
-.\" tuxpaint.1 - 2003.03.14
-.TH TUXPAINT 1 "14 Mar 2003" "0.9.11" "Tux Paint"
+.\" tuxpaint.1 - 2003.04.05
+.TH TUXPAINT 1 "05 Apr 2003" "0.9.11" "Tux Paint"
.SH NAME
tuxpaint -- A drawing program for young children.
diff --git a/src/tuxpaint.c b/src/tuxpaint.c
index 9b2596370..f928c002b 100644
--- a/src/tuxpaint.c
+++ b/src/tuxpaint.c
@@ -7,12 +7,12 @@
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
- June 14, 2002 - March 14, 2003
+ June 14, 2002 - April 5, 2003
*/
#define VER_VERSION "0.9.11"
-#define VER_DATE "2003.03.14"
+#define VER_DATE "2003.04.05"
/* #define DEBUG */
@@ -6263,15 +6263,13 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color,
unsigned char * locale_str;
char * tstr;
Uint16 unicode_char[2];
-#ifdef OLD_UTF8_WRAP
- char utf8_char[5];
-#endif
+ unsigned char utf8_char[5];
int len;
SDL_Surface * text;
SDL_Rect dest;
int utf8_str_len;
- char utf8_str[512];
+ unsigned char utf8_str[512];
/* Cursor starting position: */
@@ -6293,69 +6291,12 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color,
locale_str = strdup(gettext(str));
-#ifdef OLD_UTF8_WRAP
-
- /* For each UTF8 character: */
-
- for (i = 0; i < strlen(locale_str); i++)
- {
- /* How many bytes does this character need? */
-
- if (locale_str[i] < 128) /* 0xxx xxxx - 1 byte */
- {
- utf8_char[0] = locale_str[i];
- utf8_char[1] = '\0';
- }
- else if ((locale_str[i] & 0xE0) == 0xC0) /* 110x xxxx - 2 bytes */
- {
- utf8_char[0] = locale_str[i];
- utf8_char[1] = locale_str[i + 1];
- utf8_char[2] = '\0';
- i = i + 1;
- }
- else if ((locale_str[i] & 0xF0) == 0xE0) /* 1110 xxxx - 3 bytes */
- {
- utf8_char[0] = locale_str[i];
- utf8_char[1] = locale_str[i + 1];
- utf8_char[2] = locale_str[i + 2];
- utf8_char[3] = '\0';
- i = i + 2;
- }
- else /* 1111 0xxx - 4 bytes */
- {
- utf8_char[0] = locale_str[i];
- utf8_char[1] = locale_str[i + 1];
- utf8_char[2] = locale_str[i + 2];
- utf8_char[3] = locale_str[i + 3];
- utf8_char[4] = '\0';
- i = i + 3;
- }
-
- text = TTF_RenderUTF8_Blended(locale_font, utf8_char, color);
-
- if (x + text->w > right)
- {
- x = left;
- y = y + text->h;
- }
-
- dest.x = x;
- dest.y = y;
-
- SDL_BlitSurface(text, NULL, screen, &dest);
-
- x = x + text->w;
-
- SDL_FreeSurface(text);
- }
-
-#else
/* For each UTF8 character: */
utf8_str_len = 0;
utf8_str[0] = '\0';
- for (i = 0; i < strlen(locale_str); i++)
+ for (i = 0; i <= strlen(locale_str); i++)
{
if (locale_str[i] < 128)
{
@@ -6365,25 +6306,110 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color,
/* Space? Blit the word! (Word-wrap if necessary) */
- if (locale_str[i] == ' ')
+ if (locale_str[i] == ' ' || locale_str[i] == '\0')
{
text = TTF_RenderUTF8_Blended(locale_font, utf8_str, color);
- if (x + text->w > right)
+ /* ----------- */
+ if (text->w > right - left)
+ {
+ /* Move left and down (if not already at left!) */
+
+ if (x > left)
+ {
+ x = left;
+ y = y + text->h;
+ }
+
+
+ /* Junk the blitted word; it's too long! */
+
+ SDL_FreeSurface(text);
+
+
+ /* For each UTF8 character: */
+
+ for (j = 0; j < utf8_str_len; j++)
+ {
+ printf("%d of %d\n", j, utf8_str_len); fflush(stdout);
+
+ /* How many bytes does this character need? */
+
+ if (utf8_str[j] < 128) /* 0xxx xxxx - 1 byte */
{
- x = left;
- y = y + text->h;
+ utf8_char[0] = utf8_str[j];
+ utf8_char[1] = '\0';
}
+ else if ((utf8_str[j] & 0xE0) == 0xC0) /* 110x xxxx - 2 bytes */
+ {
+ utf8_char[0] = utf8_str[j];
+ utf8_char[1] = utf8_str[j + 1];
+ utf8_char[2] = '\0';
+ j = j + 1;
+ }
+ else if ((utf8_str[j] & 0xF0) == 0xE0) /* 1110 xxxx - 3 bytes */
+ {
+ utf8_char[0] = utf8_str[j];
+ utf8_char[1] = utf8_str[j + 1];
+ utf8_char[2] = utf8_str[j + 2];
+ utf8_char[3] = '\0';
+ j = j + 2;
+ }
+ else /* 1111 0xxx - 4 bytes */
+ {
+ utf8_char[0] = utf8_str[j];
+ utf8_char[1] = utf8_str[j + 1];
+ utf8_char[2] = utf8_str[j + 2];
+ utf8_char[3] = utf8_str[j + 3];
+ utf8_char[4] = '\0';
+ j = j + 3;
+ }
+
+ printf("-- J is now: %d\n", j); fflush(stdout);
- dest.x = x;
- dest.y = y;
+ if (utf8_char[0] != '\0')
+ {
+ text = TTF_RenderUTF8_Blended(locale_font, utf8_char, color);
+ if (text != NULL)
+ {
+ if (x + text->w > right)
+ {
+ x = left;
+ y = y + text->h;
+ }
- SDL_BlitSurface(text, NULL, screen, &dest);
+ dest.x = x;
+ dest.y = y;
- x = x + text->w;
+ SDL_BlitSurface(text, NULL, screen, &dest);
+ SDL_FreeSurface(text);
+
+ x = x + text->w;
+ }
+ }
+ }
+ }
+ else
+ {
+ /* Not too wide for one line... */
+
+ if (x + text->w > right)
+ {
+ /* This word needs to move down? */
+
+ x = left;
+ y = y + text->h;
+ }
+
+ dest.x = x;
+ dest.y = y;
+
+ SDL_BlitSurface(text, NULL, screen, &dest);
+ SDL_FreeSurface(text);
+ x = x + text->w;
+ }
+
- SDL_FreeSurface(text);
-
utf8_str_len = 0;
utf8_str[0] = '\0';
}
@@ -6413,24 +6439,6 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color,
i = i + 3;
}
}
-
- if (utf8_str_len > 0)
- {
- text = TTF_RenderUTF8_Blended(locale_font, utf8_str, color);
-
- if (x + text->w > right)
- {
- x = left;
- y = y + text->h;
- }
-
- dest.x = x;
- dest.y = y;
-
- SDL_BlitSurface(text, NULL, screen, &dest);
- SDL_FreeSurface(text);
- }
-#endif
free(locale_str);
}