#! /bin/sh

set -e

. /usr/share/debconf/confmodule

CONFDIR=/etc/fonts/conf.d

hinting_type="Native"

unhinted_2_3="10-debconf-unhinted.conf"
unhinted_2_4="10-unhinted.conf"
autohint_2_3="10-debconf-autohint.conf"
autohint_2_4="10-autohint.conf"

if [ -h $CONFDIR/$unhinted_2_4 -o -h $CONFDIR/$unhinted_2_3 ]; then
        hinting_type="None"
fi
if [ -h $CONFDIR/$autohint_2_4 -o -h $CONFDIR/$autohint_2_3 ]; then
        hinting_type="Autohinter"
fi

db_set fontconfig/hinting_type "$hinting_type"


hinting_style="hintslight"

hintnone="10-hinting-none.conf"
hintslight="10-hinting-slight.conf"
hintmedium="10-hinting-medium.conf"
hintfull="10-hinting-full.conf"

if [ -h $CONFDIR/$hintnone ]; then
    hinting_style="hintnone"
fi
if [ -h $CONFDIR/$hintslight ]; then
    hinting_style="hintslight"
fi
if [ -h $CONFDIR/$hintmedium ]; then
    hinting_style="hintmedium"
fi
if [ -h $CONFDIR/$hintfull ]; then
    hinting_style="hintfull"
fi

db_set fontconfig/hinting_style "$hinting_style"


subpixel_rendering="Automatic"

subpixel_2_3="20-debconf-sub-pixel.conf"
subpixel_2_4="10-sub-pixel-rgb.conf"
no_subpixel_2_3="20-debconf-no-sub-pixel.conf"
no_subpixel_2_4="10-no-sub-pixel.conf"

if [ -h $CONFDIR/$subpixel_2_4 -o -h $CONFDIR/$subpixel_2_3 ]; then
        subpixel_rendering="Always"
fi

if [ -h $CONFDIR/$no_subpixel_2_4 -o -h $CONFDIR/$no_subpixel_2_3 ]; then
        subpixel_rendering="Never"
fi

db_set fontconfig/subpixel_rendering "$subpixel_rendering"


enable_bitmaps="dunno"

yes_bitmaps_2_3="30-debconf-yes-bitmaps.conf"
yes_bitmaps_2_4="70-yes-bitmaps.conf"
no_bitmaps_2_3="30-debconf-no-bitmaps.conf"
no_bitmaps_2_4="70-no-bitmaps.conf"

if [ -h $CONFDIR/$yes_bitmaps_2_4 -o -h $CONFDIR/$yes_bitmaps_2_3 ]; then
        enable_bitmaps="true"
fi

if [ -h $CONFDIR/$no_bitmaps_2_4 -o -h $CONFDIR/$no_bitmaps_2_3 ]; then
        enable_bitmaps="false"
fi

# Versions prior to 2.6.0-2 are broken and leave us with no symbolic 
# link, so we have to re-ask the user his choice :(
if [ "$enable_bitmaps" = "dunno" ]; then
	db_fset fontconfig/enable_bitmaps seen false
	enable_bitmaps="false"
fi
db_set fontconfig/enable_bitmaps "$enable_bitmaps"

db_input low fontconfig/hinting_type || true
db_input low fontconfig/hinting_style || true
db_input low fontconfig/subpixel_rendering || true
db_input low fontconfig/enable_bitmaps || true
db_go
