Page 1 of 1
RegisterFontFile from Memory
Posted: Mon May 23, 2022 11:50 am
by jacdelad
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).
Re: RegisterFontFile from Memory
Posted: Mon May 23, 2022 3:39 pm
by deeproot
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:
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
Posted: Mon May 23, 2022 3:59 pm
by jacdelad
Yes, Windows. My program is meant to run on Windows and Raspi.
Re: RegisterFontFile from Memory
Posted: Mon May 23, 2022 6:46 pm
by User_Russian
AddFontMemResourceEx
It doesn't work with VectorDrawing.
Re: RegisterFontFile from Memory
Posted: Mon May 23, 2022 7:09 pm
by jacdelad
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.