From e4009ae2c9316f84a5cc8cb86c34adf952dcefaa Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Fri, 23 May 2003 07:53:02 +0000 Subject: [PATCH] Hebrew blits top-to-bottom (was blitting bottom-to-top), and is right-justified. --- docs/AUTHORS.txt | 2 +- docs/CHANGES.txt | 4 +- docs/README.txt | 2 +- docs/TODO.txt | 5 +- docs/html/README.html | 2 +- src/tuxpaint.c | 147 +++++++++++++++++++++++++++++++++--------- 6 files changed, 127 insertions(+), 35 deletions(-) diff --git a/docs/AUTHORS.txt b/docs/AUTHORS.txt index 84d843fb3..7e54834da 100644 --- a/docs/AUTHORS.txt +++ b/docs/AUTHORS.txt @@ -7,7 +7,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ -June 17, 2002 - April 25, 2003 +June 17, 2002 - May 23, 2003 * Design and Coding: diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index f9e9eb4f4..653a67de4 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -7,7 +7,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ -2003.May.22 (0.9.11) [cvs] +2003.May.23 (0.9.11) [cvs] * Windows bugfixes. John Popplewell @@ -19,6 +19,8 @@ http://www.newbreedsoftware.com/tuxpaint/ Dovix Koby + * Right-to-left language support (for Hebrew, for example). + * Updated Korean translations. Mark K. Kim diff --git a/docs/README.txt b/docs/README.txt index e228f2acf..8759ec337 100644 --- a/docs/README.txt +++ b/docs/README.txt @@ -9,7 +9,7 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ - June 14, 2002 - May 22, 2003 + June 14, 2002 - May 23, 2003 ---------------------------------------------------------------------- diff --git a/docs/TODO.txt b/docs/TODO.txt index 16a38a6a5..d568b40b2 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -6,7 +6,7 @@ Copyright (c) 2003 by Bill Kendrick bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ -May 22, 2003 +May 23, 2003 LOW-PRIORITY DOCUMENTATION CHANGES: @@ -81,6 +81,9 @@ HIGH-PRIORITY TRANSLATION STUFF: -------------------------------- * Right-justify right-to-left strings. + * Make right-to-left strings not wordwrap with the shortest line at + the top! + * Finish current translations. * Fix Romanian! diff --git a/docs/html/README.html b/docs/html/README.html index 39f836803..710f35d68 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 - May 22, 2003

+

June 14, 2002 - May 23, 2003


diff --git a/src/tuxpaint.c b/src/tuxpaint.c index f1c97e907..3dbbe8bce 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -7,12 +7,12 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ - June 14, 2002 - May 22, 2003 + June 14, 2002 - May 23, 2003 */ #define VER_VERSION "0.9.11" -#define VER_DATE "2003.05.22" +#define VER_DATE "2003.05.23" /* #define DEBUG */ @@ -557,9 +557,12 @@ void convert_close(); char * convert2utf8(char c); int converts(); int delete_utf8_char(char * utf8_str, int len); -#define MAX_UTF8_CHAR_LENGTH 6 +void anti_carriage_return(int left, int right, int cur_top, int new_top, + int cur_bot, int line_width); +#define MAX_UTF8_CHAR_LENGTH 6 + #define USEREVENT_TEXT_UPDATE 1 @@ -6333,9 +6336,9 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, unsigned char utf8_char[5]; int len; SDL_Surface * text; - SDL_Rect dest; + SDL_Rect dest, src; - int utf8_str_len; + int utf8_str_len, last_text_height; unsigned char utf8_str[512]; @@ -6343,6 +6346,8 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, x = left; y = top; + + last_text_height = 0; debug(str); debug(gettext(str)); @@ -6384,6 +6389,10 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, if (x > left) { + if (need_right_to_left(language)) + anti_carriage_return(left, right, top, top + text->h, y + text->h, + x - left); + x = left; y = y + text->h; } @@ -6391,6 +6400,7 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, /* Junk the blitted word; it's too long! */ + last_text_height = text->h; SDL_FreeSurface(text); @@ -6439,18 +6449,24 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, { if (x + text->w > right) { - x = left; + if (need_right_to_left(language)) + anti_carriage_return(left, right, top, top + text->h, + y + text->h, x - left); + + x = left; y = y + text->h; } - //if (need_right_to_left(language) == 0) - dest.x = x; - //else - // dest.x = right - (x - left) - text->w; + dest.x = x; - dest.y = y; + if (need_right_to_left(language)) + dest.y = top; + else + dest.y = y; SDL_BlitSurface(text, NULL, screen, &dest); + + last_text_height = text->h; SDL_FreeSurface(text); x = x + text->w; @@ -6466,18 +6482,24 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, { /* This word needs to move down? */ - x = left; + if (need_right_to_left(language)) + anti_carriage_return(left, right, top, top + text->h, y + text->h, + x - left); + + x = left; y = y + text->h; } - //if (need_right_to_left(language) == 0) - dest.x = x; - //else - // dest.x = right - (x - left) - text->w; + dest.x = x; - dest.y = y; + if (need_right_to_left(language)) + dest.y = top; + else + dest.y = y; SDL_BlitSurface(text, NULL, screen, &dest); + + last_text_height = text->h; SDL_FreeSurface(text); x = x + text->w; } @@ -6537,22 +6559,27 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, if (x + text->w > right) { + if (need_right_to_left(language)) + anti_carriage_return(left, right, top, top + text->h, y + text->h, + x - left); + x = left; y = y + text->h; } - //if (need_right_to_left(language) == 0) dest.x = x; - //else - // dest.x = right - (x - left) - text->w; - dest.y = y; + if (need_right_to_left(language)) + dest.y = top; + else + dest.y = y; SDL_BlitSurface(text, NULL, screen, &dest); x = x + text->w; + last_text_height = text->h; SDL_FreeSurface(text); } @@ -6597,19 +6624,23 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, if (x + text->w > right) /* Correct? */ { - x = left; + if (need_right_to_left(language)) + anti_carriage_return(left, right, top, top + text->h, y + text->h, + x - left); + + x = left; y = y + text->h; } /* Draw the word: */ - //if (need_right_to_left(language) == 0) - dest.x = x; - //else - // dest.x = right - (x - left) - text->w; + dest.x = x; - dest.y = y; + if (need_right_to_left(language)) + dest.y = top; + else + dest.y = y; SDL_BlitSurface(text, NULL, screen, &dest); @@ -6621,6 +6652,7 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, /* Free the temp. surface: */ + last_text_height = text->h; SDL_FreeSurface(text); @@ -6631,6 +6663,29 @@ void wordwrap_text(TTF_Font * font, char * str, SDL_Color color, free(tstr); } + + + /* Right-justify the final line of text, in right-to-left mode: */ + + if (need_right_to_left(language) && last_text_height > 0) + { + src.x = left; + src.y = top; + src.w = x - left; + src.h = last_text_height; + + dest.x = right - src.w; + dest.y = top; + + SDL_BlitSurface(screen, &src, screen, &dest); + + dest.x = left; + dest.y = top; + dest.w = (right - left - src.w); + dest.h = last_text_height; + + SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 192, 192, 192)); + } } @@ -7262,7 +7317,7 @@ int do_prompt(char * text, char * btn_yes, char * btn_no) /* Draw the question: */ wordwrap_text(font, text, black, - 166 + PROMPTOFFSETX, 100 + PROMPTOFFSETY, 482, 0, 0); + 166 + PROMPTOFFSETX, 100 + PROMPTOFFSETY, 475, 0, 0); /* Draw yes button: */ @@ -7272,7 +7327,7 @@ int do_prompt(char * text, char * btn_yes, char * btn_no) SDL_BlitSurface(img_yes, NULL, screen, &dest); wordwrap_text(font, btn_yes, black, 166 + PROMPTOFFSETX + 48 + 4, - 183 + PROMPTOFFSETY, 482, 0, 0); + 183 + PROMPTOFFSETY, 475, 0, 0); /* Draw no button: */ @@ -7284,7 +7339,7 @@ int do_prompt(char * text, char * btn_yes, char * btn_no) SDL_BlitSurface(img_no, NULL, screen, &dest); wordwrap_text(font, btn_no, black, - 166 + PROMPTOFFSETX + 48 + 4, 235 + PROMPTOFFSETY, 482, 0, 0); + 166 + PROMPTOFFSETX + 48 + 4, 235 + PROMPTOFFSETY, 475, 0, 0); } @@ -11116,4 +11171,36 @@ int delete_utf8_char(char *utf8_str, int len) return len; } + +/* For right-to-left languages, when word-wrapping, we need to + make sure the text doesn't end up going from bottom-to-top, too! */ + +void anti_carriage_return(int left, int right, int cur_top, int new_top, + int cur_bot, int line_width) +{ + SDL_Rect src, dest; + + + /* Move current set of text down one line (and right-justify it!): */ + src.x = left; + src.y = cur_top; + src.w = line_width; + src.h = cur_bot - cur_top; + + dest.x = right - line_width; + dest.y = new_top; + + SDL_BlitSurface(screen, &src, screen, &dest); + + + /* Clear the top line for new text: */ + + dest.x = left; + dest.y = cur_top; + dest.w = right - left; + dest.h = new_top - cur_top; + + SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255)); +} +