% 
% autometric.mf -- administrative MF routines
% 
% source file of the Feta (Font-En-Tja) pretty-but-neat music font
% 
% (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
%          Jan Nieuwenhuizen <jan@digicash.com>
% 
% these macros help create ascii logging output
% to automate generation of lily tables and tex backend
% The output should be parsed by the mf-to-table script

% font or database?
def fet_beginfont(expr name,size) =
	font_identifier:=name&decimal size;
	font_size size;
	message "@{font@:"&name&"@:"&decimal size&"@}";
	message "";
	enddef;

def fet_endfont(expr name) =
	message "@{tnof@:"&name&"@}";
	message "";
	enddef;

% group or table?
def fet_begingroup(expr name) =
	message "@{group@:"&name&"@}";
	message "";
	begingroup
enddef;

def fet_endgroup(expr name) =
	endgroup;
	message "@{puorg@:"&name&"@}";
	message "";
enddef;

def autometric_output_char=
	message "@{char@:"&charnamestr&"@:"&decimal charcode&"@:"&decimal charbp&"@:"&decimal charwd&"@:"&decimal chardp&"@:"&decimal charht&"@:"&idstr&"@:"&texstr&"@}";
enddef;

def hround_pixels(expr sharped) = hround(sharped * hppp) enddef;
def vround_pixels(expr sharped) = vround(sharped * vppp) enddef;

def tand(expr alpha) = 
	(sind alpha/cosd alpha)
	enddef;

%breapth, width, depth, height
%     breapth	x-depth
def set_char_box(expr b_sharp, w_sharp, d_sharp,h_sharp) = 
	save scharbp, scharht, scharwd, schardp;

	% some paranoia if someone calls set_char_box(charwd, charbp, .. )
	scharbp := b_sharp;
	scharht := h_sharp;
	schardp := d_sharp;
	scharwd := w_sharp;

	charbp := scharbp;
	charht := scharht;
	chardp := schardp;
	charwd := scharwd;

	w := hround(w_sharp *hppp);
	b := hround(b_sharp *hppp);
	h := hround(h_sharp *vppp);
	d := hround(d_sharp *vppp);
enddef;

def no_dimen_beginchar(expr c) =
	begingroup
	charcode := if known c: byte c else: 0; fi;
	charic := 0;
	clearxy;
	clearit;
	clearpen;
	scantokens extra_beginchar;
enddef;

code:=-1;

% starts just as plain mf's beginchar:
%     charcode, 
% and then adds:
%     charname	see below
%     id	index in lily's table
%     texstr	name of tex macro in lily's table and tex backend

% the dims are uninitialised; you should use set_char_box manually.
def fet_beginchar(expr name, id_lit, texstr_lit) =
	save texstr, idstr, charnamestr;
	save charbp;
	save w,b,h,d;
	string texstr, idstr, charnamestr;
	texstr := texstr_lit;
	charnamestr := name;
	idstr := id_lit;

	no_dimen_beginchar(incr code) name;
	enddef;


def makebox_with_breapth(text r) = 
	for y = -d, 0, h: r((-b, y),(w,y)); endfor
	for x = -b, 0, w: r((x, -d),(x, h)); endfor
enddef;

%
% override plain endchar.  We want a different box. 
%
def breapth_endchar =
	scantokens extra_endchar;
	if proofing > 0: makebox_with_breapth(proofrule); fi
	chardx := 10*(w + b);
	shipit;
	endgroup
enddef;

def fet_endchar=
	autometric_output_char;
	breapth_endchar;
	enddef;
