Skip to content

Instantly share code, notes, and snippets.

@torque
Last active August 29, 2015 14:07
Show Gist options
  • Save torque/cc9d561e115867960e57 to your computer and use it in GitHub Desktop.
Save torque/cc9d561e115867960e57 to your computer and use it in GitHub Desktop.
inspectorExample = ( sub, sel, act ) ->
dialogStart = -1
for i = 1, #sub
if 'dialogue' == sub[i].class
dialogStart = i
break
if -1 == dialogStart
log.windowError( "This script does not appear to have any dialogue lines." )
ffms = aegisub.frame_from_ms
msff = aegisub.ms_from_frame
myInspector, message = Inspector( sub )
unless myInspector
log.windowError( message )
for lineIndex in *sel
with line = sub[lineIndex]
line.assi_exhaustive = true
bounds, times = myInspector\getBounds( { line } )
if nil == bounds
log.windowError( times )
for i = 1, #bounds
rect = bounds[i]
if rect
log.dump( rect )
else
log.warn( "Line %d is invisible on frame %d", lineIndex - dialogStart + 1, ffms( times[i] ) )
-- A second example
-- bounds, times = myInspector\getBounds( { line }, { .start_time } )
-- if nil == bounds
-- log.windowError( times )
-- rect = bounds[1]
-- unless rect
-- -- line does not exist
-- log.warn( "line %d is invisble.", lineIndex - dialogStart + 1 )
aegisub.register_macro "Inspector Example", "Inspector Example", inspectorExample

A few warnings

Be very careful with font handling. The default fonts.conf included does not tell fontconfig to search any directories. The default folder passed to ASSInspector is ?script/fonts, but if that doesn't exist or has no fonts in it, all lines will be rendered blank. Yes, even ones only containing vector shapes. I don't know why.

Likewise, if you plan on opening a new script in aegisub without reloading the macro, you need to call myInspector:forceLibraryReload( newFontDirectory ) if the font directory needs to change (e.g. you are using the default and the new script is in a different directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment