Articles

Linux font substitutions

In Uncategorized on 20/07/2010 by weirdfellow Tagged: , , , , ,

Most of the sites out there expect you to have Windows fonts. The layout is usually designed with those fonts and would break if you don’t have them.

Usually the designer is nice enough to include the sans-serif font at the end of the font definition in CSS, but two sans-serif fonts can be pretty different – Tahoma and Arial Black for instance.

It is also possible to install the msttcorefonts package and use the .fonts.conf from Ubuntu wiki, but I don’t really like this approach – Linux comes with a handful of nice fonts, why not to use them?

The most obvious choice for substitutions is the Liberation family – Liberation Serif for Times New Roman, Liberation Sans for Arial and Liberation Sans Mono for Courier New. But what to do with other fonts? Courier does look different too…

I have been playing with the script below (save it as .fonts.conf in /home/username directory) for a while now. Here is the result:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Verdana</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Arial Black</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans</string></edit>
  <edit mode="assign" name="weight"><double>200</double></edit>
</match>

<match target="font"> <!-- Switch off hinging for DejaVu Sans -->
  <test compare="eq" name="family" qual="any"><string>DejaVu Sans</string></test>
  <edit name="hinting" mode="assign"><bool>false</bool></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Tahoma</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Droid Sans</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Arial</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Liberation Sans</string></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Times New Roman</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Liberation Serif</string></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Georgia</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Droid Serif</string></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Impact</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Droid Serif</string></edit>
  <edit mode="assign" name="weight"><double>200</double></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Courier New</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Nimbus Mono L</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Trebuchet MS</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Linux Biolinum O</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Lucida Console</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans Mono</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Lucida Sans Unicode</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Palatinio Linotype</string></test>
  <edit binding="same" mode="prepend" name="family"><string>URW Palladio L</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Consolas</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Inconsolata</string></edit>
</match>
</fontconfig>

Liberation fonts are usually installed, but don’t forget to install Droid font family, Inconsolata and Libertine and Biolinum families.

I have also switched off the hinting for DejaVu Sans. It does not get correctly hinted with Polish letters – I guess not everyone will have this problem – the lines 15-18 could be removed in such case.

In the result I get something like that:

I am really happy with the result. How about you?

One Response to “Linux font substitutions”

  1. Thank you. Very useful information.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: