[Win] how to load a font that is not installed?

Just starting out? Need help? Post your questions and find answers here.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

[Win] how to load a font that is not installed?

Post 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... :?
maw

Post 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 :shock:
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

maw wrote: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 :shock:
Thanks for the tip!

On linux it's very simple, just do:

Code: Select all

LoadFont(0,GetCurrentDirectory()+"accid.ttf",18)
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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
Dare2 cut down to size
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Yes found it too!

I was missing loadfont() after i loaded the font from memory :oops:

Now it works well :D


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!
Post Reply