#!/usr/bin/make -f

# Ubuntu's gnome-control-center draws /usr/share/pixmaps/ubuntu-logo-text.png (light style)
# and ubuntu-logo-text-dark.png (dark style) at their own pixel size, 260x91, so the Based
# rasters postinst links in their place are rendered to that footprint: the lockup contain-fit
# and centred on a transparent page, deep ink for the light panel and light ink for the dark
# one. brand/ is a copy of overlays/based/brand in basedlinux.com/based, and CI fails before
# the source build when it drifts from main (BASED-268).
about_width = 260
about_height = 91

%:
	dh $@

execute_after_dh_auto_build:
	mkdir -p about
	set -e; for pair in brand/lockup-dark.svg:about/ubuntu-logo-text.png brand/lockup.svg:about/ubuntu-logo-text-dark.png; do \
		svg="$${pair%%:*}"; png="$${pair#*:}"; \
		set -- $$(sed -n 's/^<svg .* width="\([0-9.]*\)" height="\([0-9.]*\)".*/\1 \2/p' "$$svg"); \
		w=$$(awk -v w="$$1" -v h="$$2" -v bw=$(about_width) -v bh=$(about_height) \
			'BEGIN { s = bw / w < bh / h ? bw / w : bh / h; printf "%d", w * s + 0.5 }'); \
		h=$$(awk -v w="$$1" -v h="$$2" -v bw=$(about_width) -v bh=$(about_height) \
			'BEGIN { s = bw / w < bh / h ? bw / w : bh / h; printf "%d", h * s + 0.5 }'); \
		rsvg-convert --format png --width "$$w" --height "$$h" \
			--page-width $(about_width) --page-height $(about_height) \
			--left $$(( ($(about_width) - w) / 2 )) --top $$(( ($(about_height) - h) / 2 )) \
			--output "$$png" "$$svg"; \
	done

execute_after_dh_auto_clean:
	rm -rf about

override_dh_missing:
	dh_missing --fail-missing

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	bats tests
endif
