Embedding font in PB code?
Embedding font in PB code?
Is it possible to embed a font in PureBasic code, even though it not installed in the OS?
DE AA EB
Re: Embedding font in PB code?
Hi davido
Code by NUM3
I did not test it but Some how I am sure that it is OK
Code by NUM3
I did not test it but Some how I am sure that it is OK

Code: Select all
OpenLibrary(0,"gdi32.dll")
fontid=CallFunction(0,"AddFontMemResourceEx",?font,?end_font-?font,0,@"1")
CloseLibrary(0)
LoadFont(0,"anorexia",12)
DataSection
font:
IncludeBinary "anorexia.fon"
end_font:
EndDataSection
Egypt my love
Re: Embedding font in PB code?
Tested works like a charm
PB 5.30 x86 Win 8.1 x64
PB 5.30 x86 Win 8.1 x64
Code: Select all
Global fontid
;OpenLibrary(0,"gdi32.dll")
fontid=AddFontMemResourceEx_(?font,?end_font-?font,0,@"1")
;CloseLibrary(0)
LoadFont(0,"SPACECRAFT",14)
OpenWindow(0,0,0,400,300,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered| #PB_Window_MaximizeGadget| #PB_Window_SizeGadget)
TextGadget(0,10,10,300,40,"This is a TEST",#SS_CENTERIMAGE | #SS_CENTER| #WS_BORDER)
SetGadgetFont(0,FontID(0))
SetGadgetColor(0,#PB_Gadget_FrontColor,#Red)
SetGadgetColor(0,#PB_Gadget_BackColor,#Yellow)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
RemoveFontMemResourceEx_(fontid)
Quit = 1
EndSelect
Until Quit = 1
End
DataSection
font:
IncludeBinary "SPACECRAFT.ttf"
end_font:
EndDataSection
Egypt my love
Re: Embedding font in PB code?
Hi RASHAD,
Great! Thank you for going to all this trouble.
Your code always works, so when I couldn't get it to work first time I wondered what I could possibly be doing wrong.
After a while I found I was entering the font-file name - not the name of the font! doh
Great! Thank you for going to all this trouble.

Your code always works, so when I couldn't get it to work first time I wondered what I could possibly be doing wrong.
After a while I found I was entering the font-file name - not the name of the font! doh

DE AA EB
Re: Embedding font in PB code?
Hi davido
You should be punished for that
We always use the font name not the font file name to LoadFont()
Be careful Dbl Click the font file and read the font name on top because sometimes they use a phony name for the file
You should be punished for that

We always use the font name not the font file name to LoadFont()
Be careful Dbl Click the font file and read the font name on top because sometimes they use a phony name for the file
Egypt my love
Re: Embedding font in PB code?
@heartbone, good thinking.heartbone wrote:Does anyone have da codes to do this wid de Linux?
Perhaps someone knows the Mac OSX equivalents, too.
DE AA EB
Re: Embedding font in PB code?
On Mac OS X you can embed a font into the app resources, see here.davido wrote:Perhaps someone knows the Mac OSX equivalents, too.
Re: Embedding font in PB code?
Note for future reference: the font name in LoadFont() must be the internal font name of the TTF file (seen when double-clicking it to preview it); and NOT be the actual TTF filename itself. I just spent hours trying to work out why this wasn't working, and that was the reason. 

Re: Embedding font in PB code?
Since PB 5.60 the native function for all OS is : RegisterFontFile()