Skip to content

Commit

Permalink
* Add support for stereoscopic 3D (disparity) (#30)
Browse files Browse the repository at this point in the history
* Add style property internal consistency unit test
  • Loading branch information
palemieux committed Sep 28, 2020
1 parent e57eea4 commit 43c0b4d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/main/python/ttconv/imsc/style_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ def extract(cls, context: StyleParsingContext, xml_attrib: str):
return styles.DirectionType[xml_attrib]


class Disparity(StyleProperty):
'''Corresponds to tts:disparity.
'''

ns = "http://www.w3.org/ns/ttml#styling"
local_name = "disparity"
model_prop = styles.StyleProperties.Disparity

@classmethod
def extract(cls, context: StyleParsingContext, xml_attrib: str):
return StyleProperties.ttml_length_to_model(context, xml_attrib)


class Display(StyleProperty):
'''Corresponds to tts:display.'''

Expand All @@ -95,6 +108,7 @@ class Display(StyleProperty):
def extract(cls, context: StyleParsingContext, xml_attrib: str):
return styles.DisplayType[xml_attrib]


class DisplayAlign(StyleProperty):
'''Corresponds to tts:displayAlign.'''

Expand Down
1 change: 1 addition & 0 deletions src/main/python/ttconv/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ class Region(ContentElement):

_applicableStyles = frozenset([
StyleProperties.BackgroundColor,
StyleProperties.Disparity,
StyleProperties.Display,
StyleProperties.DisplayAlign,
StyleProperties.Extent,
Expand Down
22 changes: 21 additions & 1 deletion src/main/python/ttconv/style_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,19 @@ def make_initial_value():
def validate(value):
return isinstance(value, DirectionType)

class Disparity(StyleProperty):
'''Corresponds to tts:disparity.'''

is_inherited = False
is_animatable = True

@staticmethod
def make_initial_value():
return LengthType()

@staticmethod
def validate(value):
return isinstance(value, LengthType)

class Display(StyleProperty):
'''Corresponds to tts:display.'''
Expand Down Expand Up @@ -581,7 +594,10 @@ class Origin(StyleProperty):

@staticmethod
def make_initial_value():
return PositionType()
return PositionType(
LengthType(0, LengthType.Units.pct),
LengthType(0, LengthType.Units.pct)
)

@staticmethod
def validate(value: PositionType):
Expand Down Expand Up @@ -611,6 +627,10 @@ class Padding(StyleProperty):
is_inherited = False
is_animatable = True

@staticmethod
def make_initial_value():
return PaddingType()

@staticmethod
def validate(value):
return isinstance(value, PaddingType)
Expand Down
2 changes: 1 addition & 1 deletion src/test/python/test_imsc_color_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''Unit tests for the IMSC color parser'''
'''Unit tests for the IMSC \\<color\\> parser'''

# pylint: disable=R0201,C0115,C0116

Expand Down
2 changes: 1 addition & 1 deletion src/test/python/test_imsc_font_families_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''Unit tests for the IMSC color parser'''
'''Unit tests for the IMSC \\<fontFamily\\> parser'''

# pylint: disable=R0201,C0115,C0116

Expand Down
41 changes: 41 additions & 0 deletions src/test/python/test_model_style_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright (c) 2020, Sandflow Consulting LLC
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''Unit tests for the style properties defined in the canonical model'''

# pylint: disable=R0201,C0115,C0116

import unittest
from ttconv.style_properties import StyleProperties

class TestModelStyleProperties(unittest.TestCase):

def test_make_initial(self):
for style in StyleProperties.ALL:
with self.subTest(style.__name__):
style.validate(style.make_initial_value())

if __name__ == '__main__':
unittest.main()

0 comments on commit 43c0b4d

Please sign in to comment.