Install fonts on Linux server

In this thread https://forum.xojo.com/15744-copy-canvas-to-imageview it appeared Picture.Graphics.Drawstring did not work for a Web Application once uploaded on a server, whereas it was working fine when run in the IDE.

The reason is that no fonts are installed on the said server. That is true for Xojo Cloud, as confirmed by Greg O’LOne in https://forum.xojo.com/15827-cdbasechartmbs-setfontsearchpath/0#p130614

That is true also for 1701 where my apps are hosted.

I tried to list fonts installed with this in the Shown event of a WebListBox and got no font :

For i As Integer = 0 To FontCount-1 me.addrow(Font(i)) Next

So I looked around the Internet and found two important pointers to help installing fonts :
http://www.ghacks.net/2009/01/09/installing-fonts-in-linux/
and
https://www.centos.org/forums/viewtopic.php?t=3028

I do not have permissions to /usr/share/fonts but was able to do the manipulation with the local fonts folder which should be quite enough for the needs of my apps :
Through SSH, to add the font metro.ttf :

mkdir ~/.fonts mv metro.ttf ~/.fonts

Then as instructed on the second link, I ran

fc-cache -f -v

It looks as if fc was successful in recognizing the font :

/usr/share/fonts: caching, new cache contents: 0 fonts, 0 dirs /usr/share/X11/fonts/Type1: skipping, no such directory /usr/share/X11/fonts/TTF: skipping, no such directory /usr/local/share/fonts: skipping, no such directory /home/bu1471a/.fonts: caching, new cache contents: 1 fonts, 0 dirs /var/cache/fontconfig: not cleaning unwritable cache directory /home/bu1471a/.fontconfig: cleaning cache directory fc-cache: succeeded

I verified the font has indeed been copied to the right place :

ls ~/.fonts Metro.ttf

I checked X11 is installed by listing /usr/share/ and it is there. I will have to assume it runs. I cannot see it when I go ps though. Maybe I need to run it somehow ?

Everything seems OK, but yet, my app does not see the installed font. Has anybody bumped into that kind of difficulty ?

For a desktop user, logged in as your account, it’s probably ok. For a webserver, whose process is not owned by you, probably you should need to put the font available to all in /usr/share/fonts but this need root access to be done. Then a reboot, just to be sure.

So far, it seems user permissions are fine to create the user fonts folder, to copy a font into it, and fcache is happy with it. Indeed it may require a restart for the font to be seen.

I started this thread essentially because from three threads recently, the issue of fonts on a server has been raised. It seems at least necessary to know what is possible or not, and eventually how.

With some degree of luck, Greg O’Lone for XC and Phillip Zedalis for 1701 will be kind enough to share their insight into that.

I would like to be able to use fonts on my site to produce features such as what can be seen here :
http://www.myfonts.com/fonts/itc/serif-gothic/

The font styles are displayed with a short phrase, one can change through the Sample Text combo box on top of the page. I believe this is obtained by generating a graphic on the server from the said font.

I do not want to use the WEFT approach to prevent people from snatching the font from the URL. If it was on the server, out of reach from pirates, I could provide all sorts of display services without running the risk to have my intellectual property stolen.

I am sure there are a lot more features Web apps developers would like to have, if they could access fronts on the server the way it is possible on a desktop machine.

Webfonts are different beasts than desktop fonts. They must be accessible (downloadable) by your webserver app to be pushed to the client part. For a typical web site, it could be on any proper folder from your website and not in you system fonts folder. The CSS (written by you or Xojo) should define a style using such font downloadable from that place, and you could use that style in your texts.

http://blog.typekit.com/2009/07/21/serving-and-protecting-fonts-on-the-web/

There was an excellent thread about how to use webfonts at https://forum.xojo.com/10782-tip-embedded-woff-fonts and I have been aware of that technology for decades (I started devising fonts in 1987).

The .webfont proposal is indeed interesting, but that’s just it. A proposal.

Whatever is accessible through a URI, however obfuscated, is fair game for hackers and WILL be pirated.

There is another reason why a font must be installed on the server system : fonts that are used to generate a PDF to print. As a matter of example, I have an application that uses a font to print MICR (the magnetic characters at the bottom of a check). Given the precision necessary to print such data, a font must be used in conjunction with PDF. This is only possible at the system level.

I am exploring the use of DynaPDF to print, but nothing will be possible if I cannot use that specific font. Actually, I doubt DynaPDF can be any help for a Web app if it cannot find any font.

Generally speaking installing the Microsoft TrueType fonts on Linux solves the issue for most font varieties. Not all fonts are easily accessible on Linux (that I can tell) but they are relatively easy to install if you have your own collection. I know Michel specializes in fonts so he would know more about the nuances than me. I simply know how to install them and get them working. :slight_smile:

In regards to web fonts the only issue I have seen is with CGI deployments. The ‘cgi-bin’ folder tends to be locked down and thus the browser cannot download the fonts sitting next to the binary. You need to place the fonts in a publicly accessible folder and link to them there. You need to account for that in whatever snippet/header/control mechanism you use to initialize the font.

Great. Is it something that can be carried out by the user, as I tried to do it, or should it be done by you ?

I have not tried it as anything other than a privileged user. It only takes a moment depending on distribution.

OK. I sent you an email. Thank you.

I believe the way around is to set the WOFF fonts as webfiles. Since the webfile provides a valid URL as long as it is in scope, it should work. I thought about that as a measure of protection, since there is no way to link to a webfile URL after it has lost scope or the session ended, but that would not prevent download while the font is displayed, so anybody using the browser developer console would be able to snatch it. The best way to prevent piracy is indeed to generate graphics from a system level font.

Two things I’d like to point out:

  1. On a web server, there may not be a shared fonts folder under /use/shared/fonts, so talk to your provider about where the fonts folder is located.

  2. The Microsoft fonts are no longer free. The license to install them on web servers expired a few years ago.

[quote=130703:@Greg O’Lone]Two things I’d like to point out:

  1. On a web server, there may not be a shared fonts folder under /use/shared/fonts, so talk to your provider about where the fonts folder is located.

  2. The Microsoft fonts are no longer free. The license to install them on web servers expired a few years ago.[/quote]

If you have the older version you can still use them. Microsoft has a great FAQ on this on their website.

This is not an issue for me, as I have my own font collection.

Google fonts can also be installed freely ; From https://developers.google.com/fonts/faq :

Can I download the fonts on Google Fonts to my own computer? Yes. To download the fonts, simply add fonts to your collection and click the "Download your Collection" link. You can download the fonts to use them for your mockups, in your documents or to host them on your own server.

In the experiments I conducted, I did not have permissions to access /usr/shared/fonts anyway. I believe only the administrator can.

So I proceeded to install in ~/.Fonts instead, which is supposed to be the users fonts folder.

The problem is, it does not seem to work. Maybe a restart is necessary, though.

The problem is your app probably runs as a different user.

I know on our[quote=130733:@Tim Hare]The problem is your app probably runs as a different user.[/quote]

This is a good point. On our servers the apps run as the same user as SSH but that may not be true for every host.

[quote=130736:@Phillip Zedalis]I know on our

This is a good point. On our servers the apps run as the same user as SSH but that may not be true for every host.[/quote]

The amazing thing is that the font did copy fine to ~/.fonts and was recognized by fc-cache but it still did not show.

Well. This is solved for me since the excellent team of my favorite host installed my custom fonts for me. Now I can concentrate on developing my application :slight_smile:

It is good to be able to rely on dependable partners who know what you do when operating web apps.

All the reason before jumping into a relationship with a potential host to go further than simply “does it run Xojo web apps ?” or “Is it the cheapest I can find?”. When your business depends on it, you better have a host that will be there for you.

I know : since 1996 I have had my content of horses dying on me :wink:

Hey guys, pay attention for path. It’s probably /usr/share/fonts/truetype or /usr/local/share/fonts/truetype

Become root:

sudo -i

Go there to check the correct place with

cd /usr …

then copy the TTFs :wink:

cp …

Make sure the files have 644 permission
and then rebuild the font cache

fc-cache -fv

You could check the fonts found with

fc-list | less

‘q’ to exit

exit

[quote=130890:@Rick Araujo]Hey guys, pay attention for path. It’s probably /usr/share/fonts/truetype or /usr/local/share/fonts/truetype

Become root:

sudo -i

Go there to check the correct place with

cd /usr …

then copy the TTFs :wink:

cp …

Make sure the files have 644 permission
and then rebuild the font cache

fc-cache -fv

You could check the fonts found with

fc-list | less

‘q’ to exit

exit[/quote]

Thank you Rick. But as I posted above, I do not have access to the root privileges. So I tried installing a font called metro.ttf in the user folder ~/.Fonts.

I then was able to verify that fc-cache had validated it. But yet, it would not show up in my test app.

After that, I requested 1701 to install the fonts for me, and they were installed fine in the system directory, so they show now in my test app.

But since your post mentions a way to see which fonts are installed, I went

 fc-list | less

And guess what ? It finds Metropolitain:style=Regular (metro.ttf)

Yet, the said font still is not seen by the web app with the regular Font(i) Xojo code.

Morality : ask your hosting provider to install the fonts.

[quote=130894:@Michel Bujardet]fc-list | less

Guess what ? It finds Metropolitain:style=Regular (metro.ttf)

Yet, the said font still is not seen by the web app with the regular Font(i) Xojo code.

Morality : ask your hosting provider to install the fonts.[/quote]

Sure, your user (process owner, SSH) and the hosting user (for example, Apache uses the default www-data user as the process owner) have different rights and different local data (~/.fonts for example) . As I, by myself, create my own virtual servers; I do have such kind of powers (as many of us maybe), so the recipe is served for people like me. :wink: