summaryrefslogtreecommitdiffstats
path: root/subreader.c
diff options
context:
space:
mode:
authoralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-03-21 16:54:03 +0000
committeralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-03-21 16:54:03 +0000
commit981ef7408bbf8e4b6e534f8cfcdb61868a5fd0f1 (patch)
tree77530fbbe139c13c0c93980d495434ad45d7d008 /subreader.c
parenta284605302fa0c8d0ba1b8688af3f723515d7cb1 (diff)
downloadmpv-981ef7408bbf8e4b6e534f8cfcdb61868a5fd0f1.tar.bz2
mpv-981ef7408bbf8e4b6e534f8cfcdb61868a5fd0f1.tar.xz
hebrew support using fribidi libs, patch by Raindel Shachar <raindel@techunix.technion.ac.il>
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9636 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'subreader.c')
-rw-r--r--subreader.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/subreader.c b/subreader.c
index 28fea35218..f5fdf30831 100644
--- a/subreader.c
+++ b/subreader.c
@@ -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 @@ 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;
@@ -1135,6 +1194,9 @@ subtitle* sub_read_file (char *filename, float fps) {
#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