Skip to content

Commit

Permalink
fixed bug that incorrectly registered the FAUSans font (strangely onl…
Browse files Browse the repository at this point in the history
…y occurred lately)
  • Loading branch information
richrobe committed Mar 31, 2023
1 parent f70c6b4 commit 3f2bdd3
Show file tree
Hide file tree
Showing 4 changed files with 1,731 additions and 139 deletions.
2 changes: 1 addition & 1 deletion fau_colors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.5.3"
__version__ = "1.6.0"

from fau_colors._utils import export_as_gpl, export_as_tex
from fau_colors.fonts import register_fausans_font
Expand Down
34 changes: 18 additions & 16 deletions fau_colors/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,27 @@ def register_fausans_font():
Path.home().joinpath(".fonts"), # Linux
Path("C:/Windows/Fonts/"), # Windows
]

font_found = False
for path in possible_paths:
if path.exists():
font_paths = sorted(path.rglob("FAUSansOffice-*.ttf"))
for font_path in font_paths:
if font_path.is_file():
# check if font is already registered
if "FAUSans Office" in font_manager.fontManager.get_font_names():
plt.rcParams["font.family"] = "sans-serif"
plt.rcParams["font.sans-serif"] = "FAUSans Office"
return
font_manager.fontManager.addfont(font_path)
print(
"Successfully registered FAU Sans font. "
"You can now use it in matplotlib by adding the following lines to your code:\n\n"
'plt.rcParams["font.family"] = "sans-serif"\n'
'plt.rcParams["font.sans-serif"] = "FAUSans Office"'
)
return

raise FileNotFoundError(
"Could not find 'FAUSansOffice-Regular.ttf' on your system. Please install it manually and try again."
)
if not font_found and "FAUSans Office" not in font_manager.fontManager.get_font_names():
print(
"Successfully registered FAU Sans font. "
"You can now use it in matplotlib by adding the following lines to your code:\n\n"
'plt.rcParams["font.family"] = "sans-serif"\n'
'plt.rcParams["font.sans-serif"] = "FAUSans Office"'
)
font_found = True

if font_found and "FAUSans Office" in font_manager.fontManager.get_font_names():
plt.rcParams["font.family"] = "sans-serif"
plt.rcParams["font.sans-serif"] = "FAUSans Office"
else:
raise FileNotFoundError(
"Could not find 'FAUSans Office' font on your system. Please install it manually and try again."
)
Loading

0 comments on commit 3f2bdd3

Please sign in to comment.