gst/subparse/gstsubparse.c: Set right caps given that we send escaped text. Also, honour <i></i>, <b></b> and <u></u>...

Original commit message from CVS:
* gst/subparse/gstsubparse.c: (subrip_unescape_formatting),
(parse_subrip), (gst_sub_parse_format_autodetect):
Set right caps given that we send escaped text. Also,
honour <i></i>, <b></b> and <u></u> markers that can be found
in .srt files (fixes #310202).
This commit is contained in:
Tim-Philipp Müller 2006-02-20 18:27:06 +00:00
parent 043c6d91df
commit 164a3128d5
2 changed files with 48 additions and 1 deletions

View file

@ -1,3 +1,11 @@
2006-02-20 Tim-Philipp Müller <tim at centricular dot net>
* gst/subparse/gstsubparse.c: (subrip_unescape_formatting),
(parse_subrip), (gst_sub_parse_format_autodetect):
Set right caps given that we send escaped text. Also,
honour <i></i>, <b></b> and <u></u> markers that can be found
in .srt files (fixes #310202).
2006-02-20 Tim-Philipp Müller <tim at centricular dot net> 2006-02-20 Tim-Philipp Müller <tim at centricular dot net>
* gst-libs/gst/audio/mixerutils.c: * gst-libs/gst/audio/mixerutils.c:

View file

@ -383,6 +383,44 @@ parse_mdvdsub (ParserState * state, const gchar * line)
return ret; return ret;
} }
/* we want to escape text in general, but retain basic markup like
* <i></i>, <u></u>, and <b></b>. The easiest and safest way is to
* just unescape a white list of allowed markups again after
* escaping everything (the text between these simple markers isn't
* necessarily escaped, so it seems best to do it like this) */
static void
subrip_unescape_formatting (gchar * txt)
{
gchar *pos;
for (pos = txt; pos != NULL && *pos != '\0'; ++pos) {
if (g_ascii_strncasecmp (pos, "&lt;u&gt;", 9) == 0 ||
g_ascii_strncasecmp (pos, "&lt;i&gt;", 9) == 0 ||
g_ascii_strncasecmp (pos, "&lt;b&gt;", 9) == 0) {
pos[0] = '<';
pos[1] = g_ascii_tolower (pos[4]);
pos[2] = '>';
/* move NUL terminator as well */
g_memmove (pos + 3, pos + 9, strlen (pos + 9) + 1);
pos += 2;
}
}
for (pos = txt; pos != NULL && *pos != '\0'; ++pos) {
if (g_ascii_strncasecmp (pos, "&lt;/u&gt;", 10) == 0 ||
g_ascii_strncasecmp (pos, "&lt;/i&gt;", 10) == 0 ||
g_ascii_strncasecmp (pos, "&lt;/b&gt;", 10) == 0) {
pos[0] = '<';
pos[1] = '/';
pos[2] = g_ascii_tolower (pos[5]);
pos[3] = '>';
/* move NUL terminator as well */
g_memmove (pos + 4, pos + 10, strlen (pos + 10) + 1);
pos += 3;
}
}
}
static gchar * static gchar *
parse_subrip (ParserState * state, const gchar * line) parse_subrip (ParserState * state, const gchar * line)
{ {
@ -440,6 +478,7 @@ parse_subrip (ParserState * state, const gchar * line)
ret = g_markup_escape_text (state->buf->str, state->buf->len); ret = g_markup_escape_text (state->buf->str, state->buf->len);
g_string_truncate (state->buf, 0); g_string_truncate (state->buf, 0);
state->state = 0; state->state = 0;
subrip_unescape_formatting (ret);
return ret; return ret;
} }
return NULL; return NULL;
@ -596,7 +635,7 @@ gst_sub_parse_format_autodetect (GstSubParse * self)
return gst_caps_new_simple ("text/x-pango-markup", NULL); return gst_caps_new_simple ("text/x-pango-markup", NULL);
case GST_SUB_PARSE_FORMAT_SUBRIP: case GST_SUB_PARSE_FORMAT_SUBRIP:
self->parse_line = parse_subrip; self->parse_line = parse_subrip;
return gst_caps_new_simple ("text/plain", NULL); return gst_caps_new_simple ("text/x-pango-markup", NULL);
case GST_SUB_PARSE_FORMAT_MPSUB: case GST_SUB_PARSE_FORMAT_MPSUB:
self->parse_line = parse_mpsub; self->parse_line = parse_mpsub;
return gst_caps_new_simple ("text/plain", NULL); return gst_caps_new_simple ("text/plain", NULL);