mirror of
https://github.com/mpv-player/mpv
synced 2025-03-29 23:07:56 +00:00
stats.lua: fix ass-escape while persistent_overlay=yes
mpv has two methods to display output from text input: - show-text (scripting: mp.osd_message) has ass disabled by default (escaped), and the property osd-ass-cc can control escaping. - osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay) has ass enabled (unescaped), and osd-ass-cc is NOT supported. By default, stats.lua uses mp.osd_message which does support escaping. That's persistent_overlay=no. When using persistent_overlay=yes then mp.set_osd_ass is used. Due to this, the no_ASS(..) function - which is supposed to escape ass, simply returned its input unmodified when persistent_overlay is enabled. This is not a new issue, and the filters on page 1 use no_ASS() to no avail in persistent mode, however, this content (filter name and value strings) rarely actually needs escaping, and users didn't notice. However, the new page 4 (keys) does break visibly when no_ASS doesn't work, because it tries to escape arbitrary key-names and command strings, and at the very least the key '{' is bound by default, which is displayed incorrectly if escaping doesn't work. Fix this by rolling our own escaping when using mp.set_osd_ass, similar to how the mpv code does it for mp.osd_message (substrings replacements). However, this means that the set_ASS(..) function can no longer behave correctly because escaping requires going through the whole content string rather than only inserting a marker. Luckily, other than at no_ASS, set_ASS was only used at one place (text_style), which is only called from two places: - generate_graph() only needs to restore styles - not to enable ass. - add_header() is only used at the begining of page output, and uses set_ASS to enable ass initially when using mp.osd_message. So remove the set_ASS function, and instead enable ass directly at print_page using osd-ass-cc when mp.osd_message is used. Fixes #9022
This commit is contained in:
parent
e2109b606b
commit
955736b7b7
@ -132,17 +132,27 @@ local function compat(p)
|
||||
return p
|
||||
end
|
||||
|
||||
|
||||
local function set_ASS(b)
|
||||
if not o.use_ass or o.persistent_overlay then
|
||||
return ""
|
||||
end
|
||||
return b and ass_start or ass_stop
|
||||
end
|
||||
|
||||
-- "\\<U+2060>" in UTF-8 (U+2060 is WORD-JOINER)
|
||||
local ESC_BACKSLASH = "\\" .. string.char(0xE2, 0x81, 0xA0)
|
||||
|
||||
local function no_ASS(t)
|
||||
return set_ASS(false) .. t .. set_ASS(true)
|
||||
if not o.use_ass then
|
||||
return t
|
||||
elseif not o.persistent_overlay then
|
||||
-- mp.osd_message supports ass-escape using osd-ass-cc/{0|1}
|
||||
return ass_stop .. t .. ass_start
|
||||
else
|
||||
-- mp.set_osd_ass doesn't support ass-escape. roll our own.
|
||||
-- similar to mpv's sub/osd_libass.c:mangle_ass(...), excluding
|
||||
-- space after newlines because no_ASS is not used with multi-line.
|
||||
-- space at the begining is replaced with "\\h" because it matters
|
||||
-- at the begining of a line, and we can't know where our output
|
||||
-- ends up. no issue if it ends up at the middle of a line.
|
||||
return tostring(t)
|
||||
:gsub("\\", ESC_BACKSLASH)
|
||||
:gsub("{", "\\{")
|
||||
:gsub("^ ", "\\h")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -161,11 +171,11 @@ local function text_style()
|
||||
return ""
|
||||
end
|
||||
if o.custom_header and o.custom_header ~= "" then
|
||||
return set_ASS(true) .. o.custom_header
|
||||
return o.custom_header
|
||||
else
|
||||
return format("%s{\\r}{\\an7}{\\fs%d}{\\fn%s}{\\bord%f}{\\3c&H%s&}" ..
|
||||
return format("{\\r}{\\an7}{\\fs%d}{\\fn%s}{\\bord%f}{\\3c&H%s&}" ..
|
||||
"{\\1c&H%s&}{\\alpha&H%s&}{\\xshad%f}{\\yshad%f}{\\4c&H%s&}",
|
||||
set_ASS(true), o.font_size, o.font, o.border_size,
|
||||
o.font_size, o.font, o.border_size,
|
||||
o.border_color, o.font_color, o.alpha, o.shadow_x_offset,
|
||||
o.shadow_y_offset, o.shadow_color)
|
||||
end
|
||||
@ -990,10 +1000,13 @@ end
|
||||
|
||||
-- Call the function for `page` and print it to OSD
|
||||
local function print_page(page, after_scroll)
|
||||
-- the page functions assume we start in ass-enabled mode.
|
||||
-- that's true for mp.set_osd_ass, but not for mp.osd_message.
|
||||
local ass_content = pages[page].f(after_scroll)
|
||||
if o.persistent_overlay then
|
||||
mp.set_osd_ass(0, 0, pages[page].f(after_scroll))
|
||||
mp.set_osd_ass(0, 0, ass_content)
|
||||
else
|
||||
mp.osd_message(pages[page].f(after_scroll),
|
||||
mp.osd_message((o.use_ass and ass_start or "") .. ass_content,
|
||||
display_timer.oneshot and o.duration or o.redraw_delay + 1)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user