diff --git a/src/main/python/ttconv/isd.py b/src/main/python/ttconv/isd.py index 797a1085..656c2dbf 100644 --- a/src/main/python/ttconv/isd.py +++ b/src/main/python/ttconv/isd.py @@ -505,6 +505,17 @@ def _process_element( styles_to_be_computed.add(spec_style_prop) isd_element.set_style(spec_style_prop, element.get_style(spec_style_prop)) + # direction special semantics + # https://www.w3.org/TR/ttml2/#style-attribute-direction-special-semantics + + if isinstance(element, model.Region) and \ + (not element.has_style(styles.StyleProperties.Direction)) and \ + element.get_style(styles.StyleProperties.WritingMode) in (styles.WritingModeType.lrtb, styles.WritingModeType.rltb): + styles_to_be_computed.add(styles.StyleProperties.Direction) + direction = styles.DirectionType.ltr if element.get_style(styles.StyleProperties.WritingMode) == styles.WritingModeType.lrtb \ + else styles.DirectionType.rtl + isd_element.set_style(styles.StyleProperties.Direction, direction) + # inherited styling if not isinstance(element, (model.Br, model.Text, model.Region)): diff --git a/src/test/python/test_isd.py b/src/test/python/test_isd.py index 6c771e7a..bbea2fcb 100644 --- a/src/test/python/test_isd.py +++ b/src/test/python/test_isd.py @@ -519,6 +519,41 @@ def test_textEmphasis_auto(self): styles.TextEmphasisType.Position.outside ) + def test_direction_special_semantics(self): + """https://github.com/sandflow/ttconv/issues/400""" + xml_str = """ + + + + + + + + +
+

tts:direction should be "rtl".

+

tts:direction should be "ltr".

+
+ +
""" + + tree = et.ElementTree(et.fromstring(xml_str)) + doc = imsc_reader.to_model(tree) + + p1 = (ISD.from_model(doc, 0).get_region("rl"))[0][0][0][0] + + self.assertEqual( + p1.get_style(styles.StyleProperties.Direction), + styles.DirectionType.rtl + ) + + p2 = (ISD.from_model(doc, 0).get_region("lr"))[0][0][0][0] + + self.assertEqual( + p2.get_style(styles.StyleProperties.Direction), + styles.DirectionType.ltr + ) + class ContentDocument1Test(unittest.TestCase): """