From d9db1601d3a34c499d85a76386253d194475f106 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:56:45 +0200 Subject: lettering along path: remove previous transforms (#2973) --- lib/lettering/__init__.py | 1 + lib/lettering/utils.py | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'lib/lettering') diff --git a/lib/lettering/__init__.py b/lib/lettering/__init__.py index dcfccaba..60d47581 100644 --- a/lib/lettering/__init__.py +++ b/lib/lettering/__init__.py @@ -5,3 +5,4 @@ from .font import Font, FontError from .utils import get_font_list +from .utils import get_font_by_id diff --git a/lib/lettering/utils.py b/lib/lettering/utils.py index f4e2b0a7..d1ec1b8e 100644 --- a/lib/lettering/utils.py +++ b/lib/lettering/utils.py @@ -13,23 +13,42 @@ from ..utils import get_bundled_dir def get_font_list(): + font_paths = get_font_paths() + fonts = [] + 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 + + +def get_font_paths(): font_paths = { get_bundled_dir("fonts"), os.path.expanduser("~/.inkstitch/fonts"), os.path.join(appdirs.user_config_dir('inkstitch'), 'fonts'), get_custom_font_dir() } + return font_paths + +def get_font_by_id(font_id): + font_paths = get_font_paths() 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 + if font.id == font_id: + return font + return None -- cgit v1.2.3