Blame Automation/centos-art.sh-render/Svg/svg_checkModelAbsref.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# svg_checkModelAbsref.sh -- This function retrives absolute files and
Alain Reguera Delgado 8f60cb
# checks their existence. In order for design templates to point
Alain Reguera Delgado 8f60cb
# different artistic motifs, design templates make use of external
Alain Reguera Delgado 8f60cb
# files which point to specific artistic motif background images. If
Alain Reguera Delgado 8f60cb
# such external files don't exist, try to create the background image
Alain Reguera Delgado 8f60cb
# required by cropping a higher background image (e.g.,
Alain Reguera Delgado 8f60cb
# 2048x1536-final.png).  If this isn't possible neither, then create
Alain Reguera Delgado 8f60cb
# the background image using a plain color and crop from it then.  We
Alain Reguera Delgado 8f60cb
# can't go on without the required background information.
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_checkModelAbsref {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local FILE=''
Alain Reguera Delgado 8f60cb
    local BG_DST_FILES=''
Alain Reguera Delgado 8f60cb
    local BG_DST_FILE=''
Alain Reguera Delgado 8f60cb
    local BG_DST_FILE_WIDTH=''
Alain Reguera Delgado 8f60cb
    local BG_DST_FILE_HEIGHT=''
Alain Reguera Delgado 8f60cb
    local BG_SRC_FILE=''
Alain Reguera Delgado 8f60cb
    local BG_SRC_FILE_COLOR=''
Alain Reguera Delgado 8f60cb
    local BG_SRC_FILE_WIDTH=''
Alain Reguera Delgado 8f60cb
    local BG_SRC_FILE_HEIGHT=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define absolute path to the translated instance of design model.
Alain Reguera Delgado 8f60cb
    FILE="$1"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify existence of file we need to retrive absolute paths from.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e "$FILE"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Retrive absolute paths from file.
Alain Reguera Delgado 8f60cb
    BG_DST_FILES=$(egrep "(sodipodi:absref|xlink:href)=\"${HOME}.+" $FILE \
Alain Reguera Delgado 8f60cb
        | sed -r "s,.+=\"(${HOME}.+\.png)\".*,\1," | sort | uniq)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify absolute paths retrived from file.
Alain Reguera Delgado 8f60cb
    for BG_DST_FILE in $BG_DST_FILES;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Print action message.
Alain Reguera Delgado 8f60cb
        cli_printMessage "$BG_DST_FILE" --as-checking-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify parent directory of absolute files retrived from
Alain Reguera Delgado 8f60cb
        # file. This is required to prevent the construction of paths
Alain Reguera Delgado 8f60cb
        # to locations that don't exist. For example, when including
Alain Reguera Delgado 8f60cb
        # background images in SVG files, it is possible that the path
Alain Reguera Delgado 8f60cb
        # information inside SVG files get outdated temporarly. If in
Alain Reguera Delgado 8f60cb
        # that exact moment, you try to render the SVG file it won't
Alain Reguera Delgado 8f60cb
        # be possible to create the image used for cropping because
Alain Reguera Delgado 8f60cb
        # the path build from the location inside SVG file doesn't
Alain Reguera Delgado 8f60cb
        # exist. In this case, centos-art.sh script will end up with
Alain Reguera Delgado 8f60cb
        # `file ... doesn't exist' errors.
Alain Reguera Delgado 8f60cb
        cli_checkFiles -d "$(dirname ${BG_DST_FILE})"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        if [[ ! -a $BG_DST_FILE ]];then
Alain Reguera Delgado 8f60cb
  
Alain Reguera Delgado 8f60cb
            # Define the source background file, the image file will
Alain Reguera Delgado 8f60cb
            # crop when no specific background informatio be available
Alain Reguera Delgado 8f60cb
            # for using. Generally, this is the most reusable
Alain Reguera Delgado 8f60cb
            # background file inside the artistic motifs (e.g,.  the
Alain Reguera Delgado 8f60cb
            # `2048x1536-final.png' file).  We can use this image file
Alain Reguera Delgado 8f60cb
            # to create almost all artworks inside The CentOS
Alain Reguera Delgado 8f60cb
            # Distribution visual manifestation when
Alain Reguera Delgado 8f60cb
            # resolution-specific backgrounds don't exist. 
Alain Reguera Delgado 8f60cb
            BG_SRC_FILE=$(echo $BG_DST_FILE \
Alain Reguera Delgado 8f60cb
                | sed -r "s!(.+)/[[:digit:]]+x[[:digit:]]+(-final\.png)!\1/2048x1536\2!")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Verify existence of source background file. If the file
Alain Reguera Delgado 8f60cb
            # doesn't exist create it using The CentOS Project default
Alain Reguera Delgado 8f60cb
            # background color information, as specified in its
Alain Reguera Delgado 8f60cb
            # corporate identity manual.
Alain Reguera Delgado 8f60cb
            if [[ ! -f $BG_SRC_FILE ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
                # Define plain color that will be used as background.
Alain Reguera Delgado 8f60cb
                BG_SRC_FILE_COLOR=$(svg_getColors)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
                # Verify format of color value.
Alain Reguera Delgado 8f60cb
                svg_checkColorFormats $BG_SRC_FILE_COLOR --format='rrggbb'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
                # Define width for the source background file the
Alain Reguera Delgado 8f60cb
                # required background information is cropped from.
Alain Reguera Delgado 8f60cb
                BG_SRC_FILE_WIDTH=$(echo $BG_SRC_FILE \
Alain Reguera Delgado 8f60cb
                    | sed -r 's!.+/([[:digit:]]+)x[[:digit:]]+-final\.png!\1!')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
                # Define height for the source background file the
Alain Reguera Delgado 8f60cb
                # required background information is cropped from.
Alain Reguera Delgado 8f60cb
                BG_SRC_FILE_HEIGHT=$(echo $BG_SRC_FILE \
Alain Reguera Delgado 8f60cb
                    | sed -r 's!.+/[[:digit:]]+x([[:digit:]]+)-final\.png!\1!')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
                # Print action message.
Alain Reguera Delgado 8f60cb
                cli_printMessage "${BG_SRC_FILE} ($BG_SRC_FILE_COLOR)" --as-creating-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
                # Create the source background file.
Alain Reguera Delgado 8f60cb
                ppmmake -quiet ${BG_SRC_FILE_COLOR} \
Alain Reguera Delgado 8f60cb
                    ${BG_SRC_FILE_WIDTH} ${BG_SRC_FILE_HEIGHT} \
Alain Reguera Delgado 8f60cb
                    | pnmtopng > ${BG_SRC_FILE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Print action message.
Alain Reguera Delgado 8f60cb
            cli_printMessage "$BG_SRC_FILE" --as-cropping-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Define the width of the required background information.
Alain Reguera Delgado 8f60cb
            BG_DST_FILE_WIDTH=$(echo $BG_DST_FILE \
Alain Reguera Delgado 8f60cb
                | sed -r 's!.+/([[:digit:]]+)x[[:digit:]]+-final\.png!\1!')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Define the height of the required background information.
Alain Reguera Delgado 8f60cb
            BG_DST_FILE_HEIGHT=$(echo $BG_DST_FILE \
Alain Reguera Delgado 8f60cb
                | sed -r 's!.+/[[:digit:]]+x([[:digit:]]+)-final\.png!\1!')
Alain Reguera Delgado 8f60cb
 
Alain Reguera Delgado 8f60cb
            # Create required backgrounnd information.
Alain Reguera Delgado 8f60cb
            convert -quiet \
Alain Reguera Delgado 8f60cb
                -crop ${BG_DST_FILE_WIDTH}x${BG_DST_FILE_HEIGHT}+0+0 \
Alain Reguera Delgado 8f60cb
                ${BG_SRC_FILE} ${BG_DST_FILE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Verify required background information.
Alain Reguera Delgado 8f60cb
            cli_checkFiles -e $BG_DST_FILE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}