From 637ef4cbeab4fbf51a857f74676554f0a73e2a70 Mon Sep 17 00:00:00 2001 From: pcochenn Date: Tue, 30 Dec 2025 16:25:30 +0000 Subject: [PATCH 1/2] 475: VTT reader does not display cues with negative line attribute values --- src/main/python/ttconv/vtt/reader.py | 4 ++-- src/test/python/test_vtt_reader.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/python/ttconv/vtt/reader.py b/src/main/python/ttconv/vtt/reader.py index 58f98d83..abeae021 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..d348166e 100644 --- a/src/test/python/test_vtt_reader.py +++ b/src/test/python/test_vtt_reader.py @@ -319,6 +319,30 @@ def test_ruby(self): self.assertIsNotNone(to_model(f)) + def test_line_origin_extent(self): + f = io.StringIO(r"""WEBVTT + +00:00:00.000 --> 00:00:02.000 line:1 +Line 1 starting from top + +00:00:03.000 --> 00:00:05.000 line:45% +Line in percentage + +00:00:07.000 --> 00:00:09.000 line:-1 +Line 1 starting from bottom +""") + doc = to_model(f) + regions = list(doc.iter_regions()) + # line 1 starting from top + self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Origin).y.value), 4) + self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Extent).height.value), 96) + # line in percentage + self.assertEqual(round(regions[1].get_style(styles.StyleProperties.Origin).y.value), 45) + self.assertEqual(round(regions[1].get_style(styles.StyleProperties.Extent).height.value), 55) + # line 1 starting from bottom + self.assertEqual(round(regions[2].get_style(styles.StyleProperties.Origin).y.value), 96) + self.assertEqual(round(regions[2].get_style(styles.StyleProperties.Extent).height.value), 4) + if __name__ == '__main__': From 4db3e3517d16a18b5144a9d1ffc320bc0796fa34 Mon Sep 17 00:00:00 2001 From: pcochenn Date: Wed, 31 Dec 2025 07:45:55 +0000 Subject: [PATCH 2/2] 475: VTT reader does not display cues with negative line attribute values --- src/main/python/ttconv/vtt/reader.py | 4 ++-- src/test/python/test_vtt_reader.py | 32 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/python/ttconv/vtt/reader.py b/src/main/python/ttconv/vtt/reader.py index abeae021..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 d348166e..ab4db3cb 100644 --- a/src/test/python/test_vtt_reader.py +++ b/src/test/python/test_vtt_reader.py @@ -322,26 +322,36 @@ def test_ruby(self): def test_line_origin_extent(self): f = io.StringIO(r"""WEBVTT -00:00:00.000 --> 00:00:02.000 line:1 -Line 1 starting from top +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 -00:00:03.000 --> 00:00:05.000 line:45% +3 +00:00:06.000 --> 00:00:08.000 line:45% Line in percentage -00:00:07.000 --> 00:00:09.000 line:-1 +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 1 starting from top - self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Origin).y.value), 4) - self.assertEqual(round(regions[0].get_style(styles.StyleProperties.Extent).height.value), 96) + # 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[1].get_style(styles.StyleProperties.Origin).y.value), 45) - self.assertEqual(round(regions[1].get_style(styles.StyleProperties.Extent).height.value), 55) + 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[2].get_style(styles.StyleProperties.Origin).y.value), 96) - self.assertEqual(round(regions[2].get_style(styles.StyleProperties.Extent).height.value), 4) + 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)