summaryrefslogtreecommitdiffstats
path: root/sub/osd_libass.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-17 20:56:45 +0100
committerwm4 <wm4@nowhere>2012-11-20 18:00:15 +0100
commit80270218cb9bda57afbb739fa22f7eb2f3a556ff (patch)
tree9e38c23238ef01e7f8d71e8adf99674e3044148e /sub/osd_libass.c
parentd23b620a89e88b0ec0d6a66c7f05c2e461579647 (diff)
downloadmpv-80270218cb9bda57afbb739fa22f7eb2f3a556ff.tar.bz2
mpv-80270218cb9bda57afbb739fa22f7eb2f3a556ff.tar.xz
osd: make the OSD and sub font more customizable
Make more aspects of the OSD font customizable. This also affects the font used for unstyled subtitles (such as SRT), or when using the --no-ass option. This adds back some customizability that was lost with commit 74e7a1 (osd: use libass for OSD rendering). Removed options: --ass-border-color --ass-color --font --subfont --subfont-text-scale Added options: --osd-color --osd-border --osd-back-color --osd-shadow-color --osd-font --osd-font-size --osd-border-size --osd-margin-x --osd-margin-y --osd-shadow-offset --osd-spacing --sub-scale The font size is now specified in pixels as it would be rendered on a window with a height of 720 pixels. OSD and subtitles are always scaled with the window height, so specifying or expecting an absolute font size doesn't make sense. Such scaled pixel units are used to specify font border etc. as well. (Note: the font size is directly passed to libass. How the fonts are actually rasterized is outside of our control, but in theory ASS font sizes map to "script" pixels and then are scaled to screen size.) The default settings should be about the same, with slight difference due to rounding to the new scales. The OSD and subtitle fonts are not separately configurable. It has limited use and would double the number of newly added options, which would be more confusing than helpful. It could be easily added later, should the need arise. Other small details that change: - ASS_Style.Encoding is not set to -1 for subs anymore (assuming subs use VSFilter direction in -no-ass mode too) - use a different WrapStyle for OSD - ASS forced styles are not applied to OSD
Diffstat (limited to 'sub/osd_libass.c')
-rw-r--r--sub/osd_libass.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index 8e7d766024..749b46d6ae 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -46,7 +46,7 @@ void osd_init_backend(struct osd_state *osd)
sizeof(osd_font_pfb) - 1);
osd->osd_render = ass_renderer_init(osd->osd_ass_library);
- mp_ass_configure_fonts(osd->osd_render);
+ mp_ass_configure_fonts(osd->osd_render, osd->opts->osd_style);
ass_set_aspect_ratio(osd->osd_render, 1.0, 1.0);
}
@@ -59,30 +59,27 @@ void osd_destroy_backend(struct osd_state *osd)
osd->osd_ass_library = NULL;
}
-static void update_font_style(ASS_Track *track, ASS_Style *style, double factor)
-{
- // Set to neutral base direction, as opposed to VSFilter LTR default
- style->Encoding = -1;
-
- // duplicated from ass_mp.c
- style->FontSize = track->PlayResY * factor / 100.;
- style->Outline = style->FontSize / 16;
-}
-
-
static ASS_Track *create_osd_ass_track(struct osd_state *osd)
{
- ASS_Track *track = mp_ass_default_track(osd->osd_ass_library, osd->opts);
- ASS_Style *style = track->styles + track->default_style;
+ ASS_Track *track = ass_new_track(osd->osd_ass_library);
+ track->track_type = TRACK_TYPE_ASS;
+ track->Timer = 100.;
+ track->PlayResY = MP_ASS_FONT_PLAYRESY;
track->PlayResX = track->PlayResY * 1.33333;
-
- update_font_style(track, style, text_font_scale_factor);
-
- style->Alignment = 5;
-
- free(style->FontName);
- style->FontName = strdup(font_name ? font_name : "Sans");
+ track->WrapStyle = 1; // end-of-line wrapping instead of smart wrapping
+
+ if (track->n_styles == 0) {
+ track->Kerning = true;
+ 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, osd->opts->osd_style);
+ // Set to neutral base direction, as opposed to VSFilter LTR default
+ style->Encoding = -1;
+ }
return track;
}
@@ -172,7 +169,7 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj)
ASS_Style *style = obj->osd_track->styles + obj->osd_track->default_style;
- style->Alignment = 10;
+ style->Alignment = 10; // all centered
style->MarginL = style->MarginR = style->MarginV = 0;
// We need a fixed font size with respect to the OSD width.
@@ -226,9 +223,12 @@ static void update_sub(struct osd_state *osd, struct osd_object *obj)
if (!obj->osd_track)
obj->osd_track = mp_ass_default_track(osd->osd_ass_library, osd->opts);
+ struct osd_style_opts font = *opts->osd_style;
+ font.font_size *= opts->sub_scale;
+
ASS_Style *style = obj->osd_track->styles + obj->osd_track->default_style;
+ mp_ass_set_style(style, &font);
- update_font_style(obj->osd_track, style, text_font_scale_factor);
#if LIBASS_VERSION >= 0x01010000
ass_set_line_position(osd->osd_render, 100 - sub_pos);
#endif