Checking Font in windows

Just starting out? Need help? Post your questions and find answers here.
Character
Enthusiast
Enthusiast
Posts: 337
Joined: Mon Aug 07, 2006 3:51 pm
Location: Netherlands

Checking Font in windows

Post 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
Cessante causa cessat effectus
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post 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....
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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")

   
Character
Enthusiast
Enthusiast
Posts: 337
Joined: Mon Aug 07, 2006 3:51 pm
Location: Netherlands

Post by Character »

Thanks! :)
Cessante causa cessat effectus
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Checking Font in windows

Post 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
Post Reply