summaryrefslogtreecommitdiffstats
path: root/subreader.c
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2009-11-22 00:09:40 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2009-11-22 00:09:40 +0000
commit03e99c5cb89a1965273da2feb3908de07b6803d4 (patch)
tree90b3ba2c49d2b40164271f547f4674521d578cdf /subreader.c
parent4a89d764516f013f380f90e2c8a1c2d142295dbe (diff)
downloadmpv-03e99c5cb89a1965273da2feb3908de07b6803d4.tar.bz2
mpv-03e99c5cb89a1965273da2feb3908de07b6803d4.tar.xz
Make fribidi (i.e. right-to-left) support work with embedded subtitles.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29950 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'subreader.c')
-rw-r--r--subreader.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/subreader.c b/subreader.c
index e93f2ac428..adb440bebd 100644
--- a/subreader.c
+++ b/subreader.c
@@ -1148,7 +1148,13 @@ subtitle* subcp_recode (subtitle *sub)
#endif
#ifdef CONFIG_FRIBIDI
-static subtitle* sub_fribidi (subtitle *sub, int sub_utf8)
+/**
+ * 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
+ * @param from first new subtitle, all lines before this are assumed to be already converted
+ */
+static subtitle* sub_fribidi (subtitle *sub, int sub_utf8, int from)
{
FriBidiChar logical[LINE_LEN+1], visual[LINE_LEN+1]; // Hopefully these two won't smash the stack
char *ip = NULL, *op = NULL;
@@ -1167,7 +1173,7 @@ static subtitle* sub_fribidi (subtitle *sub, int sub_utf8)
}else {
char_set_num = fribidi_parse_charset ("UTF-8");
}
- while (l) {
+ 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) {
@@ -1415,7 +1421,7 @@ sub_data* sub_read_file (char *filename, float fps) {
if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub);
#endif
#ifdef CONFIG_FRIBIDI
- if (sub!=ERR) sub=sub_fribidi(sub,sub_utf8);
+ if (sub!=ERR) sub=sub_fribidi(sub,sub_utf8,0);
#endif
if ( sub == ERR )
{
@@ -2269,6 +2275,7 @@ void sub_add_text(subtitle *sub, const char *txt, int len, double endpts) {
int double_newline = 1; // ignore newlines at the beginning
int i, pos;
char *buf;
+ int orig_lines = sub->lines;
if (sub->lines >= SUB_MAX_TEXT) return;
pos = 0;
buf = malloc(MAX_SUBLINE + 1);
@@ -2313,6 +2320,9 @@ void sub_add_text(subtitle *sub, const char *txt, int len, double endpts) {
if (sub->lines < SUB_MAX_TEXT &&
strlen(sub->text[sub->lines]))
sub->lines++;
+#ifdef CONFIG_FRIBIDI
+ sub = sub_fribidi(sub, sub_utf8, orig_lines);
+#endif
}
#define MP_NOPTS_VALUE (-1LL<<63)