#!/bin/sh
#
# Dafydd Harries, 2005.
#
# Requires afmutil.py from Ghostscript.

error()
{
	echo "Error: $1" >&2
	exit 1
}

warn()
{
	echo "Warning: $1" >&2
}

# This function dumps information about AFM metrics, excluding metadata
# changes which we don't care about.

dump_afm()
{
	(./afmutil.py --dump $1 || warn "AFM dump failed") |
		grep -v "^loading metric data" |
		grep -v "^Font Information for" |
		grep -v "^  Comment"
}

test $# -ge 3 || error "Usage: source destination glyph..."

source=$1
shift
destination=$1
shift
glyphs=$@

# echo "Backing up AFM"

# afm=${destination%.pfb}.afm

# dump_afm "$afm" > "$afm".dump-a

echo "Copying glyphs"

(./copy-glyphs.pe "$source" "$destination" $glyphs ||
	warn "Fontforge script failed") 2>&1 |
	grep -v "^Copyright" |
	grep -v "^FontForge used to be" |
	grep -v "^ Executable based on" |
	sed -e 's/^/ - /'

# echo "Generating AFM diff"
# 
# dump_afm "$afm" > "$afm".dump-b
# diff -u "$afm".dump-a "$afm".dump-b > "$afm".diff
# rm "$afm".dump-a "$afm".dump-b

