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

S

Samantha

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
 
M

Mike C. Fletcher

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/

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...
 
S

Samantha

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
 
M

Mike C. Fletcher

[Samantha: your email has been bouncing, might want to clear your inbox]
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...
 
S

Samantha

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 said:
[Samantha: your email has been bouncing, might want to clear your inbox]
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...
 
F

Fredrik Lundh

Samantha said:
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):
('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>
 
M

Mike C. Fletcher

Samantha said:
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...
 
P

Pierre Quentel

Samantha said:
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.
 
S

Samantha

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
 
S

Samantha

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
 
S

Samantha

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 said:
Samantha said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top