Package: python2.3-pygame
Version: 1.7.1release-2
Severity: important
This fragment of code (extracted from solarwolf) caused pygame to hang
on my system:
import pygame, pygame.font
pygame.init()
pygame.font.init()
pygame.font.SysFont('sans', 16, italic=1)
To reproduce, make sure you have Bitstream Vera and don't have Arial and
Helvetica installed.
I traced the execution; pygame is getting in an endless loop after
incorrectly parsing fontconfig's fonts.cache-1 files. Trying to read
those files is of course a gross hack. The attached patch throws all
that code away and replaces it with a function that parses the output of
the fc-list command. Still ugly, but at least it works. (The proper way
of course is to use fontconfig directly, but there doesn't seem to be a
python module for that.)
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.13-rc7
Locale: LANG=nl_BE.UTF-8, LC_CTYPE=nl_BE.UTF-8 (charmap=UTF-8)
Versions of packages python2.3-pygame depends on:
ii libc6 2.3.5-8 GNU C Library: Shared libraries an
ii libsdl-image1.2 1.2.4-1 image loading library for Simple D
ii libsdl-mixer1.2 1.2.6-1.1 mixer library for Simple DirectMed
ii libsdl-ttf2.0-0 2.0.6-5 ttf library for Simple DirectMedia
ii libsdl1.2debian 1.2.9-0.0 Simple DirectMedia Layer
ii libsmpeg0 0.4.5+cvs20030824-1.6 SDL MPEG Player Library - shared l
ii python2.3 2.3.5-9 An interactive high-level object-o
ii python2.3-numeric 24.2-1 Numerical (matrix-oriented) Mathem
ii python2.3-numeric- 24.2-1 Extension modules for Numeric Pyth
python2.3-pygame recommends no packages.
-- no debconf information
--- sysfont.py.orig 2005-11-22 02:31:35.000000000 +0100
+++ sysfont.py 2005-11-25 02:39:32.000000000 +0100
@@ -127,61 +127,16 @@
-#read the fonts from a unix 'fonts.cache-1' file
-def read_unix_fontscache(dir, file, fonts):
- file = open(os.path.join(dir, file))
- for line in file.readlines():
- try:
- font, num, vals = line.split(' ', 2)
- except ValueError:
- continue
- font = font.replace('"', '')
- if font[-4:].lower() not in [".ttf", ".ttc"]:
- continue
- font = os.path.join(dir, font)
- vals = vals.split(':')
- name = _simplename(vals[0][1:])
- bold = vals[1].find('Bold') >= 0
- italic = vals[1].find('Italic') >= 0
- _addfont(name, bold, italic, font, fonts)
-
-
-#read the fonts from a unix 'fonts.dot' file
-def read_unix_fontsdir(dir, file, fonts):
- file = open(os.path.join(dir, file))
- try: numfonts = int(file.readline())
- except ValueError: return # probably not a font file
-
- for line in file.readlines():
- font, descr = (line.split(' ', 1) + ['', ''])[:2]
- if font[-4:].lower() not in [".ttf", ".ttc"]:
-
- continue
- font = os.path.join(dir, font)
- descr = descr.split('-', 13)
- name = _simplename(descr[2])
- bold = (descr[3] == 'bold')
- italic = (descr[4] == 'i')
- _addfont(name, bold, italic, font, fonts)
-
-
-#walk the path directory trees
-def _fontwalk(fonts, path, files):
- if 'fonts.scale' in files:
- read_unix_fontsdir(path, 'fonts.scale', fonts)
- elif 'fonts.dir' in files:
- read_unix_fontsdir(path, 'fonts.dir', fonts)
- elif 'fonts.cache-1' in files:
- read_unix_fontscache(path, 'fonts.cache-1', fonts)
-
-
#read the fonts on unix
def initsysfonts_unix():
- paths = ['/usr/X11R6/lib/X11/fonts', '/usr/share/fonts']
fonts = {}
- for p in paths:
- if os.path.isdir(p):
- os.path.walk(p, _fontwalk, fonts)
+ for line in os.popen('fc-list : file family style'):
+ file, family, style = line.split(':', 2)
+ if file[-4:].lower() in ['.ttf', '.ttc']:
+ bold = style.find('Bold') >= 0
+ italic = style.find('Italic') >= 0
+ oblique = style.find('Oblique') >= 0
+ _addfont(_simplename(family), bold, italic or oblique, file, fonts)
return fonts