Blame Scripts/Bash/Functions/Render/Svg/svg_checkModelAbsref.sh

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