Font substitution with ~/.fonts.conf

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).


Solution 1:

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>

Solution 2:

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>