It is currently Mon Sep 16, 2019 9:34 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 1:24 am 
Offline
Addict
Addict
User avatar

Joined: Tue Sep 23, 2008 11:38 pm
Posts: 856
Location: Belgium (& Luxembourg)
Hi
It looks like the LoadFontResource_() API is no longer working? Perhaps since 2018 already, but I have discovered it only now.
Code:
Procedure zFontAdd(FontFileName.s)
    AddFontResource_(FontFileName.s)
    SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE, #Null, #Null)
EndProcedure

It looks like I need to use LoadFontResourceA_() or LoadFontResourceW_() ? I am not understanding APIs well, so maybe you can help me?
Using PB 5.70 LTS x64 on Windows 10 Home
https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-addfontresourcea
Thanks in advance

_________________
- Future conversation forecasting not yet implemented.
- If the future had copied a program from now, they would have called it version -1.


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 7:56 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 434
I cannot help you greatly. But I can tell you what do xxxA_() and xxxW_() mean.

A and W mean Ascii and Word. This informs you the size of each character in a string.

A = 8 bits per character (1 byte, old standard)
W = 16 bits per character (2 bytes, new standard)

Earlier, "hello" was stored as 'hello' on memory.
Now, on Unicode standard, "hello" is stored as ' h e l l o' on memory. Normally, blank spaces between each character is a zero-8-bits code. This allows to treat far more characters as just the 256 characters of ASCII. Now we can treat a set of 65536 characters (256 * 256 characters), what it allows us to treat asian characters, all european characters, etc...

To check (just one time, not everytime !) if your function is right, you can search in which DLL file, this function is stored. And check its fullname with the Purebasic DLL native library (OpenLibrary(), ExamineLibrary(), etc... ).

If the name of the function contains more than classic characters (as '@' i.e. ) post it here to have the translation. Extra characters in the name of a DLL function means the name is 'decorated' and contains a code which tells us what is the arguments template (how many variables, and which type).


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 8:33 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 512
I can offer you my code to load fonts from memory:

Code:
;CatchFont() & ReleaseFont()
;Author: Mijikai
;------------------------------------------------------------------------------------------------
;This allows you to load (catch & free) fonts from memory.
;The procedure CatchFont() returns a PureBasic #Font on success.
;It optionally returns the handle to the created resource memory.
;This memory will be freed once the program ends (PureBasic #Fonts act the same).
;So in most cases u wont really need to release the #Font / handle.
;------------------------------------------------------------------------------------------------

Procedure.i ReleaseFont(Font.i,Handle.i = #Null)
  If IsFont(Font)
    FreeFont(Font)
  EndIf
  If Handle
    ProcedureReturn RemoveFontMemResourceEx_(handle)
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i CatchFont(*Buffer,BufferSize.i,FontName.s,FontSize.i,FontStyle.i = #Null,*Handle.Integer = #Null)
  Protected handle.i
  Protected fonts.i
  Protected font.i
  fonts = 1
  handle = AddFontMemResourceEx_(*Buffer,BufferSize,#Null,@fonts)
  If handle
    font = LoadFont(#PB_Any,FontName,FontSize,FontStyle)
    If IsFont(font)
      If *Handle
        *Handle\i = handle
      EndIf
      ProcedureReturn font
    EndIf
    RemoveFontMemResourceEx_(handle)
  EndIf
  ProcedureReturn #Null
EndProcedure



Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 10:13 am 
Offline
User
User

Joined: Fri Aug 16, 2013 2:52 pm
Posts: 68
Hmm, doesn't do the build in command in PureBasic the job?

https://www.purebasic.com/documentation/font/registerfontfile.html

_________________
This signature was removed by [removed] for your own safety.


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 10:21 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 512
Yes, if theres a good reason to write it to disk before using it this will do just fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 5:25 pm 
Offline
User
User

Joined: Fri Aug 16, 2013 2:52 pm
Posts: 68
Mijikai wrote:
Yes, if theres a good reason to write it to disk before using it this will do just fine.


Sorry, couldn't get that this was an issue for the orginal question. My native language is not english. Just dropped spontaneously my thought becaus I wanted to help. Sorry again.

_________________
This signature was removed by [removed] for your own safety.


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 8:51 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Sep 23, 2008 11:38 pm
Posts: 856
Location: Belgium (& Luxembourg)
Thank you all :P
The problem is solved, thanks to Karellen, pointing out for the addition of RegisterFontFile(), that solved the problem, a feature added since PB 5.50.
It was not necessary earlier, perhaps that was the reason...

One more question:
As the font has been registered, is there no need to Unregister it? Is the font automatically unregistered when the program ends? Or when the computer is shut down?
This question to know if the memory would not be overloaded when registering several thousands of fonts.

_________________
- Future conversation forecasting not yet implemented.
- If the future had copied a program from now, they would have called it version -1.


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 9:21 pm 
Offline
User
User

Joined: Fri Aug 16, 2013 2:52 pm
Posts: 68
charvista wrote:
As the font has been registered, is there no need to Unregister it?

No, as described in the manual:
Quote:
The font file is registered for the current program only. This means that the font(s) are not accessible by other programs and will be unregistered when the program ends. No system-wide changes are made by this command.

_________________
This signature was removed by [removed] for your own safety.


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadFontResource_() API
PostPosted: Sat Jun 15, 2019 9:46 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Sep 23, 2008 11:38 pm
Posts: 856
Location: Belgium (& Luxembourg)
Thanks Karellen. It escaped me. :mrgreen:

_________________
- Future conversation forecasting not yet implemented.
- If the future had copied a program from now, they would have called it version -1.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye