Skip to content

Commit

Permalink
Use direction instead of writing mode to determine vtt test align
Browse files Browse the repository at this point in the history
  • Loading branch information
palemieux committed Nov 17, 2023
1 parent b4c3ca7 commit 2a1cee7
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/main/python/ttconv/vtt/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 2a1cee7

Please sign in to comment.