LoginSignup
14
17

More than 5 years have passed since last update.

gnome-terminalで英語と日本語のフォントを別々に指定する(fonts.conf)

Posted at

説明

~/.config/fontconfig/fonts.confを設定します。

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target="pattern">
        <test qual="any" name="family">
       <!-- アプリケーションから見たフォント(ファミリ) -->
            <string>Inconsolata</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <!-- 追加する日本語フォント -->
            <string>TakaoGothic</string>
        </edit>
    </match>
</fontconfig>

変更前

$ fc-match -s Inconsolata | head -5
Inconsolata.otf: "Inconsolata" "Medium"
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"
DejaVuSansMono-Bold.ttf: "DejaVu Sans Mono" "Bold"
n022003l.pfb: "Nimbus Mono L" "Regular"
TlwgTypo.ttf: "Tlwg Typo" "Medium"

変更後

$ fc-match -s Inconsolata | head -5
Inconsolata.otf: "Inconsolata" "Medium"
TakaoGothic.ttf: "TakaoGothic" "Regular"              # 後ろに追加された(append)
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"
DejaVuSansMono-Bold.ttf: "DejaVu Sans Mono" "Bold"
n022003l.pfb: "Nimbus Mono L" "Regular"

mode="append"について

fonts.confでググるとmode="prepend"にしている情報が大半です。筆者の環境では期待通りに動作しなかったので"append"としています。

設定例

(1)Inconsolata & Takaoゴシック

フォント名 英語部分 日本語部分
Inconsolata Inconsolata TakaoGothic

<match></match>の部分だけ抜粋(以下同)

    <match target="pattern">
        <test qual="any" name="family">
            <string>Inconsolata</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <string>Takao Gothic</string>
        </edit>
    </match>

fc_Inconsolata_TakaoGothic.png
英数字と日本語の幅が1:2になってますね。

(2)Source Code Pro & Takaoゴシック

フォント名 英語部分 日本語部分
Source Code Pro Source Code Pro TakaoGothic
    <match target="pattern">
        <test qual="any" name="family">
            <string>Source Code Pro</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <string>Takao Gothic</string>
        </edit>
    </match>

fc_SourceCodePro_TakaoGothic.png
文間と行間がスカスカですね・・・。
調整する方法があると良いのですが。

(3)Anonymous Pro & Takaoゴシック

フォント名 英語部分 日本語部分
Anonymous Pro Anonymous Pro TakaoGothic
    <match target="pattern">
        <test qual="any" name="family">
            <string>Anonymous Pro</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <string>Takao Gothic</string>
        </edit>
    </match>

fc_AnonymousPro_TakaoGothic.png
なかなか見やすいです。Inconsolataよりは幅を取ります。

応用

(1)MonospaceをInconsolataとTakaoゴシックにする

たいていのアプリでは固定幅フォントとしてMonospaceが指定されていますから、Monospaceを置き換えるとアプリ側の設定を変えなくて良さそうです。
ただ、筆者の環境(Linux Mint 16)では、Inconsolataにすると若干小さくなったので、サイズを10から12に大きくする必要がありました。(ちなみにMonospaceはDejaVu Sans Monoだったようです)

フォント名 英語部分 日本語部分
Monospace Inconsolata TakaoGothic
    <match target="pattern">
        <test qual="any" name="family">
            <string>Monospace</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <string>Inconsolata</string>
            <string>TakaoGothic</string>
        </edit>
    </match>

(2)LANGを指定する

これまでの例では、無条件に日本語フォントのTakaoゴシックを指定しています。
LANGによって指定するフォントを変えるには、例えば以下の通りとします。

    <match target="pattern">
        <!-- LANGに "ja" が含まれる場合 -->
        <test name="lang" compare="contains">
            <string>ja</string>
        </test>
        <test qual="any" name="family">
            <string>Monospace</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <string>Inconsolata</string>
            <string>TakaoGothic</string>
        </edit>
    </match>

ただし、実用的には、LANG=en_US.UTF-8の場合にも有効にしたいところです。
面倒ですが、"en" と "ja" の両方を記載します。

    <match target="pattern">
        <!-- LANGに "en" が含まれる場合 -->
        <test name="lang" compare="contains">
            <string>en</string>
        </test>
        <test qual="any" name="family">
            <string>Monospace</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <string>Inconsolata</string>
            <string>TakaoGothic</string>
        </edit>
    </match>
    <match target="pattern">
        <!-- LANGに "ja" が含まれる場合 -->
        <test name="lang" compare="contains">
            <string>ja</string>
        </test>
        <test qual="any" name="family">
            <string>Monospace</string>
        </test>
        <edit name="family" mode="append" binding="strong">
            <string>Inconsolata</string>
            <string>TakaoGothic</string>
        </edit>
    </match>

番外

gnome-terminal以外のアプリケーション

Eclipse

期待通り動作しました。
fc_Eclipse.png

gedit

期待通り動作しました。
fc_gedit.png

IntelliJ Idea

Java製のためか、全く適用されません。
ただし、エディタに複数のフォントを指定できますので困ることはないと思います。
Linuxだとレンダリングがいまいちですが・・・。
IDEA-57233: Editor font antialising/appearance problems on Linux
fonts.confの話とは関係ないですが、上記スレッドにあるとおり、ヒント情報を削除したConsolasとTakaoゴシックを組み合わせると以下のとおりです。
ConsolasをSize:14、TakaoGothicをSize:16にすると桁が揃います。
fc_Idea12.png

Oracle SQL Developer

Java製のためか、全く適用されません。
Linuxではfontconfig.propertiesでのカスタマイズもできないようです。
JDK-7175487 : Cannot customize font configuration with Java 7 on Linux

設定ファイルの分割

設定ファイルを分割するには<include></include>を使います。

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <include ignore_missing="yes">~/.config/fontconfig/fonts_en.conf</include>
    <include ignore_missing="yes">~/.config/fontconfig/fonts_ja.conf</include>
</fontconfig>
14
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
17