[MPlayer-cvslog] r33440 - in trunk: libmenu/menu.c sub/subreader.c sub/subreader.h

reimar subversion at mplayerhq.hu
Sun May 8 10:52:43 CEST 2011


Author: reimar
Date: Sun May  8 10:52:43 2011
New Revision: 33440

Log:
Move some common fribidi code into a shared function.
This should also ease hacks for compilation against older versions.

Modified:
   trunk/libmenu/menu.c
   trunk/sub/subreader.c
   trunk/sub/subreader.h

Modified: trunk/libmenu/menu.c
==============================================================================
--- trunk/libmenu/menu.c	Sun May  8 10:51:44 2011	(r33439)
+++ trunk/libmenu/menu.c	Sun May  8 10:52:43 2011	(r33440)
@@ -438,8 +438,6 @@ static char *menu_fribidi(char *txt)
   static size_t buffer_size = 1024;
   static char *outputstr;
 
-  FriBidiParType base;
-  fribidi_boolean log2vis;
   size_t len;
 
   if (menu_flip_hebrew) {
@@ -458,11 +456,8 @@ static char *menu_fribidi(char *txt)
       visual = realloc(visual, buffer_size);
       outputstr = realloc(outputstr, buffer_size);
     }
-    len = fribidi_charset_to_unicode (char_set_num, txt, len, logical);
-    base = menu_fribidi_flip_commas?FRIBIDI_PAR_ON:FRIBIDI_PAR_LTR;
-    log2vis = fribidi_log2vis (logical, len, &base, visual, NULL, NULL, NULL);
-    if (log2vis) {
-      len = fribidi_remove_bidi_marks (visual, len, NULL, NULL, NULL);
+    len = do_fribid_log2vis(char_set_num, txt, logical, visual, menu_fribidi_flip_commas);
+    if (len > 0) {
       fribidi_unicode_to_charset (char_set_num, visual, len, outputstr);
       return outputstr;
     }

Modified: trunk/sub/subreader.c
==============================================================================
--- trunk/sub/subreader.c	Sun May  8 10:51:44 2011	(r33439)
+++ trunk/sub/subreader.c	Sun May  8 10:52:43 2011	(r33440)
@@ -1231,6 +1231,20 @@ subtitle* subcp_recode (subtitle *sub)
 
 #ifdef CONFIG_FRIBIDI
 /**
+ * Helper function to share code between subreader and libmenu/menu.c
+ */
+int do_fribid_log2vis(int charset, const char *in, FriBidiChar *logical, FriBidiChar *visual, int flip_commas)
+{
+  FriBidiParType base = flip_commas ? FRIBIDI_PAR_ON : FRIBIDI_PAR_LTR;
+  int len = strlen(in);
+  len = fribidi_charset_to_unicode(charset, in, len, logical);
+  if (!fribidi_log2vis(logical, len, &base, visual, NULL, NULL, NULL))
+    return -1;
+  len = fribidi_remove_bidi_marks(visual, len, NULL, NULL, NULL);
+  return len;
+}
+
+/**
  * Do conversion necessary for right-to-left language support via fribidi.
  * @param sub subtitle to convert
  * @param sub_utf8 whether the subtitle is encoded in UTF-8
@@ -1240,11 +1254,9 @@ static subtitle* sub_fribidi (subtitle *
 {
   FriBidiChar logical[LINE_LEN+1], visual[LINE_LEN+1]; // Hopefully these two won't smash the stack
   char        *ip      = NULL, *op     = NULL;
-  FriBidiParType base;
   size_t len,orig_len;
   int l=sub->lines;
   int char_set_num;
-  fribidi_boolean log2vis;
   if (!flip_hebrew)
     return sub;
   fribidi_set_mirroring(1);
@@ -1257,20 +1269,14 @@ static subtitle* sub_fribidi (subtitle *
   }
   while (l > from) {
     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) {
+    orig_len = strlen( ip ); // We assume that we don't use full unicode, only UTF-8 or ISO8859-x
+    if(orig_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_flip_commas?FRIBIDI_PAR_ON:FRIBIDI_PAR_LTR;
-    log2vis = fribidi_log2vis (logical, len, &base,
-			       /* output */
-			       visual, NULL, NULL, NULL);
-    if(log2vis) {
-      len = fribidi_remove_bidi_marks (visual, len, NULL, NULL,
-				       NULL);
+    len = do_fribid_log2vis(char_set_num, ip, logical, visual, fribidi_flip_commas);
+    if(len > 0) {
       if((op = malloc((FFMAX(2*orig_len,2*len) + 1))) == NULL) {
 	mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: error allocating mem.\n");
 	l++;

Modified: trunk/sub/subreader.h
==============================================================================
--- trunk/sub/subreader.h	Sun May  8 10:51:44 2011	(r33439)
+++ trunk/sub/subreader.h	Sun May  8 10:52:43 2011	(r33440)
@@ -23,6 +23,11 @@
 
 #include "config.h"
 
+#ifdef CONFIG_FRIBIDI
+#include <fribidi/fribidi.h>
+int do_fribid_log2vis(int charset, const char *in, FriBidiChar *logical, FriBidiChar *visual, int flip_commas);
+#endif
+
 extern int suboverlap_enabled;
 extern int sub_no_text_pp;  // disable text post-processing
 extern int sub_match_fuzziness;


More information about the MPlayer-cvslog mailing list