From fbe2d8ac495922f9b20b29fe98f2f548ea29c351 Mon Sep 17 00:00:00 2001 From: Star Brilliant Date: Sun, 24 Nov 2013 13:59:15 +0800 Subject: [PATCH] Fix TestFreeRows --- danmaku2ass.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/danmaku2ass.py b/danmaku2ass.py index e0fe406..05df597 100755 --- a/danmaku2ass.py +++ b/danmaku2ass.py @@ -353,15 +353,26 @@ def ProcessComments(comments, f, width, height, bottomReserved, fontface, fontsi def TestFreeRows(rows, c, row, width, height, bottomReserved, lifetime): res = 0 rowmax = height-bottomReserved-c[7] - while row < rowmax and res < c[7]: - if c[4] in (1, 2): + if c[4] in (1, 2): + while row < rowmax and res < c[7]: if rows[c[4]][row] and rows[c[4]][row][0]+lifetime > c[0]: break - else: - if rows[c[4]][row] and rows[c[4]][row][0]+lifetime*(rows[c[4]][row][8]+c[8])/width > c[0]: - break - row += 1 - res += 1 + row += 1 + res += 1 + else: + try: + thresholdTime = c[0]-lifetime*(1-width/(c[8]+width)) + except ZeroDivisionError: + thresholdTime = c[0]-lifetime + while row < rowmax and res < c[7]: + targetRow = rows[c[4]][row] + try: + if targetRow and (targetRow[0] > thresholdTime or targetRow[0]+targetRow[8]*lifetime/(targetRow[8]+width) > c[0]): + break + except ZeroDivisionError: + pass + row += 1 + res += 1 return res