mirror of https://github.com/mpv-player/mpv
player: use arrays to list font mimetypes and font file extensions
This commit is contained in:
parent
fc583e74ec
commit
6878cf2832
|
@ -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)
|
static bool attachment_is_font(struct mp_log *log, struct demux_attachment *att)
|
||||||
{
|
{
|
||||||
if (!att->name || !att->type || !att->data || !att->data_size)
|
if (!att->name || !att->type || !att->data || !att->data_size)
|
||||||
return false;
|
return false;
|
||||||
// match against MIME types
|
for (int n = 0; font_mimetypes[n]; n++) {
|
||||||
if (strcmp(att->type, "application/x-truetype-font") == 0
|
if (strcmp(font_mimetypes[n], att->type) == 0)
|
||||||
|| strcmp(att->type, "application/x-font") == 0)
|
return true;
|
||||||
return true;
|
}
|
||||||
// fallback: match against file extension
|
// fallback: match against file extension
|
||||||
if (strlen(att->name) > 4) {
|
char *ext = strlen(att->name) > 4 ? att->name + strlen(att->name) - 4 : "";
|
||||||
char *ext = att->name + strlen(att->name) - 4;
|
for (int n = 0; font_exts[n]; n++) {
|
||||||
if (strcasecmp(ext, ".ttf") == 0 || strcasecmp(ext, ".ttc") == 0
|
if (strcasecmp(ext, font_exts[n]) == 0) {
|
||||||
|| strcasecmp(ext, ".otf") == 0)
|
|
||||||
{
|
|
||||||
mp_warn(log, "Loading font attachment '%s' with MIME type %s. "
|
mp_warn(log, "Loading font attachment '%s' with MIME type %s. "
|
||||||
"Assuming this is a broken Matroska file, which was "
|
"Assuming this is a broken Matroska file, which was "
|
||||||
"muxed without setting a correct font MIME type.\n",
|
"muxed without setting a correct font MIME type.\n",
|
||||||
|
|
Loading…
Reference in New Issue