summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-03 22:14:56 +0200
committerwm4 <wm4@nowhere>2013-06-03 22:40:07 +0200
commit8c63b318dc106f43d9ab17250452216bab485587 (patch)
tree0c4480c7c355fd0bdb371657718f62e16b1c5fe2 /sub
parent9f4261de65c18d3a34e70c9f969966ca85c80a8d (diff)
downloadmpv-8c63b318dc106f43d9ab17250452216bab485587.tar.bz2
mpv-8c63b318dc106f43d9ab17250452216bab485587.tar.xz
ass_mp: provide function to add default styles
Diffstat (limited to 'sub')
-rw-r--r--sub/ass_mp.c37
-rw-r--r--sub/ass_mp.h4
-rw-r--r--sub/osd_libass.c6
3 files changed, 30 insertions, 17 deletions
diff --git a/sub/ass_mp.c b/sub/ass_mp.c
index 85105a33ad..258dd57688 100644
--- a/sub/ass_mp.c
+++ b/sub/ass_mp.c
@@ -38,7 +38,9 @@
#include "stream/stream.h"
#include "core/options.h"
-void mp_ass_set_style(ASS_Style *style, struct osd_style_opts *opts)
+// res_y should be track->PlayResY
+// It determines scaling of font sizes and more.
+void mp_ass_set_style(ASS_Style *style, int res_y, struct osd_style_opts *opts)
{
if (opts->font) {
free(style->FontName);
@@ -46,9 +48,9 @@ void mp_ass_set_style(ASS_Style *style, struct osd_style_opts *opts)
style->treat_fontname_as_pattern = 1;
}
- // libass_font_size = FontSize * (window_height / MP_ASS_FONT_PLAYRESY)
- // scale translates parameters from PlayResY=720 to MP_ASS_FONT_PLAYRESY
- double scale = MP_ASS_FONT_PLAYRESY / 720.0;
+ // libass_font_size = FontSize * (window_height / res_y)
+ // scale translates parameters from PlayResY=720 to res_y
+ double scale = res_y / 720.0;
style->FontSize = opts->font_size * scale;
style->PrimaryColour = MP_ASS_COLOR(opts->color);
@@ -74,30 +76,39 @@ void mp_ass_set_style(ASS_Style *style, struct osd_style_opts *opts)
#endif
}
-ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts)
+// Add default styles, if the track does not have any styles yet.
+// Apply style overrides if the user provides any.
+void mp_ass_add_default_styles(ASS_Track *track, struct MPOpts *opts)
{
- ASS_Track *track = ass_new_track(library);
-
- track->track_type = TRACK_TYPE_ASS;
- track->Timer = 100.;
- track->PlayResY = MP_ASS_FONT_PLAYRESY;
- track->WrapStyle = 0;
-
if (opts->ass_styles_file && opts->ass_style_override)
ass_read_styles(track, opts->ass_styles_file, opts->sub_cp);
if (track->n_styles == 0) {
+ if (!track->PlayResY) {
+ track->PlayResY = MP_ASS_FONT_PLAYRESY;
+ track->PlayResX = track->PlayResY * 4 / 3;
+ }
track->Kerning = true;
int sid = ass_alloc_style(track);
track->default_style = sid;
ASS_Style *style = track->styles + sid;
style->Name = strdup("Default");
style->Alignment = 2;
- mp_ass_set_style(style, opts->sub_text_style);
+ mp_ass_set_style(style, track->PlayResY, opts->sub_text_style);
}
if (opts->ass_style_override)
ass_process_force_style(track);
+}
+
+ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts)
+{
+ ASS_Track *track = ass_new_track(library);
+
+ track->track_type = TRACK_TYPE_ASS;
+ track->Timer = 100.;
+
+ mp_ass_add_default_styles(track, opts);
return track;
}
diff --git a/sub/ass_mp.h b/sub/ass_mp.h
index 4b31a832a4..b6ec2808c0 100644
--- a/sub/ass_mp.h
+++ b/sub/ass_mp.h
@@ -44,7 +44,9 @@ struct MPOpts;
struct mp_osd_res;
struct osd_style_opts;
-void mp_ass_set_style(ASS_Style *style, struct osd_style_opts *opts);
+void mp_ass_set_style(ASS_Style *style, int res_y, struct osd_style_opts *opts);
+
+void mp_ass_add_default_styles(ASS_Track *track, struct MPOpts *opts);
ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts);
ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname,
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index 6733b9b6c2..cbf9466780 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -89,7 +89,7 @@ static void create_osd_ass_track(struct osd_state *osd, struct osd_object *obj)
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);
+ mp_ass_set_style(style, MP_ASS_FONT_PLAYRESY, osd->opts->osd_style);
// Set to neutral base direction, as opposed to VSFilter LTR default
style->Encoding = -1;
}
@@ -158,7 +158,7 @@ static void update_osd(struct osd_state *osd, struct osd_object *obj)
font.font_size *= opts->osd_scale;
ASS_Style *style = obj->osd_track->styles + obj->osd_track->default_style;
- mp_ass_set_style(style, &font);
+ mp_ass_set_style(style, obj->osd_track->PlayResY, &font);
char *text = mangle_ass(osd->osd_text);
add_osd_ass_event(obj->osd_track, text);
@@ -364,7 +364,7 @@ static void update_sub(struct osd_state *osd, struct osd_object *obj)
font.font_size *= opts->sub_scale;
ASS_Style *style = obj->osd_track->styles + obj->osd_track->default_style;
- mp_ass_set_style(style, &font);
+ mp_ass_set_style(style, obj->osd_track->PlayResY, &font);
#if LIBASS_VERSION >= 0x01010000
ass_set_line_position(osd->osd_render, 100 - opts->sub_pos);