RegisterFontFile on Windows with Roboto Light

Just starting out? Need help? Post your questions and find answers here.
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

Hi there folk!

I'm trying to load Roboto-Light.ttf with RegisterFontFile, however it seems that on Windows x64 in PureBasic 5.62 x64 RegisterFontFile simply halts program execution and does not return, at all. Has anyone else had problems with this?

The test code I used to load the most recent version of Roboto-Light.ttf:

Code: Select all

OpenConsole()

f.s = OpenFileRequester("Select font", "", "TrueType Font (*.ttf)|*.ttf", 0)
If(f <> "")
  result = RegisterFontFile(f)
  If(result)
    PrintN("success!")
  Else
    PrintN("fail!")
  EndIf 
EndIf 
- It never prints, as RegisterFontFile never seems to return.

Addition: I've had this on three Windows 10 systems with the same PureBasic version, two of which have NOD32 as AV and one of which has M$ Security Essentials. I'm not sure what is going on, as I can open the file for reading properly.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

Additional; I tried the Ubuntu Mono font, which causes the same exact issue - code execution seems to halt (0% activity on the PureBasic_Compilation0.exe process). This is weird, is this a bug in the RegisterFontFile function or am I missing something completely?
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4635
Joined: Sun Apr 12, 2009 6:27 am

Re: RegisterFontFile on Windows with Roboto Light

Post by RASHAD »

Try

Code: Select all

OpenConsole()
EnableGraphicalConsole(1)
f.s = OpenFileRequester("Select font", "", "TrueType Font (*.ttf)|*.ttf", 0)
If f <> ""
  result = RegisterFontFile(f)
  ConsoleLocate(7, 8)
  If result
    PrintN("success!")
  Else
    PrintN("fail!")
  EndIf
EndIf
Repeat
ForEver 
Egypt my love
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

Hi there Rashad,

That doesn't seem to do anything for me, can you explain what your intention was with the graphical console? I must add, my test code uses the console - however this happens with GUI applications as well

The next code also stalls completely:

Code: Select all

f.s = OpenFileRequester("Select font", "", "TrueType Font (*.ttf)|*.ttf", 0)
If f <> ""
  Debug RegisterFontFile(f)
EndIf
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: RegisterFontFile on Windows with Roboto Light

Post by Marc56us »

Try this:
(with Compiler > Compiler Option > Executable format: Console)

Code: Select all

OpenConsole()

f.s = OpenFileRequester("Select font", "", "TrueType Font (*.ttf)|*.ttf", 0)
If(f <> "")
  result = RegisterFontFile(f)
  If(result)
    PrintN("success!")
  Else
    PrintN("fail!")
  EndIf
EndIf 

; --- Added to show if program continue after If ...
PrintN("OK Done.")
Debug "OK Done."
Delay(3000)
Work for me with NOD32 activated
RASHAD example also works

:idea: (Using Debug "success!" is more easy than PrintN)
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

Yes, however as I've said, it doesn't only occur with console applications. I've tried so far:
  • Console
  • GUI
  • Thread-safe
  • Debugger enabled
  • Debugger disabled
In all of these cases program execution simply stops, also on the machine without NOD32

With regards to your remark about debug "success": yes, however I needed an output when the debugger was disabled. That's the only reason why the example is in an Console application, however I discovered it in a GUI application (non console)
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: RegisterFontFile on Windows with Roboto Light

Post by Marc56us »

With regards to your remark about debug "success": yes, however I needed an output when the debugger was disabled.
MessageRequester("RegisterFontFile ?", "Success!", #PB_MessageRequester_Info)
MessageRequester("RegisterFontFile ?", "Fail!", #PB_MessageRequester_Error)

Also works for a console application and Debug off

:wink:
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

Yes, I know that; what is your point? That's inconvenient compared to PrintN, especially when you're testing code on all platforms. This is also rather off-topic, I'm trying to discover why program execution halts when loading Ubuntu Mono or Roboto Light True Type fonts on Windows.

It doesn't even come to the point in the program that it outputs either one of those results.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
bytecave
User
User
Posts: 40
Joined: Mon Aug 13, 2012 7:26 am

Re: RegisterFontFile on Windows with Roboto Light

Post by bytecave »

This happens with several fonts, but doesn't repro reliably. Whether I extract my fonts to the TEMP folder or to the same current program folder, occasionally RegisterFontFile hangs and never returns. I've tried with PB 5.61 / 5.62, on 5 different Windows machines (3 WIn 8, 2 WIn 10), and eventually it hangs. You can put your tiny sample in a batch file and call it repeatedly until it hangs on RegisterFontFile. Exiting PB for a few hours and trying again later in the day often works. It's not random, but it repros reliably, *when* it repros at all. :)
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

bytecave wrote:This happens with several fonts, but doesn't repro reliably. Whether I extract my fonts to the TEMP folder or to the same current program folder, occasionally RegisterFontFile hangs and never returns. I've tried with PB 5.61 / 5.62, on 5 different Windows machines (3 WIn 8, 2 WIn 10), and eventually it hangs. You can put your tiny sample in a batch file and call it repeatedly until it hangs on RegisterFontFile. Exiting PB for a few hours and trying again later in the day often works. It's not random, but it repros reliably, *when* it repros at all. :)
Exactly, it happens very sporadically on two of my systems - however it seems I have found a system on which this can be reproduced on each build. On my MSI ge62 Apache Pro laptop with a fresh Windows 10 Pro install, x64 bit, it happens on every single run. This is a problem for me, as it completely breaks my application haha.

I think this can be considered a bug, no?

Thanks for confirming bytecave, I was almost going nuts! :)

Using native API on Windows does seem to work with the font:

Code: Select all

; int nResults = AddFontResourceEx(
;     m_szFontFile, 		// font file name
;     FR_PRIVATE,    	// font characteristics
;     NULL);
;     
;     

#FR_PRIVATE = $10

ImportC "gdi32.lib"
  AddFontResourceExW.i(lpszFilename.p-unicode, flags.l, *pdv)
EndImport

OpenConsole()

f.s = OpenFileRequester("Select font", "", "TrueType Font (*.ttf)|*.ttf", 0)
If(f <> "")
  start_time.q = ElapsedMilliseconds()
  result = AddFontResourceExW(f, #FR_PRIVATE, #Null)
  end_time.q = ElapsedMilliseconds()
  
  delta.q = end_time - start_time
  seconds.d = delta / 1000.0
  
  Debug "that took " + StrD(seconds, 2) + " seconds..."
  
  If(result)
    Debug "success! " + Str(result) + " fonts added"
  Else
    err = GetLastError_()
    Debug "fail: " + Str(err)
  EndIf 
EndIf
whereas the same code with the PureBasic function halts code execution. I need a cross platform solution though, and not hack in a fix for Windows like this.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
fryquez
Enthusiast
Enthusiast
Posts: 362
Joined: Mon Dec 21, 2015 8:12 pm

Re: RegisterFontFile on Windows with Roboto Light

Post by fryquez »

It is a bug.
RegisterFontFile sends #WM_FONTCHANGE Broadcast to all windows.
If one applications doesn't respond, your app freezes.

Question is why a Broadcast after adding a private font :?:

Anyways SendNotifyMessage or SendMessageTimeout should
be used by RegisterFontFile () and not SendMessage.
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

fryquez wrote:It is a bug.
RegisterFontFile sends #WM_FONTCHANGE Broadcast to all windows.
If one applications doesn't respond, your app freezes.

Question is why a Broadcast after adding a private font :?:

Anyways SendNotifyMessage or SendMessageTimeout should
be used by RegisterFontFile () and not SendMessage.
Interesting, that is indeed not required is it? How did you find out it sends this broadcast message? Is there a way of detecting the window that does not respond to it?
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

On my system, the Logitech Gaming Software that allows me to change settings in my Logitech g502 is the one not processing the message. PureBasic shouldn't wait for it to accept the message though, is there already a bugreport of this?

Code: Select all

#MAX_TITLE = 200

Procedure.i EnumWindowsProc(hWnd, lParam)
  Protected szTitle.s = Space(#MAX_TITLE)
  Protected szClass.s = Space(#MAX_TITLE)
  
  GetWindowText_(hWnd, @szTitle, #MAX_TITLE)
  GetClassName_(hWnd, @szClass, #MAX_TITLE)
  
  Debug "window: 0x" + RSet(Hex(hWnd), 8, "0")
  Debug "title:  " + szTitle
  Debug "class:  " + szClass
  
  SendMessage_(hWnd, #WM_FONTCHANGE, 0, 0)
  
  ProcedureReturn #True 
EndProcedure

EnumWindows_(@EnumWindowsProc(), 0)
outputs:

Code: Select all

... a whole lot more
window: 0x0006065C
title:  LogiDiscord Applet
class:  LogiDiscord_MessageHandler_{C8806448-C222-48bf-BC7A-B85D45CB7874}
and it never returns after that.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
fryquez
Enthusiast
Enthusiast
Posts: 362
Joined: Mon Dec 21, 2015 8:12 pm

Re: RegisterFontFile on Windows with Roboto Light

Post by fryquez »

Crusiatus Black wrote:Interesting, that is indeed not required is it? How did you find out it sends this broadcast message?
Yes, this sendmessage makes not sense to me.

To find out what a PB command does, I prefer to use IDA, there is a free version of IDA 7.0 available
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: RegisterFontFile on Windows with Roboto Light

Post by Crusiatus Black »

fryquez wrote:
Crusiatus Black wrote:Interesting, that is indeed not required is it? How did you find out it sends this broadcast message?
Yes, this sendmessage makes not sense to me.

To find out what a PB command does, I prefer to use IDA, there is a free version of IDA 7.0 available
Thank you, that indeed clears things up a lot. I'll write up a bug report, as I could not find an existing one
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
Post Reply