File: render-cursor-image

package info (click to toggle)
comixcursors 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 876 kB
  • sloc: sh: 588; makefile: 153; python: 128
file content (167 lines) | stat: -rwxr-xr-x 4,471 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#! /bin/bash
#
# bin/render-cursor-image
# Part of ComixCursors, a desktop cursor theme.
#
# Copyright © 2010–2013 Ben Finney <ben+opendesktop@benfinney.id.au>
# Copyright © 2006–2013 Jens Luetkens <j.luetkens@limitland.de>
#
# This work is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This work is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this work. If not, see <http://www.gnu.org/licenses/>.

# Generate a PNG cursor image from SVG source.
#
# Required tools:
# ImageMagick:  http://www.imagemagick.org/
# librsvg:      http://librsvg.sourceforge.net/

function show_usage_message {
    cat <<_EOT_
Usage: $0 [options] <in name> <in file> <out file>

Generate a PNG cursor image from SVG source.

Take a simple SVG file, export it to PNG.

Options:
    --help                    Show this help text, then exit.
    --orientation <facing>    Specify the orientation of this cursor.
    --frame <frame num>       Specify frame number of animated cursor.
    --duration <duration>     Duration (in milliseconds) for this frame.

_EOT_
}

# source the theme config file
THEMENAME="${THEMENAME:-Custom}"
configfile="ComixCursorsConfigs/${THEMENAME}.CONFIG"
source "${configfile}"

# don't do transparency post-processing by default
# used for ComixCursors but not for flatbedcursors
CURSORTRANS=0

# some initialisation before argument processing
orientation="RightHanded"
frame=0

# parse argument list
while [ "${1::1}" == "-" ] ; do
    case "$1" in
        --help)
            show_usage_message
            exit
            ;;
        --orientation)
            shift
            orientation="$1"
            ;;
    	--frame)
            shift
    	    frame=$1
    	    ;;
    	--duration)
    	    shift
    	    duration=$1
    	    ;;
        *)
            printf "Unexpected option: %q\n" "$1" >&2
            show_usage_message
            exit 2
            ;;
    esac
    shift
done

if [ $# -lt 3 ] ; then
    show_usage_message
    exit 2
fi

NAME="$1"
infile="$2"
outfile="$3"

if [ $VERBOSE ] ; then
    if [ "$frame" -lt 1 ]; then
        echo "processing $NAME..."
    else
        echo "processing $NAME frame $frame..."
    fi
fi

xcursor_config="${builddir}/${NAME}.conf"

# write the hotspot config file
hotspots_file="$(dirname $infile)/HOTSPOTS"
hotspot_name="$NAME"
hotspot=( $(grep "^$hotspot_name" "$hotspots_file") )

function reset_xcursor_config {
    # Delete the config file if it exists.
    local xcursor_config="$1"
    local frame="$2"
    if [ "$frame" -lt 2 ] ; then
        if [ -e "${xcursor_config}" ] ; then
            rm "${xcursor_config}"
        fi
    fi
}

function svg2png {
    # Convert a single SVG image to PNG.
    local infile="$1"
    local outfile="$2"
    local size=$3

    # Write hotspots to config file.
    hotx=$(echo "${hotspot[1]} * $size / 500" | bc)
    hoty=$(echo "${hotspot[2]} * $size / 500" | bc)

    if [ "$frame" -gt 0 ] ; then
        echo "$size $hotx $hoty $outfile $duration" >> "${xcursor_config}"
    else
        echo "$size $hotx $hoty $outfile" >> "${xcursor_config}"
    fi

    # Render png image.
    rsvg-convert --format png \
        --dpi-x 72 --dpi-y 72 \
        --width $size --height $size \
        "$infile" > "$outfile"
}

# Render the cursor image/s.

xcursor_config="${builddir}/${NAME}.conf"

if [ ${MULTISIZE} ]; then
    # Render multiple sizes combined cursors per default.
    # Reset the config file (hotspots).
    reset_xcursor_config "$xcursor_config" "$frame"
    # Render multiple cursor sizes.
    for SIZENAMES in ${SIZES[@]} ; do
        SIZENAME=${SIZENAMES%%=*}
        SIZE=${SIZENAMES##*=}
        # Render the cursor image.
        svg2png "$infile" "${outfile%.*}.${SIZE}.png" "${SIZE}"
    done
else
    # Render single sized cursors.#
    export CURSORSIZE="${CURSORSIZE:-32}"
    # Reset the config file (hotspots).
    reset_xcursor_config "$xcursor_config" "$frame" "${CURSORSIZE}"
    # Render the cursor image.
    svg2png "$infile" "${outfile%.*}.${SIZE}.png" "${CURSORSIZE}"
fi