コード例 #1
0
def get_background_color(element: ContentElement) -> Optional[str]:
    """Returns the background color hex code"""
    background_color = element.get_style(StyleProperties.BackgroundColor)

    if background_color is None:
        return None

    (r, g, b, a) = background_color.components
    return "#{:02x}{:02x}{:02x}{:02x}".format(r, g, b, a)
コード例 #2
0
ファイル: style.py プロジェクト: sandflow/ttconv
def get_font_color(element: ContentElement) -> Optional[str]:
    """Returns the font color code if present"""
    font_color = element.get_style(StyleProperties.Color)

    if font_color is None:
        return None

    (r, g, b, a) = font_color.components
    return "#{:02x}{:02x}{:02x}{:02x}".format(r, g, b, a)
コード例 #3
0
    def _process_element(self, element: ContentElement):
        """Filter ISD element style properties"""

        element_styles = list(element.iter_styles())
        for style_prop in element_styles:

            if style_prop in self.supported_style_properties.keys():
                value = element.get_style(style_prop)
                supported_values = self.supported_style_properties[style_prop]

                if len(supported_values) == 0 or value in supported_values:
                    continue

            element.set_style(style_prop, None)

        for child in element:
            self._process_element(child)
コード例 #4
0
    def _process_element(self, element: ContentElement):
        """Filter ISD element style properties"""

        element_styles = list(element.iter_styles())
        for style_prop in element_styles:

            value = element.get_style(style_prop)
            default_value = self.style_property_default_values.get(style_prop)

            parent = element.parent()
            if parent is not None and style_prop.is_inherited:
                # If the parent style property value has not been removed, it means
                # the value is not set to default, and so that the child style property
                # value may have been "forced" to the default value, so let's skip it.
                parent_value = parent.get_style(style_prop)
                if parent_value is not None and parent_value is not value:
                    continue

            # Remove the style property if its value is default (and if it is not inherited)
            if default_value is not None and value == default_value:
                element.set_style(style_prop, None)

        for child in element:
            self._process_element(child)
コード例 #5
0
ファイル: test_scc_reader.py プロジェクト: RufaelDev/ttconv
 def check_element_style(self, elem: ContentElement, style_property: Type[StyleProperty], expected_value):
   self.assertEqual(expected_value, elem.get_style(style_property))
コード例 #6
0
ファイル: style.py プロジェクト: sandflow/ttconv
def is_element_underlined(element: ContentElement) -> bool:
    """Returns whether the element text is underlined"""
    text_decoration: Optional[TextDecorationType] = element.get_style(
        StyleProperties.TextDecoration)
    return text_decoration is not None and text_decoration.underline is True
コード例 #7
0
ファイル: style.py プロジェクト: sandflow/ttconv
def is_element_italic(element: ContentElement) -> bool:
    """Returns whether the element text is italic"""
    font_style: Optional[FontStyleType] = element.get_style(
        StyleProperties.FontStyle)
    return font_style is not None and font_style is FontStyleType.italic
コード例 #8
0
ファイル: style.py プロジェクト: sandflow/ttconv
def is_element_bold(element: ContentElement) -> bool:
    """Returns whether the element text is bold"""
    font_weight: Optional[FontWeightType] = element.get_style(
        StyleProperties.FontWeight)
    return font_weight is not None and font_weight is FontWeightType.bold