Blame Automation/Modules/Render/Modules/Svg/svg_checkModelAbsref.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 2e37b0
######################################################################
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 2e37b0
#   Modules/Render/Modules/Svg/Scripts/svg_checkModelAbsref.sh -- This
Alain Reguera Delgado 2e37b0
#   function retrieves absolute pahts from source files and checks
Alain Reguera Delgado 2e37b0
#   their existence. 
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
#   In order for design templates to point different artistic motifs,
Alain Reguera Delgado 2e37b0
#   design templates make use of external files which point to
Alain Reguera Delgado 2e37b0
#   specific artistic motif background images. If such external files
Alain Reguera Delgado 2e37b0
#   don't exist, try to create the background image required by
Alain Reguera Delgado 2e37b0
#   cropping a higher background image (e.g., 2048x1536-final.png).
Alain Reguera Delgado 2e37b0
#   If this isn't possible either, then create the background image
Alain Reguera Delgado 2e37b0
#   using a plain color and crop from it then.  We can't go on without
Alain Reguera Delgado 2e37b0
#   the required background information.
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
#   Written by:
Alain Reguera Delgado 2e37b0
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 809ecc
# Copyright (C) 2009-2013 The CentOS Artwork SIG
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 809ecc
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 809ecc
# 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 2e37b0
######################################################################
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 2e37b0
    FILE="${1}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 2e37b0
    # Verify existence of file we need to retrieve absolute paths from.
Alain Reguera Delgado 786ac0
    tcar_checkFiles -ef "${FILE}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 2e37b0
    # Retrieve absolute paths from file.
Alain Reguera Delgado 2e37b0
    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 2e37b0
    # Verify absolute paths retrieved from file.
Alain Reguera Delgado 2e37b0
    for BG_DST_FILE in ${BG_DST_FILES};do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 2e37b0
        # Verify parent directory of absolute files retrieved 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 2e37b0
        # information inside SVG files get outdated temporally. 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 2e37b0
        tcar_checkFiles -d "$(dirname ${BG_DST_FILE})"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 2e37b0
        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 2e37b0
            # crop when no specific background information be
Alain Reguera Delgado 2e37b0
            # available for using. Generally, this is the most
Alain Reguera Delgado 2e37b0
            # reusable background file inside the artistic motifs
Alain Reguera Delgado 2e37b0
            # (e.g,.  the `2048x1536-final.png' file).  We can use
Alain Reguera Delgado 2e37b0
            # this image file to create almost all artworks inside The
Alain Reguera Delgado 2e37b0
            # CentOS Distribution visual manifestation when
Alain Reguera Delgado 8f60cb
            # resolution-specific backgrounds don't exist. 
Alain Reguera Delgado 2e37b0
            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 2e37b0
            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 2e37b0
                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 2e37b0
                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 2e37b0
                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 2e37b0
                tcar_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 2e37b0
            tcar_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 2e37b0
            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 2e37b0
            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 786ac0
            tcar_checkFiles -ef ${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
}