[Scummvm-git-logs] scummvm master -> 1b8f471c69a93491d2bddaffa5676d4d77f63429

sev- sev at scummvm.org
Thu Apr 30 08:32:23 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1b8f471c69 GUI: Added (partial) BiDI support


Commit: 1b8f471c69a93491d2bddaffa5676d4d77f63429
    https://github.com/scummvm/scummvm/commit/1b8f471c69a93491d2bddaffa5676d4d77f63429
Author: Zvika Haramaty (haramaty.zvika at gmail.com)
Date: 2020-04-30T10:32:18+02:00

Commit Message:
GUI: Added (partial) BiDI support

Added GNU FriBidi, thus allowing Hebrew (or other future RTL languages)
to be displayed correctly.
It's been implemented for all ScummVM GUI (as far as I have noticed),
and can be further used by the engines as needed.

This work is only partial, because for complete BiDI support we'll need
to mirror the widgets, and support input text areas (which currently
don't even support Hebrew text input at all).

Some changes are required in order to use this:
- Visual Studio:
  -- add FriBidi lib from https://github.com/ShiftMediaProject/fribidi
     (and place the files in the other libs location)
  -- add fribidi.dll to the current directory
  -- add fribidi.lib to VS library list
     (in GUI it's: Project -> scummvm Properties -> Linker ->
                   input -> Additional Dependencies)
  -- Add USE_FRIBIDI define
     either to:
         dists/msvc/ScummVM_Global.props   <PreprocessorDefinitions>
     or in GUI:
         Project -> scummvm Properties ->
         C/C++ -> Preprocessor -> Preprocessor Definitions
- GCC:
  -- install FriBidi
     e.g.,
        Ubuntu: `apt-get install libfribidi-dev`
        CentOS: `yum install fribidi-devel`
  -- rerun `configure`

Changed paths:
    common/translation.cpp
    common/translation.h
    configure
    gui/ThemeEngine.cpp
    snapcraft.yaml
    snapcraft.yaml.in


diff --git a/common/translation.cpp b/common/translation.cpp
index 1debabfb7d..86efdd5371 100644
--- a/common/translation.cpp
+++ b/common/translation.cpp
@@ -36,6 +36,10 @@
 
 #ifdef USE_TRANSLATION
 
+#ifdef USE_FRIBIDI
+#include <fribidi/fribidi.h>
+#endif
+
 namespace Common {
 
 DECLARE_SINGLETON(TranslationManager);
@@ -450,6 +454,68 @@ bool TranslationManager::checkHeader(File &in) {
 	return true;
 }
 
+String TranslationManager::convertBiDiString(const String &input) {
+	if (getCurrentLanguage() != "he")		//TODO: modify when we'll support other RTL languages, such as Arabic and Farsi
+		return input;
+
+	if (getCurrentCharset() != "iso-8859-8") {
+		warning("convertBiDiString: Unexpected charset is used with %s language: %s", getCurrentLanguage().c_str(), getCurrentCharset().c_str());
+		return input;
+	};
+
+	return TranslationManager::convertBiDiString(input, HE_ISR);
+}
+
+#ifdef USE_FRIBIDI
+String TranslationManager::convertBiDiString(const String &input, const Common::Language lang) {
+	if (lang != HE_ISR)		//TODO: modify when we'll support other RTL languages, such as Arabic and Farsi
+		return input;
+
+	int buff_length = (input.size() + 2) * 2;		// it's more than enough, but it's better to be on the safe side
+	FriBidiChar *input_unicode = (FriBidiChar *)malloc(buff_length * sizeof(FriBidiChar));
+	FriBidiChar *visual_str = (FriBidiChar *)malloc(buff_length * sizeof(FriBidiChar));
+	char *output = (char *)malloc(buff_length);
+
+	FriBidiCharType pbase_dir = FRIBIDI_TYPE_ON;
+	FriBidiCharSet char_set = FRIBIDI_CHAR_SET_ISO8859_8;
+
+	FriBidiStrIndex length = fribidi_charset_to_unicode(char_set, input.c_str(), input.size(), input_unicode);
+
+	if (!fribidi_log2vis(
+		/* input */
+		input_unicode,
+		length,
+		&pbase_dir,
+		/* output */
+		visual_str,
+		NULL,			// position_L_to_V_list,
+		NULL,			// position_V_to_L_list,
+		NULL			// embedding_level_list
+	)) {
+		warning("convertBiDiString: calling fribidi_log2vis failed");
+		free(input_unicode);
+		free(visual_str);
+		free(output);
+		return input;
+	}
+
+	fribidi_unicode_to_charset(char_set, visual_str, length, output);
+
+	String result = String(output);
+	free(input_unicode);
+	free(visual_str);
+	free(output);
+
+	return result;
+}
+#else
+String TranslationManager::convertBiDiString(const String &input, const Common::Language lang) {
+	return input;
+}
+#endif
+
+
+
 } // End of namespace Common
 
 #endif // USE_TRANSLATION
diff --git a/common/translation.h b/common/translation.h
index 3dd7039cf3..88cd86a65d 100644
--- a/common/translation.h
+++ b/common/translation.h
@@ -28,6 +28,7 @@
 #include "common/str.h"
 #include "common/singleton.h"
 #include "common/str-array.h"
+#include "common/language.h"
 
 #ifdef USE_TRANSLATION
 
@@ -174,6 +175,14 @@ public:
 	 */
 	String getCurrentLanguage() const;
 
+	/*
+	 * Wrapper for GNU FriBidi implementation of the Unicode Bidirectional Algorithm
+	 * For LTR (Left To Right) languages, returns the original input
+	 * For RTL (Right To Left) languages, returns visual representation of a logical single-line input
+	 */
+	String convertBiDiString(const String &input);
+	String convertBiDiString(const String &input, const Common::Language lang);
+
 private:
 	/**
 	 * Tries to find the given language or a derivate of it.
diff --git a/configure b/configure
index 649ddb7a3f..3d166e3f48 100755
--- a/configure
+++ b/configure
@@ -168,6 +168,7 @@ _dialogs=auto
 _iconv=auto
 _tts=auto
 _gtk=auto
+_fribidi=auto
 # Default option behavior yes/no
 _debug_build=auto
 _release_build=auto
@@ -258,6 +259,7 @@ add_feature theoradec "libtheoradec" "_theoradec"
 add_feature vorbis "Vorbis file support" "_vorbis _tremor"
 add_feature zlib "zlib" "_zlib"
 add_feature lua "lua" "_lua"
+add_feature fribidi "FriBidi" "_fribidi"
 
 # Directories for installing ScummVM.
 # This list is closely based on what GNU autoconf does,
@@ -1076,6 +1078,9 @@ Optional Libraries:
   --with-mad-prefix=DIR    prefix where libmad is installed (optional)
   --disable-mad            disable libmad (MP3) support [autodetect]
 
+  --with-fribidi-prefix=DIR    prefix where libfribidi is installed
+  --disable-fribidi            disable libfribidi support [autodetect]
+
   --with-flac-prefix=DIR   prefix where libFLAC is installed (optional)
   --disable-flac           disable FLAC support [autodetect]
 
@@ -1233,6 +1238,8 @@ for ac_option in $@; do
 	--disable-flac)               _flac=no               ;;
 	--enable-mad)                 _mad=yes               ;;
 	--disable-mad)                _mad=no                ;;
+	--enable-fribidi)             _fribidi=yes           ;;
+	--disable-fribidi)            _fribidi=no            ;;
 	--enable-zlib)                _zlib=yes              ;;
 	--disable-zlib)               _zlib=no               ;;
 	--enable-sparkle)             _sparkle=yes           ;;
@@ -1355,6 +1362,11 @@ for ac_option in $@; do
 		MAD_CFLAGS="-I$arg/include"
 		MAD_LIBS="-L$arg/lib"
 		;;
+	--with-fribidi-prefix=*)
+		arg=`echo $ac_option | cut -d '=' -f 2`
+		FRIBIDI_CFLAGS="-I$arg/include"
+		FRIBIDI_LIBS="-L$arg/lib"
+		;;
 	--with-jpeg-prefix=*)
 		arg=`echo $ac_option | cut -d '=' -f 2`
 		JPEG_CFLAGS="-I$arg/include"
@@ -5526,6 +5538,26 @@ fi
 
 define_in_config_if_yes $_pandoc 'USE_PANDOC'
 
+#
+# Check for FriBidi
+#
+echocheck "FriBidi"
+if test "$_fribidi" = auto ; then
+	_fribidi=no
+	cat > $TMPC << EOF
+#include <fribidi/fribidi.h>
+int main(void) { return 0; }
+EOF
+	cc_check $FRIBIDI_CFLAGS $FRIBIDI_LIBS -lfribidi && _fribidi=yes
+fi
+if test "$_fribidi" = yes ; then
+	append_var LIBS "$FRIBIDI_LIBS -lfribidi"
+	append_var INCLUDES "$FRIBIDI_CFLAGS"
+fi
+define_in_config_if_yes "$_fribidi" 'USE_FRIBIDI'
+echo "$_fribidi"
+
+
 # Default to plain text output for pandoc
 if test -z "$_pandocformat" -o "$_pandocformat" = "default"; then
 	_pandocformat="plain"
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index 7aec42309c..4190cc14c1 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -920,7 +920,11 @@ void ThemeEngine::drawDDText(TextData type, TextColor color, const Common::Rect
 		restoreBackground(dirty);
 
 	_vectorRenderer->setFgColor(_textColors[color]->r, _textColors[color]->g, _textColors[color]->b);
+#ifdef USE_TRANSLATION
+	_vectorRenderer->drawString(_texts[type]->_fontPtr, TransMan.convertBiDiString(text), area, alignH, alignV, deltax, ellipsis, dirty);
+#else
 	_vectorRenderer->drawString(_texts[type]->_fontPtr, text, area, alignH, alignV, deltax, ellipsis, dirty);
+#endif
 
 	addDirtyRect(dirty);
 }
diff --git a/snapcraft.yaml b/snapcraft.yaml
index 258d3c39a2..e6adf7abb2 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -39,6 +39,7 @@ parts:
       - libfreetype6-dev
       - zlib1g-dev
       - libunity-dev
+      - libfribidi-dev
     stage-packages:
       - libicu55
       - libasound2
diff --git a/snapcraft.yaml.in b/snapcraft.yaml.in
index a95477707a..b4b4b67cf9 100644
--- a/snapcraft.yaml.in
+++ b/snapcraft.yaml.in
@@ -39,6 +39,7 @@ parts:
       - libfreetype6-dev
       - zlib1g-dev
       - libunity-dev
+      - libfribidi-dev
     stage-packages:
       - libicu55
       - libasound2




More information about the Scummvm-git-logs mailing list