Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of specified font name #3429

Merged
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions manim/mobject/text/text_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,17 @@ def __init__(
**kwargs,
) -> None:
self.line_spacing = line_spacing
if font and warn_missing_font and font not in Text.font_list():
logger.warning(f"Font {font} not in {Text.font_list()}.")
if font and warn_missing_font:
fonts_list = Text.font_list()
# handle special case of sans/sans-serif
if font.lower() == "sans-serif":
font = "sans"
if font not in fonts_list:
# check if the capitalized version is in the supported fonts
if font.capitalize() in fonts_list:
font = font.capitalize()
else:
logger.warning(f"Font {font} not in {fonts_list}.")
self.font = font
self._font_size = float(font_size)
# needs to be a float or else size is inflated when font_size = 24
Expand Down Expand Up @@ -1169,8 +1178,17 @@ def __init__(
) -> None:
self.text = text
self.line_spacing = line_spacing
if font and warn_missing_font and font not in Text.font_list():
logger.warning(f"Font {font} not in {Text.font_list()}.")
if font and warn_missing_font:
fonts_list = Text.font_list()
# handle special case of sans/sans-serif
if font == "sans-serif":
font = "sans"
if font not in fonts_list:
# check if the capitalized version is in the supported fonts
if font.capitalize() in fonts_list:
font = font.capitalize()
else:
logger.warning(f"Font {font} not in {fonts_list}.")
self.font = font
self._font_size = float(font_size)
self.slant = slant
Expand Down
Loading