[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Re: Missing fonts on Ubuntu Edgy



On Thu, Mar 01, 2007 at 04:46:01PM +0200, Marius Gedminas wrote:
> Suggested fix: have pygame/sysfont.py parse ~/.fonts.cache-1.  (There's
> a slight complication: most fonts.cache-1 files have three fields per
> line (font name, some number, font properties), while ~/.fonts.cache-1
> has four (font name, some number, some other number, font properties).
>
> Actually, as I recall from a discussion about a different bug[1] (that
> still plagues me in 1.7.1), the CVS version of PyGame uses fc-list to
> find fonts on Unix systems, so this bug should be already fixed in CVS.
> 
> [1] http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/2970161

For those who do not want to wait for 1.8, here's a patch that fixes
this problem (and the other one too) in 1.7.1: attached.

Marius Gedminas
-- 
I code in vi because I don't want to learn another OS. :)
                -- Robert Love
Patch for pygame 1.7.1:

 * Also parse ~/.fonts.conf-1 on Unix systems to find more fonts (needed
   to find many TTF fonts on Ubuntu Edgy).
 * Fix font style parsing in fonts.conf-1 files (bug described in
   http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/2970161).

--- sysfont.py.orig     2007-03-01 16:25:04.000000000 +0200
+++ sysfont.py  2007-03-01 16:46:51.000000000 +0200
@@ -128,21 +128,25 @@
 
 
 #read the fonts from a unix 'fonts.cache-1' file
-def read_unix_fontscache(dir, file, fonts):
+def read_unix_fontscache(dir, file, fonts, nfields=3):
     file = open(os.path.join(dir, file))
     for line in file.readlines():
         try:
-            font, num, vals = line.split(' ', 2)
+            fields = line.split(' ', nfields-1)
         except ValueError:
             continue
-        font = font.replace('"', '')
+        font = fields[0].replace('"', '')
         if font[-4:].lower() not in [".ttf", ".ttc"]:
             continue
         font = os.path.join(dir, font)
-        vals = vals.split(':')
+
+        vals = fields[-1].split(':')
         name = _simplename(vals[0][1:])
-        bold = vals[1].find('Bold') >= 0
-        italic = vals[1].find('Italic') >= 0
+        bold = italic = 0
+        for prop in vals[1:]:
+            if prop.startswith('style='):
+                bold = prop.find('Bold') >= 0
+                italic = prop.find('Italic') >= 0
         _addfont(name, bold, italic, font, fonts)
 
 
@@ -182,6 +186,13 @@
     for p in paths:
         if os.path.isdir(p):
             os.path.walk(p, _fontwalk, fonts)
+    filename = os.path.expanduser('~/.fonts.cache-1')
+    try:
+        # Unlike other fonts.cache-1 files, this one has four fields per line
+        # rather than three
+        read_unix_fontscache('', filename, fonts, nfields=4)
+    except IOError:
+        pass
     return fonts
 
 

Attachment: signature.asc
Description: Digital signature