Hello,
I would like to have the option to include a font file without having to write it to disk before loading (if that's possible).
RegisterFontFile from Memory
RegisterFontFile from Memory
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
-
- Enthusiast
- Posts: 271
- Joined: Thu Dec 17, 2009 12:00 pm
- Location: Llangadog, Wales, UK
- Contact:
Re: RegisterFontFile from Memory
See this thread - - https://www.purebasic.fr/english/viewtopic.php?p=455022
For Windows it's quite straightforward, loading direct from a font file embedded in the data section - simple example:
For Windows it's quite straightforward, loading direct from a font file embedded in the data section - simple example:
Code: Select all
;
; Change the font filename and LoadFont as needed !!!
;
EnableExplicit
Enumeration
#Win1
#Text1
#DejaVuSansBold
EndEnumeration
Define myMemFont
Procedure CatchFont(*Memory, myMemSize)
; load font into memory
Protected myParam1 = 1
ProcedureReturn AddFontMemResourceEx_(*Memory, myMemSize, 0, @myParam1)
EndProcedure
If OpenWindow(#Win1, 0, 0, 460,100,"Font test", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
myMemFont = CatchFont(?dejafont, ?end_dejafont - ?dejafont)
LoadFont(#DejaVuSansBold, "DejaVu Sans", 12, #PB_Font_Bold)
TextGadget(#Text1, 20,40,420,25, "The quick brown fox jumps over the lazy dog")
SetGadgetFont(#Text1, FontID(#DejaVuSansBold))
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
DataSection
dejafont:
IncludeBinary "DejaVuSans-Bold.ttf"
end_dejafont:
EndDataSection
Re: RegisterFontFile from Memory
Yes, Windows. My program is meant to run on Windows and Raspi.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
-
- Addict
- Posts: 1443
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: RegisterFontFile from Memory
It doesn't work with VectorDrawing.AddFontMemResourceEx
Re: RegisterFontFile from Memory
Yes, the help also tells so. But that's not important for me.
It's just that I need a specific font that almost all systems don't have installed. And I wanted to avoid writing it temporarily onto the harddisk.
It's just that I need a specific font that almost all systems don't have installed. And I wanted to avoid writing it temporarily onto the harddisk.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB