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

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