ZNHOO Whatever you are, be a good one!

Font

  1. ABC
  2. Fontconfig
    1. Per-user installation
    2. System-wide installation
  3. Xorg FontPath
    1. Per-user configuration
    2. Rehash without logout
  4. Sphere - infinality
    1. infinality symlinks
  5. Practice
  6. Reference:

ABC

  1. Applications use fonts by font systems. There are two font systems, namely XLFD and XFT.
  2. X Logical Font Description (XLFD) is an old font system, originally designed for bitmap fonts. Later on, XLFD adds in support for scalable fonts like PostScript Type1, TrueType (.ttf) and even newer OpenType (.otf). XLFD fonts is usually located under /usr/share/fonts like 75dpi, 100dpi etc. An XLFD font name is a long string, as below:

    -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
    

    The name contains fourteen hyphen-separated fields, with each field representing a property of the font. Not all fields are required to be present. In Emacs, we can use C-x = over a character so show the XLFD name.

    XLFD is almost depcreted but still required by ancient programs like xterm, urxvt and GTK+1. To set XLFD for X, we use xfontsel, and xlsfonts.

    1. For X, we can use xset.
  3. XFT is a newer font system, supporting much more font types. depending on Fontconfig's matching feature and Freetype's font rendering feature. Freetype makes fonts (e.g. anti‑aliasing and sub‑pixel rasterization) look smooth and beautiful.

    We configure Fontconfig to use XFT /etc/fonts/fonts.conf.

  4. Application decides to use which font system. Almost all applications use XFT now, Xorg included. Emacs supports both XLFD and XFT (try M-x: describe-font).

    However, we may tune FontPath in xorg.conf covering bitmap fonts for ancient programs. Most of the time, we do not include XFT fonts in xorg.conf. To check fonts knowns to X:

    $ grep /fonts /var/log/Xorg.0.log
    or
    $ xset q
    

Fontconfig

Commands like fc-list, fc-list, fc-query, fc-match etc. can help check fonts' information.

Per-user installation

~ $ mkdir -p ~/.local/share/fonts/winfonts
~ $ cd ~/.local/share/fonts/winfonts
~ $ cp /path/to/{abc.ttf,123.otf} .

~ $ fc-cache -fv ./*
~ $ mkfontscale ./ && mkfontdir ./ && xset fp rehash
  1. For manually copied fonts, we have to create the font cache with fc-cache. Font cache is to speed up font loading. Package manager (i.e. emerge) takes care of it automatically.
  2. mkfontscale and mkfontdir will create file fonts.scale and fonts.dir for XLFD fonts. xset fp rehash makes new fonts immediately available to current X sessions.

System-wide installation

To manually install fonts for the whole system is similar except that fonts are put under /usr/share/fonts/ or /opt/fonts/.

/ # mkdir /opt/fonts/winfonts
/ # chmod 755 /opt/fonts/winfonts
/ # cd /opt/fonts/winfonts
/ # cp /path/to/{abc.ttf,123.otf} ./
/ # chmod -R 644 .
/ 
/ # fc-cache -fv ./*
/ # mkfontscale ./ && mkfontdir ./

Xorg FontPath

Most of time, Fontconfig works out of box without any further configuration. To support ancient applications that use XLFD, we might need to tune "FontPath".

For Xorg to load fonts directly (as opposed to the use of a font server - XFT), the directory for your newly added font must be added with a "FontPath" entry. This entry is located in the "Files" section of Xorg configuration file. An official example is /usr/share/doc/xorg-server-1.18.4/xorg.conf.example.bz2.

Create /etc/X11/xorg.conf.d/10-fontpath.conf:

Section "Files"
# Multiple FontPath entries are allowed (which are concatenated together),
# as well as specifying multiple comma-separated entries in one FontPath
# command (or a combination of both methods).
# The default path is shown here.
#    FontPath	/usr/share/fonts/misc/,/usr/share/fonts/TTF/,/usr/share/fonts/OTF/,/usr/share/fonts/Type1/,/usr/share/fonts/100dpi/,/usr/share/fonts/75dpi/

    FontPath "/usr/share/fonts/misc"
    FontPath "/usr/share/fonts/100dpi,/usr/share/fonts/75dpi"
    FontPath "/usr/share/fonts/util"
    FontPath "/usr/share/fonts/encodings"
    ...
    FontPath "/usr/share/fonts/winfonts"
EndSection
  1. "FontPath" entry can be a single font path or multiple comma-separated font paths (or a combination of both). Font paths must be quoted.
  2. The default pathes (i.e. 100dpi, 75dpi etc.) are always scanned.
  3. Pathes lack fonts.scale (mkfontscale) and fonts.dir (mkfontdir) are neglected.

Per-user configuration

Settings Font Path under /etc/X11/xorg.conf.d/ are system-wide effective. For per-user setting, add

xset +fp /usr/share/fonts/dejavu/           # Prepend a custom font path to Xorg's list of known font paths

to ~/.xinitrc. Alternatively, execute it on command line.

To remove a Font Path, use -fp instead.

Rehash without logout

After the setting, we want immediate effect:

# xsetq fp rehash

Sphere - infinality

infinality USE can be enabled globally in /etc/portage/make.conf.

# echo "media-libs/freetype adobe-cff infinality" > /etc/portage/package.use/freetype
# emerge -av media-libs/freetype
# eselect fontconfig list
# eselect fontconfig enable 52-infinality.conf

fontconfig-infinality will draw in its own settings (/etc/fonts/infinality) which will interfere with the other fontconfig configuration. It's recommended to disable most of Fontconfig options while keeping 52-infinality.conf. Specially, configurations related to specific fonts can be kept like 62-croscore-*.conf* and 57-dejavu-*.conf.

You will find fontconfig (/etc/fonts/) and infinality (/etc/fonts/infinality/) has the nearly the same directory architecture. The conf.d sub-directory stores the selected symlinks, while conf.avail (or conf.src) stores all existing configurations. We use eselect which chooses and creates symbolic links under conf.d sub-directory.

Optionally, refer to reference number 3, set embeddedbitmap in /etc/fonts/infinality/infinality.conf to true.

# eselect lcdfilter list
# eselect lcdfilter set 14, set to *windows-7*
# eselect infinality list
# eselect infinality set to *win7*

Make sure lcdfilter and infinality choose the same category.

Practice

  1. Use Jin Buguo Linux字体美化实战(Fontconfig配置).
    1. All fonts in this practice are manually copied.
    2. Remove Korean fonts parts.
    3. Fonts under /opt/fonts/core are fine-tuned.
    4. By default, /usr/share/fonts is shared among XLFD, XFT and X11 Font Path. It's excluded from this schema.
  2. /opt/fonts/ext are complementary to /opt/fonts/core.
    1. Put wps-office formula fonts under /opt/fonts/ext/wps-office.
    2. Include /opt/fonts/ext in fonts.conf.
  3. Ancient applications using XLFD refer to X11 Font Path directly.
    1. Make sure fonts.scale (by mkfontscale) and *fonts.dir (by mkfontdir) exist under each directory of font directory.
    2. Paths under /opt/fonts/ can be appended to Font Path if you'd like.

Reference:

  1. Gentoo Linux on T43 (7) 中文字体
  2. 字体配置local.conf详解[带Win效果和AA效果]
  3. gentoo 下字体美化该如何设置
  4. 在Gentoo上配置Infinality
  5. Gentoo Fontconfig.