hi,
I use as a font 'Courier New' and works very well on my own PC.
But if this font is not installed on a user PC, there is another font who is selected.
But this is the problem if I use fixed text width and height zones.
How can I include a font in my software ?
I use ScreenMode, Windows, and PB 561 Final (x86/x64)
Is there a special command for that except LoadFont()
Thanks,
marc
How to include specific Font i my software ...
How to include specific Font i my software ...
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
PS: sorry for my english I speak flemish ...
Re: How to include specific Font i my software ...
Jou can include it in DataSection then load it, thanks to netmaestro & Num3:
http://www.purebasic.fr/english/viewtop ... 30#p234030
http://www.purebasic.fr/english/viewtop ... 30#p234030

Re: How to include specific Font i my software ...
RegisterFontFile() added in PB 5.50
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: How to include specific Font i my software ...
Be carefull MARC, sometime it's not possible to add fonts dynamicaly if you are not admin.
I don't know if it's your case, but i had this problem and it's good to know, i have lost several time before understand the problem
For me..impossible to use RegisterFontFile() or even several API who rest without effect

I don't know if it's your case, but i had this problem and it's good to know, i have lost several time before understand the problem
For me..impossible to use RegisterFontFile() or even several API who rest without effect


Not a destination
Re: How to include specific Font i my software ...
Hi,
thanks for the info,
Did some tests ...
and I gone use the font in DataSection solution.
So I can use it in multi platform environments.
thanks again
marc
thanks for the info,
Did some tests ...
and I gone use the font in DataSection solution.
So I can use it in multi platform environments.
thanks again

marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
PS: sorry for my english I speak flemish ...
Re: How to include specific Font i my software ...
For Windows, here's how one of my apps uses a custom font without it ever being installed on the PC, and doesn't need admin rights to use.marc_256 wrote:How can I include a font in my software ?
It's a modified version of other code I found on these forums (by Rashad, of course):
Code: Select all
; At the start of my app, I add the font from the exe (never from disk):
Global myfont=AddFontMemResourceEx_(?MyFont_Start,?MyFont_End-?MyFont_Start,0,@"1")
If myfont=0
MessageRequester("Error","App couldn't start correctly; please try again.")
End
EndIf
LoadFont(0,"name",size) ; Name = the internal name of the font (not its filename).
; App goes here (main loop, procedures, etc).
; ...
; When app is ready to quit, release the font:
FreeFont(0)
RemoveFontMemResourceEx_(myfont)
End
DataSection
MyFont_Start:
IncludeBinary "MyFont.ttf"
MyFont_End:
EndDataSection
; Done! :)
Re: How to include specific Font i my software ...
This should be cross platform, i.e., doesn't use any Windows API. It writes the font out to the temporary directory (if it doesn't already exist there), but you could as easily write it to the executable directory.
EDIT: I excerpted this from my game, and edited it. Looks like I had the WriteData line wrong. Can't test at the moment, but it should be correct now. Sorry for any inconvenience!
EDIT: I excerpted this from my game, and edited it. Looks like I had the WriteData line wrong. Can't test at the moment, but it should be correct now. Sorry for any inconvenience!
Code: Select all
DataSection
start_myfont:
IncludeBinary "myfontfile.ttf"
end_myfont:
EndDataSection
Procedure.i LoadPrivateFont(strFontFile.s, strFontFace.s, *pFontStart, *pFontEnd, iPointSize.i, iFlags.i = 0)
Protected hFont.i
Protected hFile.i
strFontFile = GetTemporaryDirectory() + strFontFile
;if font file doesn't already exist, write it to disk and register it for loading
If FileSize(strFontFile) = -1
hFile = CreateFile(#PB_Any, strFontFile)
If hFile
WriteData(hFile, *pFontStart, *pFontEnd - *pFontStart)
CloseFile(hFile)
EndIf
EndIf
;If font file can't be registered, we'll get the default font below
RegisterFontFile(strFontFile)
hFont = LoadFont(#PB_Any, strFontFace, iPointSize, iFlags)
If Not IsFont(hFont)
hFont = GetGadgetFont(#PB_Default) ;or just loadfont another default font you'd like
EndIf
ProcedureReturn hFont
EndProcedure
Define hFont.i
hFont = LoadPrivateFont("myfontfile.ttf", "MyFont", ?start_myfont, ?end_myfont, 16)
Last edited by bytecave on Thu Feb 08, 2018 7:58 pm, edited 2 times in total.
Re: How to include specific Font i my software ...
Hi,
@ Dude,
thanks, but I really need multi platform application.
@ bytecave
Thanks, this is it, I 'm gone test this in the afternoon.
Thanks,
Marc
@ Dude,
thanks, but I really need multi platform application.
@ bytecave
Thanks, this is it, I 'm gone test this in the afternoon.
Thanks,
Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
PS: sorry for my english I speak flemish ...