Font substitution with ~/.fonts.conf

18

6

I'm trying using ~/.fonts.conf to replace Helvetica with Droid Sans, here's the content of the file:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="pattern">
    <test qual="any" name="family"><string>Helvetica</string></test>
    <edit name="family" mode="assign"><string>Droid Sans</string></edit>
  </match>
</fontconfig>

but no matter what, nothing seems to happen. I tried running fc-cache, I have checked in /etc/fonts/conf.d and I found 50-user.conf which seems to explicitly call user specific configurations.

What am I missing?

Thanks

EDIT: after investigation I found out that other rules in /etc/fonts/conf.d overwrite user configuration, so linking user.conf to 00-user.conf helped. Still it's just a partial success, since I can specify which fonts should be substituted, but the substitute of my choice is ignored: in other words, I can make Helvetica invalid and the system falls back to the next font (i.e. in the browser, it takes the next font specified in the style sheet, if none is present it displays standard sans-serif).

Matteo Riva

Posted 2010-03-06T12:56:13.630

Reputation: 8 341

I came here because I'd about to accomplish something similar. Hopefully someone has an answer... – Ludwig Weinzierl – 2010-03-06T17:12:54.597

still looking for an answer. – Capi Etheriel – 2010-03-11T13:11:44.200

Answers

16

I think the binding attribute was missing in your configuration. (see also fonts-conf). Depending on your other configuration, a binding of "same" or "strong" might probably work, while "weak" might not give you what you want.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="pattern">
    <test qual="any" name="family"><string>Helvetica</string></test>
    <edit name="family" mode="assign" binding="same"><string>Droid Sans</string></edit>
  </match>
</fontconfig>

frenkx

Posted 2010-03-06T12:56:13.630

Reputation: 196

1Worked for me. Seems like adding the binding attribute made the difference. I am using fontconfig-2.8.0. – MaoPU – 2010-09-20T13:55:10.403

This worked for me – miloshadzic – 2011-01-08T13:10:04.620

3

I'd think the alias mechanism would work for this:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <alias>
    <family>Helvetica</family>
    <prefer>Droid Sans</prefer>
  </alias>
</fontconfig>

Geoff Reedy

Posted 2010-03-06T12:56:13.630

Reputation: 327

1Is <alias> not just for substituting not installed fonts? – MaoPU – 2010-09-20T13:54:27.800

/\ No, it actually doesn't, unless the .conf file containing this rule is read first. – Marc.2377 – 2019-12-10T02:57:25.040

Hmm - that said, it does work if binding="strong" is used along with the <alias> element! – Marc.2377 – 2019-12-10T03:15:24.000

@MaoPU: I thought the same thing, but after reading the documentation, it led me to believe that that behavior is configured. <accept> takes precedence when font is not installed, <prefer> takes precedence regardless if font is installed. – J. M. Becker – 2013-03-03T15:20:06.337

0

I ran into a similar problem when trying to alias Helvetica as sans-serif family. For anyone hitting the same issue look at system configuration in /etc/fonts/conf.d/ which will contain links to files from /etc/fonts/conf.avail. I had to remove a lot of those aliases to get deterministic behaviour.

j605

Posted 2010-03-06T12:56:13.630

Reputation: 76

0

Does "fc-list" actually show "Helvetica"? What does fc-match say ? On my box (F-12) I get:

 >fc-match Helvetica
n019003l.pfb: "Nimbus Sans L" "Regular"

Maybe you have to add the aliased font to your substitution as well.

vasquez

Posted 2010-03-06T12:56:13.630

Reputation: 159