Page 1 of 1

Font Exists Function

Posted: Fri Jan 06, 2006 8:59 pm
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")

Posted: Fri Jan 06, 2006 9:37 pm
by Droopy
Useful :D

Posted: Sat Jan 07, 2006 2:43 am
by Dare2
Neat. Thanks.

Posted: Sat Jan 07, 2006 3:23 am
by rsts
Very nice.

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

Thanks

cheers