diff --git a/font_collector/_version.py b/font_collector/_version.py index 9aa3f90..58039f5 100644 --- a/font_collector/_version.py +++ b/font_collector/_version.py @@ -1 +1 @@ -__version__ = "2.1.0" +__version__ = "2.1.1" diff --git a/font_collector/font_loader.py b/font_collector/font_loader.py index 5502bd8..ba7d762 100644 --- a/font_collector/font_loader.py +++ b/font_collector/font_loader.py @@ -1,7 +1,7 @@ import os import pickle from .font import Font -from matplotlib import font_manager +from find_system_fonts_filename import get_system_fonts_filename from pathlib import Path from tempfile import gettempdir from typing import List, Set @@ -60,7 +60,7 @@ def add_generated_font(font: Font): @staticmethod def load_system_fonts() -> Set[Font]: system_fonts: Set[Font] = set() - fonts_paths: Set[str] = set(font_manager.findSystemFonts()) + fonts_paths: Set[str] = get_system_fonts_filename() system_font_cache_file = FontLoader.get_system_font_cache_file_path() if os.path.exists(system_font_cache_file): @@ -79,11 +79,7 @@ def load_system_fonts() -> Set[Font]: # Add font that have been installed since last execution added = fonts_paths.difference(cached_paths) for font_path in added: - try: - system_fonts.update(Font.from_font_path(font_path)) - except FileExistsError: - # matplotlib can sometimes returns file that aren't font: "C:\WINDOWS\Fonts\desktop.ini" - continue + system_fonts.update(Font.from_font_path(font_path)) # If there is a change, update the cache file if len(added) > 0 or len(removed) > 0: @@ -93,11 +89,7 @@ def load_system_fonts() -> Set[Font]: else: # Since there is no cache file, load the font for font_path in fonts_paths: - try: - system_fonts.update(Font.from_font_path(font_path)) - except FileExistsError: - # matplotlib can sometimes returns file that aren't font: "C:\WINDOWS\Fonts\desktop.ini" - continue + system_fonts.update(Font.from_font_path(font_path)) # Save the font into the cache file with open(system_font_cache_file, "wb") as file: @@ -128,8 +120,9 @@ def load_additional_fonts(additional_fonts_path: List[Path]) -> Set[Font]: if os.path.isfile(font_path): additional_fonts.update(Font.from_font_path(font_path)) elif os.path.isdir(font_path): - for path in font_manager.findSystemFonts(fontpaths=str(font_path)): - additional_fonts.update(Font.from_font_path(path)) + for file in os.listdir(font_path): + if Path(file).suffix.lstrip(".").strip().lower() in ["ttf", "otf", "ttc", "otc"]: + additional_fonts.update(Font.from_font_path(os.path.join(font_path, file))) else: raise FileNotFoundError(f"The file {font_path} is not reachable") return additional_fonts diff --git a/setup.py b/setup.py index 5120800..11cc092 100644 --- a/setup.py +++ b/setup.py @@ -69,7 +69,7 @@ def find_version(*file_paths): "ass-tag-analyzer", "fontTools>=4.38.0", "freetype-py", - "matplotlib>=3.6", + "FindSystemFontsFilename>=0.1.1", ], entry_points={"console_scripts": ["fontcollector=font_collector.__main__:main"]}, classifiers=[ diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 1d7ffb4..ee501c7 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -16,7 +16,7 @@ def test_get_used_font_by_style(): style = styles[0] font_collection = FontLoader( - [os.path.join(dir_path, "fonts", "Raleway")], False + [os.path.join(dir_path, "fonts", "Raleway", "generated_fonts")], False ).fonts font_result = Helpers.get_used_font_by_style(font_collection, style)