Skip to content

Commit

Permalink
Update font for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Jan 3, 2020
1 parent c4cc7bb commit 4f8c4b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 17 additions & 1 deletion colosseum/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys

from .validators import (ValidationError, is_color, is_font_family,
Expand Down Expand Up @@ -333,16 +334,23 @@ 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 []


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")
Expand All @@ -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)],
Expand Down
2 changes: 0 additions & 2 deletions colosseum/fonts.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 4f8c4b9

Please sign in to comment.