# -*-eselect-*- vim: ft=eselect # Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: fontconfig.eselect 728 2009-11-14 21:08:28Z dirtyepic $ DESCRIPTION="Manage ghostscript font cidfmap" AUTHOR="naota@gentoo.org" MAINTAINER="cjk@gentoo.org" SVN_DATE='$Date: 2009-11-14 15:08:28 -0600 (Sat, 14 Nov 2009) $' VERSION=$(svn_date_to_version "${SVN_DATE}") fontconfdir="${EROOT}/etc/gsfonts" LANGS="ja ko zh_CN zh_TW" get_targets() { local lang=$1 local targets local bc x i=0 bcdirs[i]="${fontconfdir}/conf.avail/${lang}/*" for bc in ${bcdirs[@]} ; do [[ -e ${bc} && ${bc} != *~ ]] && targets="${targets}\n$(basename ${bc})" done echo -ne ${targets} | sort -u } get_enabled() { local lang=$1 local target="${fontconfdir}/conf.d/cidfmap.${lang}" local mapfile [ -e "${target}" ] || return 1 mapfile=$(readlink ${target}) echo $(basename ${mapfile}) return 0 } ### list action ### describe_list() { echo "List available ghostscript font config files" } tweak_list_item() { local conf=${1} local current=${2} local mark="" if [[ ${conf} == ${current} ]]; then mark="${mark} $(highlight '*')" fi echo "${conf} ${mark}" } do_list() { local n for lang in ${LANGS}; do local targets=( $(get_targets ${lang}) ) local current=( $(get_enabled ${lang}) ) for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do targets[${i}]=$(tweak_list_item ${targets[${i}]} ${current}) done write_list_start \ "Available config files for cidfmap.${lang} ($(highlight '*') is enabled):" write_numbered_list "${targets[@]}" done return 0 } ### enable action ### describe_set() { echo "Enable specified config file" } describe_set_parameters() { echo " " } describe_set_options() { echo " : Target language" echo " : Target name or number (from 'list' action)" } do_set() { local bc bcdir="${fontconfdir}/conf.d" if [[ ${#} != 2 ]] ; then die -q "Usage: set [language] [config]" fi # create directory if necessary if [[ ! -d ${bcdir} && -w $(dirname ${bcdir}) ]] ; then mkdir ${bcdir} || die -q "Failed to create ${bcdir}" elif [[ ! -d ${bcdir} ]] ; then die -q "You don't have permission to create ${bcdir}" fi # make sure we have proper permissions [[ -w ${bcdir} ]] || \ die -q "You don't have permission to write to ${bcdir}" local lang=$1 local correct # make sure language is supported for l in ${LANGS}; do [[ "${lang}" == "${l}" ]] && correct=1 && break done [[ -z "${correct}" ]] && \ die -q "Language \"${lang}\" doesn't appear to be valid!" target=$2 targets=( $(get_targets "${lang}") ) is_number "${target}" && \ target=${targets[$(( ${target} - 1 ))]} [[ -z "${target}" ]] && \ die -q "Target \"${target}\" doesn't appear to be valid!" # what form is the argument in? case "${target}" in # absolute path /*) file="${EROOT}/${target}" ;; # relative path */*) file="${EROOT}/${PWD}/${target}" ;; # no path *) # CWD if [[ -f ${target} ]] ; then file="${EROOT}/${PWD}/${target}" # assume ${fontconfdir}/conf.avail/${lang} else file="${fontconfdir}/conf.avail/${lang}/${target}" fi ;; esac # does it exist? if [[ ! -e ${file} ]] ; then write_error_msg "${file} doesn't exist" return 1 fi local cidfmap="${bcdir}"/cidfmap.${lang} # finally, create the symlink ln -sf "${file}" "${cidfmap}" || \ die -q "Failed to create symlink from '${file}' to '${cidfmap}'" }