mirror of
https://github.com/mpv-player/mpv
synced 2024-11-18 21:16:10 +01:00
libass: match font attachments based on extension
Instead of only relying on the MIME type, use the file extension as a fallback for deciding which attachments are fonts and should be fed to libass. This also refactors the check into a separate function in mpcommon.
This commit is contained in:
parent
2fcd4cf73e
commit
b784346e78
@ -1060,10 +1060,7 @@ default: {
|
|||||||
if (ass_library) {
|
if (ass_library) {
|
||||||
for (i = 0; i < demuxer->num_attachments; ++i) {
|
for (i = 0; i < demuxer->num_attachments; ++i) {
|
||||||
demux_attachment_t* att = demuxer->attachments + i;
|
demux_attachment_t* att = demuxer->attachments + i;
|
||||||
if (use_embedded_fonts &&
|
if (use_embedded_fonts && attachment_is_font(att))
|
||||||
att->name && att->type && att->data && att->data_size &&
|
|
||||||
(strcmp(att->type, "application/x-truetype-font") == 0 ||
|
|
||||||
strcmp(att->type, "application/x-font") == 0))
|
|
||||||
ass_add_font(ass_library, att->name, att->data, att->data_size);
|
ass_add_font(ass_library, att->name, att->data, att->data_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
mpcommon.c
18
mpcommon.c
@ -297,6 +297,24 @@ int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang)
|
|||||||
return demuxer->audio->id;
|
return demuxer->audio->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool attachment_is_font(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;
|
||||||
|
// 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)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse -noconfig common to both programs */
|
/* Parse -noconfig common to both programs */
|
||||||
int disable_system_conf=0;
|
int disable_system_conf=0;
|
||||||
int disable_user_conf=0;
|
int disable_user_conf=0;
|
||||||
|
@ -35,6 +35,7 @@ void update_subtitles(struct MPContext *mpctx, struct MPOpts *opts,
|
|||||||
void update_teletext(sh_video_t *sh_video, demuxer_t *demuxer, int reset);
|
void update_teletext(sh_video_t *sh_video, demuxer_t *demuxer, int reset);
|
||||||
int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang);
|
int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang);
|
||||||
void set_osd_subtitle(struct MPContext *mpctx, subtitle *subs);
|
void set_osd_subtitle(struct MPContext *mpctx, subtitle *subs);
|
||||||
|
bool attachment_is_font(struct demux_attachment *att);
|
||||||
|
|
||||||
extern int disable_system_conf;
|
extern int disable_system_conf;
|
||||||
extern int disable_user_conf;
|
extern int disable_user_conf;
|
||||||
|
@ -3756,10 +3756,7 @@ if (opts->ass_enabled && ass_library) {
|
|||||||
struct demuxer *d = mpctx->sources[j].demuxer;
|
struct demuxer *d = mpctx->sources[j].demuxer;
|
||||||
for (int i = 0; i < d->num_attachments; i++) {
|
for (int i = 0; i < d->num_attachments; i++) {
|
||||||
struct demux_attachment *att = d->attachments + i;
|
struct demux_attachment *att = d->attachments + i;
|
||||||
if (use_embedded_fonts
|
if (use_embedded_fonts && attachment_is_font(att))
|
||||||
&& att->name && att->type && att->data && att->data_size
|
|
||||||
&& (strcmp(att->type, "application/x-truetype-font") == 0
|
|
||||||
|| strcmp(att->type, "application/x-font") == 0))
|
|
||||||
ass_add_font(ass_library, att->name, att->data, att->data_size);
|
ass_add_font(ass_library, att->name, att->data, att->data_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user