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

Re: [pygame] font.get_fonts and OS X



Hello,

Font() is documented as opening a specific font file or failing. Font(None) opens Pygame's default font file. SysFont is designed to use fallbacks. So one could add new 'default' and 'any' options to it, where SysFont("default,sans,any") does what you suggest. But then 'any' could look for 'sans' first, so "default,any" would be equivalent.

Lenard

René Dudfield wrote:
hi again,

one other thing with fonts...

perhaps we should have a fallback, for when freesansbold.ttf doesn't exist? Seems to be a common error... that we have fixed most issues with (py2exe missing not copying freesansbold.ttf in, freesansbold.ttf not being included by packagers, freesansbold.ttf having the wrong permissions, etc). However, it still would be good to try and make it not fail so easily.

Something like adding pygame.font.SysFont("sans", size) if the Font(None, size) raises an exception for a missing font... and if that fails, try and find any font.

Maybe I should also try and log a warning that the incorrect font was used.

What do you reckon?




On Fri, May 22, 2009 at 4:41 PM, René Dudfield <renesd@xxxxxxxxx <mailto:renesd@xxxxxxxxx>> wrote:

    hi,

    yeah, it looks like it is sharing fonts.  It returns some fonts in
    the X11 dirs, and some from the /Fonts/ dirs.

    I could try and create something like: XP_default_font_files, but
remove the X11 files from that list... if fc-list isn't there? Then use a method similar to the one you used for xp.

    cu,



    On Fri, May 22, 2009 at 4:19 PM, Lenard Lindstrom <len-l@xxxxxxxxx
    <mailto:len-l@xxxxxxxxx>> wrote:

        So for OS X and X11, is sysfont.py picking up the right fonts?
        Or does X11 on OS X share the Aqua fonts.

        Lenard

        René Dudfield wrote:

            hi,

            looks like the fix you committed is passing tests now :)
             http://thorbrian.com/pygame/builds.php

            Now to figure out a way to get it to pass on OSX 10.4 and
            below.  The tests pass on 10.5 and 10.4 with the optional
            X11 installed.

            cu,



            On Fri, May 22, 2009 at 3:21 AM, Lenard Lindstrom
            <len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>
            <mailto:len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>>> wrote:

               EnumFontFamilies does not map font characteristic to an
            actual
               TrueType file, so is of no use here.

               Lenard


               Lenard Lindstrom wrote:


                   Of course ctypes is used by pygame -m pygame.tests
            on Windows.
                   So requiring it for sysfont as well is reasonable.

                   Lenard

                   Lenard Lindstrom wrote:


                       Hi René,

                       win32gui creates a win32api dependency. This
            could be done
                       with ctypes, but now Python 2.4 support will be
                       compromised. Personally, I don't care if
            general Python
                       2.4 support is dropped.

                       Lenard

                       René Dudfield wrote:

                           Hi,

                           two things I found out...

                           maybe this key works?
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows[NT]\CurrentVersion\Fonts"



                           Also there is an function called
            EnumFontFamilies,
                           that is there from win95 to get font
            information.


                           Here's some code I found using the win32gui
            module...

                           import win32gui
                           hdc=win32gui.CreateDC('DISPLAY','Display',None)
                           fonts=[]
                           def callback(font, tm, fonttype, fonts):
                              fonts.append(font)
                              #print font.lfFaceName
                              #print fonttype
                              return True
                           win32gui.EnumFontFamilies(hdc, None,
            callback, fonts)

                           #print fonts

                           f = fonts[0]

                           print dir(fonts[0])






                           On Thu, May 21, 2009 at 6:59 AM, Lenard
            Lindstrom
                           <len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>
            <mailto:len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>>> wrote:

                              Hi,

                              I see there are problems with Windows XP.
                           Apparently the default
                              fonts aren't showing up in the usual
            registry place:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
                           NT\CurrentVersion\Fonts

                              I guess that is just for additional
            fonts, which
                           Brian's build
                              machine apparently does not have. Would
            there be
                           any other places
                              in the registry to search? Or must one
            start with a
                           list of
                              default Windows fonts then check for
            each in the
                           \windows\fonts
                              directory?

                              Lenard


                              René Dudfield wrote:

                                  hi,

                                  the tests pass on 10.5.7... which
            just uses the
                           unix
                                  function... (which uses fc-list).

                                  I think it should be easier to
            figure out what
                           to do for when
                                  fc-list isn't there (pre 10.5.x
            machines)...
                            by looking at
                                  the out put that the fc-list using
            function uses.

                                  cu,



                                  On Wed, May 20, 2009 at 3:33 PM,
            Lenard Lindstrom
                                  <len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>>
                                  <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>>>> wrote:

                                     I committed what I have so far.
            If OS X has
                           an fc-list
                                  equivalent
                                     take a look at the updates I made
            to the
                           Unix section of
                                     sysfont.py for Python 3 and
            unicode. Some of
                           it may be
                                  relevant.

                                     Lenard



                                     René Dudfield wrote:

                                         hello,

                                         ah, nice catch!   That's
            annoying... all
                           this time and it
                                         hasn't been
                                         working on OSX.

                                         Can you commit your tests?

                                         I can have a go at it...
            unless Brian
                           you want to have
                                  a go?


                                         Here are the main font
            paths... the X11
                           one isn't there
                                  on most
                                         installs for 10.4.x ... but
            should be
                           there on most 10.5.x
                                         installs.
                                         The last path is where OS9
            used to
                           install fonts, and
                                  some people
                                         still use that directory
            apparently.

                                         ~/Library/Fonts/
                                         /Library/Fonts/
                                         /System/Library/Fonts/
                                         /usr/X11/lib/X11/fonts/TTF/
                                         /Network/Library/Fonts/
                                         /System Folder/Fonts/


                                         cheers,




                                         On Wed, May 20, 2009 at 7:55
            AM, Lenard
                           Lindstrom
                                         <len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>>
                                  <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>>>> wrote:
                                                            Currently I am
                           filling in the font unit tests. For
                                  OS X I
                                             noticed that
                                             sysfont.py does not hunt down
                           installed fonts. The
                                             relevant function is a
                                             stub. I have no OS X
            access, so
                           can't write it
                                  myself. Is
                                             someone else
                                             willing to take care of it.
                           Otherwise when I commit the
                                             completed unit tests
                                             they will fail for OS X.

                                             Lenard


-- Lenard Lindstrom
                              <len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>
                           <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx> <mailto:len-l@xxxxxxxxx
            <mailto:len-l@xxxxxxxxx>>>>








-- Lenard Lindstrom
        <len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>>