Mercurial > mplayer.hg
changeset 33353:63dbf59fa312
Move some common fribidi code into a shared function.
This should also ease hacks for compilation against older versions.
author | reimar |
---|---|
date | Sun, 08 May 2011 08:52:43 +0000 |
parents | 2b5e0610a072 |
children | a0c9f0202d8e |
files | libmenu/menu.c sub/subreader.c sub/subreader.h |
diffstat | 3 files changed, 25 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libmenu/menu.c Sun May 08 08:51:44 2011 +0000 +++ b/libmenu/menu.c Sun May 08 08:52:43 2011 +0000 @@ -438,8 +438,6 @@ 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 @@ 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; }
--- a/sub/subreader.c Sun May 08 08:51:44 2011 +0000 +++ b/sub/subreader.c Sun May 08 08:52:43 2011 +0000 @@ -1231,6 +1231,20 @@ #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 @@ { 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 @@ } 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++;
--- a/sub/subreader.h Sun May 08 08:51:44 2011 +0000 +++ b/sub/subreader.h Sun May 08 08:52:43 2011 +0000 @@ -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;