
fet_begingroup ("brackettips");

def draw_bracket(expr thick_sharp, width_sharp, updown) =
begingroup;
	save p, thin, thick, flattening, width, hair, flare;
 	path p;
	pair tipdir;

	flattening = 0.72;
	thick# = thick_sharp;
	flare# = flattening * width#;
	width# = width_sharp;

	define_pixels (thick, width, flare);
	if updown = 1:
	        set_char_box (0, width#,
			      .5 thick# , flare#);
	else:
	        set_char_box (0, width#,
				flare#, .5 thick#);
	fi;

	thin = 2 linethickness;
	hair = 1.25 linethickness;

	pickup pencircle scaled thin;
	z7 = z1 + (3/4 thick,0); 
	z2 = z4r + (thin, 0);


	penpos3(thin, 0);
	penpos4(thin, 90);

	z3 = z4;

	top y3 = 0.5 thick;
	lft x3 = 0.0;
	x1 = x3l;
	y1 = -0.5 thick;


	z8 = .5  [z2, z7];
	top y5 = flare;
	rt x5 = width;

	save leave_angle;
	leave_angle = 10;

	p := z8{dir(leave_angle)}
		.. z5{curl 0};
	tipdir := (direction 1 of p);

	save tip_angle;
	tip_angle := 50;
	penpos5 (hair, tip_angle);
	penpos6 (hair, 90 + tip_angle);

	z5 = z6;

	pickup pencircle scaled 1;

	%draw p;
	fill
	%draw
	(z1{up} .. z3l{up}
		.. z4r{right}
		.. z2{right}
		.. z6r{tipdir}
		.. z5r .. z6l{-tipdir}
		.. z7{dir(180 + leave_angle)} & z7 .. z1{left} & cycle)
		 yscaled updown;


	if updown = 1:
		penlabels (1,2,3,4,5,6,7);
	fi;

endgroup;
enddef;

fet_beginchar ("bracket tip up", "up");
   draw_bracket (0.45 staff_space#, 1.9 staff_space#, 1);
fet_endchar;

fet_beginchar ("bracket tip down", "down"); 
   draw_bracket (0.45 staff_space#, 1.9 staff_space#, -1);
fet_endchar;

fet_endgroup ("brackettips");
