History

sub: add (sub/osd)-border-style; renaming sub options

Misaki Kasumi committed 2 years ago

Commit f2e71461 parent c0f5d239 files · +98 −70Browse files

Unified · Split

9 files
  1. DOCS/interface-changes/sub-border-style.txt +6 −0
  2. DOCS/man/options.rst +59 −36
  3. options/options.c +3 −2
  4. options/options.h +1 −1
  5. player/lua/console.lua +1 −1
  6. sub/ass_mp.c +4 −9
  7. sub/osd.c +15 −9
  8. sub/osd.h +3 −3
  9. sub/osd_libass.c +6 −9
DOCS/interface-changes/sub-border-style.txt+6−0
@@ -0,0 +1,6 @@
1+add `--sub-border-style` and `--osd-border-style` options
2+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`
3+make `--(sub/osd)-border-color` an alias of `--(sub/osd)-outline-color`
4+make `--(sub/osd)-border-size` an alias of `--(sub/osd)-outline-size`
5+make `--(sub/osd)-shadow-color` an alias of `--(sub/osd)-back-color`; they cannot both be set now
6+make `--osd-bar-border-size` an alias of `--osd-bar-outline-size`
DOCS/man/options.rst+59−36
@@ -2832,10 +2832,6 @@ Subtitles · 2831 unmodified lines
28322832
28332833 Default: 55.
28342834
2835−``--sub-back-color=<color>``
2836− See ``--sub-color``. Color used for sub text background. You can use
2837− ``--sub-shadow-offset`` to change its size relative to the text.
2838−
28392835 ``--sub-blur=<0..20.0>``
28402836 Gaussian blur factor applied to the sub font border.
28412837 0 means no blur applied (default).
@@ -2846,15 +2842,48 @@ Subtitles · 4 unmodified lines
28462842 ``--sub-italic=<yes|no>``
28472843 Format text on italic.
28482844
2849−``--sub-border-color=<color>``
2850− See ``--sub-color``. Color used for the sub font border.
2845+``--sub-outline-color=<color>``
2846+ See ``--sub-color``. Color used for the sub font outline.
2847+
2848+ ``--sub-border-color`` is an alias for ``--sub-outline-color``.
2849+
2850+``--sub-back-color=<color>``
2851+ See ``--sub-color``. Color used for sub text background.
2852+
2853+ ``--sub-shadow-color`` is an alias for ``--sub-back-color``.
2854+
2855+``--sub-outline-size=<size>``
2856+ Size of the sub font outline in scaled pixels (see ``--sub-font-size``
2857+ for details). A value of 0 disables outlines.
28512858
2852−``--sub-border-size=<size>``
2853− Size of the sub font border in scaled pixels (see ``--sub-font-size``
2854− for details). A value of 0 disables borders.
2859+ ``--sub-border-size`` is an alias for ``--sub-outline-size``.
28552860
28562861 Default: 3.
28572862
2863+``--sub-border-style=<outline-and-shadow|opaque-box|background-box>``
2864+ The style of the border.
2865+
2866+ - ``outline-and-shadow``: draw outline and shadow.
2867+ The size of the outline is determined by ``--sub-outline-size``,
2868+ and the offset of the shadow is determined by ``--sub-shadow-offset``.
2869+ The outline is colored by ``--sub-outline-color``,
2870+ and the shadow is colored by ``--sub-back-color``.
2871+ This corresponds to ``BorderStyle=1`` in the ASS spec.
2872+ - ``opaque-box``: draw outline and shadow as opaque boxes that tightly wrap each lines of text.
2873+ The margin of the outline opaque box is determined by ``--sub-outline-size``,
2874+ and the offset of the shadow opaque box is determined by ``--sub-shadow-offset``.
2875+ The outline opaque box is colored by ``--sub-outline-color``,
2876+ and the shadow opaque box is colored by ``--sub-back-color``.
2877+ Despite its name, the opaque box can be semi-transparent.
2878+ This corresponds to ``BorderStyle=3`` in the ASS spec.
2879+ - ``background-box``: draw a background box that bounds all lines of text.
2880+ The background box is colored by ``--sub-back-color``,
2881+ and the margin of the background box is determined by ``--sub-shadow-offset``.
2882+ The behavior of the outline is the same as the ``outline-and-shadow`` style.
2883+ This corresponds to ``BorderStyle=4``, which is a libass-specific extension.
2884+
2885+ Default: ``outline-and-shadow``.
2886+
28582887 ``--sub-color=<color>``
28592888 Specify the color used for unstyled text subtitles.
28602889
@@ -2924,15 +2953,6 @@ Subtitles · 63 unmodified lines
29242953 if ``--sub-ass-override`` is not set to ``no``.
29252954 Default: ``no``.
29262955
2927−``--sub-shadow-color=<color>``
2928− See ``--sub-color``. Color used for sub text shadow.
2929−
2930− .. note::
2931−
2932− ignored when ``--sub-back-color`` is
2933− specified (or more exactly: when that option is not set to completely
2934− transparent).
2935−
29362956 ``--sub-shadow-offset=<size>``
29372957 Displacement of the sub text shadow in scaled pixels (see
29382958 ``--sub-font-size`` for details). A value of 0 disables shadows.
@@ -4411,14 +4431,13 @@ OSD · 1472 unmodified lines
44114431 ``--osd-bar-h=<0.1-50>``
44124432 Height of the OSD bar, in percentage of the screen height (default: 3.125).
44134433
4414−``--osd-bar-border-size=<size>``
4415− Size of the border of the OSD bar in scaled pixels (see ``--sub-font-size``
4434+``--osd-bar-outline-size=<size>``
4435+ Size of the outline of the OSD bar in scaled pixels (see ``--sub-font-size``
44164436 for details).
44174437
4418− Default: 0.5.
4438+ ``--osd-bar-border-size`` is an alias for ``--osd-bar-outline-size``.
44194439
4420−``--osd-back-color=<color>``
4421− See ``--sub-color``. Color used for OSD text background.
4440+ Default: 0.5.
44224441
44234442 ``--osd-blur=<0..20.0>``
44244443 Gaussian blur factor applied to the OSD font border.
@@ -4430,15 +4449,27 @@ OSD · 5 unmodified lines
44304449 ``--osd-italic=<yes|no>``
44314450 Format text on italic.
44324451
4433−``--osd-border-color=<color>``
4434− See ``--sub-color``. Color used for the OSD font border.
4452+``--osd-outline-color=<color>``
4453+ See ``--sub-color``. Color used for the OSD font outline.
4454+
4455+ ``--osd-border-color`` is an alias for ``--osd-outline-color``.
4456+
4457+``--osd-back-color=<color>``
4458+ See ``--sub-color``. Color used for OSD text background.
4459+
4460+ ``--osd-shadow-color`` is an alias for ``--osd-back-color``.
44354461
4436−``--osd-border-size=<size>``
4437− Size of the OSD font border in scaled pixels (see ``--sub-font-size``
4438− for details). A value of 0 disables borders.
4462+``--osd-outline-size=<size>``
4463+ Size of the OSD font outline in scaled pixels (see ``--sub-font-size``
4464+ for details). A value of 0 disables outlines.
4465+
4466+ ``--osd-border-size`` is an alias for ``--osd-outline-size``.
44394467
44404468 Default: 3.
44414469
4470+``--osd-border-style=<outline-and-shadow|opaque-box|background-box>``
4471+ See ``--sub-border-style``. Style used for OSD text border.
4472+
44424473 ``--osd-color=<color>``
44434474 Specify the color used for OSD.
44444475 See ``--sub-color`` for details.
@@ -4495,14 +4526,6 @@ OSD · 50 unmodified lines
44954526 respect the value of this option when deciding whether the elements
44964527 are scaled with window size or not.
44974528
4498−``--osd-shadow-color=<color>``
4499− See ``--sub-color``. Color used for OSD shadow.
4500−
4501− .. note::
4502−
4503− Ignored when ``--osd-back-color`` is specified (or more exactly: when
4504− that option is not set to completely transparent).
4505−
45064529 ``--osd-shadow-offset=<size>``
45074530 Displacement of the OSD shadow in scaled pixels (see
45084531 ``--sub-font-size`` for details). A value of 0 disables shadows.
options/options.c+3−2
@@ -398,7 +398,8 @@ const struct m_sub_options mp_osd_render_sub_opts = { · 397 unmodified lines
398398 {"osd-bar-align-y", OPT_FLOAT(osd_bar_align_y), M_RANGE(-1.0, +1.0)},
399399 {"osd-bar-w", OPT_FLOAT(osd_bar_w), M_RANGE(1, 100)},
400400 {"osd-bar-h", OPT_FLOAT(osd_bar_h), M_RANGE(0.1, 50)},
401− {"osd-bar-border-size", OPT_FLOAT(osd_bar_border_size), M_RANGE(0, 1000.0)},
401+ {"osd-bar-outline-size", OPT_FLOAT(osd_bar_outline_size), M_RANGE(0, 1000.0)},
402+ {"osd-bar-border-size", OPT_ALIAS("osd-bar-outline-size")},
402403 {"osd", OPT_SUBSTRUCT(osd_style, osd_style_conf)},
403404 {"osd-scale", OPT_FLOAT(osd_scale), M_RANGE(0, 100)},
404405 {"osd-scale-by-window", OPT_BOOL(osd_scale_by_window)},
@@ -410,7 +411,7 @@ const struct m_sub_options mp_osd_render_sub_opts = { · 5 unmodified lines
410411 .osd_bar_align_y = 0.5,
411412 .osd_bar_w = 75.0,
412413 .osd_bar_h = 3.125,
413− .osd_bar_border_size = 0.5,
414+ .osd_bar_outline_size = 0.5,
414415 .osd_scale = 1,
415416 .osd_scale_by_window = true,
416417 },
options/options.h+1−1
@@ -143,7 +143,7 @@ struct mp_osd_render_opts { · 142 unmodified lines
143143 float osd_bar_align_y;
144144 float osd_bar_w;
145145 float osd_bar_h;
146− float osd_bar_border_size;
146+ float osd_bar_outline_size;
147147 float osd_scale;
148148 bool osd_scale_by_window;
149149 struct osd_style_opts *osd_style;
player/lua/console.lua+1−1
@@ -514,7 +514,7 @@ local function update() · 513 unmodified lines
514514 local clipping_coordinates = '0,' .. coordinate_top .. ',' ..
515515 screenx .. ',' .. screeny
516516 local ass = assdraw.ass_new()
517− local has_shadow = mp.get_property('osd-back-color'):sub(2, 3) == '00'
517+ local has_shadow = mp.get_property('osd-border-style'):find('box$') == nil
518518 local style = '{\\r' ..
519519 '\\1a&H00&\\3a&H00&\\1c&Heeeeee&\\3c&H111111&' ..
520520 (has_shadow and '\\4a&H99&\\4c&H000000&' or '') ..
sub/ass_mp.c+4−9
@@ -62,15 +62,10 @@ void mp_ass_set_style(ASS_Style *style, double res_y, · 61 unmodified lines
6262 style->FontSize = opts->font_size * scale;
6363 style->PrimaryColour = MP_ASS_COLOR(opts->color);
6464 style->SecondaryColour = style->PrimaryColour;
65− style->OutlineColour = MP_ASS_COLOR(opts->border_color);
66− if (opts->back_color.a) {
67− style->BackColour = MP_ASS_COLOR(opts->back_color);
68− style->BorderStyle = 4; // opaque box
69− } else {
70− style->BackColour = MP_ASS_COLOR(opts->shadow_color);
71− style->BorderStyle = 1; // outline
72− }
73− style->Outline = opts->border_size * scale;
65+ style->OutlineColour = MP_ASS_COLOR(opts->outline_color);
66+ style->BackColour = MP_ASS_COLOR(opts->back_color);
67+ style->BorderStyle = opts->border_style;
68+ style->Outline = opts->outline_size * scale;
7469 style->Shadow = opts->shadow_offset * scale;
7570 style->Spacing = opts->spacing * scale;
7671 style->MarginL = opts->margin_x * scale;
sub/osd.c+15−9
@@ -48,10 +48,14 @@ static const m_option_t style_opts[] = { · 47 unmodified lines
4848 {"font", OPT_STRING(font)},
4949 {"font-size", OPT_FLOAT(font_size), M_RANGE(1, 9000)},
5050 {"color", OPT_COLOR(color)},
51− {"border-color", OPT_COLOR(border_color)},
52− {"shadow-color", OPT_COLOR(shadow_color)},
51+ {"outline-color", OPT_COLOR(outline_color)},
5352 {"back-color", OPT_COLOR(back_color)},
54− {"border-size", OPT_FLOAT(border_size)},
53+ {"outline-size", OPT_FLOAT(outline_size)},
54+ {"border-color", OPT_ALIAS("outline-color"), .alias_use_prefix = true},
55+ {"shadow-color", OPT_ALIAS("back-color"), .alias_use_prefix = true},
56+ {"border-style", OPT_CHOICE(border_style,
57+ {"outline-and-shadow", 1}, {"opaque-box", 3}, {"background-box", 4})},
58+ {"border-size", OPT_ALIAS("outline-size"), .alias_use_prefix = true},
5559 {"shadow-offset", OPT_FLOAT(shadow_offset)},
5660 {"spacing", OPT_FLOAT(spacing), M_RANGE(-10, 10)},
5761 {"margin-x", OPT_INT(margin_x), M_RANGE(0, 300)},
@@ -79,9 +83,10 @@ const struct m_sub_options osd_style_conf = { · 21 unmodified lines
7983 .font = "sans-serif",
8084 .font_size = 55,
8185 .color = {255, 255, 255, 255},
82− .border_color = {0, 0, 0, 255},
83− .shadow_color = {240, 240, 240, 128},
84− .border_size = 3,
86+ .outline_color = {0, 0, 0, 255},
87+ .back_color = {240, 240, 240, 128},
88+ .border_style = 1,
89+ .outline_size = 3,
8590 .shadow_offset = 0,
8691 .margin_x = 25,
8792 .margin_y = 22,
@@ -98,9 +103,10 @@ const struct m_sub_options sub_style_conf = { · 10 unmodified lines
98103 .font = "sans-serif",
99104 .font_size = 55,
100105 .color = {255, 255, 255, 255},
101− .border_color = {0, 0, 0, 255},
102− .shadow_color = {240, 240, 240, 128},
103− .border_size = 3,
106+ .outline_color = {0, 0, 0, 255},
107+ .back_color = {240, 240, 240, 128},
108+ .border_style = 1,
109+ .outline_size = 3,
104110 .shadow_offset = 0,
105111 .margin_x = 25,
106112 .margin_y = 22,
sub/osd.h+3−3
@@ -145,10 +145,10 @@ struct osd_style_opts { · 144 unmodified lines
145145 char *font;
146146 float font_size;
147147 struct m_color color;
148− struct m_color border_color;
149− struct m_color shadow_color;
148+ struct m_color outline_color;
150149 struct m_color back_color;
151− float border_size;
150+ int border_style;
151+ float outline_size;
152152 float shadow_offset;
153153 float spacing;
154154 int margin_x;
sub/osd_libass.c+6−9
@@ -375,18 +375,15 @@ static void get_osd_bar_box(struct osd_state *osd, struct osd_object *obj, · 374 unmodified lines
375375
376376 mp_ass_set_style(style, track->PlayResY, opts->osd_style);
377377
378− if (osd->opts->osd_style->back_color.a) {
379− // override the default osd opaque-box into plain outline. Otherwise
380− // the opaque box is not aligned with the bar (even without shadow),
381− // and each bar ass event gets its own opaque box - breaking the bar.
382− style->BackColour = MP_ASS_COLOR(opts->osd_style->shadow_color);
383− style->BorderStyle = 1; // outline
384− }
378+ // override the default osd opaque-box into plain outline. Otherwise
379+ // the opaque box is not aligned with the bar (even without shadow),
380+ // and each bar ass event gets its own opaque box - breaking the bar.
381+ style->BorderStyle = 1; // outline
385382
386383 *o_w = track->PlayResX * (opts->osd_bar_w / 100.0);
387384 *o_h = track->PlayResY * (opts->osd_bar_h / 100.0);
388385
389− style->Outline = opts->osd_bar_border_size;
386+ style->Outline = opts->osd_bar_outline_size;
390387 // Rendering with shadow is broken (because there's more than one shape)
391388 style->Shadow = 0;
392389
@@ -428,7 +425,7 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj) · 35 unmodified lines
428425
429426 struct ass_draw *d = &(struct ass_draw) { .scale = 4 };
430427
431− if (osd->opts->osd_style->back_color.a) {
428+ if (osd->opts->osd_style->back_color.a && osd->opts->osd_style->border_style != 1) {
432429 // the bar style always ignores the --osd-back-color config - it messes
433430 // up the bar. draw an artificial box at the original back color.
434431 struct m_color bc = osd->opts->osd_style->back_color;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t