Finding a fonts true name.
BlitzPlus Forums/BlitzPlus Programming/Finding a fonts true name.
| ||
Yeah, yeah, I know you can double click the file in Windows Explorer and it will display the true name for you. But what if you want to let the user pick his own font? I'm writing a wee program that'll arrange fonts in a bitmap, but as many of you know, if you supply the fonts filename (i.e. use a file request) instead of it's true name Blitz will just shrug it's shoulders and default to Ariel without reporting any problems. Is it safe or reliable just to peek the font's header file (assuming it has one) or has someone already written a handy userlib to get the true names? I already tried the search function on the site, so I'm not too hopeful. But thanks in advance to anyone that can help. |
| ||
You can use the RequestFont() function, but if you'd rather do it behind the scenes, I wrote this DLL for you that will output every font name on the system to the system directory. Here's the file and some example code:; Userlib ; .lib "fontnames.dll" ; ExportFonts%() Graphics 640, 600, 16, 2 SetBuffer FrontBuffer() ExportFonts ; Save font names to system directory File% = ReadFile(SystemProperty("SystemDir") + "\fontnames.txt") Local x% = 1, y% = 1, tmp$ Repeat Text x, y, ReadLine(File) y = y + 16 If y >= 584 Then y = 1: x = x + 200 Until Eof(File) DeleteFile SystemProperty("SystemDir") + "\fontnames.txt" WaitKey()Only other way I know to do this would be by enumerating the fonts, but those API functions require callbacks which userlibs don't support. Hope a DLL isn't too clunky for you, and good luck with your font project thingy. |
| ||
Hey it works! Don't worry about it's "clunkyness". I've never seen another way around the problem in Blitz, and this will work fine. Thanks. I'm just writing a simple font to bitmap thing so people don't have to install fonts with the stuff I write. But this DLL nails a problem that's been bugging me for ages. Cheers. |
| ||
Good deal :) |
| ||
Gah, I discovered something very odd in your true name DLL. It seems to take it on itself to truncate certain names, meaning Blitz won't load the font as per the usual rules. "Times New Roman Bold Italic" shortens itself to "Times New Roman Baltic", and there seem to be other examples where it's not quite the true name. The DLL is still useful as it works for about 80% of my fontlist (so about 8 times more reliable than using the filename). Still, Something's up methinks! |