check a font name if exists

Just starting out? Need help? Post your questions and find answers here.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

check a font name if exists

Post by MyTrial »

Hello

I have a console program which gets a font name by command line and should build some pre text as image with that font. The problem is that LoadFont() loads a font if it is really there or not (this should work on ms windows). So i am searching for a possibility to check if a given font name real exists. PureBasic supports the fine font requester which knows all real fonts. So it should be possible to know if a font name exists. But i can not find the point to check that. And i did not found a PureBasic command to get that. Maybe i have tomatoes on my eyes and need some wipe up. ;) It should be possible to check a font name although on a gui program silently, i think. Has someone a idea or a little help for me? Thanks.

Maybe a command GetFontRealName() like discussed in http://www.purebasic.fr/english/viewtop ... me#p325409 (but with font requester) would help (both, with requester and without).

Sigi
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: check a font name if exists

Post by srod »

Have a look at the EnumFontFamiliesEx_() function on Windows. This can be used to examine a particular facename or to enumerate all fonts etc. You should be able to find some code in these forums somewhere.
I may look like a mule, but I'm not a complete ass.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Re: check a font name if exists

Post by MyTrial »

Hi srod

thanks for the quick help. I found some stuff in http://www.purebasic.fr/english/viewtop ... lies#p7808. This would be my start for the ms os. Is some same possible for a linux os?

Many thanks
Sigi
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: check a font name if exists

Post by eJan »

Try this:

Code: Select all

; Trond: http://www.purebasic.fr/english/viewtopic.php?p=233557#p233557

Procedure EnumFontFamProc(*lpelf.ENUMLOGFONT, *lpntm.NEWTEXTMETRIC, FontType, lParam)
  Name.s = Trim(PeekS(@*lpelf\elfLogFont\lfFaceName, 32))
  If UCase(Name) = UCase(PeekS(lParam))
    ProcedureReturn 0
  EndIf
  ProcedureReturn 1
EndProcedure

Procedure IsFontName(Name.s)
  hDC = GetDC_(0)
  V = EnumFonts_(hDC, 0, @EnumFontFamProc(), @Name)
  ReleaseDC_(0, hDC)
  ProcedureReturn 1 - V
EndProcedure

Debug IsFontName("Tahoma")
Last edited by eJan on Sat Jul 31, 2010 7:06 pm, edited 2 times in total.
Image
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: check a font name if exists

Post by netmaestro »

Best to compare UCase to UCase to avoid case sensitivity failures. In your snippet, "tahoma" would fail.
BERESHEIT
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: check a font name if exists

Post by eJan »

netmaestro wrote:Best to compare UCase to UCase to avoid case sensitivity failures. In your snippet, "tahoma" would fail.
Corrected. :idea:
Image
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: check a font name if exists

Post by heartbone »

MyTrial wrote:The problem is that LoadFont() loads a font if it is really there or not
This undesirable (to me) and unexpected replacement font auto loading behavior also manifests in Linux.
The IsFontName() workaround procedure that eJan kindly posted above only works for Windows®. :(

Does any member know the equivalent Linux method to determine if a font exists on the system?

Best solution:
The LoadFont() command needs a switch to turn on/off the automatic font matching behaviour
so the IsFont() command will make sense again. Right now it's useless.
Although technically not a bug.
Keep it BASIC.
Post Reply