@@ -27,7 +27,7 @@ class Line
27
27
l. text\ moveToFirstLayer!
28
28
29
29
with l
30
- . text_stripped = . isShape and . text. textBlocks[ 1 ] \ gsub( " %b{}" , " " ) or . text \ stripped!
30
+ . text_stripped = . text. textBlocks[ 1 ] \ gsub " %b{}" , " "
31
31
. duration = . end_time - . start_time
32
32
textIsBlank = Util . isBlank . text_stripped
33
33
@@ -89,7 +89,8 @@ class Line
89
89
. postspace = . text_stripped\ match( " ^%s*.-(%s*)$" ) \ len! * . space_width
90
90
91
91
-- 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*$"
93
94
else
94
95
-- to make everything more dynamic
95
96
. shape = . text_stripped
@@ -100,14 +101,15 @@ class Line
100
101
-- gets the metric values of the text
101
102
if textIsBlank
102
103
textExtents = font\ getTextExtents " "
104
+ textMetrics = font\ getMetrics!
103
105
. width = 0
104
106
. height = textExtents. height
105
- . ascent = 0
106
- . descent = 0
107
+ . ascent = textMetrics . ascent
108
+ . descent = textMetrics . descent
107
109
else
108
110
textValue = . isShape and " " or . text_stripped
109
111
textExtents = font\ getTextExtents textValue
110
- textMetrics = font\ getMetrics textValue
112
+ textMetrics = font\ getMetrics!
111
113
. width = textExtents. width * video_x_correct_factor
112
114
. height = textExtents. height
113
115
. ascent = textMetrics. ascent
@@ -168,7 +170,7 @@ class Line
168
170
. y = . bottom
169
171
170
172
-- gets all the data values from the tags blocks
171
- tagsBlocks : ( ass, l, noblank = true ) ->
173
+ tagsBlocks : ( ass, l, noblank = false ) ->
172
174
data = { width : 0 , height : 0 , n : 0 }
173
175
174
176
unless l. data
@@ -188,6 +190,7 @@ class Line
188
190
line. text_stripped = text
189
191
line. tags = tags\ clean!
190
192
line. text = Text line. tags\ __tostring! .. text
193
+ line. text. textBlocks[ 1 ] = text
191
194
192
195
-- support for the \r tag in line processing
193
196
if reset = line. tags\ getTag " r"
@@ -214,6 +217,7 @@ class Line
214
217
215
218
-- fixes the positioning of tag blocks in relation to the rendered text
216
219
for line in * data
220
+
217
221
-- sums with the previous space values
218
222
left += line. prevspace
219
223
@@ -240,7 +244,7 @@ class Line
240
244
return noblank and dataNoblank or data
241
245
242
246
-- gets all the data values from the line breaks
243
- lineBreaks : ( ass, l, noblank = true ) ->
247
+ lineBreaks : ( ass, l, noblank = false ) ->
244
248
data = { width : 0 , height : 0 , n : 0 }
245
249
246
250
unless l. data
@@ -310,7 +314,7 @@ class Line
310
314
return noblank and dataNoblank or data
311
315
312
316
-- adds all possible information to the line
313
- extend : ( ass, l, noblank) ->
317
+ extend : ( ass, l, noblank = true ) ->
314
318
Line . process ass, l
315
319
unless l. isShape
316
320
l. lines = Line . lineBreaks ass, l, noblank
@@ -326,7 +330,7 @@ class Line
326
330
Line . extend ass, l, noblank
327
331
328
332
-- splits the text word by word
329
- words : ( ass, l) ->
333
+ words : ( ass, l, noblank = false ) ->
330
334
if l. extended
331
335
words = { n : 0 }
332
336
for i = 1 , l. lines. n
@@ -339,7 +343,7 @@ class Line
339
343
lineTags = lineBreak[ j]
340
344
lineTagsText = lineTags. text_stripped
341
345
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*)"
343
347
word = Table . copy lineTags
344
348
word. tags = Tags lineTagsTags
345
349
word. text = Text wordText
@@ -367,6 +371,13 @@ class Line
367
371
words. n += 1
368
372
words[ words. n] = word
369
373
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
370
381
return words
371
382
else
372
383
error " You have to extend the line before you get the words" , 2
@@ -428,9 +439,9 @@ class Line
428
439
lineBreak = Table . copy line[ 1 ]
429
440
newBreakText = " "
430
441
for i = 1 , line. n
431
- newBreakTags = line[ i] . tags
442
+ newBreakTags = Table . copy line[ i] . tags
432
443
if i > 1
433
- newBreakTags\ clear line. data
444
+ newBreakTags\ difference line[ i - 1 ] . tags
434
445
newBreakText ..= newBreakTags\ get! .. line[ i] . text_stripped
435
446
lineBreak. y = math.max line[ i] . y, lineBreak. y
436
447
lineBreak. text = Text newBreakText
@@ -457,8 +468,9 @@ class Line
457
468
lines = { n : 0 }
458
469
for line in * l. lines
459
470
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
462
474
return lines
463
475
else
464
476
error " You have to extend the line before you get the tags" , 2
0 commit comments