* Fixed word-wrapping with no spaces in UTF-8 strings
This commit is contained in:
parent
48f0058b77
commit
45ec50ea18
5 changed files with 108 additions and 97 deletions
|
|
@ -7,7 +7,7 @@ bill@newbreedsoftware.com
|
||||||
http://www.newbreedsoftware.com/tuxpaint/
|
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.
|
* Set $OUTPUT_CHARSET for Japanese locale, to fix Win32 issue.
|
||||||
TOYAMA Shin-ichi <kyone@tky2.3web.ne.jp>
|
TOYAMA Shin-ichi <kyone@tky2.3web.ne.jp>
|
||||||
|
|
||||||
|
|
@ -33,6 +33,9 @@ http://www.newbreedsoftware.com/tuxpaint/
|
||||||
* Fixed a few typos in the manpage.
|
* Fixed a few typos in the manpage.
|
||||||
Robert Glowczynski <robertg@software.com.pl>
|
Robert Glowczynski <robertg@software.com.pl>
|
||||||
|
|
||||||
|
* Fixed UTF-8 word-wrapping bug when there were no spaces
|
||||||
|
(e.g., in some Japanese strings)
|
||||||
|
|
||||||
|
|
||||||
2003.February.22 (0.9.10)
|
2003.February.22 (0.9.10)
|
||||||
* UTF-8 stamp descriptions word-wrap around spaces.
|
* UTF-8 stamp descriptions word-wrap around spaces.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
bill@newbreedsoftware.com
|
bill@newbreedsoftware.com
|
||||||
http://www.newbreedsoftware.com/tuxpaint/
|
http://www.newbreedsoftware.com/tuxpaint/
|
||||||
|
|
||||||
June 14, 2002 - February 28, 2003
|
June 14, 2002 - April 5, 2003
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ New Breed Software</p>
|
||||||
<p><a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a><br>
|
<p><a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a><br>
|
||||||
<a href="http://www.newbreedsoftware.com/tuxpaint/">http://www.newbreedsoftware.com/tuxpaint/</a></p>
|
<a href="http://www.newbreedsoftware.com/tuxpaint/">http://www.newbreedsoftware.com/tuxpaint/</a></p>
|
||||||
|
|
||||||
<p>June 14, 2002 - February 28, 2003</p>
|
<p>June 14, 2002 - April 5, 2003</p>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
<hr size=2 noshade>
|
<hr size=2 noshade>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
.\" tuxpaint.1 - 2003.03.14
|
.\" tuxpaint.1 - 2003.04.05
|
||||||
.TH TUXPAINT 1 "14 Mar 2003" "0.9.11" "Tux Paint"
|
.TH TUXPAINT 1 "05 Apr 2003" "0.9.11" "Tux Paint"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
tuxpaint -- A drawing program for young children.
|
tuxpaint -- A drawing program for young children.
|
||||||
|
|
||||||
|
|
|
||||||
192
src/tuxpaint.c
192
src/tuxpaint.c
|
|
@ -7,12 +7,12 @@
|
||||||
bill@newbreedsoftware.com
|
bill@newbreedsoftware.com
|
||||||
http://www.newbreedsoftware.com/tuxpaint/
|
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_VERSION "0.9.11"
|
||||||
#define VER_DATE "2003.03.14"
|
#define VER_DATE "2003.04.05"
|
||||||
|
|
||||||
|
|
||||||
/* #define DEBUG */
|
/* #define DEBUG */
|
||||||
|
|
@ -6263,15 +6263,13 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color,
|
||||||
unsigned char * locale_str;
|
unsigned char * locale_str;
|
||||||
char * tstr;
|
char * tstr;
|
||||||
Uint16 unicode_char[2];
|
Uint16 unicode_char[2];
|
||||||
#ifdef OLD_UTF8_WRAP
|
unsigned char utf8_char[5];
|
||||||
char utf8_char[5];
|
|
||||||
#endif
|
|
||||||
int len;
|
int len;
|
||||||
SDL_Surface * text;
|
SDL_Surface * text;
|
||||||
SDL_Rect dest;
|
SDL_Rect dest;
|
||||||
|
|
||||||
int utf8_str_len;
|
int utf8_str_len;
|
||||||
char utf8_str[512];
|
unsigned char utf8_str[512];
|
||||||
|
|
||||||
|
|
||||||
/* Cursor starting position: */
|
/* Cursor starting position: */
|
||||||
|
|
@ -6293,69 +6291,12 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color,
|
||||||
locale_str = strdup(gettext(str));
|
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: */
|
/* For each UTF8 character: */
|
||||||
|
|
||||||
utf8_str_len = 0;
|
utf8_str_len = 0;
|
||||||
utf8_str[0] = '\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)
|
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) */
|
/* 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);
|
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;
|
utf8_char[0] = utf8_str[j];
|
||||||
y = y + text->h;
|
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;
|
if (utf8_char[0] != '\0')
|
||||||
dest.y = y;
|
{
|
||||||
|
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_len = 0;
|
||||||
utf8_str[0] = '\0';
|
utf8_str[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
@ -6413,24 +6439,6 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color,
|
||||||
i = i + 3;
|
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);
|
free(locale_str);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue