diff options
Diffstat (limited to 'lib/lettering')
| -rw-r--r-- | lib/lettering/__init__.py | 1 | ||||
| -rw-r--r-- | lib/lettering/utils.py | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/lettering/__init__.py b/lib/lettering/__init__.py index a733aa9f..dcfccaba 100644 --- a/lib/lettering/__init__.py +++ b/lib/lettering/__init__.py @@ -4,3 +4,4 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. from .font import Font, FontError +from .utils import get_font_list diff --git a/lib/lettering/utils.py b/lib/lettering/utils.py new file mode 100644 index 00000000..f4e2b0a7 --- /dev/null +++ b/lib/lettering/utils.py @@ -0,0 +1,35 @@ +# Authors: see git history +# +# Copyright (c) 2024 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +import os + +import appdirs + +from ..extensions.lettering_custom_font_dir import get_custom_font_dir +from ..lettering import Font +from ..utils import get_bundled_dir + + +def get_font_list(): + fonts = [] + font_paths = { + get_bundled_dir("fonts"), + os.path.expanduser("~/.inkstitch/fonts"), + os.path.join(appdirs.user_config_dir('inkstitch'), 'fonts'), + get_custom_font_dir() + } + + for font_path in font_paths: + try: + font_dirs = os.listdir(font_path) + except OSError: + continue + + for font_dir in font_dirs: + font = Font(os.path.join(font_path, font_dir)) + if font.marked_custom_font_name == "" or font.marked_custom_font_id == "": + continue + fonts.append(font) + return fonts |
