Snap package cannot read fonts conf

install fonts manual in
/usr/local/share/fonts

then create /etc/fonts/conf.avail/65-ubuntu-font-family-arabic.conf contains

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target="pattern">
        <test name="family" compare="eq">
            <string>Ubuntu</string>
        </test>
        <test name="lang" compare="contains">
            <string>ar</string>
        </test>
        <edit name="family" mode="assign" binding="strong">
            <string>Ubuntu Arabic</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family" compare="eq">
            <string>DejaVu</string>
        </test>
        <test name="lang" compare="contains">
            <string>ar</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>Ubuntu Arabic</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family" compare="eq">
            <string>DejaVu Sans</string>
        </test>
        <test name="lang" compare="contains">
            <string>ar</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>Ubuntu Arabic</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family" compare="eq">
            <string>DejaVu Serif</string>
        </test>
        <test name="lang" compare="contains">
            <string>ar</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>Ubuntu Arabic</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family" compare="eq">
            <string>DejaVu Serif</string>
        </test>
        <test name="lang" compare="contains">
            <string>ar</string>
        </test>
        <edit name="family" mode="assign" binding="strong">
            <string>Ubuntu Arabic</string>
        </edit>
    </match>
    <alias>
  	<family>DejaVu Serif</family>
	<prefer>
	  <family>Ubuntu Arabic</family>
	  <family>DejaVu Serif</family>
	</prefer>
    </alias>
    <alias>
  	<family>DejaVu Sans</family>
	<prefer>
	  <family>Ubuntu Arabic</family>
	  <family>DejaVu Sans</family>
	</prefer>
    </alias>
    <alias>
  	<family>DejaVu</family>
	<prefer>
	  <family>Ubuntu Arabic</family>
	  <family>DejaVu</family>
	</prefer>
    </alias>
</fontconfig>

and create syslink for it in /etc/fonts/conf.d/

have you tried putting the font into

~/.local/share/fonts/

might be that snapd’s desktop interface simply does not allow access to /usr/local/share/fonts …

As per https://gitlab.com/apparmor/apparmor/-/blob/master/profiles/apparmor.d/abstractions/fonts, it should be readable.

ah i had only checked the snapd source, not the apparmor font abstraction …

the issue not read fonts
chromium can found “Ubuntu Arabic” but cannot read conf.d that make it replace to "DejaVu "

Can you try the following? Edit ~/snap/chromium/current/.config/fontconfig/fonts.conf to add the following line:

<include ignore_missing="yes">/etc/fonts/conf.d</include>

Then save the file and restart chromium.

I’m not really sure what to expect visually, but I can tell that when stracing the snap, adding that line allowed the app to find and read your custom fonts configuration file.

3 Likes

Thank you, that work great!

how i can do it globally?

@jamesh is this something we should consider for addition to the desktop helpers?

1 Like

That will be helpful :+1:

after restart the changes removed

Ah, that’s quite unfortunate… Indeed the fontconfig file is regenerated everytime there’s an update (a new revision) to the snap. We need a way for users to define custom configs that stick.

Create an empty fontconfig-user.conf if it doesn’t exist for <include>? Only touch that file if it doesn’t exist, so that the fontconfig ruleset doesn’t break by it potentially not being present, allowing the user to add their custom rules in this separate non-generated file.

1 Like

I’m seeing the same, in two snaps (Firefox, and mattermost-desktop). Haven’t noticed others just yet.

The fix, again, a matter of editing fonts.conf:

~$ diff ~/snap/mattermost-desktop/current/.config/fontconfig/fonts.conf.busted ~/snap/mattermost-desktop/current/.config/fontconfig/fonts.conf
6c6
<   <include ignore_missing="yes">conf.d</include>
---
>   <include ignore_missing="yes">/etc/fonts/conf.d</include>

So, given that this is across multiple snaps, and the workaround doesn’t stick anyway, we need to figure a way to avoid this affecting users on an ongoing basis. Is there a bug already reported against $something to track that?

I suspect this is likely a bug in the desktop interface if it requires a manual workaround like this.

For reference: https://github.com/snapcore/snapd/blob/master/interfaces/builtin/desktop.go#L56

It sounds more like it is a bug in the desktop-helpers or in snapd’s font caching that happens during a refresh than it is with the interface itself.

What writes the file $SNAP_USER_DATA/.config/fontconfig/fonts.conf ? It seems like since it is in $SNAP_USER_DATA that it would be something the desktop-helpers would be writing.

1 Like

this issue should be fixed years before
Maybe you know how to fix it but the solution provided by @oSoMoN fix the problem for short time and his solution want me to modify files that removed after any new update for the Snap package

@oSoMoN I created PR to Snapcraft Desktop Heloper
Should it fix the issue?
Is there need to rebuild snaps to make changes affect?
The PR: https://github.com/ubuntu/snapcraft-desktop-helpers/pull/213

Can anyone review the PR?

After running this several times I’ve cheated a little:

for i in ls /etc/fonts/conf.d/*.conf ; do ln -s $i ~/.local/share/fonts/ ; done