1 % feta-klef.mf -- implement Clefs -*-Fundamental-*-
3 % part of LilyPond's pretty-but-neat music font
5 % source file of the Feta (not the Font-En-Tja) music font
7 % (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 % Jan Nieuwenhuizen <janneke@gnu.org>,
9 % Juergen Reuter <reuter@ipd.uka.de>
12 fet_begingroup ("clefs");
15 % [Wanske] says the bulbs should be positioned about 1/4 right of the
18 % TODO: The hair-curve at z6r looks a little awkward.
21 def draw_c_clef (expr reduction) =
22 save hair, norm, reduced_ss, right_edge;
25 reduced_ss# = staff_space# * reduction;
26 norm# := 2/3 reduced_ss#;
27 hair# := 0.06 reduced_ss# + 0.5 linethickness#;
28 right_edge# = 15/4 norm# + 2 hair#;
29 define_pixels (norm, reduced_ss, right_edge);
30 define_whole_vertical_blacker_pixels (hair);
32 set_char_box (0, right_edge#, 2 reduced_ss#, 2 reduced_ss#);
34 % make unreduced glyph fit exactly into five staff lines
36 h := d := 2 staff_space_rounded;
39 % assure that the gap between the left and right stem
40 % has the same number of pixels as the thickness of the right
42 draw_block ((0, -d + feta_shift),
43 (3/4 norm + 1/2 hair, h));
44 draw_block ((3/4 norm + 1/2 hair + hround (3/2 hair), -d + feta_shift),
45 (3/4 norm + 1/2 hair + 2 hround (3/2 hair), h));
52 xoff = 3/4 norm + 1/2 hair + 2 hround (3/2 hair);
53 z5l = (xoff - 3/4 hair, 0);
56 penpos1 (hair - pen_top - pen_bot, -90);
57 top z1l = (xoff + norm + hair, h);
59 penpos2 (hround (norm - 3/2 hair) - pen_lft - pen_rt, 180);
62 penpos3 (hair - pen_top - pen_bot, 90);
63 bot z3l = ((right_edge - xoff) / 2 + xoff,
64 vround (.5 norm - 1.5 hair));
66 penpos4 (hair - pen_lft - pen_rt, 0);
67 top z4 = (xoff + 1/2 norm + 1/2 hair,
68 vfloor (reduced_ss - linethickness - .2 hair));
70 bot z6 = (xoff + 3/4 norm, vround (.5 norm - .5 hair));
83 ..tension t.. flare_path (top z1l, 180, 90,
84 hair, hfloor (norm - 1/2 hair), -1)
85 ..tension t.. z2l{down}
90 filldraw pat shifted (0, feta_shift)
91 -- reverse pat yscaled -1 shifted (0, -feta_eps)
94 penlabels (1, 2, 3, 4, 5, 6);
96 % ugh, should be bulb, not flare?
98 draw_staff (-2, 2, 0);
102 fet_beginchar ("C clef", "C");
107 fet_beginchar ("C clef", "C_change");
115 % Insert a brushed piece of the path, and draw the rest of the bulb
118 % The bulb has circular form. Neat merging of the bulb and brushed path
119 % is done by playing with tension.
122 def new_bulb (expr start_point, start_angle,
124 end_point, end_angle,
125 big_radius, bulb_radius, flare,
126 direction, turning_dir) =
128 save pat, before, after;
131 path pat, before, after;
136 center = outer_tangent_point
137 + big_radius * dir (0)
138 % + (big_radius - bulb_radius) * dir (-turning_dir * 90)
141 z1' = center + bulb_radius * dir (turning_dir * 180);
142 z2' = outer_tangent_point + flare * dir (0);
143 z3' = center + bulb_radius * dir (0);
144 z4' = center + bulb_radius * dir (turning_dir * 90);
145 z5' = center - 0.5 [big_radius, bulb_radius] * dir (turning_dir * 90);
147 labels (1', 2', 3', 4', 5');
149 before := z3'{dir (turning_dir * 90)}
152 .. z1'{-dir (turning_dir* 90)};
153 after := z2'{dir (turning_dir * 90)}
154 .. end_point{dir (end_angle)};
155 (u, v) = before intersectiontimes after;
157 pat := start_point{dir (start_angle)}
158 .. outer_tangent_point{dir (-turning_dir * 90)}
161 .. subpath (0, u) of before
162 .. subpath (v, infinity) of after;
173 % There is some variation in the shape of bass clefs.
175 % * In some clefs the size of the swoosh tip almost reaches the
176 % bottom staff line; in some it crosses the 2nd line from the bottom
177 % with a small overshoot.
179 % The most popular design is where the X part of the tip is aligned
180 % with the left bulb boundary, and the Y part ends on the 2nd
181 % staffline exactly. This is what we do.
183 % * The diameter of the bulb is the width of the open space.
185 % * The vertical center of the bulb can be on or slightly above the
188 % * The vertical position of the dots can be symmetrical around the
189 % staffline, centered in the staff space. The Baerenreiter SCS has
190 % the bottom dot raised by approximately 0.1 staff space.
192 % * Uncarefully set music may have overshoots at the top. We have none.
194 % * It is not exactly clear where the vertical tangent at the right
195 % of the swoosh should be.
198 def draw_bass_clef (expr exact_center, reduction) =
199 save reduced_ss, swoosh_width;
200 save right_thickness, right_offset, tip_protude;
201 save dot_diam, bulb_y_offset, bulb_flare;
204 reduced_ss# = staff_space# * reduction;
205 2.2 dot_diam# = reduction * (staff_space# - stafflinethickness#);
206 right_thickness# = 0.37 staff_space# + 1.2 linethickness#;
207 swoosh_width# = 2.1 reduced_ss#;
208 define_pixels (swoosh_width);
209 define_whole_pixels (reduced_ss);
210 define_whole_blacker_pixels (dot_diam, right_thickness);
212 right_offset = 0.05 staff_space;
213 bulb_y_offset := 0.075 staff_space;
214 bulb_flare := 2.5 linethickness;
215 % tip_protude := (-linethickness, -.2 staff_space);
216 tip_protude := (0, 0);
218 set_char_box (-xpart exact_center,
219 xpart exact_center + swoosh_width# + 7/12 reduced_ss#,
220 -ypart exact_center + 2.5 reduced_ss#,
221 ypart exact_center + reduced_ss#);
229 y2l := vround_pixels (reduced_ss# + 0.5 linethickness#);
230 y2l - y2r = linethickness;
232 x3l - x1 = swoosh_width;
233 x3l - x3r = right_thickness;
235 % optical correction: the top dot seems farther away if y3l = 0.
238 z4 = -(0, 2.0 reduced_ss) + tip_protude;
240 penpos3 (whatever, 185);
241 penpos4 (linethickness, 135);
243 fill new_bulb (z2l, 180, z1, z2r, 0,
244 0.45 reduced_ss, 0.4 reduced_ss,
247 .. {curl 0}simple_serif (z4r, z4l, 90){curl 0}
249 ..tension 0.9.. cycle;
251 pickup pencircle scaled dot_diam;
253 lft x5 = hround (x3l + 1/3 reduced_ss - dot_diam / 2);
254 bot y5 = vfloor (.5 reduced_ss - dot_diam / 2);
258 y5 := y5 + feta_shift;
263 penlabels (1, 2, 3, 4, 5, 6);
265 draw_staff (-3, 1, 0);
269 fet_beginchar ("F clef ", "F");
270 draw_bass_clef ((0, 0), 1.0);
274 fet_beginchar ("F clef (reduced)", "F_change");
275 draw_bass_clef ((0, 0), 0.8);
281 % Inspired by Baerenreiter
284 % Beste lezers, kijk,
286 % Een bolletje hebben we bij toeval allemaal wel eens getekend, maar begint u
287 % toch eenvoudig. Eerst een eenvoudig kruis of herstellingsteken
288 % en via de dubbelslag naar een voorzichtig vlaggetje, en heb geduld!
289 % Ikzelf heb bijvoorbeeld over mijn eerste gave G-sleutel
290 % 35 kilobyte metafont, 12 patchlevels, 0 vriendinnen en 45 dagen gedaan
292 % -- vrij naar Van Kooten & De Bie
295 def debugfill = fill enddef;
297 def draw_gclef (expr reduction) =
298 save reduced_ss, downstroke_dir, downstroke_angle, center;
299 save breapth_factor, inner_thick_end, thinness, thickness, thinnib;
300 save start_angle, inner_start_angle, thinness;
301 save upward_swoosh_angle, bot_angle;
304 pair downstroke_dir, center;
306 reduced_ss# = staff_space# * reduction;
307 define_pixels (reduced_ss);
309 thinness = 0.095 staff_space + 0.75 linethickness;
310 downstroke_dir = unitvector (14, -75);
311 downstroke_angle = angle downstroke_dir;
312 bot_angle = -180; % downstroke_angle - 87
314 upward_swoosh_angle = 132;
317 breapth_factor = 21.0 /14;
318 inner_thick_end = 45;
319 inner_start_angle = downstroke_angle - 43;
320 thickness = .32 reduced_ss + 1.1 linethickness;
324 set_char_box (0, 1.71 * breapth_factor * reduced_ss#,
325 2.6 * reduced_ss#, 5 * reduced_ss#);
327 center := (breapth_factor * reduced_ss, 0);
329 z1 = center + whatever * dir (inner_start_angle);
330 x1 = xpart center - .28 reduced_ss;
331 penpos1 (thinnib, inner_start_angle);
334 y2r = vround_pixels (reduced_ss# + .5 stafflinethickness#);
335 penpos2 (thickness, 90);
337 z3 = (z4 - center) rotated inner_thick_end + center;
338 penpos3 (thinnib, -90 + inner_thick_end);
340 x4 = xpart center - .1 reduced_ss;
341 y4r = -y2r + feta_shift;
342 penpos4 (thinnib, -90);
344 x5r = -breapth_factor * reduced_ss + xpart center;
345 y5r = .37 reduced_ss + ypart center;
346 penpos5 (thickness, upward_swoosh_angle);
348 z6 = center + whatever * downstroke_dir;
349 y6 = ypart center + 2 reduced_ss;
350 % penpos6 is computed later
352 z7l - z6 = whatever * (z5 - z6) ;
353 y7l = 3.5 reduced_ss;
354 penpos7 (thickness, upward_swoosh_angle);
357 top y9l = 5 reduced_ss;
358 penpos9 (1.45 thickness, -70);
360 x11 - x13r = 1.5 reduced_ss + 0.5 thinnib;
361 y11 = ypart center - 47/28 reduced_ss;
362 y12 = ypart center - 71/28 reduced_ss;
363 y13 = .48 [y12, y4r];
364 x12r = xpart (.45 [z13r, z11] + .75 reduced_ss * downstroke_dir);
366 % z10 = center + whatever * dir (downstroke_angle - 1.5);
367 x10 = x6 - 2 thinnib;
368 y10 = ypart center + 3.5 reduced_ss;
369 y10l - y10r = 1.0 thickness;
370 z10r - z10l = .7 thinnib * dir (downstroke_angle + 90)
371 + whatever * downstroke_dir;
372 z10 = .5 [z10l, z10r];
374 z11 = center + whatever * downstroke_dir + (-0.05 reduced_ss, 0);
375 penpos11 (thinnib, start_angle + 90);
377 penpos12 (thinnib, bot_angle + 90);
378 penpos13 (thinnib + 0.14 staff_space, 180);
380 % this auxiliary point ensures good contour overlapping
381 z8 = .5 [z9l, z9r] + .25 ((z9r - z9l) rotated -90);
384 z20 = z9l - (0, .25 blot_diameter);
385 penpos20(blot_diameter, 0);
391 .. tension 1.07 % inside curve
396 & simple_serif (z20r,z20l, 60)
398 -- z9r % {dir (downstroke_angle + 0)}
399 ..tension 0.8.. z7r{down}
405 -- simple_serif (z1r, z1l, 80)
407 ..tension 0.85.. cycle;
412 .. z11{dir (start_angle)};
414 penpos6 (thinnib, angle (direction 1 of pat) + 90);
416 % two auxiliary points to simulate `draw' with `penstroke'
417 z10' = point 0.5 of pat;
418 penpos10' (thinnib, angle (direction 0.5 of pat) + 90);
420 z11' = point 1.5 of pat;
421 penpos11' (thinnib, angle (direction 1.5 of pat) + 90);
432 .. z12e{dir (bot_angle)};
434 fill new_bulb (z12r, bot_angle, z13r, z12l, bot_angle + 180,
435 0.45 reduced_ss, 0.38 reduced_ss,
436 thinnib + .05 staff_space, 1, -1)
439 penlabels (range 1 thru 20);
440 penlabels (10', 11');
442 draw_staff (-1, 3, 0);
446 fet_beginchar ("G clef", "G");
451 fet_beginchar ("G clef", "G_change");
462 % The percussion clef extent is not coincident with its bbox, since
463 % the percussion clef needs more space in front than a normal clef.
466 def draw_percussion_clef (expr reduction) =
467 save reduced_ss, razt;
469 reduced_ss# = staff_space# * reduction;
470 define_pixels (reduced_ss);
472 set_char_box (-.67 reduced_ss#, 2.0 reduced_ss#,
473 reduced_ss#, reduced_ss#);
475 razt := hround (0.45 reduced_ss);
479 draw_block ((-b, -d), (-b + razt, h));
480 draw_block ((w - razt, -d), (w, h));
482 draw_staff (-3, 1, 1);
486 fet_beginchar ("percussion clef", "percussion");
487 draw_percussion_clef (1.0);
491 fet_beginchar ("percussion clef (reduced)", "percussion_change");
492 draw_percussion_clef (.8);
496 def draw_tab_T (expr pos, siz, slant) =
503 vx = (xpart siz) * dir 0;
504 vy = (ypart siz) * dir 90;
506 penpos1 (.75 penh, 100);
507 z1 = z2 + (1/6 * vx - .15 * vy);
508 penpos2 (hround (.9 penw), 0);
509 x2l = hround xpart (pos + .75 vy);
510 y2l = ypart (pos + .75 vy);
511 penpos3 (penh, -100);
512 z3l = pos + .4 vx + vy;
514 z4 = -.1 vy + .5 [z3, z5];
515 penpos5 (.8 penh, -30);
516 x5r = xpart (pos + siz);
517 y5l = ypart (pos + siz);
519 penpos10 (penw, 170);
520 z10 = pos + .55 vx + .9 vy;
521 penpos11 (.75 [penh, penw], 170);
522 z11 = z10 - .5 vy + .025 vx;
523 penpos12 (penh, 100);
524 z12l = (xpart .5 [z13, z11], ypart (pos - .025 * siz));
525 penpos13 (.75 penh, 60);
526 z13 = pos + .2 vx + .15 vy;
528 % penlabels (range 1 thru 13);
535 slanted slant shifted (slant * -ypart pos, 0);
537 soft_end_penstroke (z10e
540 ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
541 slanted slant shifted (slant * -ypart pos, 0);
546 def draw_tab_A (expr pos, siz, slant) =
554 vx = (xpart siz) * dir 0;
555 vy = (ypart siz) * dir 90;
557 penpos1 (.75 penh, -110);
560 z2r = (.5 [x1, x3], ypart pos);
561 penpos3 (.25 [penh, penw], -30);
562 z3 = (.45 [x2, x4], .15 [y2, y4]);
563 penpos4 (1 [penh, penw], 0);
564 z4 = pos + .5 vx + .975 vy;
566 penpos5 (1 [penh, penw], -180);
568 penpos6 (.2 [penh, penw], -150);
569 z6l = (.8 [x5l, x7l], .9 [y5l, y7l]);
571 z7r = (.5 [x6, x8], ypart pos);
572 penpos8 (.75 penh, -70);
573 z8r = (xpart (pos + siz), y7r + .075 ypart (siz));
579 penpos10 (penh, angle (direction 1.2 of pat) - 180);
580 z10 = point 1.2 of pat;
581 penpos11 (.9 penh, -90);
582 z11 = .4 [z10, z6] - 0.05 vy;
583 penpos12 (.75 penh, -75);
584 z12 = .3 [z11, z6] + 0.02 vy;
586 % penlabels (range 1 thru 12);
588 soft_penstroke (z1e{(z1r - z1l) rotated 90}
592 slanted slant shifted (slant * -ypart pos, 0);
594 soft_end_penstroke (z5e
597 .. z8e{(z8r - z8l) rotated 90})
598 slanted slant shifted (slant * -ypart pos, 0);
600 soft_end_penstroke (z10e
603 slanted slant shifted (slant * -ypart pos, 0);
608 def draw_tab_B (expr pos, siz, slant) =
615 vx = (xpart siz) * dir 0;
616 vy = (ypart siz) * dir 90;
618 penpos1 (.75 penh, 100);
619 z1 = z2 + (.15 * vx - .1 * vy);
620 penpos2 (hround (.9 penw), 0);
621 x2l = hround xpart (pos + .75 vy);
622 y2l = ypart (pos + .75 vy);
623 penpos3 (penh, -100);
624 z3l = pos + .4 vx + 1.05 vy;
625 penpos4 (.8 [penh, penw], -180);
626 z4 = (xpart (pos + .75 siz), .5 [y3, y5]);
627 penpos5 (.8 penh, 90);
628 z5 = (.5 [x10, x4], ypart (pos + .55 siz));
630 penpos6 (.8 penh, 270);
633 z7l = (xpart (pos + siz), .5 [y6, y8]);
634 penpos8 (.8 penh, 45);
635 z8 = .5 [z12l, z11l] + .15 vx - .05 vy;
637 penpos10 (.75 [penh, penw], 170);
638 z10 = pos + .375 vx + vy;
639 penpos 11 (.8 [penh, penw], 150);
640 z11 = z10 - .5 vy + .04 vx;
641 penpos12 (penh, 100);
642 z12l = (xpart .5 [z13, z11], ypart pos);
643 penpos13 (.75 penh, 60);
644 z13 = pos + .1 vx + .15 vy;
646 % penlabels (range 1 thru 13);
653 slanted slant shifted (slant * -ypart pos, 0);
655 soft_end_penstroke (z6e{right}
657 .. z8e{(z8r - z8l) rotated 90})
658 slanted slant shifted (slant * -ypart pos, 0);
660 soft_end_penstroke (z10e
663 ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
664 slanted slant shifted (slant * -ypart pos, 0);
669 def draw_tab_clef (expr reduction) =
670 save reduced_ss, letterheight, penw, penh;
672 reduced_ss# = staff_space# * reduction;
673 letterheight# = 1.8 reduced_ss#;
674 define_pixels (reduced_ss, letterheight);
676 set_char_box (-.2 reduced_ss#, 2.8 reduced_ss#,
677 1.6 letterheight#, 1.6 letterheight#);
679 penw = .45 reduced_ss;
680 penh = .2 reduced_ss;
682 draw_tab_T ((-b + .15 reduced_ss, h - letterheight),
683 (2.1 reduced_ss, letterheight), 0.2);
684 draw_tab_A ((-b - .05 reduced_ss, -.5 letterheight +.15 reduced_ss),
685 (2.2 reduced_ss, letterheight), 0.4);
686 draw_tab_B ((-b + .025 reduced_ss, -d),
687 (2.1 reduced_ss, letterheight), 0.25);
689 draw_staff (-3, 2, 0.5);
693 fet_beginchar ("tab clef", "tab");
698 fet_beginchar ("tab clef (reduced)", "tab_change");
702 fet_endgroup ("clefs");