#!/bin/sh

#     DESCRIPTION
#
# Setup fontconfig


#     REQUIRES
#
# Nothing


#     INFO
#

NAME="init5-fontconfig"

verbose()
{
    if [ -n "$GLOBAL_VERBOSE" ]; then
        echo "HOOK: $NAME: $@"
    fi
}

verbose "has started"

DEST_DIR=""
CONFD="/etc/fonts/conf.d"
AVAILD="/etc/fonts/conf.avail"

turn_config_on()
{
    CONFNAME="$1"
    while [ -n "$CONFNAME" ]; do
	EXISTS=`ls -1 ${DEST_DIR}${CONFD}/??-${CONFNAME}.conf 2>/dev/null`
	if [ -z "$EXISTS" ]; then
	    AVAIL=`ls -1 ${DEST_DIR}${AVAILD}/??-${CONFNAME}.conf 2>/dev/null`
	    if [ -n "$AVAIL" ]; then
		CONF_ADD=$(basename `ls -1 ${DEST_DIR}${AVAILD}/??-${CONFNAME}.conf 2>/dev/null | head -n 1`)
		ln -s "${AVAILD}/$CONF_ADD" "${DEST_DIR}${CONFD}/$CONF_ADD" ||:
	    fi
	fi
	shift
	CONFNAME="$1"
    done
}

turn_config_off()
{
    CONFNAME="$1"
    while [ -n "$CONFNAME" ]; do
	EXISTS=`ls -1 ${DEST_DIR}${CONFD}/??-${CONFNAME}.conf 2>/dev/null`
	if [ -n "$EXISTS" ]; then
	    for CONF_REMOVE in $EXISTS; do
		rm -f $CONF_REMOVE ||:
	    done
	fi
	shift
	CONFNAME="$1"
    done
}

turn_config_off no-antialias lcdfilter-none unhinted no-sub-pixel
turn_config_on antialias lcdfilter-default hinting style-full sub-pixel-rgb
