Infosec Scribbles

March 30, 2018

Ubuntu: Better Fonts Than Windows

Coming from the Windows world, to me, Linux font rendering out of the box just sucks. Even on Ubuntu, which people on Reddit often praise for good font rendering.

What I see is broken font rendering that makes fonts bold and blurry. Thickness is inconsistent, spacing is inconsistent and eyestrain is through the roof. Some of the typeface choices just straight up annoy me. For browsing, the msttcorefonts package looks like some Shenzhen basement knockoff that renders poorly and doesn’t support Unicode. Try generating some Zalgo and see the empty boxes for yourself.

But there is a way. Ubuntu can have better font rendering and typefaces than Windows.

Infinality

First step is to get Infinality. It is a set of patches for FreeType and adjustments for fontconfig. I can only guess how many hours or days it must have taken the authors to figure out the configurations for all the fonts that are included.

On Ubuntu, you can get Infinality from a PPA. If you don’t know what PPAs are, I suggest that you do the research about their security implications.

To get the PPA installed, do this:

$ sudo add-apt-repository ppa:no1wantdthisname/ppa
$ sudo apt-get update
$ sudo apt-get install libfreetype6 fontconfig-infinality

The changes will only get applied when we restart X Org, so it makes sense to get through the whole process before doing that.

Java

Unfortunately, some packages will not get the nice font rendering just yet. One of such cases is Java applications. You can experiment with Java environment variables to get the aliasing and hinting to work, or you could install another PPA from the same author:

$ sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
$ sudo apt-get upgrade

GIMP

If you use GIMP, you will notice weird artifacts in the Text Tool. Create /etc/gimp/2.0/fonts.conf:

<fontconfig>
  <match target="font">
    <edit name="rgba" mode="assign">
      <const>none</const>
    </edit>
  </match>
</fontconfig>

Ubuntu Font Family

If you use Ubuntu Mono as your console/coding font, install font-manager and create .config/font-manager/conf.d/25-Ubuntu Mono.conf:

<?xml version="1.0"?>
<fontconfig>
  <!-- Ubuntu Mono Regular -->
  <match target="font">
    <test name="family">
      <string>Ubuntu Mono</string>
    </test>
    <test name="slant" compare="eq">
      <const>roman</const>
    </test>
    <test name="weight" compare="more_eq">
      <int>75</int>
    </test>
    <test name="weight" compare="less_eq">
      <int>80</int>
    </test>
    <test name="width" compare="eq">
      <const>normal</const>
    </test>
    <edit name="autohint" mode="assign">
      <bool>False</bool>
    </edit>
    <edit name="antialias" mode="assign">
      <bool>True</bool>
    </edit>
    <edit name="lcdfilter" mode="assign">
      <const>lcddefault</const>
    </edit>
    <edit name="embeddedbitmap" mode="assign">
      <bool>False</bool>
    </edit>
    <edit name="globaladvance" mode="assign">
      <bool>False</bool>
    </edit>
    <edit name="hinting" mode="assign">
      <bool>True</bool>
    </edit>
    <edit name="hintstyle" mode="assign">
      <const>hintslight</const>
    </edit>
  </match>
</fontconfig>

Noto Font

Noto font family is an excellent font that supports all the different languages and symbols. It comes in sans, serif and monospace editions, which covers all the OS needs. Install it like this:

$ sudo apt install fonts-noto

Tweak Tool

Ubuntu provides a nice GUI to configure GNOME fonts. Other distros have all the same settings, but you may have to get your hands dirty with file editing.

  • Hinting: Slight
  • Antialiasing: Rgba
  • Window Titles: Noto Sans UI Bold 10
  • Interface: Noto Sans UI Regular 10
  • Documents: Noto Sans Regular 11
  • Monospace: Noto Mono Regular 13

Application Settings

I find that different applications render best with certain font sizes set. Here they are:

  • Terminator: Ubuntu Mono 13.5
  • Sublime Text: Ubuntu Mono 13.4, padding-top 4, padding-bottom 4
  • IntelliJ: Ubuntu Mono 18, line height 1.4

Browsing

When you are browsing the internet, a lot of websites make implicit assumptions about your default fonts. If you are coming from the Windows world, a lot of websites will look weird to you. To fix it, you need to get Windows fonts. The traditional way of achieving this is through installing ttf-mscorefonts-installer or msttcorefonts. I find it to be garbage for reasons stated in the preface to this post. These are not the same fonts included in your Windows installation. If you have these packages installed, ditch them prior to continuing.

The workaround is to grab the fonts from your Windows installation. I Am Not A Lawyer and if you are worried about this going against Microsoft licensing, get legal advice. I just know that it would be illegal for me to provide you with the files, therefore: the fonts are available in C:\Windows\Fonts. You need the following files:

arialbd.ttf  ARIALNBI.TTF  ARIALN.TTF  comicbd.ttf  courbi.ttf  georgiab.ttf  georgiaz.ttf  timesbi.ttf  trebucbd.ttf  trebuc.ttf    verdana.ttf
arialbi.ttf  ARIALNB.TTF   arial.ttf   comic.ttf    couri.ttf   georgiai.ttf  impact.ttf    timesi.ttf   trebucbi.ttf  verdanab.ttf  verdanaz.ttf
ariali.ttf   ARIALNI.TTF   ariblk.ttf  courbd.ttf   cour.ttf    georgia.ttf   timesbd.ttf   times.ttf    trebucit.ttf  verdanai.ttf  webdings.ttf

Depending on how you access that directory, you may have to copy the files based on font family names:

  • Arial
  • Comic Sans MS
  • Courier New
  • Georgia
  • Times New Roman
  • Trebuchet MS
  • Impact
  • Verdana
  • Webdings

The files go in /usr/share/fonts/MAKE_UP_A_FOLDER_NAME.

Now just restart X Org. Easiest way on Ubuntu is through rebooting because logging out and restarting gdm sometimes results in weird artifacts. If you followed all the steps, after the reboot you should have better font rendering than you had on Windows.

Troubleshooting

If something doesn’t go as expected, the maintainer of the PPA covers pretty much everything in his readmes. The man is truly doing god’s work. At least that is what my eyes say.