vendetta / scripts / make_pngs.sh
63 lines · 57 sloc · 2.41 KB · df3630998c857099c58814a775d080e37af0d23f
Raw
1#!/bin/sh
2# make_pngs.sh regenerates the bundled PNGs in assets/icons from the SVG
3# sources in scripts/icons. assets/ is what ships — CI zips it beside the
4# binary and vab packages it into the APK whole — so its tree stays
5# runtime-only: the sources live beside this script, and nothing but the
6# PNGs ends up bundled.
7#
8# Each entry maps one source SVG (its export name found by prefix; Google's
9# export names churn with every fill/weight change) to the PNG name the
10# widget's buttons draw — the role, spelled in libvendetta/draw.v as
11# strip_icon_names — and the colour the role draws with in the compiled-in
12# vinix-dark palette (text_main, #ffffff, for every strip icon today). The
13# colour step exists because the exports carry their own #e3e3e3 fill: raster
14# colorization makes the bundle conform to the palette no matter what colour
15# the export tool is pointed at.
16#
17# ImageMagick is the rasterizer for now; it renders the 24 px viewBox
18# straight at 64 px (density 96 * 64/24 = 256), which is what the buttons and
19# their 2x ui scale need. Swap the tool at the `one` function below if the
20# rasterizer changes; the role and colour tables remain the stable part.
21set -eu
22
23here=$(cd "$(dirname "$0")" && pwd)
24svg_dir="$here/icons"
25out_dir="$here/../assets/icons"
26
27entries='play_arrow play #ffffff
28pause pause #ffffff
29replay_30 replay30 #ffffff
30forward_30 forward30 #ffffff
31volume_up volume_up #ffffff
32volume_mute volume_mute #ffffff
33volume_off volume_off #ffffff'
34
35if command -v magick >/dev/null 2>&1; then
36 rasterizer=magick
37elif command -v convert >/dev/null 2>&1; then
38 rasterizer=convert
39else
40 echo 'make_pngs: ImageMagick is missing: install magick (or convert) or replace it in one() here' >&2
41 exit 1
42fi
43
44one() {
45 # one <svg-prefix> <png-name> <colour>: raster at 64 px from the SVG's 24
46 # px viewBox, colourize the raster to the palette colour keeping alpha,
47 # and strip the export metadata the PNG bundle does not carry.
48 svg=$(ls "$svg_dir/${1}"_24dp_*.svg 2>/dev/null | head -n 1)
49 if [ -z "$svg" ]; then
50 echo "make_pngs: no *_24dp_*.svg match for prefix ${1} under ${svg_dir}" >&2
51 exit 1
52 fi
53 $rasterizer -background none -density 256 "$svg" \
54 -fill "$3" -colorize 100 -strip "$out_dir/$2.png"
55}
56
57mkdir -p "$out_dir"
58echo "$entries" | while read -r prefix png colour; do
59 [ -z "$prefix" ] && continue
60 one "$prefix" "$png" "$colour"
61done
62
63echo 'make_pngs: bundle refreshed'
64