diff --git a/DOCS/interface-changes/sub-border-style.txt b/DOCS/interface-changes/sub-border-style.txt new file mode 100644 index 0000000000..649403c2f3 --- /dev/null +++ b/DOCS/interface-changes/sub-border-style.txt @@ -0,0 +1,6 @@ +add `--sub-border-style` and `--osd-border-style` options +the border style does not depend on `--(sub/osd)-border-color` and `--(sub/osd)-shadow-color`; now it depends solely on `--(sub/osd)-border-style` +make `--(sub/osd)-border-color` an alias of `--(sub/osd)-outline-color` +make `--(sub/osd)-border-size` an alias of `--(sub/osd)-outline-size` +make `--(sub/osd)-shadow-color` an alias of `--(sub/osd)-back-color`; they cannot both be set now +make `--osd-bar-border-size` an alias of `--osd-bar-outline-size` diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index b9964c74fe..7a39be15f5 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2832,10 +2832,6 @@ Subtitles Default: 55. -``--sub-back-color=`` - See ``--sub-color``. Color used for sub text background. You can use - ``--sub-shadow-offset`` to change its size relative to the text. - ``--sub-blur=<0..20.0>`` Gaussian blur factor applied to the sub font border. 0 means no blur applied (default). @@ -2846,15 +2842,48 @@ Subtitles ``--sub-italic=`` Format text on italic. -``--sub-border-color=`` - See ``--sub-color``. Color used for the sub font border. +``--sub-outline-color=`` + See ``--sub-color``. Color used for the sub font outline. -``--sub-border-size=`` - Size of the sub font border in scaled pixels (see ``--sub-font-size`` - for details). A value of 0 disables borders. + ``--sub-border-color`` is an alias for ``--sub-outline-color``. + +``--sub-back-color=`` + See ``--sub-color``. Color used for sub text background. + + ``--sub-shadow-color`` is an alias for ``--sub-back-color``. + +``--sub-outline-size=`` + Size of the sub font outline in scaled pixels (see ``--sub-font-size`` + for details). A value of 0 disables outlines. + + ``--sub-border-size`` is an alias for ``--sub-outline-size``. Default: 3. +``--sub-border-style=`` + The style of the border. + + - ``outline-and-shadow``: draw outline and shadow. + The size of the outline is determined by ``--sub-outline-size``, + and the offset of the shadow is determined by ``--sub-shadow-offset``. + The outline is colored by ``--sub-outline-color``, + and the shadow is colored by ``--sub-back-color``. + This corresponds to ``BorderStyle=1`` in the ASS spec. + - ``opaque-box``: draw outline and shadow as opaque boxes that tightly wrap each lines of text. + The margin of the outline opaque box is determined by ``--sub-outline-size``, + and the offset of the shadow opaque box is determined by ``--sub-shadow-offset``. + The outline opaque box is colored by ``--sub-outline-color``, + and the shadow opaque box is colored by ``--sub-back-color``. + Despite its name, the opaque box can be semi-transparent. + This corresponds to ``BorderStyle=3`` in the ASS spec. + - ``background-box``: draw a background box that bounds all lines of text. + The background box is colored by ``--sub-back-color``, + and the margin of the background box is determined by ``--sub-shadow-offset``. + The behavior of the outline is the same as the ``outline-and-shadow`` style. + This corresponds to ``BorderStyle=4``, which is a libass-specific extension. + + Default: ``outline-and-shadow``. + ``--sub-color=`` Specify the color used for unstyled text subtitles. @@ -2924,15 +2953,6 @@ Subtitles if ``--sub-ass-override`` is not set to ``no``. Default: ``no``. -``--sub-shadow-color=`` - See ``--sub-color``. Color used for sub text shadow. - - .. note:: - - ignored when ``--sub-back-color`` is - specified (or more exactly: when that option is not set to completely - transparent). - ``--sub-shadow-offset=`` Displacement of the sub text shadow in scaled pixels (see ``--sub-font-size`` for details). A value of 0 disables shadows. @@ -4411,14 +4431,13 @@ OSD ``--osd-bar-h=<0.1-50>`` Height of the OSD bar, in percentage of the screen height (default: 3.125). -``--osd-bar-border-size=`` - Size of the border of the OSD bar in scaled pixels (see ``--sub-font-size`` +``--osd-bar-outline-size=`` + Size of the outline of the OSD bar in scaled pixels (see ``--sub-font-size`` for details). - Default: 0.5. + ``--osd-bar-border-size`` is an alias for ``--osd-bar-outline-size``. -``--osd-back-color=`` - See ``--sub-color``. Color used for OSD text background. + Default: 0.5. ``--osd-blur=<0..20.0>`` Gaussian blur factor applied to the OSD font border. @@ -4430,15 +4449,27 @@ OSD ``--osd-italic=`` Format text on italic. -``--osd-border-color=`` - See ``--sub-color``. Color used for the OSD font border. +``--osd-outline-color=`` + See ``--sub-color``. Color used for the OSD font outline. -``--osd-border-size=`` - Size of the OSD font border in scaled pixels (see ``--sub-font-size`` - for details). A value of 0 disables borders. + ``--osd-border-color`` is an alias for ``--osd-outline-color``. + +``--osd-back-color=`` + See ``--sub-color``. Color used for OSD text background. + + ``--osd-shadow-color`` is an alias for ``--osd-back-color``. + +``--osd-outline-size=`` + Size of the OSD font outline in scaled pixels (see ``--sub-font-size`` + for details). A value of 0 disables outlines. + + ``--osd-border-size`` is an alias for ``--osd-outline-size``. Default: 3. +``--osd-border-style=`` + See ``--sub-border-style``. Style used for OSD text border. + ``--osd-color=`` Specify the color used for OSD. See ``--sub-color`` for details. @@ -4495,14 +4526,6 @@ OSD respect the value of this option when deciding whether the elements are scaled with window size or not. -``--osd-shadow-color=`` - See ``--sub-color``. Color used for OSD shadow. - - .. note:: - - Ignored when ``--osd-back-color`` is specified (or more exactly: when - that option is not set to completely transparent). - ``--osd-shadow-offset=`` Displacement of the OSD shadow in scaled pixels (see ``--sub-font-size`` for details). A value of 0 disables shadows. diff --git a/options/options.c b/options/options.c index b0987a414f..50e2d2d396 100644 --- a/options/options.c +++ b/options/options.c @@ -398,7 +398,8 @@ const struct m_sub_options mp_osd_render_sub_opts = { {"osd-bar-align-y", OPT_FLOAT(osd_bar_align_y), M_RANGE(-1.0, +1.0)}, {"osd-bar-w", OPT_FLOAT(osd_bar_w), M_RANGE(1, 100)}, {"osd-bar-h", OPT_FLOAT(osd_bar_h), M_RANGE(0.1, 50)}, - {"osd-bar-border-size", OPT_FLOAT(osd_bar_border_size), M_RANGE(0, 1000.0)}, + {"osd-bar-outline-size", OPT_FLOAT(osd_bar_outline_size), M_RANGE(0, 1000.0)}, + {"osd-bar-border-size", OPT_ALIAS("osd-bar-outline-size")}, {"osd", OPT_SUBSTRUCT(osd_style, osd_style_conf)}, {"osd-scale", OPT_FLOAT(osd_scale), M_RANGE(0, 100)}, {"osd-scale-by-window", OPT_BOOL(osd_scale_by_window)}, @@ -410,7 +411,7 @@ const struct m_sub_options mp_osd_render_sub_opts = { .osd_bar_align_y = 0.5, .osd_bar_w = 75.0, .osd_bar_h = 3.125, - .osd_bar_border_size = 0.5, + .osd_bar_outline_size = 0.5, .osd_scale = 1, .osd_scale_by_window = true, }, diff --git a/options/options.h b/options/options.h index 3356eac28b..e1fe9c5cfb 100644 --- a/options/options.h +++ b/options/options.h @@ -143,7 +143,7 @@ struct mp_osd_render_opts { float osd_bar_align_y; float osd_bar_w; float osd_bar_h; - float osd_bar_border_size; + float osd_bar_outline_size; float osd_scale; bool osd_scale_by_window; struct osd_style_opts *osd_style; diff --git a/player/lua/console.lua b/player/lua/console.lua index 9ca51f51e3..90c8e28150 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -514,7 +514,7 @@ local function update() local clipping_coordinates = '0,' .. coordinate_top .. ',' .. screenx .. ',' .. screeny local ass = assdraw.ass_new() - local has_shadow = mp.get_property('osd-back-color'):sub(2, 3) == '00' + local has_shadow = mp.get_property('osd-border-style'):find('box$') == nil local style = '{\\r' .. '\\1a&H00&\\3a&H00&\\1c&Heeeeee&\\3c&H111111&' .. (has_shadow and '\\4a&H99&\\4c&H000000&' or '') .. diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 579fd7788d..255d0a077f 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -62,15 +62,10 @@ void mp_ass_set_style(ASS_Style *style, double res_y, style->FontSize = opts->font_size * scale; style->PrimaryColour = MP_ASS_COLOR(opts->color); style->SecondaryColour = style->PrimaryColour; - style->OutlineColour = MP_ASS_COLOR(opts->border_color); - if (opts->back_color.a) { - style->BackColour = MP_ASS_COLOR(opts->back_color); - style->BorderStyle = 4; // opaque box - } else { - style->BackColour = MP_ASS_COLOR(opts->shadow_color); - style->BorderStyle = 1; // outline - } - style->Outline = opts->border_size * scale; + style->OutlineColour = MP_ASS_COLOR(opts->outline_color); + style->BackColour = MP_ASS_COLOR(opts->back_color); + style->BorderStyle = opts->border_style; + style->Outline = opts->outline_size * scale; style->Shadow = opts->shadow_offset * scale; style->Spacing = opts->spacing * scale; style->MarginL = opts->margin_x * scale; diff --git a/sub/osd.c b/sub/osd.c index 58cc859a94..e2f3dddd81 100644 --- a/sub/osd.c +++ b/sub/osd.c @@ -48,10 +48,14 @@ static const m_option_t style_opts[] = { {"font", OPT_STRING(font)}, {"font-size", OPT_FLOAT(font_size), M_RANGE(1, 9000)}, {"color", OPT_COLOR(color)}, - {"border-color", OPT_COLOR(border_color)}, - {"shadow-color", OPT_COLOR(shadow_color)}, + {"outline-color", OPT_COLOR(outline_color)}, {"back-color", OPT_COLOR(back_color)}, - {"border-size", OPT_FLOAT(border_size)}, + {"outline-size", OPT_FLOAT(outline_size)}, + {"border-color", OPT_ALIAS("outline-color"), .alias_use_prefix = true}, + {"shadow-color", OPT_ALIAS("back-color"), .alias_use_prefix = true}, + {"border-style", OPT_CHOICE(border_style, + {"outline-and-shadow", 1}, {"opaque-box", 3}, {"background-box", 4})}, + {"border-size", OPT_ALIAS("outline-size"), .alias_use_prefix = true}, {"shadow-offset", OPT_FLOAT(shadow_offset)}, {"spacing", OPT_FLOAT(spacing), M_RANGE(-10, 10)}, {"margin-x", OPT_INT(margin_x), M_RANGE(0, 300)}, @@ -79,9 +83,10 @@ const struct m_sub_options osd_style_conf = { .font = "sans-serif", .font_size = 55, .color = {255, 255, 255, 255}, - .border_color = {0, 0, 0, 255}, - .shadow_color = {240, 240, 240, 128}, - .border_size = 3, + .outline_color = {0, 0, 0, 255}, + .back_color = {240, 240, 240, 128}, + .border_style = 1, + .outline_size = 3, .shadow_offset = 0, .margin_x = 25, .margin_y = 22, @@ -98,9 +103,10 @@ const struct m_sub_options sub_style_conf = { .font = "sans-serif", .font_size = 55, .color = {255, 255, 255, 255}, - .border_color = {0, 0, 0, 255}, - .shadow_color = {240, 240, 240, 128}, - .border_size = 3, + .outline_color = {0, 0, 0, 255}, + .back_color = {240, 240, 240, 128}, + .border_style = 1, + .outline_size = 3, .shadow_offset = 0, .margin_x = 25, .margin_y = 22, diff --git a/sub/osd.h b/sub/osd.h index bb3cbb378d..9f88fcc2de 100644 --- a/sub/osd.h +++ b/sub/osd.h @@ -145,10 +145,10 @@ struct osd_style_opts { char *font; float font_size; struct m_color color; - struct m_color border_color; - struct m_color shadow_color; + struct m_color outline_color; struct m_color back_color; - float border_size; + int border_style; + float outline_size; float shadow_offset; float spacing; int margin_x; diff --git a/sub/osd_libass.c b/sub/osd_libass.c index f2de27bd64..45da2b0b3c 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -375,18 +375,15 @@ static void get_osd_bar_box(struct osd_state *osd, struct osd_object *obj, mp_ass_set_style(style, track->PlayResY, opts->osd_style); - if (osd->opts->osd_style->back_color.a) { - // override the default osd opaque-box into plain outline. Otherwise - // the opaque box is not aligned with the bar (even without shadow), - // and each bar ass event gets its own opaque box - breaking the bar. - style->BackColour = MP_ASS_COLOR(opts->osd_style->shadow_color); - style->BorderStyle = 1; // outline - } + // override the default osd opaque-box into plain outline. Otherwise + // the opaque box is not aligned with the bar (even without shadow), + // and each bar ass event gets its own opaque box - breaking the bar. + style->BorderStyle = 1; // outline *o_w = track->PlayResX * (opts->osd_bar_w / 100.0); *o_h = track->PlayResY * (opts->osd_bar_h / 100.0); - style->Outline = opts->osd_bar_border_size; + style->Outline = opts->osd_bar_outline_size; // Rendering with shadow is broken (because there's more than one shape) style->Shadow = 0; @@ -428,7 +425,7 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj) struct ass_draw *d = &(struct ass_draw) { .scale = 4 }; - if (osd->opts->osd_style->back_color.a) { + if (osd->opts->osd_style->back_color.a && osd->opts->osd_style->border_style != 1) { // the bar style always ignores the --osd-back-color config - it messes // up the bar. draw an artificial box at the original back color. struct m_color bc = osd->opts->osd_style->back_color;