From 2a1cee75789e6be4d11788d64b082c18137a460e Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Fri, 17 Nov 2023 11:24:44 -0800 Subject: [PATCH] Use direction instead of writing mode to determine vtt test align --- src/main/python/ttconv/vtt/writer.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/python/ttconv/vtt/writer.py b/src/main/python/ttconv/vtt/writer.py index e5b54ed8..5959f7c1 100644 --- a/src/main/python/ttconv/vtt/writer.py +++ b/src/main/python/ttconv/vtt/writer.py @@ -39,7 +39,8 @@ from ttconv.isd import ISD from ttconv.vtt.cue import VttCue from ttconv.vtt.css_class import CssClass -from ttconv.style_properties import ExtentType, PositionType, StyleProperties, FontStyleType, NamedColors, FontWeightType, TextDecorationType, DisplayAlignType, WritingModeType, TextAlignType +from ttconv.style_properties import DirectionType, ExtentType, PositionType, StyleProperties, FontStyleType, NamedColors, \ + FontWeightType, TextDecorationType, DisplayAlignType, TextAlignType LOGGER = logging.getLogger(__name__) @@ -87,8 +88,8 @@ def __init__(self, config: VTTWriterConfiguration): if self._config.text_align: supported_styles.update({ - StyleProperties.WritingMode: [], StyleProperties.TextAlign: [], + StyleProperties.Direction: [], }) self._filters.append(SupportedStylePropertiesFilter(supported_styles)) @@ -166,10 +167,6 @@ def process_p(self, region: ISD.Region, element: model.P, begin: Fraction, end: cue.set_begin(begin) cue.set_end(end) - writing_mode = region.get_style(StyleProperties.WritingMode) - if writing_mode not in (None, WritingModeType.rltb, WritingModeType.lrtb): - raise ValueError("Vertical text direction is not implemented") - if self._config.line_position: display_align = region.get_style(StyleProperties.DisplayAlign) position: PositionType = region.get_style(StyleProperties.Position) @@ -186,13 +183,14 @@ def process_p(self, region: ISD.Region, element: model.P, begin: Fraction, end: cue.set_align(VttCue.LineAlignment.center) if self._config.text_align: + direction = element.get_style(StyleProperties.Direction) text_align = element.get_style(StyleProperties.TextAlign) if text_align == TextAlignType.center: cue.set_textalign(VttCue.TextAlignment.center) elif text_align == TextAlignType.start: - cue.set_textalign(VttCue.TextAlignment.right if writing_mode == WritingModeType.rltb else VttCue.TextAlignment.left) + cue.set_textalign(VttCue.TextAlignment.right if direction == DirectionType.rtl else VttCue.TextAlignment.left) elif text_align == TextAlignType.end: - cue.set_textalign(VttCue.TextAlignment.left if writing_mode == WritingModeType.rltb else VttCue.TextAlignment.right) + cue.set_textalign(VttCue.TextAlignment.left if direction == DirectionType.rtl else VttCue.TextAlignment.right) self._paragraphs.append(cue)