1#!/usr/local/bin/bash
2#
3# This file is part of plata-theme
4#
5# Copyright (C) 2018-2020 Tista <tista.gma500@gmail.com>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12
13INKSCAPE="`command -v inkscape`"
14
15SRC_DIR="assets-cinnamon/mixed/misc"
16SRC_DARK_DIR="assets-cinnamon/dark/misc"
17SRC_LIGHT_DIR="assets-cinnamon/light/misc"
18ASSETS_DIR="../cinnamon/assets"
19ASSETS_LIGHT_DIR="../cinnamon-light/assets"
20ASSETS_DARK_DIR="../cinnamon-dark/assets"
21KEY_FILE="../../gtk/sass/common/resources/_key_colors.scss"
22THUMB="thumbnail"
23
24# Default colours
25selection1="`grep 'Indigo500' ../../gtk/sass/common/_colors.scss | \
26                   cut -d' ' -f3`"
27
28# Check and re-color SVG files
29if [ -e $KEY_FILE ]; then
30    selection2="`grep 'key_selection' $KEY_FILE | \
31                 cut -d' ' -f2 | cut -d';' -f1`"
32IFS=$'
33'
34    cp -f $SRC_DIR/$THUMB.svg.in $SRC_DIR/$THUMB.svg
35    cp -f $SRC_LIGHT_DIR/$THUMB.svg.in $SRC_LIGHT_DIR/$THUMB.svg
36    cp -f $SRC_DARK_DIR/$THUMB.svg.in $SRC_DARK_DIR/$THUMB.svg
37
38    if [ $selection1 != $selection2 ]; then
39        sed -i '' "s/$selection1/$selection2/gi" $SRC_DIR/$THUMB.svg
40        sed -i '' "s/$selection1/$selection2/gi" $SRC_LIGHT_DIR/$THUMB.svg
41        sed -i '' "s/$selection1/$selection2/gi" $SRC_DARK_DIR/$THUMB.svg
42        echo $THUMB.svg is re-colored with $selection2.
43    fi
44fi
45
46ink_maj_ver="`$INKSCAPE --version | grep Ink | awk '{print $2}' | cut -c 1`"
47ink_mnr_ver="`$INKSCAPE --version | grep Ink | awk '{print $2}' | cut -c 3-4`"
48if [ "$ink_maj_ver"."$ink_mnr_ver" = 0.91 ]; then
49    non_scale_dpi=90
50else
51    non_scale_dpi=96
52fi
53
54if [ "$ink_maj_ver" -ge 1 ]; then
55    if [ "$ink_mnr_ver" = '0b' ]; then
56        ink_export_option="--export-file"
57    else
58        ink_export_option="--export-filename"
59    fi
60else
61    ink_export_option="--export-png"
62fi
63
64# Renderer
65render-non-scale() {
66    $INKSCAPE --export-dpi="$non_scale_dpi" \
67              $ink_export_option=$ASSETS_DIR/$THUMB.png \
68              $SRC_DIR/$THUMB.svg \
69              >/dev/null 2>>inkscape.log
70    $INKSCAPE --export-dpi="$non_scale_dpi" \
71              $ink_export_option=$ASSETS_LIGHT_DIR/$THUMB.png \
72              $SRC_LIGHT_DIR/$THUMB.svg \
73              >/dev/null 2>>inkscape.log
74    $INKSCAPE --export-dpi="$non_scale_dpi" \
75              $ink_export_option=$ASSETS_DARK_DIR/$THUMB.png \
76              $SRC_DARK_DIR/$THUMB.svg \
77              >/dev/null 2>>inkscape.log
78}
79
80# Generate PNG file
81if [ -f $ASSETS_DIR/$THUMB.png ] && \
82    [ $KEY_FILE -ot $ASSETS_DIR/$THUMB.png ]; then
83    echo $ASSETS_DIR/$THUMB.png exists.
84elif [ -f $ASSETS_DIR/$THUMB.png ] && \
85    [ $KEY_FILE -nt $ASSETS_DIR/$THUMB.png ]; then
86    echo Re-rendering $ASSETS_DIR/$THUMB.png
87    echo Re-rendering $ASSETS_LIGHT_DIR/$THUMB.png
88    echo Re-rendering $ASSETS_DARK_DIR/$THUMB.png
89    echo $THUMB.png >>inkscape.log
90    rm -f $ASSETS_DIR/$THUMB.png
91    rm -f $ASSETS_LIGHT_DIR/$THUMB.png
92    rm -f $ASSETS_DARK_DIR/$THUMB.png
93    render-non-scale
94else
95    echo Rendering $ASSETS_DIR/$THUMB.png
96    echo Rendering $ASSETS_LIGHT_DIR/$THUMB.png
97    echo Rendering $ASSETS_DARK_DIR/$THUMB.png
98    echo $THUMB.png >>inkscape.log
99    render-non-scale
100fi
101