diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index 3a2b0bd3df..1110258c4e 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -49,6 +49,8 @@ def construct(self): from __future__ import annotations +import functools + __all__ = ["Text", "Paragraph", "MarkupText", "register_font"] @@ -407,6 +409,11 @@ def construct(self): """ + @staticmethod + @functools.lru_cache(maxsize=None) + def font_list() -> list[str]: + return manimpango.list_fonts() + def __init__( self, text: str, @@ -431,13 +438,12 @@ def __init__( width: float = None, should_center: bool = True, disable_ligatures: bool = False, + use_svg_cache: bool = False, **kwargs, ) -> None: self.line_spacing = line_spacing - if font and warn_missing_font: - fonts_list = manimpango.list_fonts() - if font not in fonts_list: - logger.warning(f"Font {font} not in {fonts_list}.") + if font and warn_missing_font and font not in Text.font_list(): + logger.warning(f"Font {font} not in {Text.font_list()}.") self.font = font self._font_size = float(font_size) # needs to be a float or else size is inflated when font_size = 24 @@ -491,7 +497,7 @@ def __init__( height=height, width=width, should_center=should_center, - use_svg_cache=False, + use_svg_cache=use_svg_cache, **kwargs, ) self.text = text @@ -1133,6 +1139,11 @@ def construct(self): """ + @staticmethod + @functools.lru_cache(maxsize=None) + def font_list() -> list[str]: + return manimpango.list_fonts() + def __init__( self, text: str, @@ -1156,10 +1167,8 @@ def __init__( ) -> None: self.text = text self.line_spacing = line_spacing - if font and warn_missing_font: - fonts_list = manimpango.list_fonts() - if font not in fonts_list: - logger.warning(f"Font {font} not in {fonts_list}.") + if font and warn_missing_font and font not in Text.font_list(): + logger.warning(f"Font {font} not in {Text.font_list()}.") self.font = font self._font_size = float(font_size) self.slant = slant