FreeCAD Snap Package Font Problems: Fix

I recently went over to using Ubuntu 20.04 from 18.04 and my new FreeCAD installation is now a snap package rather than an installation built using the traditional apt-get install route. I’ve done this for no particular reason other than that is the way thing seem to be going and frankly I just went with the flow. I wanted to get the thing working rather than fuss over how it was installed. But I ran into some Snap package font problems.

I’d used the FreeCAD snap package for a couple of small test projects and all seemed well. Then I decided I needed to make some Christmas lettering on my Trusty Creality Ender 3. To do this all I needed to do was use the ShapeString tool to get the letters from a font on my system. I’ve done this before on Ubuntu 18.04 with a traditionally installed FreeCAD package (See this post). But on Ubuntu 20.04 I hit a road block associated with the FreeCAD snap package.

 

One of the purposes of the snap packaging format is to limit access to system files. I assume it’s for security reasons and also so the package is not dependent upon a particular system file. This means (as well as enhanced security) that a snap package for Ubuntu should work without issue on any other flavour of Linux as well. That’s the theory anyway.

One problem with this is that Ubuntu/Linux font files are usually in either /usr/share/fonts or /usr/local/share/fonts.

So neither of these system directories are available to the FreeCAD snap package.

Consequently when you try and set up the path to the font of your choice in the ShapeSting tool you will find that the only directories that are available (the rest are greyed out) are those under your home directory. So, in essence you cannot set up the path to the font! While you can actually manually type in the path into the ShapeString tool, when you hit enter you get this:

Screen capture of FreeCAD ShapeScreen font problem setting error
Notice I’ve set the path to /usr/share/fonts. It doesn’t like it!
ShapreString Font problem dialog FreeCAD
Here’s what it actually says at the bottom of the above screen. Yours may be different.

So, how do you access fonts for the ShapeString tool? Well, this below works for me, but I’d be quite happy for anyone to show me a better way.

Basically you have to make the fonts you want to use available from within the bits of the file system that the snap package can see, i.e. anywhere under the user home directory. I’d suggest that it’s best not to copy them directly into the snap package location as you will probably be updating the package sometime and the fonts will be lost if you do that. Instead create (if you don’t have one already) a dot fonts directory (i.e. /home/<user-name>/.fonts) and then copy them in there.

Example:

cd ~
cp -r /usr/share/fonts/msttcorefonts/ ~/.fonts/

So far so good.

Now, go to the FreeCAD snap setup and go to directory:

/home/<user-name>/snap/freecad/current/

In here make soft link to the new fonts directory

ln -s ~/.fonts fonts

Restart FreeCAD

Then when you come to setting up the path to the font of your choice in the ShapeString tool you can now select from anything you have copied into /home/<user-name>/.fonts via the link you have in the freecad setup.

i.e example: either:

/home<user-name>/snap/freecad/current/fonts/mstcorefonts/Comic_Sans_MS_Bold.ttf (or whatever)

or by the other route that the dialog box reveals which is to the current active package version (in my case that is version 22)

/home/<user-name>/snap/freecad/22/fonts/msttcorefonts/Comic_Sans_MS_Bold.ttf

Both of these (actually the same thing!) can be selected using the dialog box associated with setting the font which is triggered by clicking on the three dots next to the font path text box.

After doing the setup you can actually set a default font for the ShapeString tool too. So if you only ever (or mostly) use one font you can set it to that. Otherwise the font path in the ShapeString tool will be blank and need setting up everytime you use it.

Do this by first selecting Draft mode first. If you don’t do this first you won’t be able to set the path for the ShapeString default font.

Now go edit->preferences. You should see a dialog box with “Draft” as the last entry on the left. Click it.

Then select the “Text and Dimensions” tab

Then in the displayed window at the bottom set the Shapestring path to your default font using the three dot navigation tool at the end of the line.

That’s it. Now when you start the ShapeString tool it will load the default font, but you can still replace with another if you want.

I have to say I’m not entirely happy with this as a solution, but it works for me. I hope (failing finding a better solution) it works for you too. If you know a better way to deal with these snap package font problems, I’d love to know what they are.

NOTE: Evidently there is/was a similar problem with the LibreOffice snap, so these Snap package font problems are not just confined to FreeCAD. A suggestion (relating to the LibreOffice problems) was that before copying the fonts to the ~/.fonts directory you run:

sudo fc-cache -fv

This refreshes the cached fonts.

I don’t think that is necessary. Although I doubt if it will do any harm.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>