Fontconfigはフォントの一般的な太さとスタイルをオーバーライドします。

Fontconfigはフォントの一般的な太さとスタイルをオーバーライドします。

フォントの太さや一般的なスタイルをオーバーライドしたいです。次の設定では、通常のウェイト/スタイルを "medium"にオーバーライドできますが、 "normal"スタイル( "regular"と同じ重みを持つ)はまだ "medium"ではなく "regular"に固定されています。

<fontconfig>
  <alias>
    <family>sans</family>
    <prefer><family>Roboto</family>
    </prefer>
  </alias>

  <match target="pattern">
    <test name="style" qual="any" compare="eq"><string>normal</string></test>
    <edit name="style" mode="assign" binding="strong"><string>medium</string></edit>
  </match>

  <match target="pattern">
    <test name="weight" qual="any" compare="eq"><int>80</int></test>
    <edit name="weight" mode="assign" binding="strong"><int>100</int></edit>
  </match>
</fontconfig>

結果は次のとおりです。

$ fc-match "Roboto: normal"
Roboto-Regular.ttf: "Roboto" "Regular"
$ fc-match "Roboto: regular"
Roboto-Medium.ttf: "Roboto" "Medium"

私は「普通」スタイルをミディアムでカバーしたいと思います。これがうまくいかない理由と実行方法は何ですか?

ベストアンサー1

その理由は、normalスタイル/重量ではなく幅の定義だからです。

[root@ArchTestVM ~]# fc-pattern "Roboto: normal"
Pattern has 2 elts (size 16)
        family: "Roboto"(s)
        width: 100(i)(s)
[root@ArchTestVM ~]# fc-pattern "Roboto: regular"
Pattern has 2 elts (size 16)
        family: "Roboto"(s)
        weight: 80(i)(s)
[root@ArchTestVM ~]# fc-pattern "Roboto: medium"
Pattern has 2 elts (size 16)
        family: "Roboto"(s)
        weight: 100(i)(s)
[root@ArchTestVM ~]# fc-pattern "Roboto: normal:medium"
Pattern has 3 elts (size 16)
        family: "Roboto"(s)
        weight: 100(i)(s)
        width: 100(i)(s)

「Roboto:Normal」モードには、重みや系列定義が含まれていないため、Normal にマップされます。
幅を一致させ、重みを変更することは可能ですが、おそらく望むものではないかもしれません。

<match target="pattern">
    <test name="width" qual="any" compare="eq"><int>100</int></test>
    <edit name="weight" mode="assign" binding="strong"><int>100</int></edit>
</match>
<match target="pattern">
    <test name="weight" qual="any" compare="eq"><int>80</int></test>
    <edit name="weight" mode="assign" binding="strong"><int>100</int></edit>
</match>
[root@ArchTestVM ~]# fc-match "Roboto: normal"
SourceCodePro-Medium.otf: "Source Code Pro" "Medium"
[root@ArchTestVM ~]# fc-match "Roboto: normal:bold"
SourceCodePro-Medium.otf: "Source Code Pro" "Medium"
[root@ArchTestVM ~]# fc-pattern "Roboto: normal"
Pattern has 2 elts (size 16)
        family: "Roboto"(s)
        width: 100(i)(s)
[root@ArchTestVM ~]# fc-pattern "Roboto: normal:bold"
Pattern has 3 elts (size 16)
        family: "Roboto"(s)
        weight: 200(i)(s)
        width: 100(i)(s)

幅は 100 と定義されているので、太さを中間に変更できます。

それとも、デフォルトの重みを変更する方法を探しています(パターンの重みが100として定義されていない場合)。


編集する。幅の代わりに重みで明示的に指定しても機能しません。

[root@ArchTestVM ~]# fc-match "Roboto: weight=normal"
Fontconfig error: Unexpected constant name `normal' used for object `weight': should be `width'
Unable to parse the pattern

幅80には一般的な単語がありますが、幅100には他の単語がなく、キーワードを区別できるため、これは意味があります。問題は、<const>ドキュメントに従ってタグの「一般」エイリアスを「一般」として許可する理由です。

おすすめ記事