#!/bin/sh

############################################################################
#
# MODULE:       mkftcap
# AUTHOR(S):    Glynn Clements, Michael Barton, Paul Kelly
# PURPOSE:      create font typecap file
# COPYRIGHT:    (C) 2007 by the GRASS Development Team
#
#               This program is free software under the GNU General Public
#               License (>=v2). Read the file COPYING that comes with GRASS
#               for details.
#
#############################################################################


exts='ttf TTF pfa PFA pfb PFB dfont DFONT oft OFT'

(
    for dir in /usr/lib/X11/fonts /usr/share/X11/fonts /usr/share/fonts \
        "$HOME/Library/Fonts" /Library/Fonts /System/Library/Fonts \
        "$WINDIR/Fonts" \
        "$@"
    do
        if [ -d "$dir" ] ; then
            for ext in $exts ; do
                find "$dir" -type f -name '*.'"$ext" -print \
                    | sed 's!^\(.*\)/\(.*\)$!\2:\1/\2:utf-8:!' \
                    | sed 's/\.'"$ext"':/:/'
            done
        fi
    done
    
    if which fc-list >/dev/null 2>&1 ; then
        fc-list :outline file index \
            | sed -n \
                  -e 's!^\(.*\)/\(.*\)\.\([^.]*\): :index=0$!\2:\1/\2.\3:utf-8:!p' \
                  -e 's!^\(.*\)/\(.*\)\.\([^.]*\): :index=\([0-9]\+\)$!\2:\1/\2.\3|\4:utf-8:!p' \
                  -e 's!^\(.*\)/\(.*\): :index=0$!\2:\1/\2:utf-8:!p' \
                  -e 's!^\(.*\)/\(.*\): :index=\([0-9]\+\)$!\2:\1/\2|\3:utf-8:!p'
    fi

) | sort | uniq
