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