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

fet_begingroup ("clefs")


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

	reduced_il# = staff_space# * reduction;
	
	set_char_box(0.4reduced_il#, 0.0reduced_il#,
		     0.8reduced_il#, 0.8reduced_il#);

	define_pixels(reduced_il);

	pickup pencircle xscaled stafflinethickness yscaled 0.6reduced_il;

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

	za = exact_center + (-0.0reduced_il, -.45reduced_il);
	zb = exact_center + (-0.2reduced_il, -.50reduced_il);
	zc = exact_center + (-0.4reduced_il, -.25reduced_il);
	zd = exact_center + (-0.4reduced_il, +.25reduced_il);
	ze = exact_center + (-0.2reduced_il, +.50reduced_il);
	zf = exact_center + (-0.0reduced_il, +.45reduced_il);
	draw za .. zb .. zc --	% lower punctum
	     zd .. ze .. zf;	% upper punctum
enddef;


fet_beginchar("Ed. Vat. do clef", "vaticana_do", "vatdoclef")
	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", "vatcdoclef")
	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;

	%stem
	pickup pencircle scaled stafflinethickness;
	xpart za = xpart zb =
		xpart exact_center + 0.4reduced_il;
	ypart za = ypart exact_center = ypart zb + 1.5reduced_il;
	draw za .. zb;

	%left-handed punctum
	pickup pencircle xscaled stafflinethickness yscaled 0.5reduced_il;
	zc = exact_center +
		(+0.4reduced_il, -0.05reduced_il);
	zd = exact_center +
		(+0.2reduced_il, +0.05reduced_il);
	ze = exact_center +
		(+0.0reduced_il, +0.00reduced_il);
	draw zc .. zd .. ze;

	%right-handed puncta as in do clef
	draw_vaticana_do_clef(
		exact_center +
		(+0.8reduced_il + 1.25stafflinethickness, 0),
		reduction);

	set_char_box(0.0reduced_il#, 0.8reduced_il# + 1.25stafflinethickness#,
		     1.5reduced_il#, 0.8reduced_il#);
enddef;


fet_beginchar("Ed. Vat. fa clef", "vaticana_fa", "vatfaclef")
	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", "vatcfaclef")
	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# = stafflinethickness# * reduction;
	define_pixels(reduced_il);
	define_pixels(reduced_slt);

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

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

	%upper flag
	save za, zb;
	pair za, zb;
	pickup pencircle xscaled reduced_slt yscaled flag_height;
	xpart exact_center
		= xpart za + 0.5 reduced_il
		= xpart zb - 0.5 reduced_il;
	ypart za = ypart exact_center - 0.5 flag_height
			- 0.5 (staff_space - reduced_il)
			+ 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;
	xpart za = xpart zb = xpart exact_center - 0.5 reduced_il;
	ypart exact_center
		= ypart za + 1.5 reduced_il
		= ypart zb - 1.5 reduced_il;
	draw za .. zb;

	set_char_box(0.5reduced_il#, 0.5reduced_il#,
		     1.5reduced_il#, 1.5reduced_il#);
enddef;


fet_beginchar("Ed. Med. do clef", "medicaea_do", "meddoclef")
	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", "cmeddoclef")
	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# = stafflinethickness# * reduction;
	define_pixels(reduced_il);
	define_pixels(reduced_slt);

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

	%stem
	pickup pencircle scaled stafflinethickness;
	xpart za = xpart zb =
		xpart exact_center + 0.4reduced_il;
	ypart za = ypart exact_center = ypart zb + 1.5reduced_il;
	draw za -- zb;

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

	%right-handed puncta as in do clef
	draw_medicaea_do_clef(
		exact_center +
		(+1.1reduced_il + 1.25stafflinethickness, 0),
		reduction);

	set_char_box(0.5reduced_slt#,
		     1.6reduced_il# + 1.25stafflinethickness#,
		     1.5reduced_il#, 1.5reduced_il#);
enddef;


fet_beginchar("Ed. Med. fa clef", "medicaea_fa", "medfaclef")
	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", "cmedfaclef")
	draw_medicaea_fa_clef((0,0), .8);
fet_endchar;


%%%%%%%%
%
%
%
% Mensural Notation
%
%
%
brevis_wid# := 2 staff_space#;

def draw_brevis(expr exact_center, reduction, small_width, small_height) =
	%
	% inspired by function draw_brevis of
	% feta-bolletjes.mf
	%
	save reduced_slt, reduced_nht;
	save stem_width, head_width;
	save serif_size, serif_protrude;
	save holeheight, beamheight;

	reduced_slt# = stafflinethickness# * reduction;
	reduced_nht# = noteheight# * reduction;
	stem_width# = 1.4 reduced_slt#;
	if small_width:
		head_width# = 0.5brevis_wid# * reduction;
	else:
		head_width# = brevis_wid# * reduction;
	fi;
	if small_height:
		serif_size# = 0.64 reduced_slt#;
		serif_protrude# = 0.96 serif_size#;
		holeheight# = 3 reduced_slt#;
		beamheight# = 0.32(reduced_nht# - holeheight#);
	else:
		serif_size# = 1.0 reduced_slt#;
		serif_protrude# = 1.5 serif_size#;
		holeheight# = 3 reduced_slt#;
		beamheight# = 0.5(reduced_nht# - holeheight#);
	fi;
	define_pixels(reduced_slt);
	define_pixels(stem_width);
	define_pixels(head_width);
	define_pixels(serif_size);
	define_pixels(serif_protrude);
	define_pixels(beamheight);

	penpos1(stem_width, 0);
	penpos2(stem_width, 0);
	penpos3(beamheight, 90);
	penpos4(beamheight, 90);
	penpos5(stem_width, 180);

	z1l = exact_center;
	z2l = z1l + (0, -reduced_slt/2);
	z3r = z2r + serif_size*(1,-1);
	y4r = y3r;
	x4l = x1l + head_width/2;
	z5l = z3l + (-serif_size, -serif_protrude);

	penlabels(1,2,3,4,5);
	fill z1r -- z1l -- z5r{down} .. z5l{up} .. z3l{right}
		-- z4l -- z4r -- z3r{left} .. z2r{up} -- cycle;
enddef;


def draw_neo_mensural_c_clef(expr exact_center, reduction) = 
	draw_brevis(exact_center, reduction, false, false);

	save reduced_il, reduced_slt;
	save stem_width;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = stafflinethickness# * reduction;
	stem_width# = 1.4 reduced_slt#;

	define_pixels(reduced_il);
	define_pixels(reduced_slt);
	define_pixels(stem_width);

	pickup pencircle xscaled stem_width yscaled blot_diameter;
	z6 = exact_center + (stem_width/2, 0);
	z7 = z6 + (0, -2reduced_il);
	z8 = z6 + (-3reduced_slt, 0);
	z9 - z8 = z7 - z6;
	draw z6 .. z7;
	draw z8 .. z9;

	addto currentpicture also currentpicture
		yscaled -1 shifted (0, 2*(ypart exact_center));
	addto currentpicture also currentpicture 
		xscaled -1 shifted (2x4l,0);

	set_char_box(3reduced_slt#, head_width# +3reduced_slt#,
		     2reduced_il#, 2reduced_il#);
enddef;


fet_beginchar("neo-mensural c clef", "neo_mensural_c", "neomenscclef")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_neo_mensural_c_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("neo-mensural c clef", "neo_mensural_c_change", "cneomenscclef")
	draw_neo_mensural_c_clef((1.3 staff_space#,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.
	draw_brevis(exact_center, reduction, true, true);

	save half_reduced_il, reduced_il, reduced_slt;
	save stem_width, interline;
	save left_depth, left_height;

	half_reduced_il# = staff_space# * sqrt(reduction);
	reduced_il# = staff_space# * reduction;
	reduced_slt# = stafflinethickness# * reduction;
	stem_width# = 1.4 reduced_slt#;
	interline# = staff_space#;

	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(reduced_il);
	define_pixels(reduced_slt);
	define_pixels(stem_width);
	define_pixels(interline);
	define_pixels(left_depth, left_height);

	addto currentpicture also currentpicture
		yscaled -1 shifted (0, 2*(ypart exact_center) - interline);

	addto currentpicture also currentpicture 
		xscaled -1 shifted (reduction*2x4l,0);

	addto currentpicture also currentpicture
		yscaled -1 shifted (0, 4*(ypart exact_center));

	pickup pencircle xscaled stem_width yscaled blot_diameter;

	xpart z6 = xpart z7 = xpart exact_center + stem_width/2;
	ypart z6 = ypart exact_center + left_height;
	ypart z7 = ypart exact_center - left_depth;
	draw z6 .. z7;

	xpart z8 = xpart z9 = reduction*2x4l - xpart exact_center - stem_width/2;
	ypart z8 = min(ypart z6 - 0.2*half_reduced_il,
		       xpart exact_center + 2.2half_reduced_il);
	ypart z9 = max(ypart z7 + 0.2*half_reduced_il,
		       xpart exact_center - 2.2half_reduced_il);
	draw z8 .. z9;

	set_char_box(0, head_width#, left_depth#, left_height#);
enddef;


fet_beginchar("petrucci c1 clef", "petrucci_c1", "petruccic1clef")
	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", "cpetruccic1clef")
	draw_petrucci_c_clef((1.3 staff_space#,0), +2, .8);
fet_endchar;

fet_beginchar("petrucci c2 clef", "petrucci_c2", "petruccic2clef")
	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", "cpetruccic2clef")
	draw_petrucci_c_clef((1.3 staff_space#,0), +1, .8);
fet_endchar;

fet_beginchar("petrucci c3 clef", "petrucci_c3", "petruccic3clef")
	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", "cpetruccic3clef")
	draw_petrucci_c_clef((1.3 staff_space#,0), 0, .8);
fet_endchar;

fet_beginchar("petrucci c4 clef", "petrucci_c4", "petruccic4clef")
	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", "cpetruccic4clef")
	draw_petrucci_c_clef((1.3 staff_space#,0), -1, .8);
fet_endchar;

fet_beginchar("petrucci c5 clef", "petrucci_c5", "petruccic5clef")
	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", "cpetruc5iceclef")
	draw_petrucci_c_clef((1.3 staff_space#,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.
	draw_petrucci_c_clef(exact_center, 0, reduction);

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

	save half_reduced_il;
	save left_depth, left_height;

	half_reduced_il# = staff_space# * sqrt(reduction);
	left_height# = 3.2 * half_reduced_il#;
	left_depth# = left_height# + interline#;

	set_char_box(0, head_width#, left_depth#, left_height#);
enddef;


fet_beginchar("mensural c clef", "mensural_c", "menscclef")
	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", "cmenscclef")
	draw_mensural_c_clef((0,0), .8);
fet_endchar;

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

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

	rh_height# = 1.2reduced_il#;
	rh_width# / rh_height# = tand(30);

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

	pickup pencircle
		xscaled beamheight
		yscaled stem_width
		rotated 45;

	draw
		exact_center + (-rh_width/2, 0) --
		exact_center + (0, rh_height/2) --
		exact_center + (+rh_width/2, 0) --
		exact_center + (0, -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.
	%
	draw_brevis(exact_center, reduction, true, false);

	save reduced_il, reduced_slt;
	save stem_width, interline;

	reduced_il# = staff_space# * reduction;
	reduced_slt# = stafflinethickness# * reduction;
	stem_width# = 1.4 reduced_slt#;
	interline# = staff_space#;

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

	addto currentpicture also currentpicture
		yscaled -1 shifted (0, 2*(ypart exact_center));
	addto currentpicture also currentpicture 
		xscaled -1 shifted (2x4l,0);


	% brevis stem
	pickup pencircle xscaled stem_width yscaled blot_diameter;
	z6 = exact_center + (2x4l - stem_width/2, 0);
	z7 = z6 + (0, -4reduced_il);
	draw z6 .. z7;

	% upper diamond
	draw_diamond(exact_center + (1.6interline*reduction, interline/2),
		     reduction);
	pickup pencircle xscaled stem_width yscaled blot_diameter;
	z8 = exact_center +
	     (1.6interline*reduction + stem_width/2, interline*reduction);
	z9 = z8 + (0, 1.5interline*reduction);
	draw z8 .. z9; % diamond stem

	% lower diamond
	draw_diamond(exact_center + (1.6interline*reduction, -interline/2),
		     reduction);
	pickup pencircle xscaled stem_width yscaled blot_diameter;
	z10 = exact_center +
	      (1.6interline*reduction - stem_width/2, -interline*reduction);
	z11 = z10 + (0, -3.5interline*reduction);
	draw z10 .. z11; % diamond stem

	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, 1.6interline#*reduction + 0.5rh_width#,
		     4.5*interline#*reduction, 2.5*interline#*reduction);
enddef;


fet_beginchar("petrucci f clef", "petrucci_f", "petruccifclef")
	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", "cpetruccifclef")
	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 reduced_slt, stem_width, reduced_nht, holeheight, beamheight;

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

	define_pixels(beamheight, stem_width, staff_space);

	pickup pencircle
		xscaled beamheight
		yscaled stem_width
		rotated 45;

	draw
		exact_center + (1.0 staff_space, 0.55 staff_space) --
		exact_center + (1.1 staff_space, 0.45 staff_space);

	draw
		exact_center + (1.1 staff_space, -0.55 staff_space) --
		exact_center + (1.1 staff_space, -0.45 staff_space);

	draw	halfcircle scaled 1.1 staff_space rotated -90
		shifted (-exact_center + (+0.05 staff_space, 0));

	set_char_box(0.5beamheight#, 1.1staff_space# + 0.5beamheight#,
		     0.55staff_space# + 0.5stem_width#,
		     0.55staff_space# + 0.5stem_width#);
enddef;

fet_beginchar("mensural f clef", "mensural_f", "mensfclef")
	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", "cmensfclef")
	draw_mensural_f_clef((0,0), .8);
fet_endchar;


def draw_mensural_g_clef(expr exact_center, reduction) =
	%
	% TODO: Rewrite me!  This clef looks completely awful! --jr
	%

	%
	% inspired by Francisco Guerrero, "Lib. 1.  Missarum" (1566),
	% in: MGG, volume 3, col. 858 ("Ducis"); also by Stefano
	% Fabri, "Quam speciosa veteranis" (1611), in: MGG, volume 3,
	% col. 1698 ("Fabri"); also by Philippus Dulichius,
	% "Fasciculus novus ..." (1598), in: MGG, volume 3, col. 919
	% ("Dulichius"), fig. 1; also by Noe Faignient, "Ic sal de
	% Heer myn God gebenedye" (1568), in: MGG, volume 3, col. 1735
	% ("Faignient").
	%
	% Metafont code partially inspired by Schwabacher 'G' of yswab
	% font.

	save reduced_il, stem_width, height, width, apex_o, hair;

	reduced_il#=staff_space#*reduction;

	set_char_box(0.0reduced_il#, 1.2reduced_il#,
		     0.8reduced_il#, 1.5reduced_il#);

	stem_width# = 0.17 reduced_il#;
	height# = 1.5 reduced_il#;
	width# = 1.13 reduced_il#;
	apex_o# = 0.02 reduced_il#;
	hair# =  3 stafflinethickness#;
	define_pixels(reduced_il, stem_width, height, width, apex_o, hair);

	penpos1(2 stem_width, -142);
	z1l = (0.715 width, 0.742 height);
	penpos1'(hair, -90);
	z1'l = z1r;
	penpos2(1.179 stem_width, -142);
	z2l = (width, 0.466 height);
	penpos3(hair, 77);
	z3 = (0.764 width, 0.067 height); 
	z4 = (0.59 width, -apex_o);
	penpos5(1.179 stem_width, 32);
	z5l=(0, 0.457 height);
	penpos6(hair, -56.5);
	z7 = (x4 - 0.843 stem_width, height + apex_o);
	z7 - z6l = whatever * dir33.5;
	penpos8(1.286 stem_width, -130);
	z8r = (0.715 width, 0.742 height) + (-apex_o, apex_o);
	z6r - z8r = whatever * (z7 - z8l);
	filldraw
		z1'r{dir45} .. z2r{down} .. z3r{dir207} .. z5r{up} ..
		z6r{z7-z6l} & z6r -- z8r -- z8l -- z7 --- z6l ...
		z5l{down} .. z4{right} .. z3l{dir27} .. z2l{up} ..
		z1l{1/3[z6l,z7]-z1l} & z1l -- z1r -- z1'r & cycle
		shifted (-exact_center + (0, -0.75reduced_il));

	penpos9(stem_width, 0);
	x9r = x4; y9 = 0.3 height;

	pickup pencircle
		scaled stem_width
		rotated 45;
	draw	z9 -- (z9 + (0, -0.4reduced_il))
		shifted (-exact_center + (0, -0.75reduced_il));

	pickup pencircle
		xscaled stem_width
		yscaled hair
		rotated 30;

	draw halfcircle
		scaled 0.5 reduced_il
		rotated -90
		shifted z8
		shifted (0, 0.25reduced_il)
		shifted (-exact_center + (0, -0.75reduced_il));

	draw halfcircle
		scaled 0.4 reduced_il
		rotated 90
		shifted (z8 + (0, 0.45 reduced_il))
		shifted (0, 0.25reduced_il)
		shifted (-exact_center + (0, -0.75reduced_il));
enddef;


fet_beginchar("mensural g clef", "mensural_g", "mensgclef")
	if test = 1:
		draw_staff(-1,3, 0.0);
	fi;
	draw_mensural_g_clef((0,0), 1.0);
fet_endchar;
fet_beginchar("mensural g clef", "mensural_g_change", "cmensgclef")
	draw_mensural_g_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# = stafflinethickness# * reduction;
	define_pixels(reduced_il, reduced_slt);

	set_char_box(0.90 reduced_il#, 0.30 reduced_il#,
		     0.55 reduced_il#, 3.80 reduced_il#);

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

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

	za = exact_center + (+0.00 reduced_il, +0.00 reduced_il);
	zb = exact_center + (+0.20 reduced_il, +1.20 reduced_il);
	zc = exact_center + (-0.10 reduced_il, +2.00 reduced_il);
	zd = exact_center + (-0.50 reduced_il, +3.00 reduced_il);
	ze = exact_center + (+0.00 reduced_il, +3.70 reduced_il);
	zf = exact_center + (+0.20 reduced_il, +3.00 reduced_il);
	zg = exact_center + (-0.20 reduced_il, +2.00 reduced_il);
	zh = exact_center + (-0.50 reduced_il, +1.70 reduced_il);
	zi = exact_center + (-0.80 reduced_il, +0.75 reduced_il);
	zj = exact_center + (-0.60 reduced_il, +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;

	za = exact_center + (+0.25 reduced_il, +0.45 reduced_il);
	zb = exact_center + (-0.25 reduced_il, +0.45 reduced_il);
	zc = exact_center + (-0.25 reduced_il, -0.45 reduced_il);
	zd = exact_center + (+0.25 reduced_il, -0.45 reduced_il);
	ze = exact_center + (+0.30 reduced_il, +0.00 reduced_il);
	zf = exact_center + (+0.00 reduced_il, +0.00 reduced_il);

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


fet_beginchar("petrucci g clef", "petrucci_g", "petruccigclef")
	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", "cpetruccigclef")
	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;

	za = exact_center + (+0.30reduced_il, +.45reduced_il);
	zb = exact_center + (+0.20reduced_il, +.45reduced_il);
	zc = exact_center + (-0.10reduced_il, +.60reduced_il);
	zd = exact_center + (-0.40reduced_il, +.45reduced_il);
	ze = exact_center + (-0.40reduced_il, -.45reduced_il);
	zf = exact_center + (-0.20reduced_il, -.55reduced_il);
	draw za .. zb .. zc -- zd -- ze -- zf;

	set_char_box(0.60reduced_il#, 0.50reduced_il#,
		     0.70reduced_il#, 0.75reduced_il#);
enddef;


fet_beginchar("Hufnagel do clef", "hufnagel_do", "hufnageldoclef")
	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", "chufnageldoclef")
	draw_hufnagel_do_clef((1.3 staff_space#,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;

	za = exact_center + (+0.30reduced_il, +0.70reduced_il);
	zb = exact_center + (+0.20reduced_il, +0.70reduced_il);
	zc = exact_center + (-0.10reduced_il, +0.85reduced_il);
	zd = exact_center + (-0.40reduced_il, +0.70reduced_il);
	ze = exact_center + (-0.40reduced_il, -1.10reduced_il);
	draw za .. zb .. zc -- zd -- ze;

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

	zg = exact_center + (+0.30reduced_il, -0.05reduced_il);
	zh = exact_center + (+0.20reduced_il, -0.05reduced_il);
	zi = exact_center + (-0.10reduced_il, +0.10reduced_il);
	zj = exact_center + (-0.40reduced_il, -0.05reduced_il);
	draw zg .. zh .. zi -- zj;

	set_char_box(0.60reduced_il#, 0.60reduced_il#,
		     1.15reduced_il#, 1.00reduced_il#);
enddef;


fet_beginchar("Hufnagel fa clef", "hufnagel_fa", "hufnagelfaclef")
	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", "chufnagelfaclef")
	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.60reduced_il#, 0.60reduced_il#,
		     1.15reduced_il# + 2staff_space#, 0.75reduced_il#);
enddef;


fet_beginchar("Hufnagel do/fa clef", "hufnagel_do_fa", "hufnageldofaclef")
	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",
	      "chufnageldofaclef")
	draw_hufnagel_do_fa_clef((0,0), .8);
fet_endchar;


fet_endgroup ("clefs")
