# Exit on error:
set -e

wget http://downloads.sourceforge.net/project/wqy/wqy-microhei/0.2.0-beta/wqy-microhei-0.2.0-beta.tar.gz
tar xf wqy-microhei-0.2.0-beta.tar.gz
mkdir -p /share/fonts/wenquanyi/wqy-microhei/
install -m644 wqy-microhei/wqy-microhei.ttc /share/fonts/wenquanyi/wqy-microhei/

cat > /etc/fonts/conf.d/44-wqy-microhei.conf << EOF
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
	<test name="family">
		<string>WenQuanYi Micro Hei</string>
	</test>
	<edit name="globaladvance"><bool>false</bool></edit>
	<edit name="spacing"><int>0</int></edit>
	<edit name="antialias" mode="assign"><bool>true</bool></edit>
	<edit name="rh_prefer_bitmaps" mode="assign"><bool>false</bool></edit>
	<edit name="embeddedbitmap"><bool>false</bool></edit>
	<edit name="autohint" mode="assign"><bool>false</bool></edit>
	<edit name="hinting" mode="assign"><bool>true</bool></edit>
	<edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
	<edit name="rgba" mode="assign"><const>rgb</const></edit>
</match>
<match target="font">
	<test name="family">
		<string>文泉驿微米黑</string>
	</test>
	<edit name="globaladvance"><bool>false</bool></edit>
	<edit name="spacing"><int>0</int></edit>
	<edit name="antialias" mode="assign"><bool>true</bool></edit>
	<edit name="rh_prefer_bitmaps" mode="assign"><bool>false</bool></edit>
	<edit name="embeddedbitmap"><bool>false</bool></edit>
	<edit name="autohint" mode="assign"><bool>false</bool></edit>
	<edit name="hinting" mode="assign"><bool>true</bool></edit>
	<edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
	<edit name="rgba" mode="assign"><const>rgb</const></edit>
</match>
<match target="font">
	<test name="family">
		<string>文泉驛微米黑</string>
	</test>
	<edit name="globaladvance"><bool>false</bool></edit>
	<edit name="spacing"><int>0</int></edit>
	<edit name="antialias" mode="assign"><bool>true</bool></edit>
	<edit name="rh_prefer_bitmaps" mode="assign"><bool>false</bool></edit>
	<edit name="embeddedbitmap"><bool>false</bool></edit>
	<edit name="autohint" mode="assign"><bool>false</bool></edit>
	<edit name="hinting" mode="assign"><bool>true</bool></edit>
	<edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
	<edit name="rgba" mode="assign"><const>rgb</const></edit>
</match>
</fontconfig>
EOF

echo -n "Creating an index of scalable font files for X... "
mkfontscale /share/fonts/wenquanyi/wqy-microhei
echo "done."

echo -n "Creating an index of X font files in a directory... "
mkfontdir /share/fonts/wenquanyi/wqy-microhei
echo "done."

rm -rf wqy-microhei
rm wqy-microhei-0.2.0-beta.tar.gz

echo "Now type the following command as root:"
echo "fc-cache -s /share/fonts/wenquanyi/wqy-microhei"

exit 0
