Skip to content

Commit

Permalink
Keep background color by default in LCD
Browse files Browse the repository at this point in the history
Add color syntax examples
  • Loading branch information
palemieux committed Dec 28, 2023
1 parent 1ed3230 commit d9a6323
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ tt convert -i <input .scc file> -o <output .ttml file>

Example:

`tt convert -i <.scc file> -o <.ttml file> --itype SCC --otype TTML --filter lcd --config '{"general": {"progress_bar":false, "log_level":"WARN"}, "lcd": {"bg_color": "blue"}}'`
`tt convert -i <.scc file> -o <.ttml file> --itype SCC --otype TTML --filter lcd --config '{"general": {"progress_bar":false, "log_level":"WARN"}, "lcd": {"bg_color": "transparent", "color": "#FF0000"}}'`

### General configuration (`"general"`)

Expand Down Expand Up @@ -230,17 +230,23 @@ Default: `10`

`"color" : <TTML color> | null`

If not `null`, overrides text color
If not `null`, overrides text color. The syntax of `TTML color` is
specified at <https://www.w3.org/TR/ttml2/#style-value-color>.

Default: `null`

Examples: `"#FFFFFF"` (white), `"white"`

#### bg_color

`"color" : <TTML color>`
`"bg_color" : <TTML color>`

If not `null`, overrides the background color. The syntax of `TTML color` is
specified at <https://www.w3.org/TR/ttml2/#style-value-color>.

Specifies the background color of text areas
Default: `null`

Default: `"black"`
Examples: `"#FF0000"` (red), `"transparent"`, `"black`

## Library

Expand Down
10 changes: 7 additions & 3 deletions src/main/python/ttconv/filters/doc/lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def name(cls):
# overrides the text color
color: typing.Optional[ColorType] = field(default=None, metadata={"decoder": ttconv.utils.parse_color})

# specifies the paragraph background color
bg_color: typing.Optional[ColorType] = field(default=NamedColors.black.value, metadata={"decoder": ttconv.utils.parse_color})
# overrides the background color
bg_color: typing.Optional[ColorType] = field(default=None, metadata={"decoder": ttconv.utils.parse_color})

class LCDDocFilter(DocumentFilter):
"""Merges regions and removes all text formatting with the exception of color
Expand Down Expand Up @@ -109,6 +109,9 @@ def process(self, doc: ContentDocument) -> ContentDocument:
if self.config.color is None:
supported_styles.update({StyleProperties.Color: []})

if self.config.bg_color is None:
supported_styles.update({StyleProperties.BackgroundColor: []})

style_filter = SupportedStylePropertiesFilter(supported_styles)

style_filter.process_initial_values(doc)
Expand Down Expand Up @@ -236,12 +239,13 @@ def process(self, doc: ContentDocument) -> ContentDocument:
doc.remove_region(region.get_id())

# apply background color
if doc.get_body() is not None and self.config.bg_color is not None:
if self.config.bg_color is not None:
_apply_bg_color(doc.get_body(), self.config.bg_color)

# apply text color
if doc.get_body() is not None and self.config.color is not None:
doc.get_body().set_style(StyleProperties.Color, self.config.color)

# apply text align
if doc.get_body() is not None and not self.config.preserve_text_align:
doc.get_body().set_style(StyleProperties.TextAlign, TextAlignType.center)

0 comments on commit d9a6323

Please sign in to comment.