Font management under win32

S

Stefano Masini

Hi,

I have a simple need, running under windows:

1) retrieve the list of installed system fonts
2) maybe install missing fonts

Surprisingly for me, there seems to be no support for such a thing in
python. I really hope I'm mistaken, so _please_ correct me if I'm
wrong.

I found out that it all boils down to a couple of win32 syscalls:
EnumFontFamiliesEx and AddFontResourceEx. Unfortunately I'm no expert
of win32 programming whatsoever. I asked Mark Hammond about this.
While I wait for him to receive my email, I thought I'd post on the
list in case someone else was interested, or had found a different
solution.

Indeed, win32gui does contain an EnumFontFamilies (without the
trailing "Ex") function, but I found no usage example, and I couldn't
figure out how to use LOGFONT handles (since such a thing is required
as the first parameter to the call). So I decided to punt on it and
ask for wiser support.

If I could get this EnumFontFamilies to work, it could already be
enough, because I found a command line tool that allows me to do font
installation. It's got to be some no-brainer 10 lines of C code simply
calling AddFontResourceEx, but it works!

So, does anybody ever had the same problem?

thanks,
stefano
 
N

Neil Hodgson

Stefano Masini:
Indeed, win32gui does contain an EnumFontFamilies (without the
trailing "Ex") function, but I found no usage example, and I couldn't
figure out how to use LOGFONT handles (since such a thing is required
as the first parameter to the call). So I decided to punt on it and
ask for wiser support.

This section of the documentation looks confusing as it appears to
be providing LOGFONT objects rather than ENUMLOGFONT objects which
include the name which I suspect is what you are after. ctypes will
allow you to call the Win32 API directly and may be easier to use.

Neil
 
R

Roger Upole

Here's an example of how to use EnumFontFamilies:

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

The parameters to the callback need to be documented.
I had to look at the source to figure out what to expect.

hth
Roger
 
S

Stefano Masini

Here's an example of how to use EnumFontFamilies:

I'm trying the code you just posted, which works (thanks a lot), but I'm having
another problem now.

As I stated in my first post, the reason why I need to know the list
of installed fonts is that I have to decide whether to further install
some additional missing ones.
The problem I have now, is that I don't know before hand the name of
the missing fonts, I just have their .ttf or .otf files. So I'd have
to somehow go inside and look for their names.

Do you think that is possible with win32 extensions?

thanks,
stefano
 
F

Fredrik Lundh

Stefano said:
Do you think that is possible with win32 extensions?

you can do this via PIL's ImageFont module:
'Regular'

or, if you don't want to ship the entire PIL library with your app, you
can grab the _imagingft module and use low-level functions:
'Regular'

</F>
 

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,264
Messages
2,571,323
Members
48,007
Latest member
Elvis60357

Latest Threads

Top