From 05077e690706b6885249514c14b7f1cb42abbf0c Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Thu, 4 Dec 2008 00:14:02 +0000 Subject: [PATCH] Adding FriBidi support. --- Makefile | 10 ++++++---- docs/CHANGES.txt | 6 +++++- src/tuxpaint.c | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index ca13c3fa6..e3cf5f110 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ # bill@newbreedsoftware.com # http://www.tuxpaint.org/ -# June 14, 2002 - July 7, 2008 +# June 14, 2002 - December 3, 2008 # The version number, for release: @@ -74,10 +74,12 @@ PAPER_LIB:=$(call linktest,-lpaper,) PNG:=$(call linktest,-lpng,) PNG:=$(if $(PNG),$(PNG),$(call linktest,-lpng12,)) -windows_ARCH_LINKS:=-lintl $(PNG) -lwinspool -lshlwapi -osx_ARCH_LINKS:=$(PAPER_LIB) +FRIBIDI_LIB:=-lfribidi + +windows_ARCH_LINKS:=-lintl $(PNG) -lwinspool -lshlwapi $(FRIBIDI_LIB) +osx_ARCH_LINKS:=$(PAPER_LIB) $(FRIBIDI_LIB) beos_ARCH_LINKS:="-lintl $(PNG) -lz -lbe -liconv" -linux_ARCH_LINKS:=$(PAPER_LIB) +linux_ARCH_LINKS:=$(PAPER_LIB) $(FRIBIDI_LIB) ARCH_LINKS:=$($(OS)_ARCH_LINKS) windows_ARCH_HEADERS:=src/win32_print.h diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 69de07899..6475bd4d4 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -8,7 +8,7 @@ http://www.tuxpaint.org/ $Id$ -2008.December.1 (0.9.21) +2008.December.3 (0.9.21) * New Starters: ------------- * Silver Frame @@ -91,6 +91,10 @@ $Id$ * White always appears as the first color in the "New" dialog, regardless of its position (or even existence) in the color palette. + * Text tool uses FriBidi to determine when right-to-left characters have + been typed (e.g., Hebrew) so that they are drawn in the right direction. + (Mixing RtoL and LtoR works (e.g., Hebrew with numerals)) + * New localizations: ------------------ * Shuswap (Secwepemctín) translation diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 5928bce8e..7cb81bf30 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -963,6 +963,19 @@ char *papersize = NULL; #endif +#if 1 /* FIXME: ifdef for platforms that lack fribidi? */ +#include +#if !defined(FRIBIDI_H) +#error "---------------------------------------------------" +#error "If you installed libfribidi from a package, be sure" +#error "to get the development package, as well!" +#error "(eg., 'libfribidi-dev')" +#error "---------------------------------------------------" +#endif +#else +/* FIXME: define a noop function */ +#endif + enum { UNDO_STARTER_NONE, @@ -15479,7 +15492,34 @@ static void do_render_cur_text(int do_blit) if (texttool_len > 0) { - str = uppercase_w(texttool_str); + #ifdef FRIBIDI_H + FriBidiCharType baseDir = FRIBIDI_TYPE_LTR; + FriBidiChar *unicodeIn, *unicodeOut; + unsigned int i; + + unicodeIn = (FriBidiChar *) malloc(sizeof(FriBidiChar) * (texttool_len + 1)); + unicodeOut = (FriBidiChar *) malloc(sizeof(FriBidiChar) * (texttool_len + 1)); + + str = (wchar_t *) malloc(sizeof(wchar_t) * (texttool_len + 1)); + + for (i = 0; i < texttool_len; i++) + unicodeIn[i] = (FriBidiChar) texttool_str[i]; + + fribidi_log2vis(unicodeIn, texttool_len, &baseDir, unicodeOut, 0, 0, 0); + + /* FIXME: If we determine that some new text was RtoL, we should + reposition the text */ + + for (i = 0; i < texttool_len; i++) + str[i] = (long) unicodeOut[i]; + + str[texttool_len] = L'\0'; + + free(unicodeIn); + free(unicodeOut); + #else + str = uppercase_w(texttool_str); + #endif tmp_surf = render_text_w(getfonthandle(cur_font), str, color);