Repository: ManimCommunity/manim
File: manim/mobject/svg/text_mobject.py (Python)

Code before:
            * self._font_size
            / DEFAULT_FONT_SIZE
        )

    @font_size.setter
    def font_size(self, font_val):
        # TODO: use pango's font size scaling.
        if font_val <= 0:
            raise ValueError("font_size must be greater than 0.")
        else:
            self.scale(font_val / self.font_size)

    def _text2hash(self, color: Color):
        """Generates ``sha256`` hash for file name."""
        settings = (
            "MARKUPPANGO" + self.font + self.slant + self.weight + color.hex_l
        )  # to differentiate from classical Pango Text
        settings += str(self.line_spacing) + str(self._font_size)
        settings += str(self.disable_ligatures)
        settings += str(self.justify)
        id_str = self.text + settings
        hasher = hashlib.sha256()
        hasher.update(id_str.encode())
        return hasher.hexdigest()[:16]

    def _text2svg(self, color: Optional[Color]):
        """Convert the text to SVG using Pango."""
        size = self._font_size
        line_spacing = self.line_spacing
        size /= TEXT2SVG_ADJUSTMENT_FACTOR
        line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR

        dir_name = config.get_dir("text_dir")
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)
        hash_name = self._text2hash(color)
        file_name = os.path.join(dir_name, hash_name) + ".svg"
        if os.path.exists(file_name):
            svg_file = file_name
        else:
            final_text = (
                f'<span foreground="{color}">{self.text}</span>'
                if color is not None
                else self.text
            )
            logger.debug(f"Setting Text {self.text}")
            svg_file = MarkupUtils.text2svg(
                final_text,
                self.font,
                self.slant,
                self.weight,

Review comment (suggestion):
```suggestion
    def _text2svg(self, color: Color | None):
```


Code after:
            * self._font_size
            / DEFAULT_FONT_SIZE
        )

    @font_size.setter
    def font_size(self, font_val):
        # TODO: use pango's font size scaling.
        if font_val <= 0:
            raise ValueError("font_size must be greater than 0.")
        else:
            self.scale(font_val / self.font_size)

    def _text2hash(self, color: Color):
        """Generates ``sha256`` hash for file name."""
        settings = (
            "MARKUPPANGO" + self.font + self.slant + self.weight + color.hex_l
        )  # to differentiate from classical Pango Text
        settings += str(self.line_spacing) + str(self._font_size)
        settings += str(self.disable_ligatures)
        settings += str(self.justify)
        id_str = self.text + settings
        hasher = hashlib.sha256()
        hasher.update(id_str.encode())
        return hasher.hexdigest()[:16]

    def _text2svg(self, color: Color | None):
        """Convert the text to SVG using Pango."""
        size = self._font_size
        line_spacing = self.line_spacing
        size /= TEXT2SVG_ADJUSTMENT_FACTOR
        line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR

        dir_name = config.get_dir("text_dir")
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)
        hash_name = self._text2hash(color)
        file_name = os.path.join(dir_name, hash_name) + ".svg"
        if os.path.exists(file_name):
            svg_file = file_name
        else:
            final_text = (
                f'<span foreground="{color}">{self.text}</span>'
                if color is not None
                else self.text
            )
            logger.debug(f"Setting Text {self.text}")
            svg_file = MarkupUtils.text2svg(
                final_text,
                self.font,
                self.slant,
                self.weight,