From d06e9c40e648a627b5b7c5b86c171bf84340530b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 7 Dec 2009 18:30:05 +0100 Subject: [PATCH] assrender: Improve embedded font usage For this add some new mimetypes and also check the filename extension. Fixes bug #603938. --- ext/assrender/gstassrender.c | 43 +++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/ext/assrender/gstassrender.c b/ext/assrender/gstassrender.c index f9ce67243d..65319e23d5 100644 --- a/ext/assrender/gstassrender.c +++ b/ext/assrender/gstassrender.c @@ -24,7 +24,7 @@ #include "gstassrender.h" -#include +#include GST_DEBUG_CATEGORY_STATIC (gst_ass_render_debug); GST_DEBUG_CATEGORY_STATIC (gst_ass_render_lib_debug); @@ -963,6 +963,15 @@ gst_ass_render_chain_text (GstPad * pad, GstBuffer * buffer) static void gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist) { + static const gchar *mimetypes[] = { + "application/x-font-ttf", + "application/x-font-otf", + "application/x-truetype-font" + }; + static const gchar *extensions[] = { + ".otf", + ".ttf" + }; guint tag_size; guint index; @@ -975,6 +984,9 @@ gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist) GstBuffer *buf; GstCaps *caps; GstStructure *structure; + gboolean valid_mimetype, valid_extension; + guint j; + const gchar *filename; GST_DEBUG_OBJECT (render, "TAG event has attachments"); @@ -986,11 +998,32 @@ gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist) caps = GST_BUFFER_CAPS (buf); structure = gst_caps_get_structure (caps, 0); - if (gst_structure_has_name (structure, "application/x-truetype-font") - && gst_structure_has_field (structure, "filename")) { - const gchar *filename; - filename = gst_structure_get_string (structure, "filename"); + valid_mimetype = FALSE; + valid_extension = FALSE; + + for (j = 0; j < G_N_ELEMENTS (mimetypes); j++) { + if (gst_structure_has_name (structure, mimetypes[j])) { + valid_mimetype = TRUE; + break; + } + } + filename = gst_structure_get_string (structure, "filename"); + if (!filename) + continue; + + if (!valid_mimetype) { + guint len = strlen (filename); + const gchar *extension = filename + len - 4; + for (j = 0; j < G_N_ELEMENTS (extensions); j++) { + if (g_ascii_strcasecmp (extension, extensions[j]) == 0) { + valid_extension = TRUE; + break; + } + } + } + + if (valid_mimetype || valid_extension) { ass_add_font (render->ass_library, (gchar *) filename, (gchar *) GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); GST_DEBUG_OBJECT (render, "registered new font %s", filename);