Fonts and Linux

From trapsink.com
Jump to: navigation, search


Configuration Files

The exact location of the configuration depends on which release of which distro and the Desktop Environment being used.

Distro Location Notes
Fedora 17- ~/.fonts.conf none
Fedora 18+, Arch ~/.config/fontconfig/fonts.conf none


Remapping Fonts

This will remap Courier to Liberation Mono and Caladea to Carlito - Google Fonts have a habit of "stealing" these typefaces resulting in unexpected fonts when browsing the general web. Substitute DejaVu Sans Mono for Liberation Mono for a similar result depending on your desktop.

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <match target="font">
     <edit name="hinting" mode="assign"><bool>false</bool></edit>
  </match>
 
 <match target="pattern">
  <test qual="any" name="family" compare="eq">
   <string>Courier</string>
  </test>
  <edit name="family" mode="prepend" binding="same">
   <string>Liberation Mono</string>
  </edit>
 </match>
 
 <alias>
  <family>Courier</family>
   <prefer>
    <family>Liberation Mono</family>
   </prefer>
 </alias>
 
 <selectfont>
  <rejectfont>
   <pattern>
     <patelt name="scalable"><bool>false</bool></patelt>
   </pattern>
  </rejectfont>
 </selectfont>
 
 <selectfont>
  <rejectfont>
   <pattern>
    <patelt name="family">
     <string>Caladea</string>
    </patelt>
   </pattern>
   <pattern>
    <patelt name="family">
     <string>Carlito</string>
    </patelt>
   </pattern>
  </rejectfont>
 </selectfont>

</fontconfig>


Whitelisting and Blacklisting

The element <selectfont> is used in conjunction with the <acceptfont> and <rejectfontfont> elements to selectively whitelist or blacklist fonts from the resolve list and match requests. The simplest and most typical use case it to reject one font that is needed to be installed, however is getting matched for a generic font query that is causing problems within application user interfaces.

First obtain the Family name as listed in the font itself:

$ fc-scan .fonts/lklug.ttf --format='%{family}\n'
LKLUG

Then use that Family name in a <rejectfontfont> stanza:

<selectfont>
 <rejectfont>
  <pattern>
   <patelt name="family" >
    <string>LKLUG</string>
   </patelt>
  </pattern>
 </rejectfont>
</selectfont>

Typically when both elements are combined, <rejectfontfont> is first used on a more general matching glob to reject a large group (such as a whole directory), then <acceptfont> is used after it to whitelist individual fonts out of the larger blacklisted group.

<selectfont>
 <rejectfont>
  <glob>/usr/share/fonts/OTF/*</glob>
 </rejectfont>
 <acceptfont>
  <pattern>
   <patelt name="family" >
    <string>Monaco</string>
   </patelt>
  </pattern>
 <cceptfont>
</selectfont>


Disable Hinting

Chrome in XFCE can have issues with hinting resulting in bad display for instance, it might be handy to disable hinting:

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="font">
    <edit name="hinting" mode="assign"><bool>false</bool></edit>
  </match>
</fontconfig>


LCD Optimization

Assuming a standard RGB subpixel ordering:

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <match target="font">
  <edit name="antialias" mode="assign">
   <bool>true</bool>
  </edit>
  <edit name="autohint" mode="assign">
   <bool>false</bool>
  </edit>
  <edit name="hinting" mode="assign">
   <bool>true</bool>
  </edit>
  <edit name="hintstyle" mode="assign">
   <const>hintslight</const>
  </edit>
  <edit name="rgba" mode="assign">
   <const>rgb</const>
  </edit>
  <edit mode="assign" name="lcdfilter">
   <const>lcddefault</const>
  </edit>
  <edit mode="assign" name="embeddedbitmap">
   <bool>false</bool>
  </edit>
 </match>
</fontconfig>


Local Fonts

Keeping fonts locally in your home directory:

  • Make a new directory in your home called .fonts (note leading . )
  • Copy the downloaded TTF file into this directory
  • Change directory to .fonts (cd ~/.fonts/)
  • Run the command: mkfontscale (creates fonts.scale)
  • Run the command: mkfontdir (creates fonts.dir)
  • Run the command: fc-cache -fv ~/.fonts (rebuilds local cache)
  • Test with: fc-cache


Luxi Sans

This disappeared with Fedora 8 due to licensing issues, Google for this file and unpack it to get the TTF files you can install in your home directory.

  • xorg-x11-fonts-truetype-7.2-3.fc8.noarch.rpm


gVim Fonts

A snippet for your ~/.vimrc to map the editing font in gVim:

~/.vimrc
" GVIM preferences
if has("gui_running")
  let os=substitute(system('uname'), '\n', '', '')
  if os == 'Darwin' || os == 'Mac'
    set guifont=Menlo:h16
  elseif os == 'Linux'
    set guifont=Monospace\ 12
  endif
endif


LightDM Fonts

The typical config file is /etc/lightdm/lightdm-gtk-greeter.conf:

/etc/lightdm/lightdm-gtk-greeter.conf
[greeter]
font-name=Luxi Sans 12
xft-antialias=true
xft-hintstyle=hintnone
xft-rgba=rgb


References