Page 1 of 1

check a font name if exists

Posted: Thu Jul 29, 2010 8:49 am
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

Re: check a font name if exists

Posted: Thu Jul 29, 2010 9:40 am
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.

Re: check a font name if exists

Posted: Thu Jul 29, 2010 10:38 am
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

Re: check a font name if exists

Posted: Thu Jul 29, 2010 5:46 pm
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")

Re: check a font name if exists

Posted: Thu Jul 29, 2010 6:02 pm
by netmaestro
Best to compare UCase to UCase to avoid case sensitivity failures. In your snippet, "tahoma" would fail.

Re: check a font name if exists

Posted: Thu Jul 29, 2010 9:50 pm
by eJan
netmaestro wrote:Best to compare UCase to UCase to avoid case sensitivity failures. In your snippet, "tahoma" would fail.
Corrected. :idea:

Re: check a font name if exists

Posted: Mon Nov 03, 2014 4:27 am
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.