vendetta / scripts / make_pngs.sh
71 lines · 65 sloc · 2.76 KB · 80f14d8fb92068552b258c65069f3fee405c23bc
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. The page_ entries are the settings dialog's
16# navigation, in the palette's text_muted.
17#
18# ImageMagick is the rasterizer for now; it renders the 24 px viewBox
19# straight at 64 px (density 96 * 64/24 = 256), which is what the buttons and
20# their 2x ui scale need. Swap the tool at the `one` function below if the
21# rasterizer changes; the role and colour tables remain the stable part.
22set -eu
23
24here=$(cd "$(dirname "$0")" && pwd)
25svg_dir="$here/icons"
26out_dir="$here/../assets/icons"
27
28entries='play_arrow play #ffffff
29pause pause #ffffff
30replay_30 replay30 #ffffff
31forward_30 forward30 #ffffff
32volume_up volume_up #ffffff
33volume_mute volume_mute #ffffff
34volume_off volume_off #ffffff
35tune page_interface #e2e8f0
36palette page_appearance #e2e8f0
37play_circle page_playback #e2e8f0
38movie page_video #e2e8f0
39equalizer page_audio #e2e8f0
40subtitles page_subtitles #e2e8f0
41settings page_advanced #e2e8f0'
42
43if command -v magick >/dev/null 2>&1; then
44 rasterizer=magick
45elif command -v convert >/dev/null 2>&1; then
46 rasterizer=convert
47else
48 echo 'make_pngs: ImageMagick is missing: install magick (or convert) or replace it in one() here' >&2
49 exit 1
50fi
51
52one() {
53 # one <svg-prefix> <png-name> <colour>: raster at 64 px from the SVG's 24
54 # px viewBox, colourize the raster to the palette colour keeping alpha,
55 # and strip the export metadata the PNG bundle does not carry.
56 svg=$(ls "$svg_dir/${1}"_24dp_*.svg 2>/dev/null | head -n 1)
57 if [ -z "$svg" ]; then
58 echo "make_pngs: no *_24dp_*.svg match for prefix ${1} under ${svg_dir}" >&2
59 exit 1
60 fi
61 $rasterizer -background none -density 256 "$svg" \
62 -fill "$3" -colorize 100 -strip "$out_dir/$2.png"
63}
64
65mkdir -p "$out_dir"
66echo "$entries" | while read -r prefix png colour; do
67 [ -z "$prefix" ] && continue
68 one "$prefix" "$png" "$colour"
69done
70
71echo 'make_pngs: bundle refreshed'
72