Blame tcar-scripts-render/Modules/Files/Modules/Svg/svg_checkModelAbsref.sh

Alain Reguera Delgado 8daea6
#!/bin/bash
Alain Reguera Delgado 8daea6
######################################################################
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
#   svg_checkModelAbsref.sh -- This function retrieves absolute pahts
Alain Reguera Delgado 8daea6
#   from source files and checks their existence.
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
#   In order for design templates to point different artistic motifs,
Alain Reguera Delgado 8daea6
#   design templates make use of external files which point to
Alain Reguera Delgado 8daea6
#   specific artistic motif background images. If such external files
Alain Reguera Delgado 8daea6
#   don't exist, try to create the background image required by
Alain Reguera Delgado 8daea6
#   cropping a higher background image (e.g., 2048x1536.png).  If this
Alain Reguera Delgado 8daea6
#   isn't possible either, then create the background image using a
Alain Reguera Delgado 8daea6
#   plain color and crop from it then.  We can't go on without the
Alain Reguera Delgado 8daea6
#   required background information.
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
#   Written by:
Alain Reguera Delgado 8daea6
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8daea6
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8daea6
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8daea6
# your option) any later version.
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8daea6
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8daea6
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8daea6
# General Public License for more details.
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8daea6
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8daea6
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8daea6
#
Alain Reguera Delgado 8daea6
######################################################################
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
function svg_checkModelAbsref {
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
    local FILE=''
Alain Reguera Delgado 8daea6
    local BG_DST_FILES=''
Alain Reguera Delgado 8daea6
    local BG_DST_FILE=''
Alain Reguera Delgado 8daea6
    local BG_DST_FILE_WIDTH=''
Alain Reguera Delgado 8daea6
    local BG_DST_FILE_HEIGHT=''
Alain Reguera Delgado 8daea6
    local BG_SRC_FILE=''
Alain Reguera Delgado 8daea6
    local BG_SRC_FILE_COLOR=''
Alain Reguera Delgado 8daea6
    local BG_SRC_FILE_WIDTH=''
Alain Reguera Delgado 8daea6
    local BG_SRC_FILE_HEIGHT=''
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
    # Define absolute path to the translated instance of design model.
Alain Reguera Delgado 8daea6
    FILE="${1}"
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
    # Verify existence of file we need to retrieve absolute paths from.
Alain Reguera Delgado 8daea6
    tcar_checkFiles -ef "${FILE}"
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
    # Retrieve absolute paths from file.
Alain Reguera Delgado 8daea6
    BG_DST_FILES=$(egrep "(sodipodi:absref|xlink:href)=\"${HOME}.+" ${FILE} \
Alain Reguera Delgado 8daea6
        | sed -r "s,.+=\"(${HOME}.+\.png)\".*,\1," | sort | uniq)
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
    # Verify absolute paths retrieved from file.
Alain Reguera Delgado 8daea6
    for BG_DST_FILE in ${BG_DST_FILES};do
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
        # Verify parent directory of absolute files retrieved from
Alain Reguera Delgado 8daea6
        # file. This is required to prevent the construction of paths
Alain Reguera Delgado 8daea6
        # to locations that don't exist. For example, when including
Alain Reguera Delgado 8daea6
        # background images in SVG files, it is possible that the path
Alain Reguera Delgado 8daea6
        # information inside SVG files get outdated temporally. If in
Alain Reguera Delgado 8daea6
        # that exact moment, you try to render the SVG file it won't
Alain Reguera Delgado 8daea6
        # be possible to create the image used for cropping because
Alain Reguera Delgado 8daea6
        # the path build from the location inside SVG file doesn't
Alain Reguera Delgado 8daea6
        # exist. In this case, centos-art.sh script will end up with
Alain Reguera Delgado 8daea6
        # `file ... doesn't exist' errors.
Alain Reguera Delgado 8daea6
        tcar_checkFiles -d "$(dirname ${BG_DST_FILE})"
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
        if [[ ! -a ${BG_DST_FILE} ]];then
Alain Reguera Delgado 8daea6
  
Alain Reguera Delgado 8daea6
            # Define the source background file, the image file will
Alain Reguera Delgado 8daea6
            # crop when no specific background information be
Alain Reguera Delgado 8daea6
            # available for using. Generally, this is the most
Alain Reguera Delgado 8daea6
            # reusable background file inside the artistic motifs
Alain Reguera Delgado 8daea6
            # (e.g,.  the `2048x1536.png' file).  We can use this
Alain Reguera Delgado 8daea6
            # image file to create almost all artworks inside The
Alain Reguera Delgado 8daea6
            # CentOS Distribution visual manifestation when
Alain Reguera Delgado 8daea6
            # resolution-specific backgrounds don't exist. 
Alain Reguera Delgado 8daea6
            BG_SRC_FILE=$(echo ${BG_DST_FILE} \
Alain Reguera Delgado 8daea6
                | sed -r "s!(.+)/[[:digit:]]+x[[:digit:]]+!\1/2048x1536!")
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
            # Verify existence of source background file. If the file
Alain Reguera Delgado 8daea6
            # doesn't exist create it using The CentOS Project default
Alain Reguera Delgado 8daea6
            # background color information, as specified in its
Alain Reguera Delgado 8daea6
            # corporate identity manual.
Alain Reguera Delgado 8daea6
            if [[ ! -f ${BG_SRC_FILE} ]];then
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
                # Define plain color that will be used as background.
Alain Reguera Delgado 8daea6
                BG_SRC_FILE_COLOR='#204C8D'
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
                # Define width for the source background file the
Alain Reguera Delgado 8daea6
                # required background information is cropped from.
Alain Reguera Delgado 8daea6
                BG_SRC_FILE_WIDTH=$(echo ${BG_SRC_FILE} \
Alain Reguera Delgado 8daea6
                    | sed -r 's!.+/([[:digit:]]+)x[[:digit:]]+\.png!\1!')
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
                # Define height for the source background file the
Alain Reguera Delgado 8daea6
                # required background information is cropped from.
Alain Reguera Delgado 8daea6
                BG_SRC_FILE_HEIGHT=$(echo ${BG_SRC_FILE} \
Alain Reguera Delgado 8daea6
                    | sed -r 's!.+/[[:digit:]]+x([[:digit:]]+)\.png!\1!')
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
                # Print action message.
Alain Reguera Delgado 8daea6
                tcar_printMessage "${BG_SRC_FILE} (${BG_SRC_FILE_COLOR})" --as-creating-line
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
                # Create the source background file.
Alain Reguera Delgado 8daea6
                ppmmake -quiet ${BG_SRC_FILE_COLOR} \
Alain Reguera Delgado 8daea6
                    ${BG_SRC_FILE_WIDTH} ${BG_SRC_FILE_HEIGHT} \
Alain Reguera Delgado 8daea6
                    | pnmtopng > ${BG_SRC_FILE}
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
            fi
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
            # Define the width of the required background information.
Alain Reguera Delgado 8daea6
            BG_DST_FILE_WIDTH=$(echo ${BG_DST_FILE} \
Alain Reguera Delgado 8daea6
                | sed -r 's!.+/([[:digit:]]+)x[[:digit:]]+\.png!\1!')
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
            # Define the height of the required background information.
Alain Reguera Delgado 8daea6
            BG_DST_FILE_HEIGHT=$(echo ${BG_DST_FILE} \
Alain Reguera Delgado 8daea6
                | sed -r 's!.+/[[:digit:]]+x([[:digit:]]+)\.png!\1!')
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
            # Print action message.
Alain Reguera Delgado 8daea6
            tcar_printMessage "${BG_SRC_FILE} (${BG_DST_FILE_WIDTH}x${BG_DST_FILE_HEIGHT})" --as-cropping-line
Alain Reguera Delgado 8daea6
 
Alain Reguera Delgado 8daea6
            # Create required background information.
Alain Reguera Delgado 8daea6
            convert -quiet \
Alain Reguera Delgado 8daea6
                -crop ${BG_DST_FILE_WIDTH}x${BG_DST_FILE_HEIGHT}+0+0 \
Alain Reguera Delgado 8daea6
                ${BG_SRC_FILE} ${BG_DST_FILE}
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
            # Verify required background information.
Alain Reguera Delgado 8daea6
            tcar_checkFiles -ef ${BG_DST_FILE}
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
        fi
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
    done
Alain Reguera Delgado 8daea6
Alain Reguera Delgado 8daea6
}