Skip to content

Commit

Permalink
tts:direction special inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
palemieux committed Nov 17, 2023
1 parent df085d8 commit 21f6762
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/python/ttconv/isd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
35 changes: 35 additions & 0 deletions src/test/python/test_isd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """<?xml version="1.0" encoding="utf-8"?>
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="en">
<head>
<layout>
<region xml:id="rl" tts:writingMode="rl"/>
<region xml:id="lr" tts:writingMode="rl" tts:direction="ltr"/>
</layout>
</head>
<body>
<div>
<p region="rl" begin="0s" end="1s">tts:direction should be "rtl".</p>
<p region="lr" begin="0s" end="1s">tts:direction should be "ltr".</p>
</div>
</body>
</tt>"""

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):

"""
Expand Down

0 comments on commit 21f6762

Please sign in to comment.