Do you know a cross-platform trick to load font file ?
I'm trying load the iconic font


Try this:eddy wrote:I'm trying load the iconic font Font-Awesome...
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
Hi,TI-994A wrote:; 1. FontAwesome.otf should be installed
Windows only:eddy wrote:Is it possible to do this step programmatically ?
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
eddy wrote:Hi,
Do you know a cross-platform trick to load font file ?
relevancy score 33%Kiffi wrote:Windows only:eddy wrote:Is it possible to do this step programmatically ?(Source: http://www.rsbasic.de/winapi-library/)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
Greetings ... Peter
@blueb: The picture in the first posting shows 'fa-heart (@#xf004blueb 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
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
You code works very well.freak wrote:Linux solution:Remember to enable unicode to see the special chars.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