Blame Scripts/Functions/Render/render_checkSvgAbsref.sh

540e8b
#!/bin/bash
540e8b
#
ab1d67
# render_checkSvgAbsref.sh -- This function retrives absolute files
d7e760
# and 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
#
2d3646
# 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
ab1d67
function render_checkSvgAbsref {
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.
540e8b
    cli_checkFiles $FILE 'f'
540e8b
540e8b
    # Retrive absolute paths from file.
f259c7
    BG_DST_FILES=$(egrep "(sodipodi:absref|xlink:href)=\"${HOME}.+" $FILE \
3cb7a2
        | sed -r "s,.+=\"(${HOME}.+\.png)\".*,\1,")
540e8b
540e8b
    # Verify absolute paths retrived from file.
f259c7
    for BG_DST_FILE in $BG_DST_FILES;do
f259c7
f259c7
        if [[ ! -a $BG_DST_FILE ]];then
f259c7
f259c7
            # Warn about required background omission.
f259c7
            cli_printMessage "`eval_gettext "The path \\\"\\\$BG_DST_FILE\\\" doesn't exist."`" 'AsErrorLine'
f259c7
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
f259c7
                # Define plain color for the source background file
f259c7
                # the required background information is cropped from.
f259c7
                BG_SRC_FILE_COLOR='rgb:20/4C/8D'
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.
f259c7
                cli_printMessage "${BG_SRC_FILE} ($BG_SRC_FILE_COLOR)" 'AsCreatingLine'
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.
f259c7
            cli_printMessage "$BG_SRC_FILE" 'AsCroppingFromLine'
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
}