How to install Windows Vista’s new fonts on a Linux system
Sunday, 22 Apr 2007 [Monday, 18 Aug 2008]
Note: what I’m writing here isn’t news. However, I’ve not seen a set of fire-and-forget instructions so far.
- You can get the new fonts (except Segoe UI) independently of Vista: they are bundled with the PowerPoint Viewer 2007.
- This is a self-extracting cabinet archive, extractable with cabextract 1.2 or later.
- The fonts are in the
ppviewer.cab
archive withinPowerPointViewer.exe
. - System-wide font installation is system dependendent (and should be managed by the package manager anyway), but contemporary Linux distributions are configured to allow you to install fonts privately to your home directory in
~/.fonts
.
In summary, we get the following script:
#!/bin/sh
set -e
exists() { which "$1" &> /dev/null ; }
if ! [ -d ~/.fonts ] ; then
exec 2>&1
echo 'There is no .fonts directory in your home.'
echo 'Is fontconfig set up for privately installed fonts?'
exit 1
fi
# split up to keep the download command short
DL_HOST=download.microsoft.com
DL_PATH=download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26
ARCHIVE=PowerPointViewer.exe
URL="http://$DL_HOST/$DL_PATH/$ARCHIVE"
if ! [ -e "$ARCHIVE" ] ; then
if exists curl ; then curl -O "$URL"
elif exists wget ; then wget "$URL"
elif exists fetch ; then fetch "$URL"
fi
fi
TMPDIR=`mktemp -d`
trap 'rm -rf "$TMPDIR"' EXIT INT QUIT TERM
cabextract -L -F ppviewer.cab -d "$TMPDIR" "$ARCHIVE"
cabextract -L -F '*.TT[FC]' -d ~/.fonts "$TMPDIR/ppviewer.cab"
( cd ~/.fonts && mv cambria.ttc cambria.ttf && chmod 600 \
calibri{,b,i,z}.ttf cambria{,b,i,z}.ttf candara{,b,i,z}.ttf \
consola{,b,i,z}.ttf constan{,b,i,z}.ttf corbel{,b,i,z}.ttf )
fc-cache -fv ~/.fonts
Update: based on feedback I made some small improvements:
The script can now download
PowerPointViewer.exe
with any of several different utilities (the BSDs and MacOS X bundlefetch
andcurl
, respectively, rather thanwget
). Note that you can downloadPowerPointViewer.exe
manually and then run the script from the directory where you saved the downloaded file, and it will use that file – this functionality was already present in the previous version.It will check whether a
.fonts
directory exists in your home, and abort if that’s not the case. I don’t know whether I can actually assume that fontconfig is generally configured to pick up privately installed fonts in~/.fonts
, so I don’t know whether it’s reasonable to create that directory if it does not exist. I’d rather the script refuse to work in dubious circumstances than that it do something without any effect.
Also, be aware that cabextract version 1.1 or earlier will not work. These versions cannot process the PowerPoint Viewer installer’s cabinet format (although Fedora Core 6 apparently ships a patched 1.1 that can), nor do they support the -d
switch I used to keep the script simple. I would have added a version check to the code, but comparing version strings properly is difficult so the check would have bloated the script.
Update: previous versions of the script omitted the regular weight of Cambria because for some reason its extension is TTC
rather than TTF
. This is now fixed.
Update: fixed the script to account for the fact that POSIX specifies that the trap
built-in only needs to support the short symbolic signal names, not the variants with “SIG” prepended.