Skip to content

Commit 539d88c

Browse files
committed
Update Split Text
1 parent 8d1eebd commit 539d88c

File tree

3 files changed

+73
-17
lines changed

3 files changed

+73
-17
lines changed

macros/ILL.SplitText.moon

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export script_name = "ILL - Split Text"
22
export script_description = "Splits the text in several ways"
3-
export script_version = "2.0.0"
3+
export script_version = "2.1.0"
44
export script_author = "ILLTeam"
55
export script_namespace = "ILL.SplitText"
66

77
haveDepCtrl, DependencyControl = pcall require, "l0.DependencyControl"
88

9-
local depctrl, ILL, Ass, Line
9+
local depctrl, ILL
1010
if haveDepCtrl
1111
depctrl = DependencyControl {
1212
feed: "https://raw.githubusercontent.com/TypesettingTools/ILL-Aegisub-Scripts/main/DependencyControl.json",
@@ -30,14 +30,21 @@ main = (mode) ->
3030
ass = Ass sub, sel, activeLine
3131
for l, s, i, n in ass\iterSel!
3232
ass\progressLine s, i, n
33-
ass\removeLine l, s
34-
Line.extend ass, l
3533
unless l.isShape
36-
for line in *(mode == "chars" and Line.chars(ass, l, true) or Line.words(ass, l, true))
34+
ass\removeLine l, s
35+
Line.extend ass, l
36+
for line in *switch mode
37+
when "chars" then Line.chars ass, l
38+
when "words" then Line.words ass, l
39+
when "breaks" then Line.breaks ass, l
40+
when "tags" then Line.tags ass, l
3741
fr = line.data.angle != 0
3842
if fr or line.text\existsTagOr "frx", "fry", "frz"
3943
line.tags\insert {{"org", line.data.org}, true}
40-
line.tags\insert {{"pos", Line.reallocate l, line}, true}
44+
unless line.tags\existsTag "move"
45+
line.tags\insert {{"pos", Line.reallocate l, line}, true}
46+
else
47+
line.tags\insert {{"move", Line.reallocate l, line, true}, true}
4148
line.text\modifyBlock line.tags
4249
ass\insertLine line, s
4350
else
@@ -48,7 +55,11 @@ if haveDepCtrl
4855
depctrl\registerMacros {
4956
{"By Chars", "", main "chars"}
5057
{"By Words", "", main "words"}
58+
{"By Tags Blocks", "", main "tags"}
59+
{"By Line Breaks", "", main "breaks"}
5160
}
5261
else
5362
aegisub.register_macro "#{script_name}/By Chars", "", main "chars"
54-
aegisub.register_macro "#{script_name}/By Words", "", main "words"
63+
aegisub.register_macro "#{script_name}/By Words", "", main "words"
64+
aegisub.register_macro "#{script_name}/By Tags Blocks", "", main "tags"
65+
aegisub.register_macro "#{script_name}/By Line Breaks", "", main "breaks"

modules/ILL/ILL.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module_version = "1.6.2"
1+
module_version = "1.6.3"
22

33
haveDepCtrl, DependencyControl = pcall require, "l0.DependencyControl"
44

modules/ILL/ILL/Ass/Line.moon

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ class Line
316316
l.lines = Line.lineBreaks ass, l, noblank
317317
l.extended = true
318318

319+
-- updates line information
320+
update: (ass, l, noblank) ->
321+
l.lines = nil
322+
l.data = nil
323+
l.styleref = nil
324+
l.extended = false
325+
l.text = l.text\__tostring!
326+
Line.extend ass, l, noblank
327+
319328
-- splits the text word by word
320329
words: (ass, l) ->
321330
if l.extended
@@ -357,12 +366,13 @@ class Line
357366
left += word.width + postspace * spacewidth
358367
words.n += 1
359368
words[words.n] = word
369+
left += lineTags.postspace
360370
return words
361371
else
362372
error "You have to extend the line before you get the words", 2
363373

364374
-- splits the text character by character
365-
chars: (ass, l, noblank) ->
375+
chars: (ass, l, noblank = true) ->
366376
if l.extended
367377
chars = {n: 0}
368378
for i = 1, l.lines.n
@@ -398,6 +408,7 @@ class Line
398408
left += char.width
399409
chars.n += 1
400410
chars[chars.n] = char
411+
left += lineTags.postspace
401412
if noblank
402413
charsNoblank = {n: 0}
403414
for char in *chars
@@ -409,14 +420,48 @@ class Line
409420
else
410421
error "You have to extend the line before you get the characters", 2
411422

412-
-- updates line information
413-
update: (ass, l, noblank) ->
414-
l.lines = nil
415-
l.data = nil
416-
l.styleref = nil
417-
l.extended = false
418-
l.text = l.text\__tostring!
419-
Line.extend ass, l, noblank
423+
-- splits the text line break by line break
424+
breaks: (ass, l) ->
425+
if l.extended
426+
lines = {n: 0}
427+
for line in *l.lines
428+
lineBreak = Table.copy line[1]
429+
newBreakText = ""
430+
for i = 1, line.n
431+
newBreakTags = line[i].tags
432+
if i > 1
433+
newBreakTags\clear line.data
434+
newBreakText ..= newBreakTags\get! .. line[i].text_stripped
435+
lineBreak.y = math.max line[i].y, lineBreak.y
436+
lineBreak.text = Text newBreakText
437+
lineBreak.tags = Tags lineBreak.text.tagsBlocks[1]\get!
438+
lineBreak.text.tagsBlocks[1] = Tags lineBreak.text.tagsBlocks[1]\get!
439+
lineBreak.text_stripped = newBreakText
440+
left = switch l.data.an
441+
when 1, 4, 7 then l.eff_margin_l
442+
when 2, 5, 8 then (ass.meta.res_x - l.eff_margin_l - l.eff_margin_r - lineBreak.width) / 2 + l.eff_margin_l
443+
when 3, 6, 9 then ass.meta.res_x - l.eff_margin_r - lineBreak.width
444+
lineBreak.x = switch l.data.an
445+
when 1, 4, 7 then left
446+
when 2, 5, 8 then left + lineBreak.width * 0.5
447+
when 3, 6, 9 then left + lineBreak.width
448+
lines.n += 1
449+
lines[lines.n] = lineBreak
450+
return lines
451+
else
452+
error "You have to extend the line before you get the breaks", 2
453+
454+
-- splits the text tags blocks by tags blocks
455+
tags: (ass, l) ->
456+
if l.extended
457+
lines = {n: 0}
458+
for line in *l.lines
459+
for lineTags in *line
460+
lines.n += 1
461+
lines[lines.n] = Table.copy lineTags
462+
return lines
463+
else
464+
error "You have to extend the line before you get the tags", 2
420465

421466
-- callback to map between all possible lines of text
422467
callBackTags: (ass, l, fn) ->

0 commit comments

Comments
 (0)