#! /bin/sh
# Make a reduced version of an AFM file
# usage: mk-red scale afm-file-name >new-afm-file-name
# 
# rounding is done with int(x+0.5) --- this is wrong for -ve values
# doesn't deal with composites
awk 'BEGIN {'scale=$1'; }

/^FontName/ {
	print $0 "-Reduced";
	next;
	}

/^FullName/ {
	print $0, "Reduced";
	next;
	}

/^Underline/ || /^CapHeight/ || /^XHeight/ || /^Descender/ || /^Ascender/ {
	print $1, int($2*scale + 0.5); next;
}

/^FontBBox/ {
	print "FontBBox", int($2*scale+0.5), int($3*scale+0.5),	int($4*scale+0.5), int($5*scale+0.5);
	next;
}


/^C / {
	$5 = int($5 * scale + 0.5);
	$11 = int($11 * scale + 0.5);
	$12 = int($12 * scale + 0.5);
	$13 = int($13 * scale + 0.5);
	$14 = int($14 * scale + 0.5);
	print $0; next;
}

/^KPX/ {
	$4 = int($4*scale - 0.5)
	print $0; next;
}

{print}' $2