diff --git a/Scripts/Bash/Functions/Commons/cli_getConfigSectionNames.sh b/Scripts/Bash/Functions/Commons/cli_getConfigSectionNames.sh new file mode 100755 index 0000000..b9bfa05 --- /dev/null +++ b/Scripts/Bash/Functions/Commons/cli_getConfigSectionNames.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# cli_getConfigSectionNames.sh -- This function standardizes the way +# section names are retrieved from configuration files. Once section +# names are retrieved they are printed to standard output for further +# processing. +# +# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function cli_getConfigSectionNames { + + # Define absolute path to configuration file we want to retrieve + # section names from. + local CONF_FILE=$1 + + # Verify existence of configuration file. + cli_checkFiles $CONF_FILE -f + + # Output all section names without brackets, one per line. + egrep '^\[[[:alnum:]._-]+\][[:space:]]*$' $CONF_FILE \ + | sed -r 's/\[(.+)\]/\1/' + +} diff --git a/Scripts/Bash/Functions/Render/Conf/conf.sh b/Scripts/Bash/Functions/Render/Conf/conf.sh new file mode 100755 index 0000000..f6ae99a --- /dev/null +++ b/Scripts/Bash/Functions/Render/Conf/conf.sh @@ -0,0 +1,97 @@ +#!/bin/bash +# +# conf.sh -- This function standardizes the way images are produced +# from configuration files. +# +# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function conf { + + # Initialize local variables. + local MODEL='' + local -a MODELS + local FORMAT='' + local FORMATS='' + local HEIGHT='' + local HEIGHTS='' + local FGCOLOR='' + local FGCOLORS='' + local BGCOLOR='' + local BGCOLORS='' + local COMMAND='' + + # Define list with all section names. These are the final file + # names we want to produce images for. + local FILENAME='' + local FILENAMES=$(cli_getConfigSectionNames $TEMPLATE) + + for FILENAME in $FILENAMES;do + + # Retrieve models you want to produce the image from. Notice + # that relative path passed in this option must begin with + # `trunk/' directory and point to an existent file. + for MODEL in $(cli_getConfigValue "$TEMPLATE" "$FILENAME" "models");do + MODELS[((++${#MODELS[*]}))]=${TCAR_WORKDIR}/${MODEL} + done + + # Retrieve formats you want to produce the image for. This + # variable contains one or more image format supported by + # ImageMagick. For example, `xpm', `jpg', 'tiff', etc. + FORMATS=$(cli_getConfigValue "$TEMPLATE" "$FILENAME" "formats") + + # Retrieve heights you want to produce the image for. This + # variable contains one or more numerical values. For example, + # `16', `24', `32', etc. + HEIGHTS=$(cli_getConfigValue "$TEMPLATE" "$FILENAME" "heights") + + # Retrieve foreground colors you want to produce the image + # for. This variable contains one or more color number in + # hexadecimal format. For example, `000000', `ffffff', etc. + FGCOLORS=$(cli_getConfigValue "$TEMPLATE" "$FILENAME" "fgcolors") + + # Retrieve background colors you want to produce the image + # for. This variable contains one or more color number in + # hexadecimal format with opacity information included. + # Opacity is specified between 0.0 and 1.0 where 0.0 is full + # transparency and 1.0 full opacity. For example, the + # following values are accepted: `000000-0', `ffffff-1', etc. + BGCOLORS=$(cli_getConfigValue "$TEMPLATE" "$FILENAME" "bgcolors") + + # Retrieve command-line you want execute to produce the image. + # For example, `/usr/bin/convert +append' + COMMAND=$(cli_getConfigValue "$TEMPLATE" "$FILENAME" "command") + + for FGCOLOR in $FGCOLORS;do + for BGCOLOR in $BGCOLORS;do + for HEIGHT in $HEIGHTS;do + conf_doBaseActions + done + done + done + + # Reset models list to prevent it from growing for each file + # name (configuration section) iteration and create this way + # unexpected images as final result. + unset MODELS + + done + +} diff --git a/Scripts/Bash/Functions/Render/Conf/conf_doBaseActions.sh b/Scripts/Bash/Functions/Render/Conf/conf_doBaseActions.sh new file mode 100755 index 0000000..c543dd9 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Conf/conf_doBaseActions.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# +# conf_doBaseActions.sh -- This function standardizes base actions +# related to image production through configuration files. +# +# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function conf_doBaseActions { + + local COUNTER=0 + local INKSCAPE_EXPORTID="CENTOSARTWORK" + local -a MODEL_INSTANCES + local -a INKSCAPE_OUTPUT + local -a INKSCAPE_COMMANDS + + # Define absolute path to output location. This is the location + # inside the working copy all images will be stored in. + local OUTPUT=${OUTPUT}/${FGCOLOR}/${BGCOLOR}/${HEIGHT}/${FILENAME} + + # Define which command will be used to output the template + # content. This is required because template files might be found + # as compressed files inside the repository. + local VIEWER="/bin/cat" + + while [[ $COUNTER -lt ${#MODELS[*]} ]];do + + # Verify existence of design models. + cli_checkFiles ${MODELS[$COUNTER]} -f + + # Define file name for design model instances. + MODEL_INSTANCES[$COUNTER]=${TMPDIR}/$(basename ${MODELS[$COUNTER]}) + + # Define file name for image instances. + IMAGE_INSTANCES[$COUNTER]=${TMPDIR}/$(basename ${MODELS[$COUNTER]} \ + | sed -r 's/\.(svgz|svg)$/.png/') + + # Redefine command used to read design models. + if [[ $(file -b -i ${MODELS[$COUNTER]}) =~ '^application/x-gzip$' ]];then + VIEWER="/bin/zcat" + fi + + # Create uncompressed design model instances in order to make + # color replacements without affecting original design models. + $VIEWER ${MODELS[$COUNTER]} > ${MODEL_INSTANCES[$COUNTER]} + + # Make your best to be sure the design model instance you are + # processing is a valid scalable vector graphic. + cli_checkFiles ${MODEL_INSTANCES[$COUNTER]} --mime="text/xml" + + # Make color replacements to each design model instance before + # render them using Inkscape. + if [[ ${FGCOLOR} != '000000' ]];then + sed -i -r "s/((fill|stroke):#)000000/\1${FGCOLOR}/g" ${MODEL_INSTANCES[$COUNTER]} + fi + + # Create list of Inkscape commands based for each design model + # set in the configuration file. + INKSCAPE_COMMANDS[${COUNTER}]="${MODEL_INSTANCES[$COUNTER]} \ + --export-id=${INKSCAPE_EXPORTID} \ + --export-png=${IMAGE_INSTANCES[$COUNTER]} \ + --export-background=$(echo ${BGCOLOR} | cut -d'-' -f1) \ + --export-background-opacity=$(echo ${BGCOLOR} | cut -d'-' -f2) \ + --export-height=${HEIGHT}" + + # Create PNG image based on design models. + inkscape ${INKSCAPE_COMMANDS[$COUNTER]} > /dev/null + + COUNTER=$(( $COUNTER + 1 )) + + done + + # Verify existence of output directory. + if [[ ! -d $(dirname ${OUTPUT}) ]];then + mkdir -p $(dirname ${OUTPUT}) + fi + + # Apply command to PNG images produced from design models to + # construct the final PNG image. + cli_printMessage "${OUTPUT}" --as-creating-line + ${COMMAND} ${IMAGE_INSTANCES[*]} ${OUTPUT} + + # Convert images from PNG to those formats specified in the + # configuration file. + local TARGET=$(echo $OUTPUT | sed -r 's/\.(.+)$//') + for FORMAT in ${FORMATS};do + cli_printMessage "${TARGET}.${FORMAT}" --as-creating-line + convert ${OUTPUT} ${TARGET}.${FORMAT} + done + +}