Load font file - Font-Awesome

Just starting out? Need help? Post your questions and find answers here.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Load font file - Font-Awesome

Post 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
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Load font file - Font-Awesome

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Load font file - Font-Awesome

Post by eddy »

TI-994A wrote:; 1. FontAwesome.otf should be installed
Hi,
Is it possible to do this step programmatically ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Kiffi
Addict
Addict
Posts: 1500
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Load font file - Font-Awesome

Post 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
Hygge
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Load font file - Font-Awesome

Post 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%
Keep it BASIC.
User avatar
Kiffi
Addict
Addict
Posts: 1500
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Load font file - Font-Awesome

Post by Kiffi »

Peter: relevancy score 33%
heartbone: relevancy score 0%
Hygge
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Load font file - Font-Awesome

Post 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
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Load font file - Font-Awesome

Post 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.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Load font file - Font-Awesome

Post 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_)
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Load font file - Font-Awesome

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Load font file - Font-Awesome

Post 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.
quidquid Latine dictum sit altum videtur
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Load font file - Font-Awesome

Post by Vera »

Image Image Image Image Image Image ~ that is great. I had no idea I had a fontconfic-devel on my OS.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Load font file - Font-Awesome

Post 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
Keep it BASIC.
Post Reply