Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50462

Re: How do I get the OS System Font Directory(Cross-Platform) in python?

Date 2013-07-11 18:12 +0200
From Chris “Kwpolska” Warrick <kwpolska@gmail.com>
Subject Re: How do I get the OS System Font Directory(Cross-Platform) in python?
References <3d97de86-f690-40ad-aba8-972120af7ff3@googlegroups.com> <faa7fdb3-99e9-40ed-8a62-1df85d49edd4@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4594.1373559184.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Thu, Jul 11, 2013 at 08:54:17AM -0700, Metallicow wrote:
> For a portable font install tool.
> 
> Finding if a particular font exists,
> useful when testing apps in virtual environent,
> rendering text from a font,
> Font file manipulations,
> etc..
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Then do a nice little `if` checking the user’s OS.

http://docs.python.org/2/library/sys.html#sys.platform hints what to use,
and you need to do:

if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
    FONTDIRS = [os.path.join(os.environ['WINDIR'], 'Fonts')
elif sys.platform.startswith('darwin'):
    # [see below and devise it yourself]
else: # linux, *bsd and everything else
    # [see below, commit suicide and develop this bit]

Windows:
    The easiest of those three, all the fonts are in %WINDIR%/Fonts.
    In Python: os.path.join(os.environ['WINDIR'], 'Fonts')

Mac OS X:
    http://support.apple.com/kb/ht2435 (and not all of them are
    guaranteed to exist).  `os.expanduser()` may be useful for
    that first one.

Linux, and everything else running that fancy open stuff (eg. *BSD):
    Hardcore.  You just need to parse a nice tiny 155-line XML file.

    It’s /etc/fonts/fonts.conf, and it has some <dir> tags.
    Some of them may have a `prefix="xdg"` attribute which makes you
    prepend the value with $XDG_DATA_HOME (~/.local/share if that is
    empty).  You also need `os.expanduser()`.

    Oh: and you need to go recursively through them, as subdirectories
    are also checked for fonts (and it probably goes further)

-- 
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How do I get the OS System Font Directory(Cross-Platform) in python? Metallicow <metaliobovinus@gmail.com> - 2013-07-11 08:32 -0700
  Re: How do I get the OS System Font Directory(Cross-Platform) in python? Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-07-11 17:48 +0200
  Re: How do I get the OS System Font Directory(Cross-Platform) in python? Metallicow <metaliobovinus@gmail.com> - 2013-07-11 08:54 -0700
    Re: How do I get the OS System Font Directory(Cross-Platform) in python? Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-07-11 18:12 +0200
  Re: How do I get the OS System Font Directory(Cross-Platform) in python? Metallicow <metaliobovinus@gmail.com> - 2013-07-11 10:19 -0700
    Re: How do I get the OS System Font Directory(Cross-Platform) in python? Christian Heimes <christian@python.org> - 2013-07-12 03:27 +0200
      Re: How do I get the OS System Font Directory(Cross-Platform) in python? Metallicow <metaliobovinus@gmail.com> - 2013-07-11 21:24 -0700
        Re: How do I get the OS System Font Directory(Cross-Platform) in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-12 04:55 +0000
        Re: How do I get the OS System Font Directory(Cross-Platform) in python? Chris Angelico <rosuav@gmail.com> - 2013-07-12 14:58 +1000
  Re: How do I get the OS System Font Directory(Cross-Platform) in python? Nobody <nobody@nowhere.com> - 2013-07-11 18:47 +0100
    Re: How do I get the OS System Font Directory(Cross-Platform) in python? Metallicow <metaliobovinus@gmail.com> - 2013-07-11 11:25 -0700
      Re: How do I get the OS System Font Directory(Cross-Platform) in python? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-11 20:13 -0400
      Re: How do I get the OS System Font Directory(Cross-Platform) in python? Tim Roberts <timr@probo.com> - 2013-07-12 22:36 -0700
        Re: How do I get the OS System Font Directory(Cross-Platform) in python? Metallicow <metaliobovinus@gmail.com> - 2013-07-12 23:38 -0700
          Re: How do I get the OS System Font Directory(Cross-Platform) in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-13 07:20 +0000

csiph-web