Page 1 of 1

LoadFont() never return zero

Posted: Mon Jan 23, 2017 9:36 am
by auraes
Hi,
If the font was not loaded successfully, LoadFont() returns nonzero instead of zero.

Code: Select all

If OpenWindow(0, 0, 0, 270, 160, "Loading font...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  r = LoadFont(1, "", 24)
  Debug r
  r = LoadFont(#PB_Any, "", 24)
  Debug r
  
  r = LoadFont(1, "anything", 24)
  Debug r
  r = LoadFont(#PB_Any, "anything", 24)
  Debug r
  
  r = LoadFont(1, "Arial", 24)
  Debug r
  r = LoadFont(#PB_Any, "Arial", 24)
  Debug r
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
PureBasic 5.51 (Windows - x64)
PureBasic 5.51 (Linux - x64)

Re: LoadFont() never return zero

Posted: Mon Jan 23, 2017 10:13 am
by Fred
This is documented, it's the way Windows works:

Code: Select all

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... 

Re: LoadFont() never return zero

Posted: Mon Jan 23, 2017 12:01 pm
by auraes
Thank you.
I get the same thing under Linux (Lubuntu 16.04.1 LTS, 64-bit)
So, LoadFont() and IsFont() never seem to return zero... Why not !?
I'll take a look at RegisterFontFile() to be sure to have the good Font.

Re: LoadFont() never return zero

Posted: Mon Jan 23, 2017 12:36 pm
by Dude
auraes wrote:LoadFont() and IsFont() never seem to return zero... Why not !?
Fred just told you why. :)