By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,404 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,404 IT Pros & Developers. It's quick & easy.

Probably over my head... Trying to get Font Names

P: n/a
I am attempting to extract the Font Names from the installed windows fonts.
I am having a heck of a time getting these rather than the file names.
Examples can be seen by going to Control Panel > Fonts

Any help or direction is appreciated.
S
Jul 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
If you don't have a GUI library to use, TTFQuery+Fonttools will retrieve
this information:

from ttfquery import _scriptregistry
fonts = _scriptregistry.registry.fonts.keys()
fonts.sort()
for name in fonts:
print name

if you do have a GUI, your GUI library will almost certainly have a
mechanism to retrieve the list of fonts. With wxPython, for instance,
it's called wxFontEnumerator. If you just want the user to choose a
font, most GUI libraries already have controls/dialogues that can handle it.

TTFQuery is going out, reading the .ttf fonts with Fonttools and storing
their metadata in an index for faster access, whereas your GUI library
will be using a simple API call to retrieve the metadata. That means
TTFQuery is going to be heavier, but it can, for instance, also give you
information about fonts not installed on the system.

HTH,
Mike

TTFQuery:
http://ttfquery.sourceforge.net/
Samantha wrote:
I am attempting to extract the Font Names from the installed windows fonts.
I am having a heck of a time getting these rather than the file names.
Examples can be seen by going to Control Panel > Fonts

Any help or direction is appreciated.
S

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
PyCon is coming...

Jul 18 '05 #2

P: n/a
Thanks Mike. I must have not installed the ttfquery and font tools
correctly. I get an error. This error:

Traceback (most recent call last):
File "C:\Python24\Lib\font-getter.py", line 1, in -toplevel-
from ttfquery import _scriptregistry
File "C:\Python24\Lib\site-packages\ttfquery\_scriptregistry.py", line 1,
in -toplevel-
from ttfquery import ttffiles
File "C:\Python24\Lib\site-packages\ttfquery\ttffiles.py", line 10,
in -toplevel-
from ttfquery import describe, findsystem
File "C:\Python24\Lib\site-packages\ttfquery\describe.py", line 2,
in -toplevel-
from fontTools import ttLib
ImportError: No module named fontTools

Like I said I think I am way in over my short head.
S
"Mike C. Fletcher" <mc******@rogers.com> wrote in message
news:ma***************************************@pyt hon.org...
If you don't have a GUI library to use, TTFQuery+Fonttools will retrieve
this information:

from ttfquery import _scriptregistry
fonts = _scriptregistry.registry.fonts.keys()
fonts.sort()
for name in fonts:
print name

if you do have a GUI, your GUI library will almost certainly have a
mechanism to retrieve the list of fonts. With wxPython, for instance,
it's called wxFontEnumerator. If you just want the user to choose a font,
most GUI libraries already have controls/dialogues that can handle it.

TTFQuery is going out, reading the .ttf fonts with Fonttools and storing
their metadata in an index for faster access, whereas your GUI library
will be using a simple API call to retrieve the metadata. That means
TTFQuery is going to be heavier, but it can, for instance, also give you
information about fonts not installed on the system.

HTH,
Mike

TTFQuery:
http://ttfquery.sourceforge.net/
Samantha wrote:
I am attempting to extract the Font Names from the installed windows
fonts. I am having a heck of a time getting these rather than the file
names. Examples can be seen by going to Control Panel > Fonts

Any help or direction is appreciated.
S

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
PyCon is coming...

Jul 18 '05 #3

P: n/a
[Samantha: your email has been bouncing, might want to clear your inbox]

Samantha wrote:
Thanks Mike. I must have not installed the ttfquery and font tools
correctly. I get an error. This error:

....
ImportError: No module named fontTools

Like I said I think I am way in over my short head.
S

Does look as though you missed getting FontTools installed. You realise
it's a separate package from TTFQuery, right?

http://sourceforge.net/projects/fonttools/

You'll have to do the standard:

python setup.py install

to get it installed on your system.

HTH,
Mike

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
PyCon is coming...
Jul 18 '05 #4

P: n/a
Mike,
Not sure why that email bounced.
I downloaded these files:
WinTTX2.0b1.exe
TTFQuery-1.0.0.win32.exe
numarray-1.1.1.win32-py2.4.exe

They all seemed to install. Is WinTTX2.0b1.exe not the fontTools file?
S

"Mike C. Fletcher" <mc******@rogers.com> wrote in message
news:ma***************************************@pyt hon.org...
[Samantha: your email has been bouncing, might want to clear your inbox]

Samantha wrote:
Thanks Mike. I must have not installed the ttfquery and font tools
correctly. I get an error. This error:

...
ImportError: No module named fontTools

Like I said I think I am way in over my short head.
S

Does look as though you missed getting FontTools installed. You realise
it's a separate package from TTFQuery, right?

http://sourceforge.net/projects/fonttools/

You'll have to do the standard:

python setup.py install

to get it installed on your system.

HTH,
Mike

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
PyCon is coming...

Jul 18 '05 #5

P: n/a
"Samantha" <sa**********@hotmail.com> wrote:
I am attempting to extract the Font Names from the installed windows fonts. I am having a heck of a
time getting these rather than the file names. Examples can be seen by going to Control Panel >
Fonts


here's one way to do it (using Tkinter):
import Tkinter, tkFont
tk = Tkinter.Tk()
tkFont.families()

('System', 'Terminal', 'Fixedsys', 'Roman', 'Script', 'Modern', 'Small Fonts', 'MS Serif', ...)

here's another way (using PIL):

import os
from PIL import ImageFont

fontdir = os.path.join(os.environ["windir"], "fonts")

for fontfile in os.listdir(fontdir):
try:
font = ImageFont.truetype(os.path.join(fontdir, fontfile), 1)
except IOError:
pass
else:
print font.font.family, font.font.style

(this prints a list of family/style combinations). You can get PIL from

http://www.pythonware.com/products/pil/ (1.1.4)
http://effbot.org/downloads/#pil (1.1.5 betas)

</F>

Jul 18 '05 #6

P: n/a
Samantha wrote:
Mike,
Not sure why that email bounced.

That last one bounced too, btw.
I downloaded these files:
WinTTX2.0b1.exe
TTFQuery-1.0.0.win32.exe
numarray-1.1.1.win32-py2.4.exe

They all seemed to install. Is WinTTX2.0b1.exe not the fontTools file?

I believe WinTTX is a font-editing program from which fontTools was
split out into a separate project.

As well, though I don't *know* that this will cause problems, I'd
thought fontTools required Numeric (Numpy) rather than Numarray. Would
try the fontTools package first with the Numarray you've installed, and
if you then find problems with it not being able to find Numeric,
install the Numpy release.

HTH,
Mike

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
PyCon is coming...

Jul 18 '05 #7

P: n/a
"Samantha" <sa**********@hotmail.com> wrote in message news:<B8********************@adelphia.com>...
I am attempting to extract the Font Names from the installed windows fonts.
I am having a heck of a time getting these rather than the file names.
Examples can be seen by going to Control Panel > Fonts

Any help or direction is appreciated.
S


Try this :

Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
from Tkinter import Tk
import tkFont
root=Tk()
print tkFont.families(root)

Jul 18 '05 #8

P: n/a
Thanks Fredrik,
The Tkinter method didn't give any results but using PIL did. I'll have to
play with it a little.
Thanks again,
S
"Fredrik Lundh" <fr*****@pythonware.com> wrote in message
news:ma***************************************@pyt hon.org...
"Samantha" <sa**********@hotmail.com> wrote:

Jul 18 '05 #9

P: n/a
Mike,
Strange Hotmail.
I'll start over with the installs and you are correct on it being Numpy. I
got the wrong file.
I'll give it a go and let you know.
Thanks!!!!
S
"Mike C. Fletcher" <mc******@rogers.com> wrote in message
news:ma***************************************@pyt hon.org...
Samantha wrote:

Jul 18 '05 #10

P: n/a
Thank you Pierre, that worked. I am still going to try and get the
TTFQuery+Fonttools to work just out of curiosity.
Thanks again to everyone!!!
S

"Pierre Quentel" <qu************@wanadoo.fr> wrote in message
news:32**************************@posting.google.c om...
"Samantha" <sa**********@hotmail.com> wrote in message
news:<B8********************@adelphia.com>...
I am attempting to extract the Font Names from the installed windows
fonts.
I am having a heck of a time getting these rather than the file names.
Examples can be seen by going to Control Panel > Fonts

Any help or direction is appreciated.
S


Try this :

Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
from Tkinter import Tk
import tkFont
root=Tk()
print tkFont.families(root)

Jul 18 '05 #11

P: n/a
Mike I did get the last msg. Still trying to get things under control.....
S
"Mike C. Fletcher" <mc******@rogers.com> wrote in message
news:ma***************************************@pyt hon.org...
Samantha wrote:
Mike,
Not sure why that email bounced.

That last one bounced too, btw.
I downloaded these files:
WinTTX2.0b1.exe
TTFQuery-1.0.0.win32.exe
numarray-1.1.1.win32-py2.4.exe

They all seemed to install. Is WinTTX2.0b1.exe not the fontTools file?

I believe WinTTX is a font-editing program from which fontTools was split
out into a separate project.

As well, though I don't *know* that this will cause problems, I'd thought
fontTools required Numeric (Numpy) rather than Numarray. Would try the
fontTools package first with the Numarray you've installed, and if you
then find problems with it not being able to find Numeric, install the
Numpy release.

HTH,
Mike

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
PyCon is coming...

Jul 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.