@@ -316,6 +316,15 @@ class Line
316
316
l. lines = Line . lineBreaks ass, l, noblank
317
317
l. extended = true
318
318
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
+
319
328
-- splits the text word by word
320
329
words : ( ass, l) ->
321
330
if l. extended
@@ -357,12 +366,13 @@ class Line
357
366
left += word. width + postspace * spacewidth
358
367
words. n += 1
359
368
words[ words. n] = word
369
+ left += lineTags. postspace
360
370
return words
361
371
else
362
372
error " You have to extend the line before you get the words" , 2
363
373
364
374
-- splits the text character by character
365
- chars : ( ass, l, noblank) ->
375
+ chars : ( ass, l, noblank = true ) ->
366
376
if l. extended
367
377
chars = { n : 0 }
368
378
for i = 1 , l. lines. n
@@ -398,6 +408,7 @@ class Line
398
408
left += char. width
399
409
chars. n += 1
400
410
chars[ chars. n] = char
411
+ left += lineTags. postspace
401
412
if noblank
402
413
charsNoblank = { n : 0 }
403
414
for char in * chars
@@ -409,14 +420,48 @@ class Line
409
420
else
410
421
error " You have to extend the line before you get the characters" , 2
411
422
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
420
465
421
466
-- callback to map between all possible lines of text
422
467
callBackTags : ( ass, l, fn) ->
0 commit comments