Blame Scripts/Bash/Functions/Identity/identity_doImages.sh

4c79b5
#!/bin/bash
4c79b5
#
e912f5
# identity_doIdentityImages.sh -- This function renders image-based
07c2fe
# identity contents.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
e912f5
function identity_doIdentityImages {
4c79b5
f60cb0
    local FILE=''
f60cb0
    local OUTPUT=''
4c79b5
    local EXPORTID=''
f60cb0
    local TEMPLATE=''
f60cb0
    local TRANSLATION=''
e4d34a
    local EXTERNALFILE=''
f60cb0
    local EXTERNALFILES=''
d659a9
    local COMMONDIRCOUNT=0
4c79b5
4c79b5
    # Export id used inside design templates. This value defines the
4c79b5
    # design area we want to export.
4c79b5
    EXPORTID='CENTOSARTWORK'
4c79b5
15b1d2
    # Start processing the base rendition list of FILES. Fun part
4c79b5
    # approching :-).
f60cb0
    for FILE in $FILES; do
4c79b5
891cdf
        # Define final location of translation file.
891cdf
        TRANSLATION=$(dirname $FILE \
891cdf
           | sed -r 's!/trunk/(Identity/)!/trunk/Locales/\1!')/$(cli_getCurrentLocale).po
891cdf
891cdf
        # Print final location of translation file.
891cdf
        if [[ ! -f "$TRANSLATION" ]];then
891cdf
            cli_printMessage "`gettext "None"`" "AsTranslationLine"
891cdf
        else
891cdf
            cli_printMessage "$TRANSLATION" 'AsTranslationLine'
891cdf
        fi
891cdf
891cdf
        # Define final location of template file.
891cdf
        TEMPLATE=${FILE}
891cdf
891cdf
        # Print final location of template file.
891cdf
        if [[ ! -f "$TEMPLATE" ]];then
891cdf
            cli_printMessage "`gettext "None"`" "AsDesignLine"
891cdf
        else
891cdf
            cli_printMessage "$TEMPLATE" 'AsDesignLine'
891cdf
        fi
891cdf
 
891cdf
        # Define final location of output directory.
e912f5
        identity_getIdentityDirOutput
891cdf
891cdf
        # Get relative path to file. The path string (stored in FILE)
891cdf
        # has two parts: 1. the variable path and 2. the common path.
891cdf
        # The variable path is before the common point in the path
891cdf
        # string. The common path is after the common point in the
891cdf
        # path string. The common point is the name of the parent
891cdf
        # directory (stored in PARENTDIR).
891cdf
        #
891cdf
        # trunk/Locales/Identity/.../Firstboot/3/splash-small.svg
891cdf
        # -------------------------^| the     |^------------^
891cdf
        # variable path             | common  |    common path
891cdf
        # -------------------------v| point   |    v------------v
891cdf
        # trunk/Identity/Themes/M.../Firstboot/Img/3/splash-small.png
891cdf
        #
891cdf
        # What we do here is remove the varibale path, the common
891cdf
        # point, and the file extension parts in the string holding
891cdf
        # the path retrived from design models directory structure.
891cdf
        # Then we use the common path as relative path to store the
891cdf
        # the final image file.
891cdf
        #
891cdf
        # The file extension is removed from the common path because
891cdf
        # it is set when we create the final image file. This
891cdf
        # configuration let us use different extensions for the same
891cdf
        # file name.
891cdf
        #
891cdf
        # When we render using renderImage function, the structure of
891cdf
        # files under the output directory will be the same used after
891cdf
        # the common point in the related design model directory
891cdf
        # structure.
891cdf
        FILE=$(echo ${FILE} \
891cdf
            | sed -r "s!.*${PARENTDIR}/!!" \
891cdf
            | sed -r "s/\.(svgz|svg)$//")
891cdf
891cdf
        # Define absolute path to final file (without extension).
891cdf
        FILE=${OUTPUT}/$(basename "${FILE}")
891cdf
891cdf
        # Define instance name from design model.
891cdf
        INSTANCE=$(cli_getTemporalFile ${TEMPLATE})
891cdf
891cdf
        if [[ -f ${TRANSLATION} ]];then
38482c
891cdf
            # Create translated instance from design model.
38482c
            /usr/bin/xml2po -p ${TRANSLATION} ${TEMPLATE} > ${INSTANCE}
38482c
38482c
            # Remove .xml2po.mo temporal file.
38482c
            if [[ -f ${PWD}/.xml2po.mo ]];then
38482c
                rm ${PWD}/.xml2po.mo
38482c
            fi
38482c
891cdf
        else
38482c
891cdf
            # Create non-translated instance form design model.
891cdf
            /bin/cat ${TEMPLATE} > ${INSTANCE}    
38482c
891cdf
        fi
891cdf
891cdf
        # Apply replacement of translation markers to design model
891cdf
        # translated instance.
891cdf
        cli_replaceTMarkers ${INSTANCE}
4c79b5
4c79b5
        # Check export id inside design templates.
4c79b5
        grep "id=\"$EXPORTID\"" $INSTANCE > /dev/null
4c79b5
        if [[ $? -gt 0 ]];then
9b4d7d
            cli_printMessage "`eval_gettext "There is no export id (\\\$EXPORTID) inside \\\$TEMPLATE."`" "AsErrorLine"
15b1d2
            cli_printMessage '-' 'AsSeparatorLine'
4c79b5
            continue
4c79b5
        fi
4c79b5
34fcce
        # Check existence of external files. In order for design
34fcce
        # templates to point different artistic motifs, design
34fcce
        # templates make use of external files that point to specific
34fcce
        # artistic motif background images. If such external files
34fcce
        # doesn't exist, print a message and stop script execution.
f60cb0
        # We cannot continue without background information.
e912f5
        identity_checkAbsolutePaths "$INSTANCE"
4c79b5
4c79b5
        # Render template instance and modify the inkscape output to
4c79b5
        # reduce the amount of characters used in description column
4c79b5
        # at final output.
2d50e8
        cli_printMessage "$(inkscape $INSTANCE \
f60cb0
            --export-id=$EXPORTID --export-png=${FILE}.png | sed -r \
2d50e8
            -e "s!Area !`gettext "Area"`: !" \
2d50e8
            -e "s!Background RRGGBBAA:!`gettext "Background"`: RRGGBBAA!" \
2d50e8
            -e "s!Bitmap saved as:!`gettext "Saved as"`:!")" \
2d50e8
            'AsRegularLine'
4c79b5
4c79b5
        # Remove template instance. 
4c79b5
        if [[ -a $INSTANCE ]];then
4c79b5
            rm $INSTANCE
4c79b5
        fi
4c79b5
15b1d2
        # Execute post-rendition actions.
f3bce7
        for ACTION in "${POSTACTIONS[@]}"; do
4c79b5
4c79b5
            case "$ACTION" in
4c79b5
46f314
                renderSyslinux* )
e912f5
                    identity_doIdentityImageSyslinux "${FILE}" "$ACTION"
4c79b5
                    ;;
4c79b5
46f314
                renderGrub* )
e912f5
                    identity_doIdentityImageGrub "${FILE}" "$ACTION"
4c79b5
                    ;;
4c79b5
4c79b5
                renderFormats:* )
e912f5
                    identity_doIdentityImageFormats "${FILE}" "$ACTION"
4c79b5
                    ;;
4c79b5
ff3ea9
                groupByType:* )
e912f5
                    identity_doIdentityGroupByType "${FILE}" "$ACTION"
4c79b5
                    ;;
4c79b5
4c79b5
            esac
4c79b5
4c79b5
        done
4c79b5
15b1d2
        # Output separator line.
15b1d2
        cli_printMessage '-' 'AsSeparatorLine'
4c79b5
d659a9
        # Apply last-rendition actions. As convenction, last-rendition
d659a9
        # actions are applied after all images inside the same
d659a9
        # directory structure have been produced. Notice that, in
d659a9
        # order to apply last-rendition actions correctly,
d659a9
        # centos-art.sh needs to "predict" what the last file in the
d659a9
        # same directory structure would be. There is no magic here,
d659a9
        # so we need to previously define which are the common
d659a9
        # directory structures centos-art.sh could produce content
d659a9
        # for inside an array variable. Later, using the index of that
d659a9
        # array variable we could check the next item in the array
d659a9
        # against the file being currently produced. If they match, we
d659a9
        # haven't reached the end of the same directory structure, but
d659a9
        # if they don't match, we do have reach the end of the same
d659a9
        # directory structure and it is time for last-rendition
d659a9
        # actions to be evaluated before go producing the next
d659a9
        # directory structure in the list of files to process.
f60cb0
        if [[ $(dirname "$TEMPLATE") != ${COMMONDIRS[$(($COMMONDIRCOUNT + 1))]} ]];then
f60cb0
f60cb0
            # At this point centos-art.sh should be producing the last
f60cb0
            # file from the same unique directory structure, so,
f60cb0
            # before producing images for the next directory structure
f60cb0
            # lets evaluate last-rendition actions for the current
d659a9
            # directory structure. 
d659a9
            for ACTION in "${LASTACTIONS[@]}"; do
d659a9
d659a9
                case "$ACTION" in
d659a9
d659a9
                    renderKSplash )
e912f5
                        identity_doIdentityImageKsplash
d659a9
                        ;;
d659a9
d659a9
                    renderDm:* )
e912f5
                        identity_doIdentityImageDm "$ACTION"
d659a9
                        ;;
d659a9
d659a9
                    groupByType:* )
e912f5
                        identity_doIdentityGroupByType "$ACTION"
d659a9
                        ;;
d659a9
f60cb0
                    renderBrands )
e912f5
                        identity_doIdentityImageBrands "${FILE}" "$ACTION"
f60cb0
                        ;;
18ba58
d659a9
                esac
d659a9
            done
d659a9
        fi
ff3ea9
d659a9
        # Increment common directory counter.
d659a9
        COMMONDIRCOUNT=$(($COMMONDIRCOUNT + 1))
f3bce7
f3bce7
    done
4c79b5
4c79b5
}