Skip to content

Instantly share code, notes, and snippets.

@rmi1974
Last active July 22, 2024 02:54
Show Gist options
  • Save rmi1974/0a613d721851fef4cb6babd02d65a97c to your computer and use it in GitHub Desktop.
Save rmi1974/0a613d721851fef4cb6babd02d65a97c to your computer and use it in GitHub Desktop.
How to hide all system / distro provided fonts from Wine #wine #fonts #fontconfig

How to hide all system / distro provided fonts from Wine

Wine uses fontconfig to manage distro provided fonts.

To hide all system / distro installed fonts (/usr/share/fonts/... etc.) use a local fontconfig configuration file.

Content of example wine_no_system_fonts with no font paths configured:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/fonts.conf file to configure system font access -->
<fontconfig>
	<its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
		<its:translateRule translate="no" selector="/fontconfig/*[not(self::description)]"/>
	</its:rules>

</fontconfig>

Export the environment variable FONTCONFIG_FILE with the custom fontconfig file path in current shell or prefix all commands with it:

export FONTCONFIG_FILE=$PWD/wine_no_system_fonts.conf

⚠️ This change effects all programs started within the shell!

Check that fontconfig no longer lists fonts:

fc-list : file

Re-create the WINEPREFIX as Wine does persist / caches system fonts data (paths to files) in registry.

rm -rf ~/.wine

wineboot -u

For testing, start wordpad and check that only Wine "builtin" fonts are listed in drop-down font list:

wine wordpad
@ndgnuh
Copy link

ndgnuh commented Jul 21, 2024

Thanks, this worked for me. However, to make it more convenient to use, I patched all the commands that are related to wine.

# Put this in .zshenv, .xsessionrc, .profile or /etc/profile
# I have only tested this with zsh

write_wine_fc() {
    echo '<?xml version="1.0"?>
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
    <!-- /etc/fonts/fonts.conf file to configure system font access -->
    <fontconfig>
        <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
            <its:translateRule translate="no" selector="/fontconfig/*[not(self::description)]"/>
        </its:rules>
    </fontconfig>' > "/tmp/.winefonts.conf"
}

# All my wine binaries are installed separately from the system binaries (`/opt/wine-stagging/bin`), 
# so I can just drop the `wine*` part, but for the people who uses distro
# shipped version of wine, this is needed to not mess with other applications.
WINE_BINARY_DIR="$(dirname $(which wine))"
for winecmd in $(ls $WINE_BINARY_DIR/wine*)
do
    $winecmd () {
        write_wine_fc 
        FONTCONFIG_FILE="/tmp/.winefonts.conf" "$WINE_BINARY_DIR/$0" $@
    }
done

@ndgnuh
Copy link

ndgnuh commented Jul 22, 2024

Thanks, this worked for me. However, to make it more convenient to use, I patched all the commands that are related to wine.

# Put this in .zshenv, .xsessionrc, .profile or /etc/profile
# I have only tested this with zsh

write_wine_fc() {
    echo '<?xml version="1.0"?>
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
    <!-- /etc/fonts/fonts.conf file to configure system font access -->
    <fontconfig>
        <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
            <its:translateRule translate="no" selector="/fontconfig/*[not(self::description)]"/>
        </its:rules>
    </fontconfig>' > "/tmp/.winefonts.conf"
}

# All my wine binaries are installed separately from the system binaries (`/opt/wine-stagging/bin`), 
# so I can just drop the `wine*` part, but for the people who uses distro
# shipped version of wine, this is needed to not mess with other applications.
WINE_BINARY_DIR="$(dirname $(which wine))"
for winecmd in $(ls $WINE_BINARY_DIR/)
do
    $winecmd () {
        write_wine_fc 
        FONTCONFIG_FILE="/tmp/.winefonts.conf" "$WINE_BINARY_DIR/$0" $@
    }
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment