changeset 23228:2e95dcd49946

support for hebrew through fribidi in libmenu (geexbox patch #580)
author ben
date Mon, 07 May 2007 15:59:53 +0000
parents a142b048c65e
children ae2a2d5ca64b
files cfg-mplayer.h libmenu/menu.c
diffstat 2 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cfg-mplayer.h	Mon May 07 15:55:58 2007 +0000
+++ b/cfg-mplayer.h	Mon May 07 15:59:53 2007 +0000
@@ -72,6 +72,11 @@
 extern int menu_startup;
 extern int menu_utf8;
 extern int menu_unicode;
+#ifdef  USE_FRIBIDI
+extern char *menu_fribidi_charset;
+extern int menu_flip_hebrew;
+extern int menu_fribidi_flip_commas;
+#endif
 #endif
 
 #ifdef HAVE_ZR
@@ -295,6 +300,13 @@
 	{"menu-startup", &menu_startup, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
 	{"menu-utf8", &menu_utf8, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"menu-unicode", &menu_unicode, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+#ifdef USE_FRIBIDI
+	{"menu-fribidi-charset", &menu_fribidi_charset, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"menu-flip-hebrew", &menu_flip_hebrew, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"menu-noflip-hebrew", &menu_flip_hebrew, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+	{"menu-flip-hebrew-commas", &menu_fribidi_flip_commas, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+	{"menu-noflip-hebrew-commas", &menu_fribidi_flip_commas, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+#endif
 #else
 	{"menu", "OSD menu support was not compiled in.\n", CONF_TYPE_PRINT,0, 0, 0, NULL},
 #endif
--- a/libmenu/menu.c	Mon May 07 15:55:58 2007 +0000
+++ b/libmenu/menu.c	Mon May 07 15:59:53 2007 +0000
@@ -326,6 +326,56 @@
   }
 }
 
+#ifdef USE_FRIBIDI
+#include <fribidi/fribidi.h>
+static char *menu_fribidi_charset = NULL;
+static int menu_flip_hebrew = 0;
+static int menu_fribidi_flip_commas = 0;
+
+static char *menu_fribidi(char *txt)
+{
+  static int char_set_num = -1;
+  static FriBidiChar *logical, *visual;
+  static size_t buffer_size = 1024;
+  static char *outputstr;
+
+  FriBidiCharType base;
+  fribidi_boolean log2vis;
+  size_t len;
+
+  if (menu_flip_hebrew) {
+    len = strlen(txt);
+    if (char_set_num == -1) {
+      fribidi_set_mirroring (1);
+      fribidi_set_reorder_nsm (0);
+      if (menu_utf8 == 0) {
+        char_set_num = fribidi_parse_charset(menu_fribidi_charset ? menu_fribidi_charset : "ISO8859-8");
+      } else {
+        char_set_num = fribidi_parse_charset("UTF-8");
+      }
+      buffer_size = 1024 > (len+1) ? 1024 : (len+1);
+      logical = (FriBidiChar*) malloc(buffer_size);
+      visual = (FriBidiChar*) malloc(buffer_size);
+      outputstr = (char*) malloc(buffer_size);
+    } else if (len+1 > buffer_size) {
+      buffer_size = len+1;
+      logical = (FriBidiChar*) realloc(logical, buffer_size);
+      visual = (FriBidiChar*) realloc(visual, buffer_size);
+      outputstr = (char*) realloc(outputstr, buffer_size);
+    }
+    len = fribidi_charset_to_unicode (char_set_num, txt, len, logical);
+    base = menu_fribidi_flip_commas?FRIBIDI_TYPE_ON:FRIBIDI_TYPE_L;
+    log2vis = fribidi_log2vis (logical, len, &base, visual, NULL, NULL, NULL);
+    if (log2vis) {
+      len = fribidi_remove_bidi_marks (visual, len, NULL, NULL, NULL);
+      fribidi_unicode_to_charset (char_set_num, visual, len, outputstr);
+      return outputstr;
+    }
+  }
+  return txt;
+}
+#endif
+
 void menu_draw_text(mp_image_t* mpi,char* txt, int x, int y) {
   draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);
   int font;
@@ -335,6 +385,9 @@
     return;
   }
 
+#ifdef USE_FRIBIDI
+  txt = menu_fribidi(txt);
+#endif
   render_txt(txt);
 
   while (*txt) {
@@ -366,6 +419,9 @@
     return;
   }
 
+#ifdef USE_FRIBIDI
+  txt = menu_fribidi(txt);
+#endif
   render_txt(txt);
 
   if(x > mpi->w || y > mpi->h)