@@ -314,12 +314,107 @@ class Line
314
314
Line . process ass, l
315
315
unless l. isShape
316
316
l. lines = Line . lineBreaks ass, l, noblank
317
+ l. extended = true
318
+
319
+ -- splits the text word by word
320
+ words : ( ass, l) ->
321
+ if l. extended
322
+ words = { n : 0 }
323
+ for i = 1 , l. lines. n
324
+ lineBreak = l. lines[ i]
325
+ left = switch l. data. an
326
+ when 1 , 4 , 7 then l. eff_margin_l
327
+ when 2 , 5 , 8 then ( ass. meta. res_x - l. eff_margin_l - l. eff_margin_r - lineBreak. width) / 2 + l. eff_margin_l
328
+ when 3 , 6 , 9 then ass. meta. res_x - l. eff_margin_r - lineBreak. width
329
+ for j = 1 , lineBreak. n
330
+ lineTags = lineBreak[ j]
331
+ lineTagsText = lineTags. text_stripped
332
+ lineTagsTags = lineTags. tags\ get!
333
+ for prevspace, wordText, postspace in lineTagsText\ gmatch " (%s*)(%S+)(%s*)"
334
+ word = Table . copy lineTags
335
+ word. tags = Tags lineTagsTags
336
+ word. text = Text wordText
337
+ word. text. tagsBlocks[ 1 ] = Tags lineTagsTags
338
+ word. text_stripped = wordText
339
+ font = Font word. data
340
+ textExtents = font\ getTextExtents wordText
341
+ prevspace = prevspace\ len!
342
+ postspace = postspace\ len!
343
+ spacewidth = font\ getTextExtents( " " ) . width
344
+ left += prevspace * spacewidth
345
+ word. width = textExtents. width * ass. meta. video_x_correct_factor
346
+ word. left = left
347
+ word. center = left + word. width * 0.5
348
+ word. right = left + word. width
349
+ word. top = lineTags. top
350
+ word. middle = lineTags. middle
351
+ word. bottom = lineTags. bottom
352
+ word. x = switch l. data. an
353
+ when 1 , 4 , 7 then word. left
354
+ when 2 , 5 , 8 then word. center
355
+ when 3 , 6 , 9 then word. right
356
+ word. y = lineTags. y
357
+ left += word. width + postspace * spacewidth
358
+ words. n += 1
359
+ words[ words. n] = word
360
+ return words
361
+ else
362
+ error " You have to extend the line before you get the words" , 2
363
+
364
+ -- splits the text character by character
365
+ chars : ( ass, l, noblank) ->
366
+ if l. extended
367
+ chars = { n : 0 }
368
+ for i = 1 , l. lines. n
369
+ lineBreak = l. lines[ i]
370
+ left = switch l. data. an
371
+ when 1 , 4 , 7 then l. eff_margin_l
372
+ when 2 , 5 , 8 then ( ass. meta. res_x - l. eff_margin_l - l. eff_margin_r - lineBreak. width) / 2 + l. eff_margin_l
373
+ when 3 , 6 , 9 then ass. meta. res_x - l. eff_margin_r - lineBreak. width
374
+ for j = 1 , lineBreak. n
375
+ lineTags = lineBreak[ j]
376
+ lineTagsText = lineTags. text_stripped
377
+ lineTagsTags = lineTags. tags\ get!
378
+ for ci, charText in UTF8 ( lineTagsText) \ chars!
379
+ char = Table . copy lineTags
380
+ char. tags = Tags lineTagsTags
381
+ char. text = Text charText
382
+ char. text. tagsBlocks[ 1 ] = Tags lineTagsTags
383
+ char. text_stripped = charText
384
+ font = Font char. data
385
+ textExtents = font\ getTextExtents charText
386
+ char. width = textExtents. width * ass. meta. video_x_correct_factor
387
+ char. left = left
388
+ char. center = left + char. width * 0.5
389
+ char. right = left + char. width
390
+ char. top = lineTags. top
391
+ char. middle = lineTags. middle
392
+ char. bottom = lineTags. bottom
393
+ char. x = switch l. data. an
394
+ when 1 , 4 , 7 then char. left
395
+ when 2 , 5 , 8 then char. center
396
+ when 3 , 6 , 9 then char. right
397
+ char. y = lineTags. y
398
+ left += char. width
399
+ chars. n += 1
400
+ chars[ chars. n] = char
401
+ if noblank
402
+ charsNoblank = { n : 0 }
403
+ for char in * chars
404
+ unless Util . isBlank char. text_stripped
405
+ charsNoblank. n += 1
406
+ charsNoblank[ charsNoblank. n] = char
407
+ return charsNoblank
408
+ return chars
409
+ else
410
+ error " You have to extend the line before you get the characters" , 2
317
411
318
412
-- updates line information
319
413
update : ( ass, l, noblank) ->
320
414
l. lines = nil
321
415
l. data = nil
322
416
l. styleref = nil
417
+ l. extended = false
323
418
l. text = l. text\ __tostring!
324
419
Line . extend ass, l, noblank
325
420
0 commit comments