Skip to content

Commit

Permalink
1.4.0: added function to register the official font of the FAU CI (FA…
Browse files Browse the repository at this point in the history
…USans) to matplotlib, assuming it was manually installed before.
  • Loading branch information
richrobe committed Jan 3, 2023
1 parent ae3d942 commit 4706e94
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 786 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.3.0"
__version__ = "1.4.0"

from fau_colors._utils import export_as_gpl
from fau_colors.v2021 import cmaps, colors, colors_all, colors_dark, colors_light, register_cmaps, unregister_cmaps
30 changes: 30 additions & 0 deletions fau_colors/fonts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path

from matplotlib import font_manager


def register_fausans_font():
"""Register the FAU Sans font.
This function tries to register the FAU Sans font by scanning the common font directories.
If the font is not found, it will throw an error.
Raises
------
FileNotFoundError
If the font file is not found.
"""
possible_paths = [
Path("/Library/Fonts/FAUSansOffice-Regular.ttf"), # macOS
Path("/usr/share/fonts/truetype/fausans/FAUSansOffice-Regular.ttf"), # Linux
Path("C:/Windows/Fonts/FAUSansOffice-Regular.ttf"), # Windows
]
for path in possible_paths:
if path.exists():
font_manager.fontManager.addfont(path)
return

raise FileNotFoundError(
"Could not find 'FAUSansOffice-Regular.ttf' on your system. Please install it manually and try again."
)
Loading

0 comments on commit 4706e94

Please sign in to comment.