Fix ugly font displayed in browser (e.g. Firefox) – Definitive Guide

Sometimes, in some intallations,  can happen that some font displayed in a browser as Firefox (or also other) can appear degraded. This is due to missing installed fonts and/or incorrect fonts configuration.

Step 1: install all possible font;
Step 2: install correct font configuration package...

Then... for step 1 I realized a script that automate the installation of all fonts find in repositories (see https://wiki.archlinux.org/index.php/unofficial_user_repositories" to setting up many other repositories). The script works in the following way: it use yaourt and grep commands to find only uninstalled font and try to install it. The name of script is fontinstall.sh. If you run it without parameters it ask for any font to install. Otherwise you can append -a parameter to allow the script to install finding not already installed font, without asking for installation. If a font wouldn't install for any reason, the script add it in an exclusion list named "pkgexclusion.list", so that, in the event of a subsequent restart, this is discarded from reinstall. To run yaourt without prompting, you first need to change file .yaourtrc in your home directory by adding (or uncomment) the following lines:

TMPDIR="$HOME/tmp"
SUDONOVERIF=0 # Avoid multiple sudo checks when timestamp_timeout=0
# Prompt
NOCONFIRM=1
UP_NOCONFIRM=1 # No prompt while build upgrades (including -Sbu)
BUILD_NOCONFIRM=1 # Only prompt for editing files
PU_NOCONFIRM=1 # Add --noconfirm to $PACMAN -U
EDITFILES=0
NOENTER=1

Following the script program (you can copy/paste in your preferred editor and save it with name fontinstall.sh, or other preferred name - NOTE: some terms are in italian language - sorry):

----------------------------- copy from here -------------------------------------

#!/bin/bash
#
# Install fonts found in Archlinux repositories.
#

auto=false
param=$1
case $param in
    "-a")    auto=true
        ;;
    "" )    auto=false
        ;;
    *    )        echo "Parameter $param unknown..."
                exit 10
        ;;
esac

pkgexlst="$HOME/pkgexclusion.list"

function scelta {
    local s
    while true; do
        echo $1
        read -p "Install? [y/n] ([RETURN] to exit): " s
        case $s in
            [nN]) return 0
                ;;
            [yY]) return 1
                ;;
            "")        return 2
                ;;
            * )     clear # loop
                ;;
        esac
    done
}

saveIFS=$IFS
IFS=$'\n'

i=0; j=0
declare -a lineres lineres2 result
totline=""
clear
echo -n "Please wait..."
touch $pkgexlst
for line in $(yaourt -Ss 'font' | egrep '^\w' | egrep -v '\[installed'); do
    lineres2[$i]=$line
    ((i=$i+1))
done

if [[ $i -eq 0 ]]; then
    echo "No packages found..."
    exit 2
else
    echo "Found $i packages..."
    read totline resto <<< $(wc -l $pkgexlst)
    echo "Total discarded packages: $totline..."
fi

# Create new array without discarded fonts.
j1=0
for ((j2=0; j2<i; j2++)); do
    found=false
    IFS=' '
    read line resto <<< ${lineres2[j2]} # Get only package name
    result=($(grep $line $pkgexlst))
    IFS=$'\n'
    for linefound in ${result[@]}; do
        if [[ $linefound == $line ]]; then
            found=true
            break
        fi
    done
    if ! $found; then     # it is not in the exclusion...
        if $auto; then
            echo "$line"
        fi
        lineres[j1]=$line    # ...then I insert it in the final array.
        ((j1=$j1+1))       
    fi
done

if $auto; then
    while true; do
        read -p "Do you want to proceed with the automatic installation? [y/n] " s
        case $s in
            [nN]) exit 20
                ;;
            [yY]) break
                ;;
            * )     echo "Wrong choice..."
                        sleep 2
                ;;
        esac
    done
fi

IFS=' '
i=$j1; j1=0;
for ((j=0; j<i; j++)); do
    clear
    ((j1=$j+1))
    echo "Package n. $j1 of $i"
    if $auto; then
        yaourt -S --noconfirm ${lineres[j]}
        ret=$?
        echo "exit code: $ret"
        if [[ $ret -ne 0 ]]; then
            echo ${lineres[j]} >> $pkgexlst # Exclusion list
            echo "Package ${lineres[j]} discarded..."
            sleep 1
        fi
    else
        scelta ${lineres[j]}
        case $? in
            0 )    echo ${lineres[j]} >> $pkgexlst # Exclusion list
                ;;
            1 )    yaourt -S --noconfirm ${lineres[j]}
                    echo "exit code: $?"
                    while true; do
                        read -p "[RETURN] to continue; \"x\" to discard ${lineres[j]}: " s
                        case $s in
                            [xX])    echo ${lineres[j]} >> $pkgexlst # Exclusion list
                                        echo "Package ${lineres[j]} discarded..."
                                        sleep 3
                                        break
                                        ;;
                            ""     )    break
                                        ;;
                            *     )    echo "Wrong choice..."
                                        sleep 3
                                        clear
                                        ;;
                        esac
                    done
                ;;
            2 ) break
                ;;
        esac
    fi
done

#IFS=$saveIFS
set IFS=$saveIFS

exit $?
----------------------------- copy up to here -------------------------------------

After previous script installed every fonts, you may have the need to correct same misconfigured font (step 2). To do this, you first do uninstall standard fontconfig by the command:

    yaourt -Rdd fontconfig

then uninstall freetype2 font:

    yaourt -Rdd freetype2
 
then you install new font configuration package named fontconfig-infinality-ultimate:

    yaourt -S fontconfig-infinality-ultimate

then new freetype2 font:

    yaourt -S freetype2-infinality-ultimate

Now all your fonts work fine...


---
Flavio Antonini

Contributors:

(Visited 3,499 times, 1 visits today)

Pin It on Pinterest

Share This