Lenard Lindstrom avatar 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 ftfont.py, the freetype
based equivalent. Module ftfont.py passes the font_test.py unit tests
except in one case, ftfont.Font handles code points above 0xFFFF, so
does not raise a UnicodeError.

Comments (0)

Files changed (3)

 """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
             extensions.append(e)
     del tmp_extensions
 
+# if not building font, try replacing with ftfont
+alternate_font = os.path.join('lib', 'font.py')
+if os.path.exists(alternate_font):
+    os.remove(alternate_font)
+have_font = False
+have_freetype = False
+for e in extensions:
+    if e.name == 'font':
+        have_font = True
+    if e.name == '_freetype':
+        have_freetype = True
+if not have_font and have_freetype:
+    shutil.copyfile(os.path.join('lib', 'ftfont.py'), alternate_font)
+
 #extra files to install
 data_path = os.path.join(distutils.sysconfig.get_python_lib(), 'pygame')
 pygame_data_files = []

test/font_test.py

         else:
             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")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.