Page 1 of 1

Checking Font in windows

Posted: Thu Feb 21, 2008 11:31 am
by Character
Hi people, I've a quick question:

I want to check if a font is present in windows.
But, according the help file, in windows if a font is not present, another font is loaded.
How, can I check then if a specific font is present or not?

(this code propably checks if any font is loaded only...)

Code: Select all

If IsFont(LoadFont(#PB_Any, "Tahoma", 8)) = #False 
  Debug "ouch"
Else 
  Debug Font = LoadFont(#PB_Any, "Tahoma", 8)
EndIf

Posted: Thu Feb 21, 2008 11:44 am
by dell_jockey
Thanks for pointing out the defaul behaviour on Windows, I wasn't aware of that.
I suppose that not even prior checking whether a file called "c:\windows\fonts\tahoma*.ttf" exists at all would indeed guarantee that it will be loaded correctly....

Posted: Thu Feb 21, 2008 12:27 pm
by Trond

Code: Select all

Procedure EnumFontFamProc(*lpelf.ENUMLOGFONT, *lpntm.NEWTEXTMETRIC,	FontType, lParam)
  Name.s = Trim(PeekS(@*lpelf\elfLogFont\lfFaceName, 32))
  If Name = 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")

   

Posted: Thu Feb 21, 2008 12:38 pm
by Character
Thanks! :)

Re: Checking Font in windows

Posted: Sat Jul 18, 2015 11:51 pm
by Michael Vogel
How to check if a font is also available in italic?

Code: Select all

Procedure EnumFontFamProc(*lpelf.ENUMLOGFONT, *lpntm.NEWTEXTMETRIC,   FontType, lParam)
	Name.s = Trim(PeekS(@*lpelf\elfLogFont\lfFaceName, 32))
	If Name = 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("Book Antiqua");			1
Debug IsFontName("Book Antiqua Italic");		0
Debug IsFontName("Cambria");				1
Debug IsFontName("Cambria Italic");			should be 1