% -%-Fundamental-%- -*-Metafont-*-
% parmesan-clefs.mf -- implement ancient clefs
% 
% source file of LilyPond's pretty-but-neat music font
%
% (c) 2001--2006 Juergen Reuter <reuter@ipd.uka.de>
%

fet_begingroup ("clefs")

%
% character aligment:
%
%   Each clef is associated with a particular pitch: the treble clef
%   with the 'g', the alto clef with the 'c', the bass clef with the
%   'f', etc.  The shape of each clef character defines a vertical
%   position that is assumed to represent this pitch.  For the treble
%   clef, it is the vertical position of the center of the spiral
%   ending that represents the 'g' pitch.  For the bass clef, it is
%   the center between the two fat dots that define the vertical
%   position of the 'f' pitch.  For the alto clef, it is the vertical
%   center of the clef that is aligned with the 'c' pitch.  For each
%   clef character, this center should be vertically aligned with the
%   point (0, 0).  The horizontal alignment of each clef character
%   should be such that the vertical line through the point (0, 0)
%   touches the left-most edge of the clef.
%
%   TODO: document exact_center
%
% set_char_box() conventions:
%
% * breapth: Ignored (as far as I know).  Should be set to 0.
%
% * width: Should match the head's width.
%
% * depth: Should match the bottom edge of the head.  Affects vertical
%   collision handling.
%
% * height: Should match the top edge of the head.  Affects vertical
%   collision handling.
%


%%%%%%%%
%
%
%
% Editio Vaticana
%
%
%
def draw_vaticana_do_clef(expr exact_center, reduction) = 
	save reduced_il;

	reduced_il# = staff_space# * reduction;
	set_char_box(0 - xpart exact_center,
		     0.5reduced_il# + xpart exact_center,
		     0.8reduced_il# - ypart exact_center,
		     0.8reduced_il# + ypart exact_center);

	define_pixels(reduced_il);

	pickup pencircle xscaled 0.6linethickness yscaled 0.6 reduced_il;

	save za, zb, zc, zd, ze, zf;
	pair za, zb, zc, zd, ze, zf;

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	rt  za = (xoffs + 0.50reduced_il, yoffs - .45reduced_il);
	    zb = (xoffs + 0.25reduced_il, yoffs - .50reduced_il);
	lft zc = (xoffs + 0.00reduced_il, yoffs - .25reduced_il);
	lft zd = (xoffs + 0.00reduced_il, yoffs + .25reduced_il);
	    ze = (xoffs + 0.25reduced_il, yoffs + .50reduced_il);
	rt  zf = (xoffs + 0.50reduced_il, yoffs + .45reduced_il);
	draw za .. zb .. zc --	% lower punctum
	     zd .. ze .. zf;	% upper punctum
enddef;


fet_beginchar("Ed. Vat. do clef", "vaticana.do")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_vaticana_do_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("Ed. Vat. do clef", "vaticana.do_change")
	draw_vaticana_do_clef((0,0), 1.0); % no reduction
fet_endchar;


def draw_vaticana_fa_clef(expr exact_center, reduction) = 

	save reduced_il, z;
	reduced_il# = staff_space# * reduction;
	define_pixels(reduced_il);

	save za, zb, zc, zd, ze;
	pair za, zb, zc, zd, ze;

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	%left-handed punctum
	pickup pencircle xscaled 0.6linethickness yscaled 0.5reduced_il;
	lft za = (xoffs + 0.00reduced_il, xoffs + 0.00reduced_il);
	    zb = (xoffs + 0.25reduced_il, xoffs + 0.05reduced_il);
	rt  zc = (xoffs + 0.50reduced_il, xoffs - 0.05reduced_il);
	draw za .. zb .. zc;

	%stem
	pickup pencircle scaled 0.6linethickness;
	xpart zc = xpart zd = xpart ze;
	ypart zd = yoffs = bot ypart ze + 1.5reduced_il;
	draw zd -- ze;

	%right-handed puncta as in do clef
	draw_vaticana_do_clef(exact_center + (0.55reduced_il#, 0), reduction);

	set_char_box(0 - xpart exact_center,
		     1.05reduced_il# + xpart exact_center,
		     1.5reduced_il# - ypart exact_center,
		     0.8reduced_il# + ypart exact_center);
enddef;


fet_beginchar("Ed. Vat. fa clef", "vaticana.fa")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_vaticana_fa_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("Ed. Vat. fa clef", "vaticana.fa_change")
	draw_vaticana_fa_clef((0,0), 1.0); % no reduction
fet_endchar;

%%%%%%%%
%
%
%
% Editio Medicaea
%
%
%
def draw_medicaea_do_clef(expr exact_center, reduction) = 
	save reduced_il, reduced_slt;
	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	define_pixels(reduced_il);
	define_pixels(reduced_slt);

	save flag_height;
	flag_height# = 0.5 reduced_il#;
	define_pixels(flag_height);

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	%upper flag
	save za, zb;
	pair za, zb;
	pickup pencircle xscaled reduced_slt yscaled flag_height;
	xoffs = lft xpart za = rt xpart zb - reduced_il;
	ypart za = yoffs + 0.5 (reduced_il - flag_height - staff_space);
	ypart zb = ypart za - reduced_il + flag_height;
	draw za -- zb;

	%lower flag
	save za, zb;
	pair za, zb;
	pickup pencircle xscaled reduced_slt yscaled flag_height;
	xoffs = lft xpart za = rt xpart zb - reduced_il;
	ypart za = yoffs + 0.5 (reduced_il - flag_height + staff_space);
	ypart zb = ypart za - reduced_il + flag_height;
	draw za -- zb;

	%stem
	save za, zb;
	pair za, zb;
	pickup pencircle scaled reduced_slt;
	lft xpart za = lft xpart zb = xoffs;
	yoffs = top ypart zb - 1.5 reduced_il = bot ypart za + 1.5 reduced_il;
	draw za -- zb;

	set_char_box(0 - xpart exact_center,
		     1.0reduced_il# + xpart exact_center,
		     1.5reduced_il# - ypart exact_center,
		     1.5reduced_il# + ypart exact_center);
enddef;


fet_beginchar("Ed. Med. do clef", "medicaea.do")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_medicaea_do_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("Ed. Med. do clef", "medicaea.do_change")
	draw_medicaea_do_clef((0,0), .8);
fet_endchar;


def draw_medicaea_fa_clef(expr exact_center, reduction) = 
	% inspired by Regensburger Edition of Medicaea (1885/86), in:
	% MGG, volume 2, col. 1327 ("Choralreform"), fig. 2.

	save reduced_il, reduced_slt;
	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	define_pixels(reduced_il);
	define_pixels(reduced_slt);

	save za, zb, zc, zd, ze;
	pair za, zb, zc, zd, ze;

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	%stem
	pickup pencircle scaled linethickness;
	xpart za = xpart zb = xoffs + 0.4reduced_il;
	ypart za = yoffs = bot ypart zb + 1.5reduced_il;
	draw za -- zb;

	%left-handed punctum
	pickup pencircle xscaled reduced_slt yscaled reduced_il;
	lft zc = (xoffs, yoffs);
	zd = lft zc + (0.4reduced_il, 0);
	draw zc -- zd;

	%right-handed puncta as in do clef
	draw_medicaea_do_clef(exact_center + (0.7reduced_il#, 0), reduction);

	set_char_box(0 - xpart exact_center,
		     1.7reduced_il# + xpart exact_center,
		     1.5reduced_il# - ypart exact_center,
		     1.5reduced_il# + ypart exact_center);
enddef;


fet_beginchar("Ed. Med. fa clef", "medicaea.fa")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_medicaea_fa_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("Ed. Med. fa clef", "medicaea.fa_change")
	draw_medicaea_fa_clef((0,0), .8);
fet_endchar;


%%%%%%%%
%
%
%
% Mensural Notation
%
%
%

%
% width:        interval from left end to right end
% height:       interval from bottom of lower beam to top of upper beam
% exact_center: the coordinates of the vertical center point of the
%               left edge.
%
def draw_brevis(expr exact_center, bwidth, bheight, blinethickness) =

	save brevis_width, brevis_height, linethickness;
	brevis_width# = bwidth; brevis_height# = bheight;
	linethickness# = blinethickness;

	save beam_width, beam_height, serif_size, serif_protrude, hole_height;
	beam_width# = 1.4 linethickness#;
	hole_height# = 3 linethickness#;
	2 beam_height# + hole_height# = brevis_height#;
	serif_size# = (hole_height# - linethickness#)/2;
	serif_protrude# = 1.5 serif_size#;

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	define_pixels(brevis_width, brevis_height, linethickness);
	define_pixels(beam_width, beam_height, serif_size, serif_protrude);

	penpos1(beam_width, 0);
	penpos2(beam_width, 0);
	penpos3(beam_height, 90);
	penpos4(beam_height, 90);
	penpos5(beam_width, 180);
	z1l = (xoffs, yoffs);
	z2l = z1l + (0, -linethickness);
	z3r = z2r + serif_size*(1,-1);
	y4r = y3r;
	x4l = x1l + brevis_width/2;
	z5l = z3l + (-serif_size, -serif_protrude);
	fill z1r -- z1l -- z5r{down} .. z5l{up} .. z3l{right}
		-- z4l -- z4r -- z3r{left} .. z2r{up} -- cycle;

	addto currentpicture also currentpicture
		yscaled -1 shifted (0, 2*yoffs);

	pickup pencircle scaled linethickness;
	top y6 = yoffs + brevis_height/2;
	bot y7 = yoffs - brevis_height/2;
	lft x6 = lft x7 = xoffs;
	draw z6 -- z7;

	addto currentpicture also currentpicture
		xscaled -1 shifted (2xoffs + brevis_width, 0);
enddef;


def draw_neomensural_c_clef(expr exact_center, reduction) = 
	save reduced_il, reduced_slt, stem_width;
	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	stem_width# = 1.4 reduced_slt#;
	define_pixels(reduced_il, reduced_slt, stem_width);

	draw_brevis(exact_center + (3reduced_slt#, 0),
		    2reduced_il#, reduced_il#, reduced_slt#);

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	pickup pencircle xscaled stem_width yscaled blot_diameter;
	lft x8  = lft x9  = xoffs;
	lft x10 = lft x11 = lft x8  + 3reduced_slt;
	rt  x12 = rt  x13 = lft x10 + 2reduced_il;
	rt  x14 = rt  x15 = rt  x12 + 3reduced_slt;
	top y9 - bot y8 = 4reduced_il;
	top y9 + bot y8 = 2yoffs;
	y12 = y14 = y10 = y8; y13 = y15 = y11 = y9;
	draw z8 -- z9;
	draw z10 -- z11;
	draw z12 -- z13;
	draw z14 -- z15;

	set_char_box(0 - xpart exact_center,
		     2reduced_il# + 6reduced_slt# + xpart exact_center,
		     2reduced_il# - ypart exact_center,
		     2reduced_il# + ypart exact_center);
enddef;


fet_beginchar("neo-mensural c clef", "neomensural.c")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_neomensural_c_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("neo-mensural c clef", "neomensural.c_change")
	draw_neomensural_c_clef((0,0), .8);
fet_endchar;


def draw_petrucci_c_clef(expr exact_center, flare_align, reduction) = 
	% inspired by Josquin Desprez, "Stabat Mater", Libro tertio,
	% 1519, printed by Petrucci, in: MGG, volume 7, Table 11.
	% Also by Petrucci's Canti C, Venedig 1503.  In: MGG, volume
	% 9, p. 1681/1682.

	save reduced_il, reduced_slt;
	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	define_pixels(reduced_il);

	draw_brevis(exact_center + (0, 0.5staff_space#),
		    reduced_il#, reduced_il#, reduced_slt#);

	addto currentpicture also currentpicture shifted (0, -staff_space);

	save half_reduced_il, left_depth, left_height;
	half_reduced_il# = staff_space# * sqrt(reduction);
	left_height# = half_reduced_il# * min(3.2, 3.2 + 0.2 + flare_align);
	left_depth# = half_reduced_il# * min(3.2, 3.2 + 0.2 - flare_align);

	define_pixels(half_reduced_il);
	define_pixels(left_depth, left_height);

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	pickup pencircle xscaled 1.4 linethickness yscaled blot_diameter;
	lft x8 = lft x9 = xoffs;
	top y8 = yoffs + left_height;
	bot y9 = yoffs - left_depth;
	draw z8 .. z9;

	rt x10 = rt x11 = xoffs + brevis_width;
	y10 = min(y8 - 0.2*half_reduced_il, yoffs + 2.2half_reduced_il);
	y11 = max(y9 + 0.2*half_reduced_il, yoffs - 2.2half_reduced_il);
	draw z10 .. z11;

	set_char_box(0 - xpart exact_center,
		     reduced_il# + xpart exact_center,
		     left_depth# - ypart exact_center,
		     left_height# + ypart exact_center);
enddef;


fet_beginchar("petrucci c1 clef", "petrucci.c1")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_c_clef((0,0), +2, 1.0);
fet_endchar;
fet_beginchar("petrucci c1 clef", "petrucci.c1_change")
	draw_petrucci_c_clef((0,0), +2, .8);
fet_endchar;

fet_beginchar("petrucci c2 clef", "petrucci.c2")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_c_clef((0,0), +1, 1.0);
fet_endchar;
fet_beginchar("petrucci c2 clef", "petrucci.c2_change")
	draw_petrucci_c_clef((0,0), +1, .8);
fet_endchar;

fet_beginchar("petrucci c3 clef", "petrucci.c3")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_c_clef((0,0), 0, 1.0);
fet_endchar;
fet_beginchar("petrucci c3 clef", "petrucci.c3_change")
	draw_petrucci_c_clef((0,0), 0, .8);
fet_endchar;

fet_beginchar("petrucci c4 clef", "petrucci.c4")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_c_clef((0,0), -1, 1.0);
fet_endchar;
fet_beginchar("petrucci c4 clef", "petrucci.c4_change")
	draw_petrucci_c_clef((0,0), -1, .8);
fet_endchar;

fet_beginchar("petrucci c5 clef", "petrucci.c5")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_c_clef((0,0), -2, 1.0);
fet_endchar;
fet_beginchar("petrucci c5 clef", "petrucci.c5_change")
	draw_petrucci_c_clef((0,0), -2, .8);
fet_endchar;


def draw_mensural_c_clef(expr exact_center, reduction) =
	% inspired by Ockeghem, "Missa Prolationum", in: MGG, volume
	% 9, table 94.

	save reduced_il;
	reduced_il# = staff_space# * reduction;
	draw_brevis(exact_center + (0, 0.5staff_space#),
		    2reduced_il#, 0.8staff_space#, 0.8linethickness#);
	define_pixels(reduced_il);
	addto currentpicture also currentpicture shifted (0, -staff_space);
	addto currentpicture also currentpicture shifted (0, -staff_space);

	save half_reduced_il;
	half_reduced_il# = staff_space# * sqrt(reduction);
	define_pixels(half_reduced_il);

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	pickup pencircle xscaled 1.4 linethickness yscaled blot_diameter;
	lft x8 = lft x9 = xoffs;
	top y8 = yoffs + 2.2 half_reduced_il;
	bot y9 = yoffs - 2.2 half_reduced_il - staff_space;
	draw z8 .. z9;

	rt x10 = rt x11 = xoffs + brevis_width;
	y10 = yoffs + 1.4half_reduced_il;
	y11 = yoffs - 1.4half_reduced_il - staff_space;
	draw z10 .. z11;

	set_char_box(0 - xpart exact_center,
		     2reduced_il# + xpart exact_center,
		     2.2 half_reduced_il# + staff_space# - 2 ypart exact_center,
		     2.2 half_reduced_il# + 2 ypart exact_center);
enddef;


fet_beginchar("mensural c clef", "mensural.c")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_mensural_c_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("mensural c clef", "mensural.c_change")
	draw_mensural_c_clef((0,0), .8);
fet_endchar;

def draw_diamond(expr exact_center, reduction) =
	save stem_width, reduced_nht, holeheight, beamheight;
	save rh_height, rh_width;

	stem_width# = 1.4 reduced_slt#;
	reduced_nht# = noteheight# * reduction;
	holeheight# = 3 reduced_slt#;
	beamheight# = 0.4(reduced_nht# - holeheight#);

	rh_height# = 1.2 staff_space# * reduction;
	rh_width# / rh_height# = tand(30);

	define_pixels(beamheight);
	define_pixels(stem_width);
	define_pixels(rh_height);
	define_pixels(rh_width);

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	pickup pencircle
		xscaled beamheight
		yscaled stem_width
		rotated 45;

	draw
		(xoffs - rh_width/2, yoffs) --
		(xoffs, yoffs + rh_height/2) --
		(xoffs + rh_width/2, yoffs) --
		(xoffs, yoffs - rh_height/2) --
		cycle;
enddef;

def draw_petrucci_f_clef(expr exact_center, reduction) =
	% inspired by L'homme arme super voces musicales in Misse
	% Josquin, 1502, Petrucci, in: MGG, volume 7, col. 200; also
	% inspired by Gaspar van Weerbeke, "Virgo Maria" (1502), in:
	% MGG, volume 9, col. 653 ("Motette"), fig. 3.; also by Andr'e
	% Campra, "Entr'ee des s'er'enades" (1710), in: MGG, volume 2,
	% col. 1649 ("Contredanse"), fig. 2.
	%

	save interline, reduced_il, reduced_slt;
	interline# = staff_space#;
	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;

	draw_brevis(exact_center, reduced_il#, reduced_il#, reduced_slt#);
	draw_diamond(exact_center + (1.6interline#*reduction, interline#/2),
		     reduction);
	draw_diamond(exact_center + (1.6interline#*reduction, -interline#/2),
		     reduction);

	define_pixels(interline);
	define_pixels(reduced_il);
	define_pixels(reduced_slt);

	save stem_width;
	stem_width# = 1.4 reduced_slt#;
	define_pixels(stem_width);

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;

	define_pixels(xoffs, yoffs);

	% brevis stem
	pickup pencircle xscaled stem_width yscaled blot_diameter;
	rt z8 = (xoffs + reduced_il, yoffs);
	z9 = z8 + (0, -4reduced_il);
	draw z8 .. z9;

	% upper diamond's stem
	pickup pencircle xscaled stem_width yscaled blot_diameter;
	z10 = (xoffs + 1.6interline*reduction + stem_width/2,
	  yoffs + interline*reduction);
	top z11 = z10 + (0, 1.5interline*reduction);
	draw z10 .. z11;

	% lower diamond's stem
	pickup pencircle xscaled stem_width yscaled blot_diameter;
	z12 = (xoffs + 1.6interline*reduction - stem_width/2,
	  yoffs - interline*reduction);
	bot z13 = z12 + (0, -3.5interline*reduction);
	draw z12 .. z13;

	save reduced_il, rh_height, rh_width;
	reduced_il# = staff_space# * reduction;
	rh_height# = 1.2reduced_il#;
	rh_width# / rh_height# = tand(30);
	set_char_box(0 - xpart exact_center,
		     1.6interline#*reduction + 0.5rh_width# + xpart exact_center,
		     4.5*interline#*reduction - ypart exact_center,
		     2.5*interline#*reduction + ypart exact_center);
enddef;


fet_beginchar("petrucci f clef", "petrucci.f")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_f_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("petrucci f clef", "petrucci.f_change")
	draw_petrucci_f_clef((0,0), .8);
fet_endchar;


def draw_mensural_f_clef(expr exact_center, reduction) =
	%
	% inspired by Philippe le Duc, "Dite Signori" (1590), in: MGG,
	% volume 3, col. 848 ("Duc"); also by John Dowland, "The First
	% Booke of Songes" (1597), in: MGG, volume 3, col. 721
	% ("Dowland"), fig. 3.

	save width, reduced_slt, stem_width, dot_diameter;

	width# = 1.2staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	stem_width# = 1.4 reduced_slt#;
	dot_diameter# = 0.1 reduction * staff_space#;
	define_pixels(width, stem_width, staff_space, dot_diameter);

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	pickup pencircle
		xscaled 0.2width
		yscaled stem_width
		rotated 45;

	% half circle
	lft z5 = (0, 0);
	draw	halfcircle scaled width rotated -90
		shifted (z5-(xoffs, yoffs));


	% upper dot
	rt x2 = xoffs + width;
	top y1 = yoffs + 0.5width;
	z2 - z1 = (dot_diameter, -dot_diameter);
	draw z1 -- z2;

	% lower dot
	x3 = x1;
	top y1 - bot y4 = width;
	z4 - z3 = (dot_diameter, -dot_diameter);
	draw z3 -- z4;

	set_char_box(0 - xpart exact_center,
		     width# + xpart exact_center,
		     0.5width# - ypart exact_center,
		     0.5width# + ypart exact_center);
enddef;

fet_beginchar("mensural f clef", "mensural.f")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_mensural_f_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("mensural f clef", "mensural.f_change")
	draw_mensural_f_clef((0,0), .8);
fet_endchar;


def draw_petrucci_g_clef(expr exact_center, reduction) =
	% inspired by Josquin Desprez, "Stabat Mater", Libro tertio,
	% 1519, printed by Petrucci, in: MGG, volume 7, Table 11.

	save reduced_il, reduced_slt;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = linethickness# * reduction;
	define_pixels(reduced_il, reduced_slt);

	set_char_box(0 - xpart exact_center,
		     1.25 reduced_il# + xpart exact_center,
		     0.65 reduced_il# - ypart exact_center,
		     3.80 reduced_il# + ypart exact_center);

	save za, zb, zc, zd, ze, zf, zg, zh, zi, zj;
	pair za, zb, zc, zd, ze, zf, zg, zh, zi, zj;

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	pickup pencircle
		xscaled 0.50 reduced_slt
		yscaled 0.22 reduced_il
		rotated -35;

	lft za = (xoffs + 0.80 reduced_il, yoffs + 0.00 reduced_il);
	lft zb = (xoffs + 1.00 reduced_il, yoffs + 1.20 reduced_il);
	lft zc = (xoffs + 0.70 reduced_il, yoffs + 2.00 reduced_il);
	lft zd = (xoffs + 0.30 reduced_il, yoffs + 3.00 reduced_il);
	lft ze = (xoffs + 0.80 reduced_il, yoffs + 3.70 reduced_il);
	lft zf = (xoffs + 1.00 reduced_il, yoffs + 3.00 reduced_il);
	lft zg = (xoffs + 0.60 reduced_il, yoffs + 2.00 reduced_il);
	lft zh = (xoffs + 0.30 reduced_il, yoffs + 1.70 reduced_il);
	lft zi = (xoffs + 0.00 reduced_il, yoffs + 0.75 reduced_il);
	lft zj = (xoffs + 0.20 reduced_il, yoffs + 0.60 reduced_il);

	draw za{-1,2} .. zb .. zc .. zd .. ze .. zf .. zg .. zh .. zi .. zj;

	save za, zb, zc, zd, ze, zf;
	pair za, zb, zc, zd, ze, zf;

	pickup pencircle
		xscaled 0.75 reduced_slt
		yscaled 0.33 reduced_il
		rotated -35;

	lft za = (xoffs + 1.05 reduced_il, yoffs + 0.45 reduced_il);
	lft zb = (xoffs + 0.55 reduced_il, yoffs + 0.45 reduced_il);
	lft zc = (xoffs + 0.55 reduced_il, yoffs - 0.45 reduced_il);
	lft zd = (xoffs + 1.05 reduced_il, yoffs - 0.45 reduced_il);
	lft ze = (xoffs + 1.10 reduced_il, yoffs + 0.00 reduced_il);
	lft zf = (xoffs + 0.80 reduced_il, yoffs + 0.00 reduced_il);

	draw za .. zb .. zc .. zd .. {up}ze -- zf;
enddef;


fet_beginchar("petrucci g clef", "petrucci.g")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_g_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("petrucci g clef", "petrucci.g_change")
	draw_petrucci_g_clef((0,0), .8);
fet_endchar;


def draw_mensural_g_clef(expr exact_center, reduction) =
  % TODO: Rewrite me.  The former mensural g clef looked ugly, and the
  % code was removed when it broke for small font sizes after some
  % global changes in the font.  Currently, the character is mapped to
  % a copy of the petrucci g clef (which, after all, *is* a mensural g
  % clef, but not the one that we have in mind here). -- jr
  %
  % Possible sources of inspiration for this clef include: Francisco
  % Guerrero, "Lib. 1.  Missarum" (1566), in: MGG, volume 3, col. 858
  % ("Ducis"); Stefano Fabri, "Quam speciosa veteranis" (1611), in:
  % MGG, volume 3, col. 1698 ("Fabri"); Philippus Dulichius,
  % "Fasciculus novus ..."  (1598), in: MGG, volume 3, col. 919
  % ("Dulichius"), fig. 1; Noe Faignient, "Ic sal de Heer myn God
  % gebenedye" (1568), in: MGG, volume 3, col. 1735 ("Faignient").
enddef;

%
% FIXME: This clef is preliminarily mapped to the petrucci g clef
% until the code for the mensural g clef will be rewritten.
%
fet_beginchar("mensural g clef", "mensural.g")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_petrucci_g_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("mensural g clef", "mensural.g_change")
	draw_petrucci_g_clef((0,0), .8);
fet_endchar;



%%%%%%%%
%
%
%
% Hufnagel
%
%
%
def draw_hufnagel_do_clef(expr exact_center, reduction) =
	%
	% inspired by Graduale of Friedrich Zollner (1442), in: MGG,
	% volume 9, col. 1413 ("Neustift"), fig. 1.
	%
	save reduced_il;

	reduced_il# = staff_space# * reduction;

	define_pixels(reduced_il);

	pickup pencircle
		xscaled (0.60reduced_il)
		yscaled (0.10reduced_il)
		rotated 40;
	save za, zb, zc, zd, ze, zf;
	pair za, zb, zc, zd, ze, zf;

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	za = (xoffs + 0.90reduced_il, yoffs + .45reduced_il);
	zb = (xoffs + 0.80reduced_il, yoffs + .45reduced_il);
	zc = (xoffs + 0.50reduced_il, yoffs + .60reduced_il);
	zd = (xoffs + 0.20reduced_il, yoffs + .45reduced_il);
	ze = (xoffs + 0.20reduced_il, yoffs - .45reduced_il);
	zf = (xoffs + 0.40reduced_il, yoffs - .55reduced_il);
	draw za .. zb .. zc -- zd -- ze -- zf;

	set_char_box(0 - xpart exact_center,
		     1.10reduced_il# + xpart exact_center,
		     0.70reduced_il# - ypart exact_center,
		     0.75reduced_il# + ypart exact_center);
enddef;


fet_beginchar("Hufnagel do clef", "hufnagel.do")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_hufnagel_do_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("Hufnagel do clef", "hufnagel.do_change")
	draw_hufnagel_do_clef((0,0), .8);
fet_endchar;


def draw_hufnagel_fa_clef(expr exact_center, reduction) =
	%
	% inspired by Bamberger Manuscript (15th century), in:
	% MGG, volume 2, table 59.
	%
	save reduced_il;

	reduced_il# = staff_space# * reduction;

	define_pixels(reduced_il);

	pickup pencircle
		xscaled (0.60reduced_il)
		yscaled (0.10reduced_il)
		rotated 40;
	save za, zb, zc, zd, ze, zf;
	pair za, zb, zc, zd, ze, zf;

	save xoffs, yoffs;
	xoffs# = xpart exact_center;
	yoffs# = ypart exact_center;
	define_pixels(xoffs, yoffs);

	za = (xoffs + 0.90reduced_il, yoffs + 0.70reduced_il);
	zb = (xoffs + 0.80reduced_il, yoffs + 0.70reduced_il);
	zc = (xoffs + 0.50reduced_il, yoffs + 0.85reduced_il);
	zd = (xoffs + 0.20reduced_il, yoffs + 0.70reduced_il);
	ze = (xoffs + 0.20reduced_il, yoffs - 1.10reduced_il);
	draw za .. zb .. zc -- zd -- ze;

	save zg, zh, zi, zj;
	pair zg, zh, zi, zj;

	zg = (xoffs + 0.90reduced_il, yoffs - 0.05reduced_il);
	zh = (xoffs + 0.80reduced_il, yoffs - 0.05reduced_il);
	zi = (xoffs + 0.50reduced_il, yoffs + 0.10reduced_il);
	zj = (xoffs + 0.20reduced_il, yoffs - 0.05reduced_il);
	draw zg .. zh .. zi -- zj;

	set_char_box(0 - xpart exact_center,
		     1.20reduced_il# + xpart exact_center,
		     1.15reduced_il# - ypart exact_center,
		     1.00reduced_il# + ypart exact_center);
enddef;


fet_beginchar("Hufnagel fa clef", "hufnagel.fa")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_hufnagel_fa_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("Hufnagel fa clef", "hufnagel.fa_change")
	draw_hufnagel_fa_clef((0,0), .8);
fet_endchar;


def draw_hufnagel_do_fa_clef(expr exact_center, reduction) =
	draw_hufnagel_do_clef(exact_center, reduction);
	draw_hufnagel_fa_clef(exact_center + (0, -2staff_space#), reduction);
	set_char_box(0 - xpart exact_center,
		     1.20reduced_il# + xpart exact_center,
		     1.15reduced_il# + 2staff_space# - ypart exact_center,
		     0.75reduced_il# + ypart exact_center);
enddef;


fet_beginchar("Hufnagel do/fa clef", "hufnagel.do.fa")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_hufnagel_do_fa_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("Hufnagel do/fa clef", "hufnagel.do.fa_change")
	draw_hufnagel_do_fa_clef((0,0), .8);
fet_endchar;


fet_endgroup ("clefs")
