[MPlayer-dev-eng] [PATCH] Hebrew-bidi support using fribidi

Raindel Shachar raindel at techunix.technion.ac.il
Wed Mar 19 23:23:08 CET 2003


  Hi, I am attaching a patch, which enable displaying "Logically"
(ISO8859-8-l) encoded subtitles. It still misses a run-time option to turn
it off.

  Regards
  Shachar

-------------- next part --------------
diff -ur original/Makefile patchtest/Makefile
--- original/Makefile	Fri Feb 21 14:44:28 2003
+++ patchtest/Makefile	Wed Mar 19 23:57:09 2003
@@ -36,9 +36,9 @@
 VO_LIBS = $(AA_LIB) $(X_LIB) $(SDL_LIB) $(GGI_LIB) $(MP1E_LIB) $(MLIB_LIB) $(SVGA_LIB) $(DIRECTFB_LIB) 
 AO_LIBS = $(ARTS_LIB) $(ESD_LIB) $(NAS_LIB) $(SGIAUDIO_LIB)
 CODEC_LIBS = $(AV_LIB) $(FAME_LIB) $(MAD_LIB) $(VORBIS_LIB) $(FAAD_LIB) $(LIBLZO_LIB) $(DECORE_LIB) $(XVID_LIB) $(PNG_LIB) $(Z_LIB) $(JPEG_LIB) $(ALSA_LIB) $(XMMS_LIB)
-COMMON_LIBS = libmpcodecs/libmpcodecs.a mp3lib/libMP3.a liba52/liba52.a libmpeg2/libmpeg2.a $(W32_LIB) $(DS_LIB) libaf/libaf.a libmpdemux/libmpdemux.a input/libinput.a postproc/libswscale.a osdep/libosdep.a $(CSS_LIB) $(CODEC_LIBS) $(FREETYPE_LIB) $(TERMCAP_LIB) $(CDPARANOIA_LIB) $(STREAMING_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS)
+COMMON_LIBS = libmpcodecs/libmpcodecs.a mp3lib/libMP3.a liba52/liba52.a libmpeg2/libmpeg2.a $(W32_LIB) $(DS_LIB) libaf/libaf.a libmpdemux/libmpdemux.a input/libinput.a postproc/libswscale.a osdep/libosdep.a $(CSS_LIB) $(CODEC_LIBS) $(FREETYPE_LIB) $(TERMCAP_LIB) $(CDPARANOIA_LIB) $(STREAMING_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS) $(FRIBIDI_LIB)
 
-CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) # -Wall
+CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(FRIBIDI_INC)  # -Wall
 
 ifeq ($(TARGET_ALTIVEC),yes)
 ifeq ($(TARGET_OS),Darwin)
diff -ur original/configure patchtest/configure
--- original/configure	Sat Mar 15 14:31:49 2003
+++ patchtest/configure	Wed Mar 19 23:55:58 2003
@@ -165,6 +165,7 @@
   --disable-new-conf     Disable new experimental config parser code [enabled]
   --enable-menu          Enable osd menu support (needs new config) [disabled]
   --disable-sortsub      Disable subtitles sorting [enabled]
+  --enable-fribidi       Enable using the FriBiDi libs [disabled]
   --disable-macosx       Disable Mac OS X specific features [autodetect]
 
 Codecs:
@@ -292,6 +293,8 @@
   --with-xmmslibdir=DIR    path to libxmms.so.1
   --with-cdparanoiaincdir=DIR  cdparanoia headers in DIR
   --with-cdparanoialibdir=DIR  cdparanoia libraries (libcdda_*) in DIR
+  --with-fribidi-config=PATH  path to fribidi-config
+                           (e.g. /opt/bin/fribidi-config)
 
 EOF
     exit 0
@@ -1067,7 +1070,9 @@
 _qtx_codecs=auto
 _macosx=auto
 _sortsub=yes
+_fribidi=no
 _freetypeconfig='freetype-config'
+_fribidiconfig='fribidi-config'
 
 for ac_option do
   case "$ac_option" in
@@ -1253,6 +1258,9 @@
   --enable-unrarlib)	_unrarlib=yes	;;
   --disable-unrarlib)	_unrarlib=no	;;
 
+  --enable-fribidi)     _fribidi=yes    ;;
+  --disable-fribidi)    _fribidi=no     ;;
+
   --enable-dga) _dga=auto ;; # as we don't know if it's 1 or 2
   --enable-dga=*) _dga=`echo $ac_option | cut -d '=' -f 2` ;;
   --disable-dga) _dga=no ;;
@@ -1371,6 +1379,9 @@
   --with-freetype-config=*)
     _freetypeconfig=`echo $ac_option | cut -d '=' -f 2`
     ;;
+  --with-fribidi-config=*)
+    _fribidiconfig=`echo $ac_option | cut -d '=' -f 2`
+    ;;
   --with-gtk-config=*)
     _gtkconfig=`echo $ac_option | cut -d '=' -f 2`
     ;;
@@ -3756,6 +3767,39 @@
 fi
 echores "$_freetype"
 
+
+echocheck "fribidi with charsets"
+if test "$_fribidi" = yes ; then
+    if ( $_fribidiconfig --version ) >/dev/null 2>&1 ; then
+	cat > $TMPC << EOF
+#include <stdio.h>
+#include <fribidi/fribidi.h>
+int main()
+{
+    if(fribidi_parse_charset("UTF-8") != FRIBIDI_CHARSET_UTF8) {
+       printf("Fribidi headers are not consistents with the library!\n");
+       exit(1);
+    }
+    return 0;
+}
+EOF
+	_fribidi=no
+	cc_check `$_fribidiconfig --cflags` `$_fribidiconfig --libs` && ( $TMPO >> "$TMPLOG" ) && _fribidi=yes
+    else
+	_fribidi=no
+    fi
+fi
+if test "$_fribidi" = yes ; then
+    _def_fribidi='#define USE_FRIBIDI'
+    _inc_fribidi=`$_fribidiconfig --cflags`
+    _ld_fribidi=`$_fribidiconfig --libs`
+else
+    _def_fribidi='#undef USE_FRIBIDI'
+fi
+echores "$_fribidi"
+
+
+
 echocheck "zlib"
 cat > $TMPC << EOF
 #include <zlib.h>
@@ -5011,6 +5055,8 @@
 CDPARANOIA_LIB = $_ld_cdparanoia
 FREETYPE_INC = $_inc_freetype
 FREETYPE_LIB = $_ld_freetype
+FRIBIDI_INC = $_inc_fribidi
+FRIBIDI_LIB = $_ld_fribidi
 LIBLZO_LIB= $_ld_liblzo
 MAD_LIB = $_ld_mad
 VORBIS_LIB = $_ld_vorbis $_ld_libdv
@@ -5400,6 +5446,9 @@
 /* enable FreeType support */
 $_def_freetype
 
+/* enable FriBiDi usage */
+$_def_fribidi
+
 /* liblzo support */
 $_def_liblzo
 
diff -ur original/subreader.c patchtest/subreader.c
--- original/subreader.c	Tue Feb 11 21:15:53 2003
+++ patchtest/subreader.c	Wed Mar 19 23:54:11 2003
@@ -22,6 +22,9 @@
 #include <iconv.h>
 char *sub_cp=NULL;
 #endif
+#ifdef USE_FRIBIDI
+#include <fribidi/fribidi.h>
+#endif
 
 /* Maximal length of line of a subtitle */
 #define LINE_LEN 1000
@@ -1012,6 +1015,62 @@
 }
 #endif
 
+#ifdef USE_FRIBIDI
+#define ALLOCATE(tp,ln) ((tp *) malloc (sizeof (tp) * (ln)))
+#define max(a,b)  (((a)>(b))?(a):(b))
+subtitle* sub_fribidi (subtitle *sub, int sub_utf8)
+{
+  FriBidiChar logical[LINE_LEN+1], visual[LINE_LEN+1]; // Hopefully these two won't smash the stack
+  char        *ip      = NULL, *op     = NULL;
+  FriBidiCharType base;
+  size_t len,orig_len;
+  int l=sub->lines;
+  int char_set_num;
+  fribidi_boolean log2vis;
+  fribidi_set_mirroring (FRIBIDI_TRUE);
+  fribidi_set_reorder_nsm (FRIBIDI_FALSE);
+   
+  if( sub_utf8 == 0 ) {
+    char_set_num = fribidi_parse_charset ("ISO8859-8");//We might want to make this a config option
+  }else {
+    char_set_num = fribidi_parse_charset ("UTF-8");
+  }
+  while (l) {
+    ip = sub->text[--l];
+    orig_len = len = strlen( ip ); // We assume that we don't use full unicode, only UTF-8 or ISO8859-x
+    if(len > LINE_LEN) {
+      mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: sub->text is longer than LINE_LEN.\n");
+      l++;
+      break;
+    }
+    len = fribidi_charset_to_unicode (char_set_num, ip, len, logical);
+    base = FRIBIDI_TYPE_ON;
+    log2vis = fribidi_log2vis (logical, len, &base,
+			       /* output */
+			       visual, NULL, NULL, NULL);
+    if(log2vis) {
+      len = fribidi_remove_bidi_marks (visual, len, NULL, NULL,
+				       NULL);
+      if((op = ALLOCATE(char,(max(2*orig_len,2*len) + 1))) == NULL) {
+	mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: error allocating mem.\n");
+	l++;
+	break;	
+      }
+      fribidi_unicode_to_charset ( char_set_num, visual, len,op);
+      free (ip);
+      sub->text[l] = op;
+    }
+  }
+  if (l){
+    for (l = sub->lines; l;)
+      free (sub->text[--l]);
+    return ERR;
+  }
+  return sub;
+}
+
+#endif
+
 static void adjust_subs_time(subtitle* sub, float subtime, float fps, int block){
 	int n,m;
 	subtitle* nextsub;
@@ -1135,6 +1194,9 @@
 #ifdef USE_ICONV
 	if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub);
 #endif
+#ifdef USE_FRIBIDI
+	if (sub!=ERR) sub=sub_fribidi(sub,sub_utf8);
+#endif
 	if ( sub == ERR )
 	 {
 #ifdef USE_ICONV


More information about the MPlayer-dev-eng mailing list