From 6878cf283292fe5962ed3ff53fc25ae16de8a8fc Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 29 Dec 2013 13:45:41 +0100 Subject: player: use arrays to list font mimetypes and font file extensions --- player/loadfile.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/player/loadfile.c b/player/loadfile.c index 64db70687b..f527cb852d 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -843,20 +843,26 @@ static void open_subtitles_from_resolve(struct MPContext *mpctx) } } +static const char *font_mimetypes[] = { + "application/x-truetype-font", + "application/x-font", + NULL +}; + +static const char *font_exts[] = {".ttf", ".ttc", ".otf", NULL}; + static bool attachment_is_font(struct mp_log *log, struct demux_attachment *att) { if (!att->name || !att->type || !att->data || !att->data_size) return false; - // match against MIME types - if (strcmp(att->type, "application/x-truetype-font") == 0 - || strcmp(att->type, "application/x-font") == 0) - return true; + for (int n = 0; font_mimetypes[n]; n++) { + if (strcmp(font_mimetypes[n], att->type) == 0) + return true; + } // fallback: match against file extension - if (strlen(att->name) > 4) { - char *ext = att->name + strlen(att->name) - 4; - if (strcasecmp(ext, ".ttf") == 0 || strcasecmp(ext, ".ttc") == 0 - || strcasecmp(ext, ".otf") == 0) - { + char *ext = strlen(att->name) > 4 ? att->name + strlen(att->name) - 4 : ""; + for (int n = 0; font_exts[n]; n++) { + if (strcasecmp(ext, font_exts[n]) == 0) { mp_warn(log, "Loading font attachment '%s' with MIME type %s. " "Assuming this is a broken Matroska file, which was " "muxed without setting a correct font MIME type.\n", -- cgit v1.2.3