2012-08-18 18:43:11 +02:00
-- Automation 4 demo script
2007-01-10 04:59:57 +01:00
-- Converts halfwidth (ASCII) Latin letters to fullwidth JIS Latin letters
2012-03-13 00:35:37 +01:00
local tr = aegisub.gettext
script_name = tr ( " Make text fullwidth " )
script_description = tr ( " Shows how to use the unicode include to iterate over characters and a lookup table to convert those characters to something else. " )
2007-01-10 04:59:57 +01:00
script_author = " Niels Martin Hansen "
script_version = " 1 "
include ( " unicode.lua " )
lookup = {
[ ' ! ' ] = ' ! ' , [ ' " ' ] = ' ” ' , [ ' # ' ] = ' # ' , [ ' $ ' ] = ' $ ' ,
[ ' % ' ] = ' % ' , [ ' & ' ] = ' & ' , [ " ' " ] = ' ’ ' , [ ' ( ' ] = ' ( ' ,
[ ' ) ' ] = ' ) ' , [ ' * ' ] = ' * ' , [ ' + ' ] = ' + ' , [ ' , ' ] = ' , ' ,
[ ' - ' ] = ' - ' , [ ' . ' ] = ' . ' , [ ' / ' ] = ' / ' ,
[ ' 1 ' ] = ' 1 ' , [ ' 2 ' ] = ' 2 ' , [ ' 3 ' ] = ' 3 ' , [ ' 4 ' ] = ' 4 ' ,
[ ' 5 ' ] = ' 5 ' , [ ' 6 ' ] = ' 6 ' , [ ' 7 ' ] = ' 7 ' , [ ' 8 ' ] = ' 8 ' ,
[ ' 9 ' ] = ' 9 ' , [ ' 0 ' ] = ' 0 ' ,
[ ' : ' ] = ' : ' , [ ' ; ' ] = ' ; ' , [ ' < ' ] = ' < ' , [ ' = ' ] = ' = ' ,
[ ' > ' ] = ' > ' , [ ' ? ' ] = ' ? ' , [ ' @ ' ] = ' @ ' ,
[ ' A ' ] = ' A ' , [ ' B ' ] = ' B ' , [ ' C ' ] = ' C ' , [ ' D ' ] = ' D ' ,
[ ' E ' ] = ' E ' , [ ' F ' ] = ' F ' , [ ' G ' ] = ' G ' , [ ' H ' ] = ' H ' ,
[ ' I ' ] = ' I ' , [ ' J ' ] = ' J ' , [ ' K ' ] = ' K ' , [ ' L ' ] = ' L ' ,
[ ' M ' ] = ' M ' , [ ' N ' ] = ' N ' , [ ' O ' ] = ' O ' , [ ' P ' ] = ' P ' ,
[ ' Q ' ] = ' Q ' , [ ' R ' ] = ' R ' , [ ' S ' ] = ' S ' , [ ' T ' ] = ' T ' ,
[ ' U ' ] = ' U ' , [ ' V ' ] = ' V ' , [ ' W ' ] = ' W ' , [ ' X ' ] = ' X ' ,
[ ' Y ' ] = ' Y ' , [ ' Z ' ] = ' Z ' ,
[ ' [ ' ] = ' [ ' , [ ' \\ ' ] = ' \ ' , [ ' ] ' ] = ' ] ' , [ ' ^ ' ] = ' ^ ' ,
[ ' a ' ] = ' a ' , [ ' b ' ] = ' b ' , [ ' c ' ] = ' c ' , [ ' d ' ] = ' d ' ,
[ ' e ' ] = ' e ' , [ ' f ' ] = ' f ' , [ ' g ' ] = ' g ' , [ ' h ' ] = ' h ' ,
[ ' i ' ] = ' i ' , [ ' j ' ] = ' j ' , [ ' k ' ] = ' k ' , [ ' l ' ] = ' l ' ,
[ ' m ' ] = ' m ' , [ ' n ' ] = ' n ' , [ ' o ' ] = ' o ' , [ ' p ' ] = ' p ' ,
[ ' q ' ] = ' q ' , [ ' r ' ] = ' r ' , [ ' s ' ] = ' s ' , [ ' t ' ] = ' t ' ,
[ ' u ' ] = ' u ' , [ ' v ' ] = ' v ' , [ ' w ' ] = ' w ' , [ ' x ' ] = ' x ' ,
[ ' y ' ] = ' y ' , [ ' z ' ] = ' z ' ,
[ ' _ ' ] = ' _ ' , [ ' ` ' ] = ' ‘ ' ,
[ ' { ' ] = ' { ' , [ ' | ' ] = ' | ' , [ ' } ' ] = ' } ' , [ ' ~ ' ] = ' ~ ' ,
}
function make_fullwidth ( subtitles , selected_lines , active_line )
for z , i in ipairs ( selected_lines ) do
local l = subtitles [ i ]
aegisub.debug . out ( string.format ( ' Processing line %d: "%s" \n ' , i , l.text ) )
aegisub.debug . out ( " Chars: \n " )
local in_tags = false
local newtext = " "
for c in unicode.chars ( l.text ) do
aegisub.debug . out ( c .. ' -> ' )
if c == " { " then
in_tags = true
end
if in_tags then
aegisub.debug . out ( c .. " (ignored, in tags) \n " )
newtext = newtext .. c
else
if lookup [ c ] then
aegisub.debug . out ( lookup [ c ] .. " (converted) \n " )
newtext = newtext .. lookup [ c ]
else
aegisub.debug . out ( c .. " (not found in lookup) \n " )
newtext = newtext .. c
end
end
if c == " } " then
in_tags = false
end
end
l.text = newtext
subtitles [ i ] = l
end
2012-03-13 00:35:37 +01:00
aegisub.set_undo_point ( tr " Make fullwidth " )
2007-01-10 04:59:57 +01:00
end
2012-03-13 00:35:37 +01:00
aegisub.register_macro ( tr " Make fullwidth " , tr " Convert Latin letters to SJIS fullwidth letters " , make_fullwidth )