How to install "standard" TTF Microsoft fonts

Hi there, this "how to" is mainly targeting new users that come from Linux and expect to simply install a package that has some Microsoft hints in its name, which it doesn't. As a matter of fact the port that installs standard Microsoft TTF fonts is called webfonts, and in order to use such fonts you need to install it and set up X.org properly (this is not required on Linux distributions anymore).
This "how to" is based on this section of the handbook: https://docs.freebsd.org/en/books/handbook/x11/#x-fonts

1) Switch to root, install the package and update the font cache:
Code:
$ su -l
# pkg install webfonts
f# fc-cache -f

If the fonts are still unavailable:

1) Switch to root, create an entry for X.org:
Code:
$ su -l
# ee /usr/local/etc/X11/xorg.conf.d/90-fonts.conf

2) Copy and paste the configuration below, then save it and close ee:
Code:
Section "Files"
  FontPath "/usr/local/share/fonts/webfonts/"
EndSection

Section "Module"
  Load "freetype"
EndSection

3) Exit from root typing exit; restart X.org, for instance logging out from your LightDM session.
Log in again and there you are:

Code:
ls /usr/local/share/fonts/webfonts/
andalemo.ttf  ariali.ttf    cour.ttf      fonts.dir     georgiai.ttf  timesbd.ttf   trebucbd.ttf  verdanab.ttf
arial.ttf     ariblk.ttf    courbd.ttf    fonts.scale   georgiaz.ttf  timesbi.ttf   trebucbi.ttf  verdanai.ttf
arialbd.ttf   comic.ttf     courbi.ttf    georgia.ttf   impact.ttf    timesi.ttf    trebucit.ttf  verdanaz.ttf
arialbi.ttf   comicbd.ttf   couri.ttf     georgiab.ttf  times.ttf     trebuc.ttf    verdana.ttf   webdings.ttf

If you don't have a login manager simply restart your computer to make those changes actives and permanent.
 
Last edited:
Quite useful.

Some minor notes:
  • FontPath is missing a close quote.
  • Should the pkg and editor command be prefixed with # to signify root user?
 
and set up X.org properly (this is not required on Linux distributions anymore).
This shouldn't be required on any OS. The X11 font path is only relevant for "core fonts" (rendered server-side). They're practically dead noawadays (e.g. as they're only designed for bitmap fonts without alpha channel), applications use fontconfig to find fonts and freetype to rasterize them and then either XRender to upload/render the glyphs (the Xft library does that), or even more often nowadays render the glyphs fully client side (e.g. with cairo) and just upload the resulting pixmaps (AFAIK gtk and Qt do it this way).

I never added anything to Xorg's font path for many years and never ran into some app not finding fonts because it relies on X11 core fonts...

That said, adding your config certainly doesn't hurt. It's just extremely unlikely to be required for anything nowadays ?
 
This shouldn't be required on any OS. [...] ?

I installed the fonts and those weren't available, then I created the rule for X.org and eventually they were recognized, but perhaps it is because I didn't reloaded the fonts and when I restarted then the fonts were update automagically.
 
perhaps it is because I didn't reloaded the fonts and when I restarted then the fonts were update automagically.
Yep, unless you expected those fonts to appear in ancient things using X11 core fonts (e.g. xfontsel(1) ;)), the X11 font path is irrelevant, but fontconfig's cache is. If the fonts are installed in a default location, just running fc-cache(1) without parameters should make them available without restarting.
 
If the fonts are installed in a default location, just running fc-cache(1) without parameters should make them available without restarting.

Updating the font cache should be triggered automatically by /usr/local/share/pkg/triggers/fontconfig.ucl when installing a font package:
Code:
path: [ "/usr/local/share/fonts", /usr/local/etc/fonts/conf.d ]
trigger: {
    type: lua
    sandbox: false
    script: <<EOS
print("Running fc-cache to build fontconfig cache...")
pkg.exec({"/usr/local/bin/fc-cache", "-s" })
EOS
}
 
Back
Top