+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>
* gst-libs/gst/audio/mixerutils.c:
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, "<u>", 9) == 0 ||
+ g_ascii_strncasecmp (pos, "<i>", 9) == 0 ||
+ g_ascii_strncasecmp (pos, "<b>", 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, "</u>", 10) == 0 ||
+ g_ascii_strncasecmp (pos, "</i>", 10) == 0 ||
+ g_ascii_strncasecmp (pos, "</b>", 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 *
parse_subrip (ParserState * state, const gchar * line)
{
ret = g_markup_escape_text (state->buf->str, state->buf->len);
g_string_truncate (state->buf, 0);
state->state = 0;
+ subrip_unescape_formatting (ret);
return ret;
}
return NULL;
return gst_caps_new_simple ("text/x-pango-markup", NULL);
case GST_SUB_PARSE_FORMAT_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:
self->parse_line = parse_mpsub;
return gst_caps_new_simple ("text/plain", NULL);