Last active
August 9, 2020 03:29
-
-
Save petzku/ca85b44fce765d5741ff95b87558d240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright (c) 2020, petzku <petzku@zku.fi> | |
-- | |
-- Permission to use, copy, modify, and distribute this software for any | |
-- purpose with or without fee is hereby granted, provided that the above | |
-- copyright notice and this permission notice appear in all copies. | |
-- | |
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
-- Provides dimensions of a clip on the currently active line | |
script_name = "Clip Size" | |
script_description = "Calculates dimensions of a vectorial clip" | |
script_author = "petzku" | |
script_version = "1.1" | |
function clipsize(subs, sel) | |
-- consider only first active line; clip tools usually deselect all others anyway | |
line = subs[sel[1]] | |
local clip = line.text:match("\\i?clip(%b())") | |
aegisub.log(5, "clip match: `%s`\n", clip) | |
coords = {} | |
for x,y in clip:gmatch("(%d+) (%d+)") do | |
table.insert(coords, {tonumber(x), tonumber(y)}) | |
end | |
aegisub.log(5, "coords size: %d\n", #coords) | |
dialog = {{class='label', x=0, y=0, label="Clip sizes:"}} | |
for i = 1, #coords-1 do | |
aegisub.log(5, "current coords: %d %d\n", coords[i][1], coords[i][2]) | |
dx = coords[i+1][1] - coords[i][1] | |
dy = coords[i+1][2] - coords[i][2] | |
dx_string = align_number(dx, 5) | |
dy_string = align_number(dy, 5) | |
-- aegisub.log(3, "delta: %s, %s\n", dx_string, dy_string) | |
table.insert(dialog, {class='label', x=1, y=i, label=dx_string}) | |
table.insert(dialog, {class='label', x=3, y=i, label=dy_string}) | |
end | |
aegisub.dialog.display(dialog) | |
end | |
function align_number(n, width) | |
-- https://en.wikipedia.org/wiki/Figure_space, thanks bucket3432 | |
return string.format("%"..width.."d", n):gsub(' ', ' ') | |
end | |
aegisub.register_macro(script_name, script_description, clipsize) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment