LoadFont returns Arial instead of 0.

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 1316
Joined: Sun May 14, 2017 1:48 am

LoadFont returns Arial instead of 0.

Post by AZJIO »

If it fails to load the font, then Arial or "Segoe UI" is loaded. I expect a rather old "Courier New" font if no Consolas is found, but not as Arial.

Code: Select all

If LoadFont(0, "Conso111las", 10)
	SetGadgetFont(#Combo1, FontID(0))
Else
	If LoadFont(0, "Courier New", 10)
		SetGadgetFont(#Combo1, FontID(0))
	EndIf
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: LoadFont returns Arial instead of 0.

Post by RASHAD »

On Windows the font mapper will always attempt to locate a font. If a font name which does not exist such as: "Tim Now Ronin", is used, then the font mapper will attempt to find the closest match. This will be based upon such criteria as: the font name, the font height, the style and so forth. Therefore, the assumption can not be made that a font will not be loaded, due only to an incorrect font name, size, ect...
Egypt my love
AZJIO
Addict
Addict
Posts: 1316
Joined: Sun May 14, 2017 1:48 am

Re: LoadFont returns Arial instead of 0.

Post by AZJIO »

I read this in the help, but I expected that despite the fact that the font is loaded, the function will return 0. If I load the font without "If", then I get the FontID(0) descriptor, but if I check the return flag, then this helps me unload Arial and load another font for index 0. As a result, I can't make protection if Consolas font is missing in WinXP. It remains for me to use WinAPI.

Code: Select all

LoadFont(0, "Conso111las", 10)
SetGadgetFont(#Combo1, FontID(0))
When using WinAPI I get the same result. If the font is incorrect, then I get the "handle" and Arial font.

Code: Select all

hFont = CreateFont_(16, 0, 0, 0, #FW_NORMAL, 0, 0, 0, #DEFAULT_CHARSET, #OUT_DEFAULT_PRECIS, #CLIP_DEFAULT_PRECIS, #PROOF_QUALITY, #DEFAULT_PITCH, @"Consolas")
If hFont
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: LoadFont returns Arial instead of 0.

Post by Mijikai »

I posted a workaround in the german forum mby also interesting:
https://www.purebasic.fr/german/viewtop ... 84#p359884
Post Reply