Page 1 of 1
LoadFontResource_() API
Posted: Sat Jun 15, 2019 1:24 am
by charvista
Hi
It looks like the LoadFontResource_() API is no longer working? Perhaps since 2018 already, but I have discovered it only now.
Code: Select all
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/window ... tresourcea
Thanks in advance
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 7:56 am
by Olliv
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).
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 8:33 am
by Mijikai
I can offer you my code to load fonts from memory:
Code: Select all
;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
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 10:13 am
by Karellen
Hmm, doesn't do the build in command in PureBasic the job?
https://www.purebasic.com/documentation ... tfile.html
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 10:21 am
by Mijikai
Yes, if theres a good reason to write it to disk before using it this will do just fine.
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 5:25 pm
by Karellen
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.
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 8:51 pm
by charvista
Thank you all
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.
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 9:21 pm
by Karellen
charvista wrote: As the font has been registered, is there no need to Unregister it?
No, as described in the manual:
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.
Re: LoadFontResource_() API
Posted: Sat Jun 15, 2019 9:46 pm
by charvista
Thanks Karellen. It escaped me.