osd_libass: update styles when OSD changes PlayRes
The OSD style settings depend on the PlayRes, simply because all style values are implicitly scaled by the PlayResY in libass. Also, the OSC changes the PlayResY in certain situations, so something could go wrong. But not sure if this actually matters in practice.
This commit is contained in:
1 parent
78b5324eee
commit
6dcebd9130
2 files changed
+15
-8
No files matched your search
+5
-3
@@ -43,9 +43,11 @@ void mp_ass_set_style(ASS_Style *style, double res_y,
|
||||
const struct osd_style_opts *opts)
|
||||
{
|
||||
if (opts->font) {
|
||||
free(style->FontName);
|
||||
style->FontName = strdup(opts->font);
|
||||
style->treat_fontname_as_pattern = 1;
|
||||
if (!style->FontName || strcmp(style->FontName, opts->font) != 0) {
|
||||
free(style->FontName);
|
||||
style->FontName = strdup(opts->font);
|
||||
style->treat_fontname_as_pattern = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// libass_font_size = FontSize * (window_height / res_y)
|
||||
|
||||
+10
-5
@@ -96,31 +96,36 @@ static void create_ass_track(struct osd_state *osd, struct osd_object *obj,
|
||||
track->PlayResY = res_y ? res_y : MP_ASS_FONT_PLAYRESY;
|
||||
track->PlayResX = res_x ? res_x : track->PlayResY * aspect;
|
||||
track->WrapStyle = 1; // end-of-line wrapping instead of smart wrapping
|
||||
track->Kerning = true;
|
||||
|
||||
// Force libass to clear its internal cache - it doesn't check for
|
||||
// PlayRes changes itself.
|
||||
if (old_res_x != track->PlayResX || old_res_y != track->PlayResY)
|
||||
ass_set_frame_size(obj->osd_render, 1, 1);
|
||||
|
||||
if (track->n_styles == 0) {
|
||||
track->Kerning = true;
|
||||
if (track->n_styles < 2) {
|
||||
int sid = ass_alloc_style(track);
|
||||
track->default_style = sid;
|
||||
ASS_Style *style = track->styles + sid;
|
||||
style->Alignment = 5; // top-title, left
|
||||
style->Name = strdup("OSD");
|
||||
mp_ass_set_style(style, track->PlayResY, osd->opts->osd_style);
|
||||
// Set to neutral base direction, as opposed to VSFilter LTR default
|
||||
style->Encoding = -1;
|
||||
|
||||
sid = ass_alloc_style(track);
|
||||
assert(sid == track->default_style + 1);
|
||||
style = track->styles + sid;
|
||||
style->Name = strdup("Default");
|
||||
const struct osd_style_opts *def = osd_style_conf.defaults;
|
||||
mp_ass_set_style(style, track->PlayResY, def);
|
||||
style->Encoding = -1;
|
||||
}
|
||||
|
||||
ASS_Style *s_osd = track->styles + track->default_style;
|
||||
mp_ass_set_style(s_osd, track->PlayResY, osd->opts->osd_style);
|
||||
|
||||
ASS_Style *s_def = track->styles + track->default_style + 1;
|
||||
const struct osd_style_opts *def = osd_style_conf.defaults;
|
||||
mp_ass_set_style(s_def, track->PlayResY, def);
|
||||
|
||||
obj->osd_track = track;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user