Aegisub/aegisub/automation/autoload/macro-2-mkfullwitdh.lua
Amar Takhar a067bd560d SVN Transition Step 3/7
1. cd aegisub/
  2. svn mv *cpp *h src/
  3. svn mv Makefile.am MatroskaParser.c auto4_perldata.inc bitmaps boost \
     changelog.txt config gl include libosxutil libresrc md5.c msvc mythes.cxx \
     mythes.hxx res.rc src/
  4. cd ..
  5. svn mv FFmpegSource2/ INSTALL Makefile.am README  acinclude.m4 \
     autogen.sh automation/ bin build configure.in desktop dummy.txt lib \
     libass/ m4macros/ packages/ po/ scripts/ universalchardet/ aegisub/
  6. mkdir -p docs/wiki_convert
  7. svn add docs/wiki_convert
  8. cd docs
  9. svn mv aegisub_convert_docs.pl convert.bat output wiki_convert/

* See r2749 for full description.

Originally committed to SVN as r2752.
2009-03-08 08:30:39 +00:00

78 lines
2.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Automation 4 demo script
-- Converts halfwidth (ASCII) Latin letters to fullwidth JIS Latin letters
script_name = "Make text fullwidth"
script_description = "Shows how to use the unicode include to iterate over characters and a lookup table to convert those characters to something else."
script_author = "Niels Martin Hansen"
script_version = "1"
include("unicode.lua")
lookup = {
['!'] = '', ['"'] = '', ['#'] = '', ['$'] = '',
['%'] = '', ['&'] = '', ["'"] = '', ['('] = '',
[')'] = '', ['*'] = '', ['+'] = '', [','] = '',
['-'] = '', ['.'] = '', ['/'] = '',
['1'] = '', ['2'] = '', ['3'] = '', ['4'] = '',
['5'] = '', ['6'] = '', ['7'] = '', ['8'] = '',
['9'] = '', ['0'] = '',
[':'] = '', [';'] = '', ['<'] = '', ['='] = '',
['>'] = '', ['?'] = '', ['@'] = '',
['A'] = '', ['B'] = '', ['C'] = '', ['D'] = '',
['E'] = '', ['F'] = '', ['G'] = '', ['H'] = '',
['I'] = '', ['J'] = '', ['K'] = '', ['L'] = '',
['M'] = '', ['N'] = '', ['O'] = '', ['P'] = '',
['Q'] = '', ['R'] = '', ['S'] = '', ['T'] = '',
['U'] = '', ['V'] = '', ['W'] = '', ['X'] = '',
['Y'] = '', ['Z'] = '',
['['] = '', ['\\'] = '', [']'] = '', ['^'] = '',
['a'] = '', ['b'] = '', ['c'] = '', ['d'] = '',
['e'] = '', ['f'] = '', ['g'] = '', ['h'] = '',
['i'] = '', ['j'] = '', ['k'] = '', ['l'] = '',
['m'] = '', ['n'] = '', ['o'] = '', ['p'] = '',
['q'] = '', ['r'] = '', ['s'] = '', ['t'] = '',
['u'] = '', ['v'] = '', ['w'] = '', ['x'] = '',
['y'] = '', ['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
aegisub.set_undo_point("Make fullwidth")
end
aegisub.register_macro("Make fullwidth", "Convert Latin letters to SJIS fullwidth letters", make_fullwidth)