diff --git a/src/main/python/ttconv/vtt/reader.py b/src/main/python/ttconv/vtt/reader.py index 58f98d83..802f7f93 100644 --- a/src/main/python/ttconv/vtt/reader.py +++ b/src/main/python/ttconv/vtt/reader.py @@ -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": diff --git a/src/test/python/test_vtt_reader.py b/src/test/python/test_vtt_reader.py index 6540da79..ab4db3cb 100644 --- a/src/test/python/test_vtt_reader.py +++ b/src/test/python/test_vtt_reader.py @@ -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__':