views:

355

answers:

2

I'm trying to write a font viewer for TrueType / OpenType fonts with VB6 / VB5 code (under Windows).

it is surprisingly difficult:

1) in VB / winAPI, i did not find how to extract the font's name, or font properties in general.

2) i can install the font (using AddFontResource API function), but then have to uninstall it. However, while (AddFontResource" expects a pathname, removing the font requires the font's name which is unknown to me.

is there a way to use an non-installed font ttf) ?

is there a way to extract a font's properties using vb6 ?

(I can write the program in wxPython but i know even less about fonts in python than with VB)

A: 

It indeed is. I have faced the same problem myself (see my question). I ended up writing my own parser though because I needed to detect if the font was corrupt or not. There is a AddFontMemResourceEx function which:

When the function succeeds, the caller of this function can free the memory pointed to by pbFont because the system has made its own copy of the memory. To remove the fonts that were installed, call RemoveFontMemResourceEx. However, when the process goes away, the system will unload the fonts even if the process did not call RemoveFontMemResource.

Also, you can use the Font and Text Functions to get the font metrics.

dirkgently
+1  A: 

You could use the FreeType library.

Wim Coenen
+1. Much more pleasant and potentially cross-platform compatible than dealing with native installed fonts. Also makes for a much more useful application! There is a Python binding called ft2 available that calls itself beta-quality; personally I have used FreeType through PIL before with some success, though certainly that's a limited subset of functionality, probably not enough for a font viewer util. I don't know about for VB6, but I wouldn't want to be writing anything much in classic-VB these days really.
bobince