Skip to content

Commit 31f4ec5

Browse files
committed
Update Files
1 parent 75f9413 commit 31f4ec5

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

macros/ILL.SplitText.moon

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

@@ -13,7 +13,7 @@ if haveDepCtrl
1313
{
1414
{
1515
"ILL.ILL"
16-
version: "1.6.1"
16+
version: "1.6.4"
1717
url: "https://github.com/TypesettingTools/ILL-Aegisub-Scripts/"
1818
feed: "https://raw.githubusercontent.com/TypesettingTools/ILL-Aegisub-Scripts/main/DependencyControl.json"
1919
}
@@ -27,17 +27,17 @@ else
2727

2828
main = (mode) ->
2929
(sub, sel, activeLine) ->
30-
ass = Ass sub, sel, activeLine
30+
ass = Ass sub, sel, activeLine, false
3131
for l, s, i, n in ass\iterSel!
3232
ass\progressLine s, i, n
3333
unless l.isShape
3434
ass\removeLine l, s
35-
Line.extend ass, l
35+
Line.extend ass, l, false
3636
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
37+
when "chars" then Line.chars ass, l, true
38+
when "words" then Line.words ass, l, true
39+
when "breaks" then Line.breaks ass, l, true
40+
when "tags" then Line.tags ass, l, true
4141
fr = line.data.angle != 0
4242
if fr or line.text\existsTagOr "frx", "fry", "frz"
4343
line.tags\insert {{"org", line.data.org}, true}

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.3"
1+
module_version = "1.6.4"
22

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

modules/ILL/ILL/Ass/Line.moon

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Line
2727
l.text\moveToFirstLayer!
2828

2929
with l
30-
.text_stripped = .isShape and .text.textBlocks[1]\gsub("%b{}", "") or .text\stripped!
30+
.text_stripped = .text.textBlocks[1]\gsub "%b{}", ""
3131
.duration = .end_time - .start_time
3232
textIsBlank = Util.isBlank .text_stripped
3333

@@ -89,7 +89,8 @@ class Line
8989
.postspace = .text_stripped\match("^%s*.-(%s*)$")\len! * .space_width
9090

9191
-- removes the spaces between the text
92-
.text_stripped = .text_stripped\match "^%s*(.-)%s*$"
92+
unless textIsBlank
93+
.text_stripped = .text_stripped\match "^%s*(.-)%s*$"
9394
else
9495
-- to make everything more dynamic
9596
.shape = .text_stripped
@@ -100,14 +101,15 @@ class Line
100101
-- gets the metric values of the text
101102
if textIsBlank
102103
textExtents = font\getTextExtents " "
104+
textMetrics = font\getMetrics!
103105
.width = 0
104106
.height = textExtents.height
105-
.ascent = 0
106-
.descent = 0
107+
.ascent = textMetrics.ascent
108+
.descent = textMetrics.descent
107109
else
108110
textValue = .isShape and "" or .text_stripped
109111
textExtents = font\getTextExtents textValue
110-
textMetrics = font\getMetrics textValue
112+
textMetrics = font\getMetrics!
111113
.width = textExtents.width * video_x_correct_factor
112114
.height = textExtents.height
113115
.ascent = textMetrics.ascent
@@ -168,7 +170,7 @@ class Line
168170
.y = .bottom
169171

170172
-- gets all the data values from the tags blocks
171-
tagsBlocks: (ass, l, noblank = true) ->
173+
tagsBlocks: (ass, l, noblank = false) ->
172174
data = {width: 0, height: 0, n: 0}
173175

174176
unless l.data
@@ -188,6 +190,7 @@ class Line
188190
line.text_stripped = text
189191
line.tags = tags\clean!
190192
line.text = Text line.tags\__tostring! .. text
193+
line.text.textBlocks[1] = text
191194

192195
-- support for the \r tag in line processing
193196
if reset = line.tags\getTag "r"
@@ -214,6 +217,7 @@ class Line
214217

215218
-- fixes the positioning of tag blocks in relation to the rendered text
216219
for line in *data
220+
217221
-- sums with the previous space values
218222
left += line.prevspace
219223

@@ -240,7 +244,7 @@ class Line
240244
return noblank and dataNoblank or data
241245

242246
-- gets all the data values from the line breaks
243-
lineBreaks: (ass, l, noblank = true) ->
247+
lineBreaks: (ass, l, noblank = false) ->
244248
data = {width: 0, height: 0, n: 0}
245249

246250
unless l.data
@@ -310,7 +314,7 @@ class Line
310314
return noblank and dataNoblank or data
311315

312316
-- adds all possible information to the line
313-
extend: (ass, l, noblank) ->
317+
extend: (ass, l, noblank = true) ->
314318
Line.process ass, l
315319
unless l.isShape
316320
l.lines = Line.lineBreaks ass, l, noblank
@@ -326,7 +330,7 @@ class Line
326330
Line.extend ass, l, noblank
327331

328332
-- splits the text word by word
329-
words: (ass, l) ->
333+
words: (ass, l, noblank = false) ->
330334
if l.extended
331335
words = {n: 0}
332336
for i = 1, l.lines.n
@@ -339,7 +343,7 @@ class Line
339343
lineTags = lineBreak[j]
340344
lineTagsText = lineTags.text_stripped
341345
lineTagsTags = lineTags.tags\get!
342-
for prevspace, wordText, postspace in lineTagsText\gmatch "(%s*)(%S+)(%s*)"
346+
for prevspace, wordText, postspace in lineTagsText\gmatch "(%s*)(.+)(%s*)"
343347
word = Table.copy lineTags
344348
word.tags = Tags lineTagsTags
345349
word.text = Text wordText
@@ -367,6 +371,13 @@ class Line
367371
words.n += 1
368372
words[words.n] = word
369373
left += lineTags.postspace
374+
if noblank
375+
wordsNoblank = {n: 0}
376+
for word in *words
377+
unless Util.isBlank word.text_stripped
378+
wordsNoblank.n += 1
379+
wordsNoblank[wordsNoblank.n] = word
380+
return wordsNoblank
370381
return words
371382
else
372383
error "You have to extend the line before you get the words", 2
@@ -428,9 +439,9 @@ class Line
428439
lineBreak = Table.copy line[1]
429440
newBreakText = ""
430441
for i = 1, line.n
431-
newBreakTags = line[i].tags
442+
newBreakTags = Table.copy line[i].tags
432443
if i > 1
433-
newBreakTags\clear line.data
444+
newBreakTags\difference line[i-1].tags
434445
newBreakText ..= newBreakTags\get! .. line[i].text_stripped
435446
lineBreak.y = math.max line[i].y, lineBreak.y
436447
lineBreak.text = Text newBreakText
@@ -457,8 +468,9 @@ class Line
457468
lines = {n: 0}
458469
for line in *l.lines
459470
for lineTags in *line
460-
lines.n += 1
461-
lines[lines.n] = Table.copy lineTags
471+
unless Util.isBlank lineTags.text_stripped
472+
lines.n += 1
473+
lines[lines.n] = Table.copy lineTags
462474
return lines
463475
else
464476
error "You have to extend the line before you get the tags", 2

modules/ILL/ILL/Ass/Text/Tags.moon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ class Tags
185185
@tags = table.concat [s\__tostring! for s in *newSplit]
186186
@close!
187187

188+
-- performs a difference operation on the tags
189+
-- tags A = Tags {\fs20\bord10}
190+
-- tags B = Tags {\fs20\bord10\fs100}
191+
-- result = {\fs100}
192+
difference: (tags) =>
193+
for {:name, :value} in *tags\split!
194+
if @existsTag name
195+
if @getTag(name).value == value
196+
@remove name
197+
@close!
198+
188199
-- checks if the tag exists in the tags
189200
existsTag: (name) =>
190201
if name != "t"

modules/ILL/ILL/Ass/Text/Text.moon

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,31 +189,12 @@ class Text
189189
tagsBlock = tagsBlocks[i]
190190
textBlock = textBlocks[i]
191191
new ..= tostring(tagsBlock)\gsub("{(.-)\\N}", "\\N{%1}") .. textBlock
192-
new = new\gsub "}{", ""
192+
-- new = new\gsub "}{", ""
193193

194194
-- gets the line breaks
195195
breaks = Util.splitByPattern new, "\\N"
196196
n = #breaks
197197

198-
-- solves cases where the initial tags are only blanks
199-
i = 1
200-
while true
201-
if breaks[i] and Util.isBlank breaks[i]\gsub "%b{}", ""
202-
n -= 1
203-
i -= 1
204-
table.remove breaks, 1
205-
else
206-
break
207-
i += 1
208-
209-
-- fixes a bug of extreme masochism
210-
if n >= 1
211-
breaks[1] = Text(breaks[1])\__tostring!
212-
breaks[1] = breaks[1]\gsub "}%s*{", ""
213-
if n > 1
214-
breaks[n] = Text(breaks[n])\__tostring!
215-
breaks[n] = breaks[n]\gsub "}%s*{", ""
216-
217198
return breaks, n
218199

219200
__tostring: =>

0 commit comments

Comments
 (0)