Skip to content

Commit 55190a9

Browse files
VTT reader does not display cues with negative line attribute values (#476)
#475
1 parent 3788df9 commit 55190a9

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/main/python/ttconv/vtt/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def _get_or_make_region(
292292
line_num = parse_vtt_int(value[0])
293293
if line_num is not None:
294294
if writing_mode in (styles.WritingModeType.rltb, styles.WritingModeType.lrtb):
295-
line_offset = 100 * line_num/_DEFAULT_ROWS if line_num > 0 else 100 - 100 * line_num/_DEFAULT_ROWS
295+
line_offset = 100 * line_num/_DEFAULT_ROWS if line_num >= 0 else 100 + 100 * line_num/_DEFAULT_ROWS
296296
else:
297-
line_offset = 100 * line_num/_DEFAULT_COLS if line_num > 0 else 100 - 100 * line_num/_DEFAULT_COLS
297+
line_offset = 100 * line_num/_DEFAULT_COLS if line_num >= 0 else 100 + 100 * line_num/_DEFAULT_COLS
298298

299299
if line_offset is not None:
300300
if line_align == "center":

src/test/python/test_vtt_reader.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,40 @@ def test_ruby(self):
319319
self.assertIsNotNone(to_model(f))
320320

321321

322+
def test_line_origin_extent(self):
323+
f = io.StringIO(r"""WEBVTT
324+
325+
1
326+
00:00:00.000 --> 00:00:02.000 line:0
327+
Line 0 starting from top
328+
329+
2
330+
00:00:03.000 --> 00:00:05.000 line:5
331+
Line 5 starting from top
332+
333+
3
334+
00:00:06.000 --> 00:00:08.000 line:45%
335+
Line in percentage
336+
337+
4
338+
00:00:09.000 --> 00:00:11.000 line:-1
339+
Line 1 starting from bottom
340+
""")
341+
doc = to_model(f)
342+
regions = list(doc.iter_regions())
343+
# line 0 starting from top
344+
self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Origin).y.value), 0)
345+
self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Extent).height.value), 100)
346+
# line 5 starting from top
347+
self.assertEqual(round(regions[1].get_style(styles.StyleProperties.Origin).y.value), 22)
348+
self.assertEqual(round(regions[1].get_style(styles.StyleProperties.Extent).height.value), 78)
349+
# line in percentage
350+
self.assertEqual(round(regions[2].get_style(styles.StyleProperties.Origin).y.value), 45)
351+
self.assertEqual(round(regions[2].get_style(styles.StyleProperties.Extent).height.value), 55)
352+
# line 1 starting from bottom
353+
self.assertEqual(round(regions[3].get_style(styles.StyleProperties.Origin).y.value), 96)
354+
self.assertEqual(round(regions[3].get_style(styles.StyleProperties.Extent).height.value), 4)
355+
322356

323357

324358
if __name__ == '__main__':

0 commit comments

Comments
 (0)