Blame Scripts/Bash/Functions/Render/Svg/svg_getTTFont.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# cli_getFont.sh -- This function creates a list of all True Type
878a2b
# Fonts (TTF) installed in your workstation and returns the absolute
878a2b
# path of the file matching the pattern passed as first argument.
878a2b
# Assuming more than one value matches, the first one in the list is
878a2b
# used. In case no match is found, the function verifies if there is
878a2b
# any file in the list that can be used (giving preference to sans
878a2b
# files). If no file is found at this point, an error will be printed
878a2b
# out.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
3b3b38
function svg_getTTFont {
878a2b
878a2b
    local -a FONT_PATTERNS
878a2b
    local FONT_PATTERN=''
878a2b
    local FONT_FILE=''
878a2b
878a2b
    # Define list of patterns used to build the list of TTF files.
878a2b
    FONT_PATTERNS[((++${#FONT_PATTERNS[*]}))]="/${1}\.ttf$"
878a2b
    FONT_PATTERNS[((++${#FONT_PATTERNS[*]}))]="sans\.ttf$"
878a2b
    FONT_PATTERNS[((++${#FONT_PATTERNS[*]}))]="\.ttf$"
878a2b
878a2b
    # Define directory location where fonts are installed in your
878a2b
    # workstation.
878a2b
    local FONT_DIR='/usr/share/fonts'
878a2b
878a2b
    # Define list of all TTF files installed in your workstation.
878a2b
    local FONT_FILES=$(cli_getFilesList ${FONT_DIR} --pattern="\.ttf")
878a2b
878a2b
    # Define TTF absolute path based on pattern. Notice that if the
878a2b
    # pattern matches more than one value, only the first one of a
878a2b
    # sorted list will be used.
878a2b
    for FONT_PATTERN in ${FONT_PATTERNS[@]};do
878a2b
       
878a2b
        FONT_FILE=$(echo "$FONT_FILES" | egrep ${FONT_PATTERN} \
878a2b
            | head -n 1)
878a2b
878a2b
        if [[ -f $FONT_FILE ]];then
878a2b
            break
878a2b
        fi
878a2b
878a2b
    done
878a2b
878a2b
    # Output TTF absolute path.
878a2b
    if [[ -f $FONT_FILE ]];then
878a2b
        echo $FONT_FILE
878a2b
    else
878a2b
        cli_printMessage "`gettext "The font provided doesn't exist."`" --as-error-line
878a2b
    fi
878a2b
878a2b
}