Fixes to make kara-templater actually work... oops.

Originally committed to SVN as r1221.
This commit is contained in:
Niels Martin Hansen 2007-06-15 23:20:45 +00:00
parent 9b00ecf2ed
commit 40525074e3

View file

@ -295,9 +295,18 @@ function set_ctx_syl(varctx, line, syl)
varctx.mid = varctx.smid varctx.mid = varctx.smid
varctx.si = syl.i varctx.si = syl.i
varctx.i = varctx.si varctx.i = varctx.si
varctx.sleft = math.floor(syl.left+0.5) varctx.sleft = math.floor(line.left + syl.left+0.5)
varctx.scenter = math.floor(syl.center+0.5) varctx.scenter = math.floor(line.left + syl.center+0.5)
varctx.sright = math.floor(syl.right+0.5) varctx.sright = math.floor(line.left + syl.right+0.5)
if syl.isfuri then
varctx.sbottom = varctx.ltop
varctx.stop = varctx.ltop - syl.height
varctx.smiddle = varctx.ltop - syl.height/2
else
varctx.stop = varctx.ltop
varctx.smiddle = varctx.lmiddle
varctx.sbottom = varctx.lbottom
end
if line.halign == "left" then if line.halign == "left" then
varctx.sx = math.floor(line.left + syl.left + 0.5) varctx.sx = math.floor(line.left + syl.left + 0.5)
elseif line.halign == "center" then elseif line.halign == "center" then
@ -305,10 +314,14 @@ function set_ctx_syl(varctx, line, syl)
elseif line.halign == "right" then elseif line.halign == "right" then
varctx.sx = math.floor(line.left + syl.right + 0.5) varctx.sx = math.floor(line.left + syl.right + 0.5)
end end
-- FIXME: furigana needs different y
varctx.sy = math.floor(line.y+0.5) varctx.sy = math.floor(line.y+0.5)
varctx.left = varctx.sleft varctx.left = varctx.sleft
varctx.center = varctx.scenter varctx.center = varctx.scenter
varctx.right = varctx.sright varctx.right = varctx.sright
varctx.top = varctx.stop
varctx.middle = varctx.smiddle
varctx.bottom = varctx.sbottom
varctx.x = varctx.sx varctx.x = varctx.sx
varctx.y = varctx.sy varctx.y = varctx.sy
end end
@ -336,6 +349,9 @@ function apply_line(meta, styles, subs, line, templates, tenv)
lleft = math.floor(line.left+0.5), lleft = math.floor(line.left+0.5),
lcenter = math.floor(line.left + line.width/2 + 0.5), lcenter = math.floor(line.left + line.width/2 + 0.5),
lright = math.floor(line.left + line.width + 0.5), lright = math.floor(line.left + line.width + 0.5),
ltop = math.floor(line.top + 0.5),
lmiddle = math.floor(line.middle + 0.5),
lbottom = math.floor(line.bottom + 0.5),
lx = math.floor(line.x+0.5), lx = math.floor(line.x+0.5),
ly = math.floor(line.y+0.5) ly = math.floor(line.y+0.5)
-- TODO? more positioning vars -- TODO? more positioning vars
@ -350,6 +366,9 @@ function apply_line(meta, styles, subs, line, templates, tenv)
varctx.left = varctx.lleft varctx.left = varctx.lleft
varctx.center = varctx.lcenter varctx.center = varctx.lcenter
varctx.right = varctx.lright varctx.right = varctx.lright
varctx.top = varctx.ltop
varctx.middle = varctx.lmiddle
varctx.bottom = varctx.lbottom
varctx.x = varctx.lx varctx.x = varctx.lx
varctx.y = varctx.ly varctx.y = varctx.ly
@ -402,16 +421,20 @@ function apply_line(meta, styles, subs, line, templates, tenv)
for i = 0, line.kara.n do for i = 0, line.kara.n do
local syl = line.kara[i] local syl = line.kara[i]
applied_templates = applied_templates or aegisub.debug.out(5, "Applying templates to syllable: %s\n", syl.text)
apply_syllable_templates(syl, line, templates.syl, tenv, varctx, subs) if apply_syllable_templates(syl, line, templates.syl, tenv, varctx, subs) then
applied_templates = true
end
end end
-- Loop over furigana -- Loop over furigana
for i = 1, line.furi.n do for i = 1, line.furi.n do
local furi = line.furi[i] local furi = line.furi[i]
applied_templates = applied_templates or aegisub.debug.out(5, "Applying templates to furigana: %s\n", furi.text)
apply_syllable_templates(furi, line, templates.furi, tenv, varctx, subs) if apply_syllable_templates(furi, line, templates.furi, tenv, varctx, subs) then
applied_templates = true
end
end end
return applied_templates return applied_templates
@ -486,12 +509,13 @@ function apply_syllable_templates(syl, line, templates, tenv, varctx, subs)
local applied_templates = false local applied_templates = false
-- Loop over all templates matching the line style -- Loop over all templates matching the line style
for t in matching_templates(templates.syl, line) do for t in matching_templates(templates, line) do
tenv.syl = syl tenv.syl = syl
set_ctx_syl(varctx, line, syl) set_ctx_syl(varctx, line, syl)
applied_templates = applied_templates or if apply_one_syllable_template(syl, line, t, tenv, varctx, subs, false, false) then
apply_one_syllable_template(syl, line, t, tenv, varctx, subs, false, false) applied_templates = true
end
end end
return applied_templates return applied_templates
@ -513,21 +537,25 @@ end
function apply_one_syllable_template(syl, line, template, tenv, varctx, subs, skip_perchar, skip_multi) function apply_one_syllable_template(syl, line, template, tenv, varctx, subs, skip_perchar, skip_multi)
local t = template local t = template
aegisub.debug.out(5, "Applying template to one syllable with text: %s\n", syl.text)
-- Check for right inline_fx -- Check for right inline_fx
if t.inline_fx and t.inline_fx ~= syl.inline_fx then if t.inline_fx and t.inline_fx ~= syl.inline_fx then
aegisub.debug.out(5, "Syllable has wrong inline-fx (wanted '%s', got '%s'), skipping.\n", t.inline_fx, syl.inline_fx)
return false return false
end end
if t.noblank and is_syl_blank(syl) then if t.noblank and is_syl_blank(syl) then
aegisub.debug.out(5, "Syllable is blank, skipping.\n")
return false return false
end end
-- Recurse to per-char if required -- Recurse to per-char if required
if not skip_perchar and t.perchar then if not skip_perchar and t.perchar then
aegisub.debug.out(5, "Doing per-character effects...\n")
local charsyl = table.copy(syl) local charsyl = table.copy(syl)
tenv.basesyl = tenv.basesyl or syl tenv.basesyl = tenv.basesyl or syl
tenv.syl = charsyl tenv.syl = charsyl
set_ctx_syl(varctx, line, charsyl)
local left, width = syl.left, 0 local left, width = syl.left, 0
for c in unicode.chars(syl.text_stripped) do for c in unicode.chars(syl.text_stripped) do
@ -541,6 +569,7 @@ function apply_one_syllable_template(syl, line, template, tenv, varctx, subs, sk
charsyl.right = left + width charsyl.right = left + width
charsyl.prespacewidth, charsyl.postspacewidth = 0, 0 -- whatever... charsyl.prespacewidth, charsyl.postspacewidth = 0, 0 -- whatever...
left = left + width left = left + width
set_ctx_syl(varctx, line, charsyl)
apply_one_syllable_template(charsyl, line, t, tenv, varctx, subs, true, false) apply_one_syllable_template(charsyl, line, t, tenv, varctx, subs, true, false)
end end
@ -550,16 +579,17 @@ function apply_one_syllable_template(syl, line, template, tenv, varctx, subs, sk
-- Recurse to multi-hl if required -- Recurse to multi-hl if required
if not skip_multi and t.multi then if not skip_multi and t.multi then
aegisub.debug.out(5, "Doing multi-highlight effects...\n")
local hlsyl = table.copy(syl) local hlsyl = table.copy(syl)
tenv.basesyl = tenv.basesyl or syl tenv.basesyl = tenv.basesyl or syl
tenv.syl = hlsyl tenv.syl = hlsyl
set_ctx_syl(varctx, line, hlsyl)
for hl = 1, syl.highlights.n do for hl = 1, syl.highlights.n do
local hldata = syl.highlights[hl] local hldata = syl.highlights[hl]
hlsyl.start_time = hldata.start_time hlsyl.start_time = hldata.start_time
hlsyl.end_time = hldata.end_time hlsyl.end_time = hldata.end_time
hlsyl.duration = hldata.duration hlsyl.duration = hldata.duration
set_ctx_syl(varctx, line, hlsyl)
apply_one_syllable_template(hlsyl, line, t, tenv, varctx, subs, true, true) apply_one_syllable_template(hlsyl, line, t, tenv, varctx, subs, true, true)
end end
@ -568,21 +598,24 @@ function apply_one_syllable_template(syl, line, template, tenv, varctx, subs, sk
end end
-- Regular processing -- Regular processing
if not t.inline_fx or t.inline_fx == syl.inline_fx then if t.code then
if t.code then aegisub.debug.out(5, "Running code line\n")
run_code_template(t, tenv) run_code_template(t, tenv)
else else
for j = 1, t.loops do aegisub.debug.out(5, "Running %d effect loops\n", t.loops)
tenv.j = j for j = 1, t.loops do
local newline = table.copy(line) tenv.j = j
tenv.line = newline local newline = table.copy(line)
newline.text = run_text_template(t.t, tenv, varctx) newline.styleref = syl.style
if t.addtext then newline.style = syl.style.name
newline.text = newline.text .. syl.text_stripped tenv.line = newline
end newline.text = run_text_template(t.t, tenv, varctx)
newline.effect = "fx" if t.addtext then
subs.append(newline) newline.text = newline.text .. syl.text_stripped
end end
newline.effect = "fx"
aegisub.debug.out(5, "Generated line with text: %s\n", newline.text)
subs.append(newline)
end end
end end