Skip to content

* Impose positive length constraints on data model to match IMSC#486

Merged
palemieux merged 11 commits intomasterfrom
issues/impose-imsc11-constraints-to-model
Mar 2, 2026
Merged

* Impose positive length constraints on data model to match IMSC#486
palemieux merged 11 commits intomasterfrom
issues/impose-imsc11-constraints-to-model

Conversation

@palemieux
Copy link
Contributor

@palemieux palemieux commented Mar 1, 2026

  • Fix WebVTT reader positioning algorithm

Closes #483
Closes #487

@palemieux
Copy link
Contributor Author

@eko I would appreciate your quick review of this PR. The algorithm for converting WebVTT cue positioning to IMSC region positioning has been modified, for the better I hope.

Copy link
Contributor

@eko eko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @palemieux,

This VTT reader rewrite looks like a significant improvement, the ipd/bpd decomposition is much cleaner, and the positioning logic seems more correct.

I've converted a few subtitle files I had on hand, and the results look correct :-)

The style_properties.py changes are in the same direction we were heading (enforcing positive lengths at the model level).

I've left a few comments, I'm not sure about all of them, but I hope they can be helpful for your review.

value = cue_settings.get("align")
if value in ("left", "right", "start", "center", "end"):
cue_text_align = value
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about moving to elif value is not None: here?

Because when align is not in the cue settings, value is None, which falls into else and logs "Bad align setting value: center". The old code had elif value is not None: to guard against this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 7595386

if not isinstance(self.units, LengthType.Units):
raise ValueError("Invalid units")

def is_positive(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 is_positive() returns self.value >= 0, which is mathematically "non-negative", not "positive". is_non_negative() would be clearer.

Copy link
Contributor Author

@palemieux palemieux Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my mind, value > 0 is strictly positive, so that value >= 0 is positive :)

... but non-negative is completely unambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed at 7595386

# position value
cue_position = parse_vtt_pct(value[0])
if cue_position is None:
LOGGER.warning("Bad position alignment setting value: %s", cue_position_align)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cue_position_align looks to be None at this point, I think you wanted to use cue_position here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed at 7595386

def validate(value: Numeric):
return isinstance(value, numbers.Number)

return isinstance(value, numbers.Number) and value > 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 I am not sure about this one but TTML spec says that luminanceGain is a non-negative number and here it's strictly positive, maybe this value should be >= 0.0?

https://www.w3.org/TR/2018/REC-ttml2-20181108/#style-attribute-luminanceGain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tts:luminanceGain == 0 is absurd, but, as you say, syntactically permitted in TTML 2!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed at 7595386

@palemieux palemieux requested a review from eko March 2, 2026 02:04
@palemieux
Copy link
Contributor Author

@eko Thanks so much for the review. I plan to release a beta version shortly.

@palemieux palemieux merged commit 99b9779 into master Mar 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebVTT reader generates regions that extends past the root container Validate length polarity at StyleProperties

2 participants