Font Exists Function

Share your advanced PureBasic knowledge/code with the community.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Font Exists Function

Post by Xombie »

Code updated for 5.20+

I messed with some code from El_Choni ( viewtopic.php?t=2732 ) in order to change it from a simple enumeration function into a function to test whether a font name exists. Nothing special but here you go.

Code: Select all

Procedure EnumFontExists(*lpelf.ENUMLOGFONT, *lpntm.NEWTEXTMETRIC, FontType, lParam) 
  ;
  If LCase(PeekS(lParam)) = LCase(PeekS(@*lpelf\elfLogFont\lfFaceName[0])) : ProcedureReturn 0 : EndIf
  ;
  ProcedureReturn #True
  ;
EndProcedure

Procedure.b ExistsFont(FontName.s) 
  ;
  hWnd = GetDesktopWindow_()
  ;
  hDC = GetDC_(hWnd) 
  ;
  lResult = EnumFontFamilies_(hDC, 0, @EnumFontExists(), @FontName)
  ;
  ReleaseDC_ (hWnd, hDC)
  ;
  If lResult : ProcedureReturn #False : Else : ProcedureReturn #True : EndIf
  ;
EndProcedure

Debug ExistsFont("Arial")
Debug ExistsFont("Test")
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Useful :D
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Neat. Thanks.
@}--`--,-- A rose by any other name ..
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Very nice.

Now I'll be able to determine if I need an alternative/default.

Thanks

cheers
Post Reply