RegisterFontFile from Memory

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

RegisterFontFile from Memory

Post 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).
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
deeproot
Enthusiast
Enthusiast
Posts: 284
Joined: Thu Dec 17, 2009 12:00 pm
Location: Llangadog, Wales, UK
Contact:

Re: RegisterFontFile from Memory

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: RegisterFontFile from Memory

Post by jacdelad »

Yes, Windows. My program is meant to run on Windows and Raspi.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: RegisterFontFile from Memory

Post by User_Russian »

AddFontMemResourceEx
It doesn't work with VectorDrawing.
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: RegisterFontFile from Memory

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply