1. pygame
  2. pygame
  3. pygame
  4. Issues


Issue #179 closed

Need to update system font lists in sysfont.py (2013)

Jason Marshall
created an issue

The system font lists for Windows and OS X are out-of-date. Update per the following:

OS X font locations: http://support.apple.com/kb/HT2435

Mac OS X 10.3 list: http://support.apple.com/kb/HT2444

Mac OS X 10.4 list: http://support.apple.com/kb/HT1538

Mac OS X 10.5 list: http://support.apple.com/kb/HT1642

Mac OS X 10.6 list: http://support.apple.com/kb/ht5154

Mac OS X 10.7 list: http://support.apple.com/kb/HT5098

OS X 10.8 list: http://support.apple.com/kb/ht5379

OS X 10.9 list: http://support.apple.com/kb/HT5944

Windows font lists: http://www.microsoft.com/typography/fonts/


Comments (25)

  1. Jason Marshall reporter

    Dan Ross Thanks for reporting your issue. I haven't installed OS X 10.9 yet, so I haven't seen your issue first-hand. I won't get to it for a few months, so if you want to figure it out and patch it, that would be great!

  2. René Dudfield

    I added a fix for the fc-list hang in OSX in commit 4ed9cb7. However it still requires the optional X11 to be installed.

    There is a list of ways to list fonts on OS X at this url. http://stackoverflow.com/questions/1113040/list-of-installed-fonts-os-x-c

    Maybe the Cocoa code in there could be done via ctypes, so as to not require PyObjC (which isn't installed everywhere).

    Otherwise there is some half finished code in sysfont which doesn't require any dependencies. It simply lists directories where fonts are. What needs to be added is a check against a list of hard coded family information (gathered from systems with fc-list installed).

  3. Jason Marshall reporter

    fc-list output on Mac OS X 10.3.9 with X11 installed from the install discs. No other extra options (such as extra fonts) or extra programs installed. fc-list didn't run from the Terminal app; I had to use the XTerm that comes with X11. It probably has to do with the environment's search path.

  4. Jason Marshall reporter
    • edited description

    Here's an idea: rather than maintaining a full list of all fonts installed by default for all supported operating systems, we could shorten the OS font lists to contain just default fonts for serif, sans-serif and monospace families. I think this would be more maintainable.

  5. Jason Marshall reporter

    I like the way Tk handles font options. I am thinking that sysfont.py should offer similarly-limited functionality.

    Here's an excerpt from the Tk font documentation:

    -family name

    The case-insensitive font family name. Tk guarantees to support the font families named Courier (a monospaced "typewriter" font), Times (a serifed "newspaper" font), and Helvetica (a sans-serif "European" font). The most closely matching native font family will automatically be substituted when one of the above font families is used. The name may also be the name of a native, platform-specific font family; in that case it will work as desired on one platform but may not display correctly on other platforms. If the family is unspecified or unrecognized, a platform-specific default font will be chosen.

  6. Jason Marshall reporter

    Removed hard-coded font lists. They're not necessary, and updating them every time that a new OS is released would be a burden. Now, sysfont will depend on the registry (on Windows) or X11 fc-list (on any other OS) to generate a system's font list. Ad-hoc tested sysfont changes on Windows 7 with Python 2.4 and 3.4. Tested on Mac OS X 10.4 with Python 2.7. Close #179. Processed with autopep8.

    → <<cset ae2e36dc3f4c>>

  7. Ben Bass

    Just done following to test an old pygame demo I had from a few years ago - this is on macOS Sierra (10.12.4):

    $ brew install sdl
    $ pip3 install --user pygame
    $ python3 race_game.py
    ... <HANGS FOR AGES - Ctrl-C>
      File "race_game.py", line 34, in <module>
        sys_font = pygame.font.SysFont('monospace', 20)
      File "/Users/ben/Library/Python/3.4/lib/python/site-packages/pygame/sysfont.py", line 280, in SysFont
      File "/Users/ben/Library/Python/3.4/lib/python/site-packages/pygame/sysfont.py", line 230, in initsysfonts
        fonts = initsysfonts_darwin()
      File "/Users/ben/Library/Python/3.4/lib/python/site-packages/pygame/sysfont.py", line 146, in initsysfonts_darwin
        fonts = initsysfonts_unix("/usr/X11/bin/fc-list")
      File "/Users/ben/Library/Python/3.4/lib/python/site-packages/pygame/sysfont.py", line 167, in initsysfonts_unix
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 952, in communicate
        stdout, stderr = self._communicate(input, endtime, timeout)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 1581, in _communicate
        ready = selector.select(timeout)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/selectors.py", line 364, in select
        fd_event_list = self._poll.poll(timeout)
    $ time fc-list
    real    0m34.613s
    user    0m28.388s
    sys 0m3.365s

    The program did eventually run, but I had to leave it well over the 34s it lists here.

  8. Log in to comment