From d9a632341e28cdda7ecb6bfd602dcfeffd0d6b64 Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Thu, 28 Dec 2023 08:59:06 -0800 Subject: [PATCH] Keep background color by default in LCD Add color syntax examples --- README.md | 16 +++++++++++----- src/main/python/ttconv/filters/doc/lcd.py | 10 +++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ec3e4ee9..8ab498f6 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ tt convert -i -o 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"`) @@ -230,17 +230,23 @@ Default: `10` `"color" : | null` -If not `null`, overrides text color +If not `null`, overrides text color. The syntax of `TTML color` is +specified at . Default: `null` +Examples: `"#FFFFFF"` (white), `"white"` + #### bg_color -`"color" : ` +`"bg_color" : ` + +If not `null`, overrides the background color. The syntax of `TTML color` is +specified at . -Specifies the background color of text areas +Default: `null` -Default: `"black"` +Examples: `"#FF0000"` (red), `"transparent"`, `"black` ## Library diff --git a/src/main/python/ttconv/filters/doc/lcd.py b/src/main/python/ttconv/filters/doc/lcd.py index 6f7b6697..a0eed011 100644 --- a/src/main/python/ttconv/filters/doc/lcd.py +++ b/src/main/python/ttconv/filters/doc/lcd.py @@ -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 @@ -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) @@ -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)