Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/python/ttconv/vtt/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ def _get_or_make_region(
line_num = parse_vtt_int(value[0])
if line_num is not None:
if writing_mode in (styles.WritingModeType.rltb, styles.WritingModeType.lrtb):
line_offset = 100 * line_num/_DEFAULT_ROWS if line_num > 0 else 100 - 100 * line_num/_DEFAULT_ROWS
line_offset = 100 * line_num/_DEFAULT_ROWS if line_num >= 0 else 100 + 100 * line_num/_DEFAULT_ROWS
else:
line_offset = 100 * line_num/_DEFAULT_COLS if line_num > 0 else 100 - 100 * line_num/_DEFAULT_COLS
line_offset = 100 * line_num/_DEFAULT_COLS if line_num >= 0 else 100 + 100 * line_num/_DEFAULT_COLS

if line_offset is not None:
if line_align == "center":
Expand Down
34 changes: 34 additions & 0 deletions src/test/python/test_vtt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,40 @@ def test_ruby(self):
self.assertIsNotNone(to_model(f))


def test_line_origin_extent(self):
f = io.StringIO(r"""WEBVTT

1
00:00:00.000 --> 00:00:02.000 line:0
Line 0 starting from top

2
00:00:03.000 --> 00:00:05.000 line:5
Line 5 starting from top

3
00:00:06.000 --> 00:00:08.000 line:45%
Line in percentage

4
00:00:09.000 --> 00:00:11.000 line:-1
Line 1 starting from bottom
""")
doc = to_model(f)
regions = list(doc.iter_regions())
# line 0 starting from top
self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Origin).y.value), 0)
self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Extent).height.value), 100)
# line 5 starting from top
self.assertEqual(round(regions[1].get_style(styles.StyleProperties.Origin).y.value), 22)
self.assertEqual(round(regions[1].get_style(styles.StyleProperties.Extent).height.value), 78)
# line in percentage
self.assertEqual(round(regions[2].get_style(styles.StyleProperties.Origin).y.value), 45)
self.assertEqual(round(regions[2].get_style(styles.StyleProperties.Extent).height.value), 55)
# line 1 starting from bottom
self.assertEqual(round(regions[3].get_style(styles.StyleProperties.Origin).y.value), 96)
self.assertEqual(round(regions[3].get_style(styles.StyleProperties.Extent).height.value), 4)



if __name__ == '__main__':
Expand Down