Page 1 of 1

Load font file - Font-Awesome

Posted: Tue Sep 15, 2015 10:01 pm
by eddy
Hi,

Do you know a cross-platform trick to load font file ?

I'm trying load the iconic font :arrow: Font-Awesome : https://fortawesome.github.io/Font-Awesome/

Image

Re: Load font file - Font-Awesome

Posted: Wed Sep 16, 2015 7:08 am
by TI-994A
eddy wrote:I'm trying load the iconic font Font-Awesome...
Try this:

Code: Select all

;
; https://fortawesome.github.io/Font-Awesome/
; 1. FontAwesome.otf should be installed 
; 2. compiler should be set to Unicode 
; 3. tested with v5.31 (x64) on Windows 8.1 & OSX Mavericks

LoadFont(0, "FontAwesome", 20)

txt$ = "I " + Chr(61444) + " PureBasic! It runs on   "
txt$ + Chr(61818) + "   ,   " + Chr(61817) + "   and   " + Chr(61820) + "   ."

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Any, #PB_Any, 600, 100, "FontAwesome", wFlags)
TextGadget(1, 10, 30, 580, 100, txt$, #PB_Text_Center)
SetGadgetFont(1, FontID(0))

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 
It works on Windows and OSX. :wink:

Re: Load font file - Font-Awesome

Posted: Wed Sep 16, 2015 9:01 am
by eddy
TI-994A wrote:; 1. FontAwesome.otf should be installed
Hi,
Is it possible to do this step programmatically ?

Re: Load font file - Font-Awesome

Posted: Wed Sep 16, 2015 11:45 am
by Kiffi
eddy wrote:Is it possible to do this step programmatically ?
Windows only:

Code: Select all

Procedure InstallAdditionalFonts(font$)
  AddFontResource_(font$)
  SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE,0,0)
EndProcedure

Procedure DeinstallAdditionalFonts(Font$)
  RemoveFontResource_(font$)
  SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE,0,0)
EndProcedure 

InstallAdditionalFonts("YourFont.ttf") ; or *.otf
(Source: http://www.rsbasic.de/winapi-library/)

Greetings ... Peter

Re: Load font file - Font-Awesome

Posted: Wed Sep 16, 2015 3:34 pm
by heartbone
eddy wrote:Hi,
Do you know a cross-platform trick to load font file ?
Kiffi wrote:
eddy wrote:Is it possible to do this step programmatically ?
Windows only:

Code: Select all

Procedure InstallAdditionalFonts(font$)
  AddFontResource_(font$)
  SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE,0,0)
EndProcedure

Procedure DeinstallAdditionalFonts(Font$)
  RemoveFontResource_(font$)
  SendMessage_(#HWND_BROADCAST,#WM_FONTCHANGE,0,0)
EndProcedure 

InstallAdditionalFonts("YourFont.ttf") ; or *.otf
(Source: http://www.rsbasic.de/winapi-library/)

Greetings ... Peter
relevancy score 33%

Re: Load font file - Font-Awesome

Posted: Wed Sep 16, 2015 5:55 pm
by Kiffi
Peter: relevancy score 33%
heartbone: relevancy score 0%

Re: Load font file - Font-Awesome

Posted: Wed Sep 16, 2015 5:58 pm
by blueb
Font-Awesome looked interesting so I installed it.

TI- 994A I have a question:

How did you determine the "Chr(61444)" numbering system?

Using extended features of Character Map program, I found the "heart''
but my program displays that the icon number is: U + 2665

Is there a better program for searching through fonts? :?:

blueb

Re: Load font file - Font-Awesome

Posted: Wed Sep 16, 2015 7:49 pm
by Demivec
blueb wrote:How did you determine the "Chr(61444)" numbering system?

Using extended features of Character Map program, I found the "heart''
but my program displays that the icon number is: U + 2665
@blueb: The picture in the first posting shows 'fa-heart (@#xf004;)'. This would mean that the character value is $f004 hex or 61444 decimal.

Re: Load font file - Font-Awesome

Posted: Thu Sep 17, 2015 6:06 am
by Danilo
On Mac OS X you can embed the font into you .app bundle, see: Mac OS X: Load a font from file (like AddFontResource_)

Re: Load font file - Font-Awesome

Posted: Thu Sep 17, 2015 9:40 pm
by Vera
Hi, I too hope this awesome thread will include a Linux-solution one day. :)

Now on my own researches I also came across a page that offers a download of all AwesomeFont-images in 4 different formats. Thinking the one or other might be interested here's the link: Font Awesome - Vector icon (SVG & EPS), PNG & PSD (6mb)

greets ~ Vera

Re: Load font file - Font-Awesome

Posted: Thu Sep 17, 2015 11:22 pm
by freak
Linux solution:

Code: Select all

ImportC "-lfontconfig"
  FcConfigAppFontAddFile(*config, file.p-ascii)
EndImport

FcConfigAppFontAddFile(#Null, "/home/freak/pb/Test/fontawesome-webfont.ttf")


LoadFont(0, "FontAwesome", 20)

txt$ = "I " + Chr(61444) + " PureBasic! It runs on   "
txt$ + Chr(61818) + "   ,   " + Chr(61817) + "   and   " + Chr(61820) + "   ."

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Any, #PB_Any, 600, 100, "FontAwesome", wFlags)
TextGadget(1, 10, 30, 580, 100, txt$, #PB_Text_Center)
SetGadgetFont(1, FontID(0))

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 
Remember to enable unicode to see the special chars.

Re: Load font file - Font-Awesome

Posted: Fri Sep 18, 2015 9:55 am
by Vera
Image Image Image Image Image Image ~ that is great. I had no idea I had a fontconfic-devel on my OS.

Re: Load font file - Font-Awesome

Posted: Fri Sep 18, 2015 2:47 pm
by heartbone
freak wrote:Linux solution:

Code: Select all

ImportC "-lfontconfig"
  FcConfigAppFontAddFile(*config, file.p-ascii)
EndImport

FcConfigAppFontAddFile(#Null, "/home/freak/pb/Test/fontawesome-webfont.ttf")


LoadFont(0, "FontAwesome", 20)

txt$ = "I " + Chr(61444) + " PureBasic! It runs on   "
txt$ + Chr(61818) + "   ,   " + Chr(61817) + "   and   " + Chr(61820) + "   ."

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Any, #PB_Any, 600, 100, "FontAwesome", wFlags)
TextGadget(1, 10, 30, 580, 100, txt$, #PB_Text_Center)
SetGadgetFont(1, FontID(0))

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 
Remember to enable unicode to see the special chars.
You code works very well.
Thanks for the awesome knowledge. :D