Skip to content

Disallow 'c' units for all style properties with the exception of ebutts:linePadding #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 57 additions & 13 deletions src/main/python/ttconv/style_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class ExtentType:
height: LengthType = LengthType()
width: LengthType = LengthType()

def __post_init__(self):
if not isinstance(self.height, LengthType) or not isinstance(self.width, LengthType):
raise ValueError("Dimensions must be a length")

class GenericFontFamilyType(Enum):
'''\\<generic-family-name\\>
'''
Expand Down Expand Up @@ -186,6 +190,10 @@ class PaddingType:
after: LengthType = LengthType()
start: LengthType = LengthType()

def __post_init__(self):
if not isinstance(self.before, LengthType) or not isinstance(self.end, LengthType) \
or not isinstance(self.after, LengthType) or not isinstance(self.start, LengthType):
raise ValueError("Dimensions must be a length")

class RubyAlignType(Enum):
'''tts:rubyAlign value
Expand All @@ -209,6 +217,10 @@ class Position(Enum):
position: Position = Position.outside
length: LengthType = None

def __post_init__(self):
if self.length is not None and not isinstance(self.length, LengthType):
raise ValueError("Length must be a length")

class ShowBackgroundType(Enum):
'''tts:showBackground values
'''
Expand Down Expand Up @@ -313,8 +325,11 @@ class Shadow:
blur_radius: typing.Optional[LengthType] = None
color: typing.Optional[ColorType] = None

shadows: typing.Tuple[TextShadowType.Shadow]
def __post_init__(self):
if self.blur_radius is not None and not isinstance(self.blur_radius, LengthType):
raise ValueError("The blur_radius value must be a length")

shadows: typing.Tuple[TextShadowType.Shadow]

class UnicodeBidiType(Enum):
'''tts:unicodeBidi values
Expand Down Expand Up @@ -354,6 +369,9 @@ class CoordinateType:
x: LengthType
y: LengthType

def __post_init__(self):
if not isinstance(self.x, LengthType) or not isinstance(self.y, LengthType):
raise ValueError("Coordinates must be a length")

@dataclass(frozen=True)
class PositionType:
Expand All @@ -372,6 +390,13 @@ class VEdge(Enum):
h_edge: HEdge = HEdge.left
v_edge: VEdge = VEdge.top

def __post_init__(self):
if not isinstance(self.h_offset, LengthType) or not isinstance(self.v_offset, LengthType):
raise ValueError("Offset must be a length")

if LengthType.Units.c in (self.h_offset.units, self.v_offset.units):
raise ValueError("Offset must not be in 'c' units")

#
# Style properties
#
Expand Down Expand Up @@ -465,7 +490,7 @@ def make_initial_value():

@staticmethod
def validate(value):
return isinstance(value, LengthType)
return isinstance(value, LengthType) and value.units != LengthType.Units.c

class Display(StyleProperty):
'''Corresponds to tts:display.'''
Expand Down Expand Up @@ -514,8 +539,8 @@ def make_initial_value():
@staticmethod
def validate(value: ExtentType):
return isinstance(value, ExtentType) \
and value.width.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.c, LengthType.Units.rw) \
and value.height.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.c, LengthType.Units.rh)
and value.width.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.rw) \
and value.height.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.rh)


class FillLineGap(StyleProperty):
Expand Down Expand Up @@ -605,7 +630,7 @@ def make_initial_value():

@staticmethod
def validate(value):
return value == SpecialValues.normal or isinstance(value, LengthType)
return value == SpecialValues.normal or (isinstance(value, LengthType) and value.units != LengthType.Units.c)


class LinePadding(StyleProperty):
Expand Down Expand Up @@ -685,8 +710,8 @@ def make_initial_value():
@staticmethod
def validate(value: CoordinateType):
return isinstance(value, CoordinateType) \
and value.x.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.c, LengthType.Units.rw) \
and value.y.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.c, LengthType.Units.rh)
and value.x.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.rw) \
and value.y.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.rh)


class Overflow(StyleProperty):
Expand Down Expand Up @@ -716,8 +741,10 @@ def make_initial_value():

@staticmethod
def validate(value):
return isinstance(value, PaddingType)
if not isinstance(value, PaddingType):
return False

return LengthType.Units.c not in (value.before.units, value.end.units, value.after.units, value.start.units)

class Position(StyleProperty):
'''Corresponds to tts:position.'''
Expand All @@ -735,8 +762,8 @@ def make_initial_value():
@staticmethod
def validate(value: PositionType):
return isinstance(value, PositionType) \
and value.h_offset.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.c, LengthType.Units.rw) \
and value.v_offset.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.c, LengthType.Units.rh)
and value.h_offset.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.rw) \
and value.v_offset.units in (LengthType.Units.pct, LengthType.Units.px, LengthType.Units.rh)

class RubyAlign(StyleProperty):
'''Corresponds to tts:rubyAlign.'''
Expand Down Expand Up @@ -780,8 +807,13 @@ def make_initial_value():

@staticmethod
def validate(value):
return value == SpecialValues.none or isinstance(value, RubyReserveType)
if value == SpecialValues.none:
return True

if not isinstance(value, RubyReserveType):
return False

return value.length is None or value.length.units != LengthType.Units.c

class Shear(StyleProperty):
'''Corresponds to tts:shear.'''
Expand Down Expand Up @@ -892,7 +924,13 @@ def make_initial_value():

@staticmethod
def validate(value):
return value == SpecialValues.none or isinstance(value, TextOutlineType)
if value == SpecialValues.none:
return True

if not isinstance(value, TextOutlineType):
return False

return value.thickness.units != LengthType.Units.c


class TextShadow(StyleProperty):
Expand All @@ -908,7 +946,13 @@ def make_initial_value():

@staticmethod
def validate(value):
return value == SpecialValues.none or isinstance(value, TextShadowType)
if value == SpecialValues.none:
return True

if not isinstance(value, TextShadowType):
return False

return all(s.blur_radius is None or s.blur_radius.units != LengthType.Units.c for s in value.shadows)


class UnicodeBidi(StyleProperty):
Expand Down
1 change: 1 addition & 0 deletions src/test/python/test_isd.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def test_compute_extent_px(self):
self.assertAlmostEqual(extent.height.value, 100*25/doc.get_px_resolution().height)
self.assertEqual(extent.height.units, styles.LengthType.Units.rh)

@unittest.skip("Removing support for 'c' units other with ebutts:linePadding")
def test_compute_extent_c(self):
doc = model.ContentDocument()

Expand Down