| 1 | #! /bin/bash |
| 2 | # |
| 3 | # bin/build-cursors |
| 4 | # Part of ComixCursors, a desktop cursor theme. |
| 5 | # |
| 6 | # Copyright © 2010–2013 Ben Finney <[email protected]> |
| 7 | # Copyright © 2006–2013 Jens Luetkens <[email protected]> |
| 8 | # |
| 9 | # This work is free software: you can redistribute it and/or modify it |
| 10 | # under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation, either version 3 of the License, or |
| 12 | # (at your option) any later version. |
| 13 | # |
| 14 | # This work is distributed in the hope that it will be useful, but |
| 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | # General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | # Create the cursor image files from SVG source. |
| 23 | |
| 24 | THEMENAME="${THEMENAME:-Custom}" |
| 25 | export THEMENAME |
| 26 | ORIENTATION="${ORIENTATION:-RightHanded}" |
| 27 | export ORIENTATION |
| 28 | |
| 29 | bindir="$(dirname $0)" |
| 30 | |
| 31 | themename_stem="ComixCursors" |
| 32 | configfile_dir="${themename_stem}Configs" |
| 33 | configfile="${configfile_dir}/${THEMENAME}.CONFIG" |
| 34 | theme_template="${configfile_dir}/${themename_stem}.theme" |
| 35 | |
| 36 | # source the theme config file |
| 37 | source "${configfile}" |
| 38 | if [ ${THEMEINCLUDE} ] ; then |
| 39 | source "${configfile_dir}/${THEMEINCLUDE#-}.INCLUDE" |
| 40 | fi |
| 41 | |
| 42 | SHADOWOPAQ=$(echo "1 - $SHADOWTRANS" | bc | sed 's/^\./0\./' | sed 's/\.0$//') |
| 43 | CURSOROPAQ=$(echo "1 - $CURSORTRANS" | bc | sed 's/^\./0\./' | sed 's/\.0$//') |
| 44 | |
| 45 | function svg_substitutions { |
| 46 | # Process an SVG file with custom substitutions. |
| 47 | local infile="$1" |
| 48 | |
| 49 | substitutions=( |
| 50 | "s/#000000/$OUTLINECOLOR/g" |
| 51 | "s/stroke-width:20/stroke-width:$OUTLINE/g" |
| 52 | "s/#999999/$CURSORCOLORHI/g" |
| 53 | "s/#555555/$CURSORCOLORLO/g" |
| 54 | "s/#999933/$HILIGHTHI/g" |
| 55 | "s/#666600/$HILIGHTLO/g" |
| 56 | "s/#010101/$HAIR/g" |
| 57 | "s/#111111/$SHADOWCOLOR/g" |
| 58 | "s/opacity:0.05/opacity:$SHADOWOPAQ/g" |
| 59 | "s/opacity:0.75/opacity:$CURSOROPAQ/g" |
| 60 | ) |
| 61 | |
| 62 | sed $(for subst in "${substitutions[@]}" ; do printf " -e ${subst}" ; done) \ |
| 63 | "$infile" |
| 64 | } |
| 65 | |
| 66 | function svg_rotate { |
| 67 | # Apply rotation angle. |
| 68 | local infile="$1" |
| 69 | local angle="$2" |
| 70 | |
| 71 | sed \ |
| 72 | -e "s/rotate(0,/rotate($angle,/" \ |
| 73 | "$infile" |
| 74 | } |
| 75 | |
| 76 | svgdir="svg" |
| 77 | |
| 78 | indir="${svgdir}/${ORIENTATION}" |
| 79 | workdir="tmp" |
| 80 | builddir="${builddir:-build/${THEMEVARIANT}}" |
| 81 | # builddir="build/${THEMENAME}" |
| 82 | xcursor_builddir="cursors/${THEMEVARIANT}" |
| 83 | export workdir builddir |
| 84 | |
| 85 | mkdir --parents "${builddir}" |
| 86 | mkdir --parents "${workdir}" |
| 87 | mkdir --parents "${xcursor_builddir}" |
| 88 | |
| 89 | # Copy the HOTSPOTS file to the working directory. |
| 90 | hotspots_file="${indir}/HOTSPOTS" |
| 91 | cp "$hotspots_file" "$workdir"/. |
| 92 | |
| 93 | function generate_theme { |
| 94 | # Process the theme file. |
| 95 | local name="$1" |
| 96 | local sizename="${SIZENAME//-/ }" |
| 97 | xcursor_theme="${builddir}/${name}.theme" |
| 98 | custom_theme="ComixCursorsConfigs/${name}.theme" |
| 99 | themename=${name//-/ } |
| 100 | if [[ $ORIENTATION == "LeftHanded" ]] ; then |
| 101 | facing=" left-handed" |
| 102 | else |
| 103 | facing="" |
| 104 | fi |
| 105 | |
| 106 | variation=" ${THEMEINCLUDE#-}" && [ -v ${THEMEINCLUDE} ] && variation="" |
| 107 | variation=${variation//-/ } |
| 108 | |
| 109 | if [ -f "$custom_theme" ] ; then |
| 110 | sed "s/THEMENAME/$themename/g" "$custom_theme" | sed "s/ORIENTATION/$facing/g" | sed "s/SIZENAME/$sizename/g" | sed "s/VARIATION/$variation/g" > "$xcursor_theme" |
| 111 | elif [ -f "$theme_template" ] ; then |
| 112 | sed "s/THEMENAME/$themename/g" "$theme_template" | sed "s/ORIENTATION/$facing/g" | sed "s/SIZENAME/$sizename/g" | sed "s/VARIATION/$variation/g" > "$xcursor_theme" |
| 113 | fi |
| 114 | } |
| 115 | |
| 116 | function generate_animation_source_frames { |
| 117 | # Generate the source frame images for an animation. |
| 118 | local name="$1" |
| 119 | local frames_count=$2 |
| 120 | |
| 121 | first_frame_file="${indir}/${name}.svg" |
| 122 | for frame in $(seq --equal-width 1 $frames_count) ; do |
| 123 | frame_file="${indir}/${name}.frame${frame}.svg" |
| 124 | case $frame in |
| 125 | 1) |
| 126 | cp "$first_frame_file" "$frame_file" |
| 127 | ;; |
| 128 | *) |
| 129 | angle=$(echo "360 / $frames_count * ($frame - 1)" | bc) |
| 130 | svg_rotate "$first_frame_file" $angle > "$frame_file" |
| 131 | ;; |
| 132 | esac |
| 133 | done |
| 134 | } |
| 135 | |
| 136 | function render_cursor_image { |
| 137 | # Render SVG source image to finished PNG image. |
| 138 | local name="$1" |
| 139 | local compose_opts="$2" |
| 140 | local frame=$3 |
| 141 | local frame_duration=$4 |
| 142 | |
| 143 | compose_opts="${compose_opts} --orientation $ORIENTATION" |
| 144 | |
| 145 | if [[ "$frame" ]] ; then |
| 146 | image_name="${name}.frame${frame}" |
| 147 | compose_opts="${compose_opts} --frame $frame" |
| 148 | if [[ "$frame_duration" ]] ; then |
| 149 | compose_opts="${compose_opts} --duration $frame_duration" |
| 150 | fi |
| 151 | else |
| 152 | frame=0 |
| 153 | image_name="${name}" |
| 154 | fi |
| 155 | |
| 156 | infile="${indir}/${image_name}.svg" |
| 157 | if [[ ! -f "$infile" ]] ; then |
| 158 | echo "skipping $name; no svg file found." |
| 159 | return 1 |
| 160 | fi |
| 161 | tempfile="${workdir}/$(basename $infile)" |
| 162 | outfile="${builddir}/${image_name}.png" |
| 163 | svg_substitutions "$infile" > "$tempfile" |
| 164 | "${bindir}"/render-cursor-image $compose_opts "$name" "$tempfile" "$outfile" |
| 165 | } |
| 166 | |
| 167 | ## Generate the theme file. Process the size argument only if the |
| 168 | ## configuration has only one SIZES() item. |
| 169 | #if [ ${#SIZES[@]} -eq 1 ]; then |
| 170 | # sizename=${SIZES[0]%%=*} |
| 171 | #fi |
| 172 | |
| 173 | generate_theme "$THEMENAME" |
| 174 | |
| 175 | # the basic cursors |
| 176 | names=" |
| 177 | all-scroll |
| 178 | cell |
| 179 | col-resize |
| 180 | crosshair |
| 181 | default |
| 182 | ew-resize |
| 183 | grabbing |
| 184 | nesw-resize |
| 185 | not-allowed |
| 186 | ns-resize |
| 187 | nwse-resize |
| 188 | pencil |
| 189 | pirate |
| 190 | pointer |
| 191 | right-arrow |
| 192 | row-resize |
| 193 | text |
| 194 | up-arrow |
| 195 | vertical-text |
| 196 | X-cursor |
| 197 | zoom-in |
| 198 | zoom-out |
| 199 | alias |
| 200 | context-menu |
| 201 | copy |
| 202 | move |
| 203 | no-drop |
| 204 | " |
| 205 | |
| 206 | for name in $names ; do |
| 207 | compose_opts="" |
| 208 | render_cursor_image "$name" "$compose_opts" |
| 209 | done |
| 210 | |
| 211 | # the animated cursors |
| 212 | |
| 213 | name="help" |
| 214 | compose_opts="" |
| 215 | frames_count=2 |
| 216 | generate_animation_source_frames "$name" $frames_count |
| 217 | render_cursor_image "$name" "$compose_opts" 1 2000 |
| 218 | render_cursor_image "$name" "$compose_opts" 2 500 |
| 219 | |
| 220 | name="progress" |
| 221 | frames_count=24 |
| 222 | generate_animation_source_frames "$name" $frames_count |
| 223 | for frame in $(seq --equal-width 1 $frames_count) ; do |
| 224 | compose_opts="" |
| 225 | render_cursor_image "$name" "$compose_opts" $frame |
| 226 | done |
| 227 | |
| 228 | name="wait" |
| 229 | frames_count=36 |
| 230 | generate_animation_source_frames "$name" $frames_count |
| 231 | for frame in $(seq --equal-width 1 $frames_count) ; do |
| 232 | compose_opts="" |
| 233 | render_cursor_image "$name" "$compose_opts" $frame |
| 234 | done |