From 9837e374905a76b38ca6775f4fa71d81a7881a2b Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: May 23 2011 23:21:33 +0000 Subject: Update render_svg_getColors.sh. --- diff --git a/Scripts/Functions/Render/render_svg_getColors.sh b/Scripts/Functions/Render/render_svg_getColors.sh index 6bab04e..a40228b 100755 --- a/Scripts/Functions/Render/render_svg_getColors.sh +++ b/Scripts/Functions/Render/render_svg_getColors.sh @@ -1,8 +1,16 @@ #!/bin/bash # -# render_svg_getColors.sh -- This function takes one palette produced by -# Gimp (e.g., syslinux.gpl) as input and outputs a list of colors as -# specified. +# render_svg_getColors.sh -- This function takes one palette produced +# by Gimp (e.g., syslinux.gpl) as input and outputs a list of colors +# in the specified format. In order for this function to output the +# color in the format specified, it is needed that the fourth column +# in the gpl palette be set in the `rrggbb' format and the appropriate +# conversion be implemented here. +# +# Notice that using both the `--head' and `--tail' options it is +# possible to control how many consecutive items does the list of +# colors is going to have. It is possible to output all colors in the +# list, or a consecutive range of them. # # Copyright (C) 2009, 2010, 2011 The CentOS Project # @@ -26,19 +34,120 @@ function render_svg_getColors { - # Define path to GPL palette. This is the .gpl file we use to - # retrive color information from. - local PALETTE_GPL="$1" - - # Retrive fourth column of information from GPL palette. The - # fourth column of GPL palette contains the palette commentary - # field. The palette commentary field can be anything, but for the - # sake of our own convenience we use it to store the color - # hexadecimal value. Notice that you can put your comments from - # the fifth column on. - local COLORS=$(sed -r '1,/^#/d' $PALETTE_GPL | awk '{ printf "%s\n", $4 }') - - # Output list of colors. - echo "$COLORS" - + # Define short options. + local ARGSS='' + + # Define long options. + local ARGSL='head:,tail:,format:' + + # Initialize ARGUMENTS with an empty value and set it as local + # variable to this function scope. + local ARGUMENTS='' + + # Initialize both head and tail values to return the first line of + # color information from the palette. + local HEAD=1 + local TAIL=1 + + # Initialize format value used as default when no format option be + # provided. + local FORMAT='rrggbb' + + # Initialize list of colors. + local COLORS='' + + # Redefine ARGUMENTS variable using current positional parameters. + cli_parseArgumentsReDef "$@" + + # Redefine ARGUMENTS variable using getopt output. + cli_parseArguments + + # Redefine positional parameters using ARGUMENTS variable. + eval set -- "$ARGUMENTS" + + # Look for options passed through positional parameters. + while true;do + + case "$1" in + + --head ) + HEAD=$2 + shift 2 + ;; + + --tail ) + TAIL=$2 + shift 2 + ;; + + --format ) + FORMAT=$2 + shift 2 + ;; + + -- ) + shift 1 + break + ;; + esac + done + + # Define path to gpl palette. This is the first file we use to + # retrive color information from. Only the first file provided + # will be used. + local PALETTE=$(echo $@ | cut -d' ' -f1) + + if [[ $PALETTE == '' ]];then + + # Define palette path inside the theme's artistic motif. + local MOTIF_PALETTE=$(cli_getRepoTLDir)/Identity/Images/Themes/$(cli_getPathComponent $ACTIONVAL --motif)/Palettes/grub.gpl + + # Define palette path inside the theme's design model. + local MODEL_PALETTE=$(cli_getRepoTLDir)/Identity/Models/Themes/${THEME_MODEL_NAME}/Palettes/grub.gpl + + # Redefine default background color using palettes provided by + # artistic motif first, and design model later. Assuming none + # of them is present, use The CentOS Project default color + # then. + if [[ -f $MOTIF_PALETTE ]];then + COLORS=$(render_svg_getColors $MOTIF_PALETTE --head=1 --tail=1) + elif [[ -f $MODEL_PALETTE ]];then + COLORS=$(render_svg_getColors $MODEL_PALETTE --head=1 --tail=1) + else + COLORS='#204c8d' + fi + + else + + # Retrive the fourth column from GPL palette. The fourth + # column of a GPL palette contains the palette commentary + # field. The palette commentary field can be anything, but for + # the sake of our own convenience we use it to store the color + # value in hexadecimal format (e.g., rrggbb). Notice that you + # can put your comments from the fifth column on using an + # space as field separator. + COLORS=$(sed -r '1,/^#/d' $PALETTE \ + | awk '{ printf "%s\n", $4 }' | head -n $HEAD | tail -n $TAIL) + + fi + + # Implement color formats convertions from rrggbb to other formats + # that you might need to use. + for COLOR in $COLORS;do + + case $FORMAT in + + rrggbb|* ) + if [[ ! $COLOR =~ '^#' ]];then + COLOR="#${COLOR}" + fi + ;; + + esac + + # Output color value. + echo "$COLOR" + + done + }