Page 1 of 1
[Win] how to load a font that is not installed?
Posted: Sun Feb 24, 2008 12:06 pm
by Num3
I've been scratching my head with this one...
How can i load a font, i.e. from the executable directory, that is not installed in the FONTS directory?
Maybe PB could have a catchfont() command, so fonts could be included in the executable binary...

Posted: Sun Feb 24, 2008 12:51 pm
by maw
You can do an IncludeBinary on the font and use AddFontMemResourceEx to catch it. Or if you prefer to have the font as a file you use AddFontResourceEx.
http://msdn2.microsoft.com/en-us/library/ms533942.aspx
http://msdn2.microsoft.com/en-us/library/ms533937.aspx
Assuming you are using Windows that is. If not, I haven't got a clue

Posted: Sun Feb 24, 2008 1:09 pm
by Num3
Thanks for the tip!
On linux it's very simple, just do:
Code: Select all
LoadFont(0,GetCurrentDirectory()+"accid.ttf",18)
Posted: Sun Feb 24, 2008 1:34 pm
by Dare
I think Nettie (netmaestro) gave some code for that somewhere here but can't find the thread.
Edit: Found it (I think):
http://www.purebasic.fr/english/viewtop ... light=font
Posted: Sun Feb 24, 2008 1:45 pm
by Num3
Yes found it too!
I was missing loadfont() after i loaded the font from memory
Now it works well
Load from DataSection:
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
Load From executable directory:
Code: Select all
OpenLibrary(0,"gdi32.dll")
AddFontResource_(GetCurrentDirectory()+"anorexia.fon")
SendMessage_(#HWND_BROADCAST, #WM_FONTCHANGE, 0, 0)
CloseLibrary(0)
LoadFont(0,"anorexia",12)
--EDIT--
@Fred,
Maybe you could polish loadfont under windows and detect path and extension part on the font name parameter, so it loads from it if the font if it's not installed!