diff --git a/src/i18n.c b/src/i18n.c index d6468f87f..4b47eaea7 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -25,7 +25,7 @@ $Id$ - June 14, 2002 - July 19, 2007 + June 14, 2002 - July 26, 2007 */ #include @@ -163,10 +163,16 @@ int lang_use_right_to_left[] = { -1 }; +int lang_use_right_to_left_word[] = { + LANG_HE, + -1 +}; + char *langstr; int need_own_font; int need_right_to_left; +int need_right_to_left_word; const char *lang_prefix; const language_to_locale_struct language_to_locale_array[] = { @@ -385,10 +391,13 @@ void set_current_language(void) lang_prefix = lang_prefixes[langint]; need_own_font = search_int_array(langint, lang_use_own_font); need_right_to_left = search_int_array(langint, lang_use_right_to_left); + need_right_to_left_word = search_int_array(langint, lang_use_right_to_left_word); #ifdef DEBUG - fprintf(stderr, "DEBUG: Language is %s (%d) %s\n", - lang_prefix, langint, need_right_to_left ? "(RTL)" : ""); + fprintf(stderr, "DEBUG: Language is %s (%d) %s/%s\n", + lang_prefix, langint, + need_right_to_left ? "(RTL)" : "", + need_right_to_left_word ? "(RTL words)" : ""); fflush(stderr); #endif diff --git a/src/i18n.h b/src/i18n.h index f0ecc0996..1318cb4a8 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -10,7 +10,7 @@ $Id$ - June 14, 2002 - July 14, 2007 + June 14, 2002 - July 26, 2007 */ @@ -117,7 +117,8 @@ extern int lang_use_own_font[]; extern int lang_use_right_to_left[]; extern char *langstr; extern int need_own_font; -extern int need_right_to_left; +extern int need_right_to_left; // Right-justify +extern int need_right_to_left_word; // Words need to be reversed, too! (e.g., Hebrew, but not Arabic) extern const char *lang_prefix; extern const language_to_locale_struct language_to_locale_array[]; diff --git a/src/tuxpaint.c b/src/tuxpaint.c index ba8efa108..5813ca765 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -1466,8 +1466,10 @@ static void draw_image_title(int t, SDL_Rect dest); static void handle_keymouse(SDLKey key, Uint8 updown); static void handle_active(SDL_Event * event); static char *remove_slash(char *path); +#ifdef NO_SDLPANGO static void anti_carriage_return(int left, int right, int cur_top, int new_top, int cur_bot, int line_width); +#endif static int mySDL_WaitEvent(SDL_Event * event); static int mySDL_PollEvent(SDL_Event * event); static void load_starter_id(char *saved_id); @@ -7038,6 +7040,12 @@ static void setup(int argc, char *argv[]) locale_font = load_locale_font(medium_font, 18); +#ifndef NO_SDLPANGO + if (need_right_to_left) + SDLPango_SetBaseDirection(locale_font->pango_context, SDLPANGO_DIRECTION_RTL); +#endif + + #if 0 // put elsewhere for THREADED_FONTS /* Load user fonts, for the text tool */ @@ -9508,23 +9516,51 @@ static void wordwrap_text_ex(const char *const str, SDL_Color color, int left, int top, int right, int want_right_to_left, Uint8 locale_text) { + SDL_Surface *text; + TuxPaint_Font *myfont = medium_font; + SDL_Rect dest; +#ifdef NO_SDLPANGO + int len; int x, y, j; unsigned int i; char substr[512]; unsigned char *locale_str; char *tstr; unsigned char utf8_char[5]; - int len; - SDL_Surface *text; - SDL_Rect dest, src; - TuxPaint_Font *myfont = medium_font; - + SDL_Rect src; int utf8_str_len, last_text_height; unsigned char utf8_str[512]; +#else + SDLPango_Matrix pango_color; +#endif + + + if (str == NULL || str[0] == '\0') + return; // No-op! if (need_own_font && (strcmp(gettext(str), str) || locale_text)) myfont = locale_font; + +#ifndef NO_SDLPANGO + /* Letting SDL_Pango do all this stuff! */ + + sdl_color_to_pango_color(color, &pango_color); + + SDLPango_SetDefaultColor(myfont->pango_context, &pango_color); + SDLPango_SetMinimumSize(myfont->pango_context, right - left, canvas->h - top); + SDLPango_SetText(myfont->pango_context, gettext(str), -1); + text = SDLPango_CreateSurfaceDraw(myfont->pango_context); + + dest.x = left; + dest.y = top; + if (text != NULL) + { + SDL_BlitSurface(text, NULL, screen, &dest); + SDL_FreeSurface(text); + } +#else + /* Cursor starting position: */ x = left; @@ -9544,10 +9580,14 @@ static void wordwrap_text_ex(const char *const str, SDL_Color color, want_right_to_left = 0; } +#ifdef NO_SDLPANGO if (want_right_to_left == 0) locale_str = (unsigned char *) strdup(gettext(str)); else locale_str = (unsigned char *) textdir(gettext(str)); +#else + locale_str = (unsigned char *) strdup(gettext(str)); +#endif /* For each UTF8 character: */ @@ -9837,6 +9877,7 @@ static void wordwrap_text_ex(const char *const str, SDL_Color color, SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255)); } +#endif } @@ -14716,7 +14757,7 @@ static char *textdir(const char *const str) dstr = malloc(strlen(str) + 5); - if (need_right_to_left) + if (need_right_to_left_word) { dstr[strlen(str)] = '\0'; @@ -15304,6 +15345,7 @@ static char *remove_slash(char *path) /* 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! */ +#ifdef NO_SDLPANGO static void anti_carriage_return(int left, int right, int cur_top, int new_top, int cur_bot, int line_width) { @@ -15332,6 +15374,7 @@ static void anti_carriage_return(int left, int right, int cur_top, SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255)); } +#endif static int mySDL_WaitEvent(SDL_Event * event)