diff --git a/Makefile b/Makefile index 93852b50f6..ec2750b81d 100644 --- a/Makefile +++ b/Makefile @@ -36,9 +36,9 @@ OBJS_MPLAYER = $(SRCS_MPLAYER:.c=.o) 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) $(SMBSUPPORT_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) $(SMBSUPPORT_LIB) $(FRIBIDI_LIB) -CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(SMBSUPPORT_INC) # -Wall +CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(SMBSUPPORT_INC) $(FRIBIDI_INC) # -Wall ifeq ($(TARGET_ALTIVEC),yes) ifeq ($(TARGET_OS),Darwin) diff --git a/configure b/configure index 94ba3b7201..401bf45f6d 100755 --- a/configure +++ b/configure @@ -166,6 +166,7 @@ Optional features: --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: @@ -293,6 +294,8 @@ Use these options if autodetection fails: --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 @@ -1070,6 +1073,8 @@ _qtx_codecs=auto _macosx=auto _sortsub=yes _freetypeconfig='freetype-config' +_fribidi=no +_fribidiconfig='fribidi-config' for ac_option do case "$ac_option" in @@ -1257,6 +1262,9 @@ for ac_option do --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 ;; @@ -1375,6 +1383,9 @@ for ac_option do --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` ;; @@ -3789,6 +3800,38 @@ else fi echores "$_freetype" + +echocheck "fribidi with charsets" +if test "$_fribidi" = yes ; then + if ( $_fribidiconfig --version ) >/dev/null 2>&1 ; then + cat > $TMPC << EOF +#include +#include +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 @@ -5044,6 +5087,8 @@ CDPARANOIA_INC = $_inc_cdparanoia 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 @@ -5438,6 +5483,9 @@ $_def_gif_tvt_hack /* enable FreeType support */ $_def_freetype +/* enable FriBiDi usage */ +$_def_fribidi + /* liblzo support */ $_def_liblzo diff --git a/subreader.c b/subreader.c index 28fea35218..f5fdf30831 100644 --- a/subreader.c +++ b/subreader.c @@ -22,6 +22,9 @@ #include char *sub_cp=NULL; #endif +#ifdef USE_FRIBIDI +#include +#endif /* Maximal length of line of a subtitle */ #define LINE_LEN 1000 @@ -1012,6 +1015,62 @@ subtitle* subcp_recode1 (subtitle *sub) } #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; @@ -1134,6 +1193,9 @@ subtitle* sub_read_file (char *filename, float fps) { if(!sub) break; // EOF #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 ) {