Blame Automation/centos-art.sh-mods/Render/Svg/svg_convertPngToBranded.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# svg_convertPngToBranded.sh -- This function standardizes image
Alain Reguera Delgado 8f60cb
# branding. Once the base PNG image is rendered and the
Alain Reguera Delgado 8f60cb
# `--with-brands' option is provided, this function composites a new
Alain Reguera Delgado 8f60cb
# branded image using the preferences set in the related
Alain Reguera Delgado 8f60cb
# `branding.conf' file.  The `branding.conf' file must be stored
Alain Reguera Delgado 8f60cb
# inside the related design model component used as reference to
Alain Reguera Delgado 8f60cb
# produce the base PNG image.
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_convertPngToBranded {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify whether the option `--with-brands' was provided or not to
Alain Reguera Delgado 8f60cb
    # `centos-art.sh' script command-line.
Alain Reguera Delgado 8f60cb
    if [[ $FLAG_WITH_BRANDS == 'false' ]];then
Alain Reguera Delgado 8f60cb
        return
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local BRANDING_CONF_FILE=''
Alain Reguera Delgado 8f60cb
    local BRANDING_CONF_SECTION=''
Alain Reguera Delgado 8f60cb
    local BRANDING_CONF_VALUES=''
Alain Reguera Delgado 8f60cb
    local BRANDING_CONF_VALUE=''
Alain Reguera Delgado 8f60cb
    local BRANDFILE=''
Alain Reguera Delgado 8f60cb
    local POSITION=''
Alain Reguera Delgado 8f60cb
    local POSITIONS=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define absolute path to branding configuration file.
Alain Reguera Delgado 8f60cb
    BRANDING_CONF_FILE="$(dirname ${TEMPLATE})/branding.conf"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify absolute path to branding configuration file. This is
Alain Reguera Delgado 8f60cb
    # required in order to avoid trying to render branded content
Alain Reguera Delgado 8f60cb
    # which doesn't have an associated `branding.conf' file. If there
Alain Reguera Delgado 8f60cb
    # is no associated `branding.conf' file don't stop the script
Alain Reguera Delgado 8f60cb
    # execution. Instead, continue with the next action in the list.
Alain Reguera Delgado 8f60cb
    # This is required in order to perform massive rendition inside
Alain Reguera Delgado 8f60cb
    # structures like themes where components might or might not have
Alain Reguera Delgado 8f60cb
    # `branding.conf' files associated. For example, the `Concept'
Alain Reguera Delgado 8f60cb
    # component doesn't have branding information associated but most
Alain Reguera Delgado 8f60cb
    # elements inside `Distro' component do.
Alain Reguera Delgado 8f60cb
    if [[ ! -f "$BRANDING_CONF_FILE" ]];then
Alain Reguera Delgado 8f60cb
        continue
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define regular expression matching the variable name (i.e., the
Alain Reguera Delgado 8f60cb
    # left column), inside the configuration line, you want to match
Alain Reguera Delgado 8f60cb
    # on.
Alain Reguera Delgado 8f60cb
    BRANDING_CONF_VARNAME=$(basename ${TEMPLATE})
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of configuration lines related to current design
Alain Reguera Delgado 8f60cb
    # model. This are the lines that tell us how and where to apply
Alain Reguera Delgado 8f60cb
    # branding information on base PNG image. Be sure that only
Alain Reguera Delgado 8f60cb
    # configuration lines from supported section names (e.g.,
Alain Reguera Delgado 8f60cb
    # `symbol', `type', `logo') be read, no need to waste resources
Alain Reguera Delgado 8f60cb
    # with others.
Alain Reguera Delgado 8f60cb
    BRANDING_CONF_VALUES=$(\
Alain Reguera Delgado 8f60cb
        for BRANDING_CONF_SECTION in $(echo "types symbols logos");do
Alain Reguera Delgado 8f60cb
            cli_getConfigValue "${BRANDING_CONF_FILE}" "${BRANDING_CONF_SECTION}" "${BRANDING_CONF_VARNAME}"
Alain Reguera Delgado 8f60cb
        done)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    for BRANDING_CONF_VALUE in $BRANDING_CONF_VALUES;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to image file used as brand. This is
Alain Reguera Delgado 8f60cb
        # the image put over the PNG image produced as result of
Alain Reguera Delgado 8f60cb
        # design models base rendition.
Alain Reguera Delgado 8f60cb
        BRANDFILE=${TCAR_WORKDIR}/Identity/Images/Brands/$(echo $BRANDING_CONF_VALUE \
Alain Reguera Delgado 8f60cb
            | gawk 'BEGIN{ FS=":" } { print $1 }' )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify absolute path to image file used as brand. Assuming
Alain Reguera Delgado 8f60cb
        # no brand image file is found, continue with the next
Alain Reguera Delgado 8f60cb
        # configuration line.
Alain Reguera Delgado 8f60cb
        if [[ ! -f $BRANDFILE ]];then
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define list of positions using the format of ImageMagick
Alain Reguera Delgado 8f60cb
        # `-geometry' option argument. 
Alain Reguera Delgado 8f60cb
        POSITIONS=$(echo "$BRANDING_CONF_VALUE" | cut -d: -f2- | tr ':' ' ')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Loop through list of brand image positions and use the
Alain Reguera Delgado 8f60cb
        # composite command from ImageMagick, to overlap the unbranded
Alain Reguera Delgado 8f60cb
        # image just rendered with the branded version of itself.
Alain Reguera Delgado 8f60cb
        for POSITION in $POSITIONS;do
Alain Reguera Delgado 8f60cb
            composite -geometry ${POSITION} ${BRANDFILE} ${FILE}.png ${FILE}.png
Alain Reguera Delgado 8f60cb
        done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}