Lenard Lindstrom  committed f2c2fd4

Install a freetype replacement for pygame.font if font is not built

If pygame._freetype is built in place of the SDL_ttf based pygame.font
extension module then replace pygame.font with, the freetype
based equivalent. Module passes the unit tests
except in one case, ftfont.Font handles code points above 0xFFFF, so
does not raise a UnicodeError.

  • Participants
  • Parent commits 3f25a2e

Comments (0)

Files changed (3)

File lib/

 """pygame module for loading and rendering fonts (freetype alternative)"""
-from pygame._freetype import (init, Face as _Face, get_default_resolution,
-                              quit, get_default_font, was_init as _was_init)
+__all__ = ['Font', 'init', 'quit', 'get_default_font', 'get_init', 'SysFont']
+from pygame._freetype import init, Face as _Face, get_default_resolution
+from pygame._freetype import quit, get_default_font, was_init as _was_init
+from pygame._freetype import __PYGAMEinit__
 from pygame.sysfont import match_font, get_fonts, SysFont as _SysFont
 from pygame import encode_file_path
 from pygame.compat import bytes_, unicode_, as_unicode, as_bytes
                        "-Wnested-externs -Wshadow -Wredundant-decls"
     sys.argv.remove ("-warnings")
-import os.path, glob, stat
+import os.path, glob, stat, shutil
 import distutils.sysconfig
 from distutils.core import setup, Extension, Command
 from distutils.extension import read_setup_file
     del tmp_extensions
+# if not building font, try replacing with ftfont
+alternate_font = os.path.join('lib', '')
+if os.path.exists(alternate_font):
+    os.remove(alternate_font)
+have_font = False
+have_freetype = False
+for e in extensions:
+    if == 'font':
+        have_font = True
+    if == '_freetype':
+        have_freetype = True
+if not have_font and have_freetype:
+    shutil.copyfile(os.path.join('lib', ''), alternate_font)
 #extra files to install
 data_path = os.path.join(distutils.sysconfig.get_python_lib(), 'pygame')
 pygame_data_files = []

File test/

             self.assert_(not equal_images(su, sb))
-        if UCS_4:
-            # SDL_ttf only handles UCS-2
+        # If the font module is SDL_ttf based, then it can only supports  UCS-2;
+        # it will raise an exception for an out-of-range UCS-4 code point.
+        if UCS_4 and not hasattr(f, 'ucs4'):
             ucs_2 = as_unicode(r"\uFFEE")
             s = f.render(ucs_2, False, [0, 0, 0], [255, 255, 255])
             ucs_4 = as_unicode(r"\U00010000")