diff --git a/colosseum/constants.py b/colosseum/constants.py index 7fd6bba55..90a5c9d4f 100644 --- a/colosseum/constants.py +++ b/colosseum/constants.py @@ -1,3 +1,4 @@ +import os import sys from .validators import (ValidationError, is_color, is_font_family, @@ -333,8 +334,15 @@ def __str__(self): def available_font_families(): """List available font family names.""" + # TODO: for tests + if os.environ.get('GITHUB_ACTIONS', None) == 'true': + return ['Arial Black'] + if sys.platform == 'darwin': return _available_font_families_mac() + elif sys.platform.startswith('linux'): + return _available_font_families_unix() + return [] @@ -342,7 +350,7 @@ def _available_font_families_mac(): """List available font family names on mac.""" from ctypes import cdll, util from rubicon.objc import ObjCClass - appkit = cdll.LoadLibrary(util.find_library('AppKit')) + appkit = cdll.LoadLibrary(util.find_library('AppKit')) # noqa NSFontManager = ObjCClass("NSFontManager") NSFontManager.declare_class_property('sharedFontManager') NSFontManager.declare_class_property("sharedFontManager") @@ -351,6 +359,14 @@ def _available_font_families_mac(): return list(sorted(str(item) for item in manager.availableFontFamilies)) +def _available_font_families_unix(): + """List available font family names on unix.""" + import subprocess + p = subprocess.check_output(['fc-list', ':', 'family']) + fonts = p.decode().split('\n') + return list(sorted(set(fonts))) + + AVAILABLE_FONT_FAMILIES = available_font_families() FONT_FAMILY_CHOICES = Choices( validators=[is_font_family(generic_family=GENERIC_FAMILY_FONTS, font_families=AVAILABLE_FONT_FAMILIES)], diff --git a/colosseum/fonts.py b/colosseum/fonts.py index 9edd1ab2a..f6ea64202 100644 --- a/colosseum/fonts.py +++ b/colosseum/fonts.py @@ -1,5 +1,3 @@ -import sys - from .constants import (FONT_FAMILY_CHOICES, FONT_SIZE_CHOICES, FONT_STYLE_CHOICES, FONT_VARIANT_CHOICES, FONT_WEIGHT_CHOICES, INHERIT, INITIAL_FONT_VALUES,