This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Fontconfig

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Fontconfig and the translation is 47% complete.
Outdated translations are marked like this.
Resources

fontconfig ライブラリ (media-libs/fontconfig)は、すべての GUI アプリケーションに対して、フォントの選択と設定を単一にすることを企図したものです。デスクトップ環境が独自にフォント上書きやフォント設定のためのユーティリティを提供していることが一般的ですが、それでもなお、fontconfig が基盤的なライブラリです。

Installing

When fontconfig is needed, it will almost certainly be installed already. If not, make sure to set up the graphical subsystem (i.e., X or Wayland) and desktop environment properly.

USE flags

fontconfig doesn't know many USE flags.

USE flags for media-libs/fontconfig A library for configuring and customizing font access

doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
nls Add Native Language Support (using gettext - GNU locale utilities)
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)

設定

注意
fontconfig のファイルへの変更は、変更後に起動したアプリケーションにしか反映されません!

一般論

fontconfig は、 /etc/fonts/ ディレクトリ下の XML ファイルを読み込んで、ライブラリ内部に設定を構築します。初期設定において読み込まれるファイルは /etc/fonts/fonts.conf (このファイルはユーザーが編集するものではありません!) です。このファイルは、適切な既定値を設定した上で、通常は /etc/fonts/conf.d/ ディレクトリの内容を読み込むコードが含まれます。これらに加えて、/etc/fonts/conf.avail/ ディレクトリには、fontconfig の多様な機能を設定するために使用できる、数々の設定ファイルが配置されています。この中から必要なファイルを /etc/fonts/conf.d/ へシンボリックリンクするのが慣行です。ファイルは名前順に実行されるため、ファイル名は2桁の数字で始まります。10の位の値が、クラスと呼ばれる、ファイルが設定する機能の種類を表します。

Gentoo 特有の部分

Gentoo が提供する eselect モジュール (eselect fontconfig) の目的は、一般論として説明した作業そのものの自動化です。つまり、/etc/fonts/conf.d/ に存在する /etc/fonts/conf.avail/ 内のファイルへのシンボリックリンクの、追加と削除を行います。当然のことながら、システム全体の設定を変更するには、適切な権限が求められます。

下記のサブセクションでは、fontconfig eselect モジュールの使用法を説明します。

利用可能なファイルのリスト表示

list は利用できる fontconfig を表示します。有効になっているファイルには、アスタリスク (*) が付いています。

root #eselect fontconfig list
Available fontconfig .conf files (* is enabled):
  [1]   10-autohint.conf *
  [2]   10-no-sub-pixel.conf
  [3]   10-sub-pixel-bgr.conf
  [4]   10-sub-pixel-rgb.conf
  [5]   10-sub-pixel-vbgr.conf
  [6]   10-sub-pixel-vrgb.conf
  [7]   10-unhinted.conf
  [8]   11-lcdfilter-default.conf
  [9]   11-lcdfilter-legacy.conf
  ...
Warning
fonts.avail 下のファイルはそれぞれのシステムによって異なるため、出力結果も同じく異なります。ブログや wiki に記載されたものなど、他のシステムにおける番号を思慮なしに使ってはなりません。

ファイルの有効化

ファイルの有効化は、ファイル名と番号の両方によって可能です。この2行は同じことを行います:

root #eselect fontconfig enable 10-sub-pixel-rgb.conf
root #eselect fontconfig enable 4

ファイルの無効化

以下のようにすると、ファイルの無効化が可能です:

root #eselect fontconfig disable 10-sub-pixel-rgb.conf
root #eselect fontconfig disable 4

システム全体の設定をカスタマイズ

システム全体で使われるカスタムfontconfigファイルを作成するためには、51-local.confを有効化して、/etc/fonts/local.confを作成してください。このファイルはXML形式です。

FILE /etc/fonts/local.confサンセリフに使用したいフォントの優先順位を変更するファイルの例
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <alias>
    <family>sans-serif</family>
    <prefer>
      <family>Ubuntu</family>
      <family>TakaoPGothic</family>
      <family>Droid Sans</family>
    </prefer>
    <default><family>DejaVu Sans</family></default>
  </alias>
</fontconfig>

To be clear, this says that when it comes to sans-serif fonts, we prefer using Ubuntu, TakaoPGothic, and Droid Sans fonts (in that order) over DejaVu Sans (which can be used as a default choice only when necessary). Obviously, different choices can be made here.

ユーザー単位での設定

To create per-user fontconfig files, enable 50-user.conf (which might be enabled by default), and have the end users use the ~/.config/fontconfig/fonts.conf file. This file has the same XML format as local.conf.

Note
This is one way how a desktop environment might try to affect font rendering. It might be prudent to disable this to be sure that what's being shown is actually system wide configuration when customizing it. Disabling it also makes font rendering more uniform across user accounts.
Note
The previously used ~/.fonts.conf is now deprecated in favor of the $XDG_CONFIG_HOME based location. This variable by defaults points to ~/.config.

設定の確認

Check the default font replacement, for example for Arial, by typing:

user $fc-match Arial

アンチエイリアス、ヒンティング、サブピクセルレンダリング

Rendering aspects can be tuned as well. In the following sections the Anti-aliasing, Hinting and Sub-pixel rendering features are tuned.

Feature Description
Anti-aliasing is enabled by default and makes fonts less blocky.
Hinting is an attempt to cope with the low pixel count per unit of area of current displays. Correct hinting makes characters more crisp but since font metrics aren't changed (and arguably should not change) affects how overall the rendered text looks like.
Sub-pixel rendering uses the fact that LCD matrix has three primaries to effectively triple the resolution of text but can make characters appear not entirely black. To combat that lcdfilter is to be used with sub-pixel rendering (available for newer fontconfig) but it can blur the characters too much. In the end this entirely depends on person how they like their text.

ヒンティングの強制

The default fontconfig behavior regarding hinting is rather undocumented, but it can be made deterministically sub-optimal by making a system wide default.

  1. First enable /etc/fonts/local.conf
  2. Edit the local.conf file to include full hinting by default

次の local.conf スニペットは完全なヒンティングを有効化します:

FILE /etc/fonts/local.confヒンティングを full に設定する
<match target="font">
  <edit mode="assign" name="hintstyle">
    <const>hintfull</const>
  </edit>
</match>
Note
Most fonts look best with full hinting but others need slight or more rarely some other other hinting option. Some fonts for one reason or another will always be ugly.

サブピクセルレンダリングの使用

It's important to determine the sub-pixel layout of the LCD matrix. It's usually RGB (10-sub-pixel-rgb.conf) but the only way to be sure is to either consult display specification or use this sub-pixel layout test to determine it.

Once determined, enable the appropriate 10-sub-pixel-<matrix type>.conf file.

root #eselect fontconfig enable 10-sub-pixel-rgb.conf

It's strongly advised that lcdfilter, if available, is used with sub-pixel rendering. It comes in different varieties but the default (11-lcdfilter-default.conf) should be appropriate for all common fonts.

root #eselect fontconfig enable 11-lcdfilter-default.conf
Warning
The bindist USE flag in media-libs/freetype disables sub-pixel rendering altogether due to potential patenting issues. In order to use sub-pixel rendering, the USE flag must be disabled (i.e., -bindist) for this package.

Regarding autohinter

Autohinter attempts to do automatic hinting disregarding any existing hinting information. Until recently it was the default because TrueType2 was covered by patents but now that they have expired there's very little reason to use it. From technical point of view it does better than broken or no hinting information but it will be strongly sub-optimal for fonts with good hinting information. Generally system fonts are of the second kind so autohinter should not be used.

警告
オートヒンターとサブピクセルレンダリングとは、互換性がありません。同時に両方を使用しないでください!

Infinality

Infinality is a (somewhat controversial) set of patches for FreeType and accompanying fontconfig files. The goal of Infinality is to provide higher quality font rendering including emulation of other OS font rendering styles.

Note
As usual with software still in development it is prudent to always use only the latest version available unless there are known problems with it.

Infinality の有効化

make.confを直接に編集するか、euseツールを利用して、'infinality' USE フラグを有効にします。

root #euse -E infinality

次に、影響を受けるプログラムを再ビルドします。

root #emerge --ask -uvDU @world

再ビルド後に表示されるメッセージの内容にかかわらず、 52-infinality.conf を有効にします。

root #eselect fontconfig enable 52-infinality.conf

Infinality の設定

Infinality can be configured in various ways including custom configurations, but easiest is to use pre-made profiles shipped in media-libs/fontconfig-infinality that along with eselect modules should have been installed as dependencies of the infinality USE flag.

簡単で合理的な設定

root #eselect infinality set infinality
root #eselect lcdfilter set infinality
Note
As always, fontconfig changes affect only applications started after changes have been made.

It's also recommended to disable all fontconfig settings except for 52-infinality.conf as they interfere with the rendering of infinality styles:

root #eselect fontconfig disable <number>

Certain fontconfig settings do not interfere with how the fonts are rendered, but rather determine the default fonts for font-types (such as Monospace, sans-serif, etc.). Such settings (for example the 62-croscore-*.conf configurations) can be left enabled.

解説

Infinality provides FreeType environment variables that can be used to configure features introduced with its patches as well as fontconfig files to be used with these changes. fontconfig file sets are administrated on Gentoo via eselect infinality while the FreeType behaviour is set using eselect lcdfilter.

These eselect modules function as usual:

  • Listing available fontconfig file sets.
root #eselect infinality list
  • Listing available FreeType variable sets.
root #eselect lcdfilter list
  • Both sets should match of course except when there are multiple matches possible such as shown below.
root #eselect infinality set win7
root #eselect lcdfilter set windows-7-light

フォントの選択

Choosing the right font can be trickier than deciding on the right hinting type. For one reason or another, some fonts will never be perfect — but it's certainly possible to make them look better than, say, the Windows 7 default font configuration.

Here are some recommendations regarding well known fonts in Gentoo:

Font family Pros Cons
Liberation
media-fonts/liberation-fonts
Red Hat's fonts, which are metric-compatible with MS TrueType corefonts, have a decent, modern look. This is the Gentoo Fonts team recommendation for default Latin fonts. Covers about 2,600 code points. Latin, Greek, Cyrillic, and Hebrew only. A few glyphs may have hinting trouble.
Linux Libertine
media-fonts/libertine
Very similar to Liberation, covering about 2,700 code points. Linux Libertine itself is proportional serif only, but the package contains less extensive sans and mono fonts, as well. Can be used as a fallback for some glyphs not in Liberation. Latin, Greek, Cyrillic, and Hebrew only. Sans and mono fonts are limited.
Noto
media-fonts/noto
Google's font family that aims to support all the world's languages (so, well over 60,000 code points). It goes well with Liberation or Droid. Adobe's Source Han Sans fonts are included for CJK. Recommended as a fallback for many glyphs not covered by Liberation. Big download.
DejaVu
media-fonts/dejavu
Many styles and covers a lot of code points (about 6,100 for sans). Exceptionally wide — even condensed is wider than same-height monospace. Overall second to Verdana (an MS font) in width. Sans-serif font is only average.
Droid
media-fonts/droid
Covers a lot of code points and scripts. Very dry, wide yet thin glyphs. Clearly designed with handheld devices and their small screens in mind.
Gentium Plus
media-fonts/sil-gentium
Fairly distinctive; might appeal to people who like narrow fonts. Serif only. As with other SIL fonts, the hinting is questionable.
Ubuntu
media-fonts/ubuntu-font-family
Used in Ubuntu (obviously). A distinctive font family with a style which might not appeal to everyone. Overall looks good and covers a fair number of code points. Only the sans-serif font is truly polished; narrow and monospaced versions are unfinished. No known serif font that would accompany it well.
URW
media-fonts/urw-fonts
Metric compatible with popular Adobe fonts (among others?). Seem to require slight hinting.
MS TrueType corefonts
media-fonts/corefonts
Includes most fonts used in documents and on the web. MS does not distribute them nowadays, so the available fonts are from many years ago and do not reflect their current state (not to mention the state of the art). Obviously, lacks fonts introduced more recently. Require full hinting.
Unifont
media-fonts/unifont
Covers a lot of code points. In addition to being ugly as sin, it also fails some basic requirements to be considered a typeface. Is it sans-serif? Is it serif? Please never use this.

外部の情報