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