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
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
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).
;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
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.
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.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
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.