Will using a custom font require installing it?

Post

Posted
Rating:
#1 (In Topic #1093)
Regular
JumpyVB is in the usergroup ‘Regular’
I want to use a specific font in my Gambas app.

Is it possible to do so without "installing" it to /usr/share/fonts/ + $ sudo fc-cache -v -f

For example

Code (gambas)

  1. TextLabel1.Font = Font["./myasetts/fa_solid.ttf"]
doesn't seem to work.

It's a font containing glyph icons. So it would not make sense to install for system wide use.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
The Short answer is "Yes" a font needs to be installed, but not necessarily in the systems /usr/share/fonts/ dir

have you tried installing it to  ~/.local/share/fonts ?
~/.local/share/fonts will not require root privileges to install there and delete.
Possibly your program can install the font there on load, then use it, then remove it when quitting?

I just tried this and it works….

Code (gambas)

  1.  
  2. ' Load font during _init() to ensure is loaded before other components
  3. Static Public Sub _init()
  4.  
  5.   If Not Exist(User.Home &/ ".local/share/fonts") Then Mkdir User.Home &/ ".local/share/fonts"
  6.   If Not Exist(User.Home &/ ".local/share/fonts/Autumn Wind.ttf") Then Copy "./Autumn Wind.ttf" To User.Home &/ ".local/share/fonts/Autumn Wind.ttf"
  7.  
  8.  
  9. Public Sub Form_Open()
  10.  
  11.   tb.Text = "hello"
  12.   tb.Height = 32
  13.  
  14.   tb.Font = Font["Autumn Wind, 16"]
  15.  
  16.  
  17.  
  18. ' Remove font file on exit
  19. Public Sub Form_Close()
  20.  
  21.   If Exist(User.Home &/ ".local/share/fonts/Autumn Wind.ttf") Then Kill User.Home &/ ".local/share/fonts/Autumn Wind.ttf"
  22.  
  23.  
  24.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
I also found i did not need to run fc-cache it works without it :)
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’
With Ubuntu and Linux Mint you can also use the folder "<COLOR color="#800000">User.Home &/ ".fonts</COLOR>".

Reusing the example of BruceSteers:

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   If Not Exist(User.Home &/ ".fonts") Then Mkdir User.Home &/ ".fonts"
  4.   If Not Exist(User.Home &/ ".fonts/FreeMono.ttf") Then Copy "/usr/share/fonts/truetype/freefont/FreeMono.ttf" To User.Home &/ ".fonts/FreeMono.ttf"
  5.   TextArea1.Text = "hello"
  6.   TextArea1.Height = 32
  7.  
  8.   TextArea1.Font = Font["FreeMono, 16"]
  9.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
JumpyVB is in the usergroup ‘Regular’

BruceSteers said

The Short answer is "Yes" a font needs to be installed, but not necessarily in the systems /usr/share/fonts/ dir

have you tried installing it to  ~/.local/share/fonts ?
~/.local/share/fonts will not require root privileges to install there and delete.
Possibly your program can install the font there on load, then use it, then remove it when quitting?

I just tried this and it works….

Code (gambas)

  1. ' Load font during _init() to ensure is loaded before other components
  2. Static Public Sub _init()
  3.   If Not Exist(User.Home &/ ".local/share/fonts") Then Mkdir User.Home &/ ".local/share/fonts"
  4.   If Not Exist(User.Home &/ ".local/share/fonts/Autumn Wind.ttf") Then Copy "./Autumn Wind.ttf" To User.Home &/ ".local/share/fonts/Autumn Wind.ttf"
  5. Public Sub Form_Open()
  6.   tb.Text = "hello"
  7.   tb.Height = 32
  8.   tb.Font = Font["Autumn Wind, 16"]

Yeas I like this solution thank you. And thank you for reintroducing me to ~.local/share/fonts - I had forgot it completely. And a huge plus not having to run fc-cache to use fonts in this location!

PS: I think I will skip removing the font at the end for now. But if I decide to do it, I think I will maybe use the default ramdisk location /dev/shm/ as the temporary store for the font asset and make a link pointing to it from ~.local/share/fonts - To speed things up and preserve ssd wrtite cycles.
Online now: No Back to the top

Post

Posted
Rating:
#6
Trainee
 I tried different ways to do it without installing but nothing worked. That's why I just install it.
Online now: No Back to the top
1 guest and 0 members have just viewed this.