From 7a76b577d85ddc8f9e255b1a1c195ee88b76a7d8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 6 Mar 2020 18:20:11 +0100 Subject: command: extend osd-overlay command with bounds reporting This is more or less a minimal hack to make _some_ text measurement functionality available to scripts. Since libass does not support such a thing, this simply uses the bounding box of the rendered text. This is far from ideal. Problems include: - using a bitmap bounding box - additional memory waste and/or flushing caches - dependency on window size - odd small deviations with different window sizes (run osd-test.lua and resize the window after each timer update; the bounding boxes aren't adjusted in an overly useful way) - inability to query the size _after_ actual rendering But I guess it's a start. Since I'm aware that it's crap, add a threat to the manpage that this may be changed/removed again. For now, I'm interested whether anyone will have use for it in its current form, as it's an often requested feature. --- TOOLS/lua/osd-test.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 TOOLS/lua/osd-test.lua (limited to 'TOOLS') diff --git a/TOOLS/lua/osd-test.lua b/TOOLS/lua/osd-test.lua new file mode 100644 index 0000000000..1b1781956d --- /dev/null +++ b/TOOLS/lua/osd-test.lua @@ -0,0 +1,35 @@ +local assdraw = require 'mp.assdraw' +local utils = require 'mp.utils' + +things = {} +for i = 1, 2 do + things[i] = { + osd1 = mp.create_osd_overlay("ass-events"), + osd2 = mp.create_osd_overlay("ass-events") + } +end +things[1].text = "{\\an5}hello\\Nworld" +things[2].text = "{\\pos(400, 200)}something something" + +mp.add_periodic_timer(2, function() + for i, thing in ipairs(things) do + thing.osd1.data = thing.text + thing.osd1.compute_bounds = true + --thing.osd1.hidden = true + local res = thing.osd1:update() + print("res " .. i .. ": " .. utils.to_string(res)) + + thing.osd2.hidden = true + if res ~= nil and res.x0 ~= nil then + local draw = assdraw.ass_new() + draw:append("{\\alpha&H80}") + draw:draw_start() + draw:pos(0, 0) + draw:rect_cw(res.x0, res.y0, res.x1, res.y1) + draw:draw_stop() + thing.osd2.hidden = false + thing.osd2.data = draw.text + end + thing.osd2:update() + end +end) -- cgit v1.2.3