]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-clefs.mf
d96f5f399dbdcd28e24cb9109431dd0babfc498f
[lilypond.git] / mf / feta-clefs.mf
1 % Feta (not the Font-En-Tja) music font --  implement Clefs -*-Fundamental-*-
2 % This file is part of LilyPond, the GNU music typesetter.
3 %
4 % Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>,
5 % Jan Nieuwenhuizen <janneke@gnu.org>,
6 % Juergen Reuter <reuter@ipd.uka.de>
7 %
8 % The LilyPond font is free software: you can redistribute it and/or modify
9 % it under the terms of the GNU General Public License as published by
10 % the Free Software Foundation, either version 3 of the License, or
11 % (at your option) any later version, or under the SIL Open Font License.
12 %
13 % LilyPond is distributed in the hope that it will be useful,
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 % GNU General Public License for more details.
17 %
18 % You should have received a copy of the GNU General Public License
19 % along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
20
21
22 fet_begingroup ("clefs");
23
24
25 %
26 % New bulb routine:
27 %
28 % Insert a brushed piece of the path, and draw the rest of the bulb
29 % separately.
30 %
31 % The bulb has circular form.  Neat merging of the bulb and brushed path
32 % is done by playing with tension.
33 %
34
35 def new_bulb (expr start_point, start_angle,
36               outer_tangent_point,
37               end_point, end_angle,
38               big_radius, bulb_radius, flare,
39               direction, turning_dir) =
40 begingroup;
41         save pat, before, after;
42         save center;
43         save u, v;
44         path pat, before, after;
45         pair center;
46
47         clearxy;
48
49         center = outer_tangent_point
50                  + big_radius * dir (0);
51 %                + (big_radius - bulb_radius) * dir (-turning_dir * 90)
52
53         z1' = center + bulb_radius * dir (turning_dir * 180);
54         z2' = outer_tangent_point + flare * dir (0);
55         z3' = center + bulb_radius * dir (0);
56         z4' = center + bulb_radius * dir (turning_dir * 90);
57         z5' = center - 0.5 [big_radius, bulb_radius] * dir (turning_dir * 90);
58
59         labels (1', 2', 3', 4', 5');
60
61         before := z3'{dir (turning_dir * 90)}
62                   .. z4'{-dir (0)}
63                   ..tension 1.1.. z1'{-dir (turning_dir* 90)};
64         after := z2'{dir (turning_dir * 90)}
65                  .. end_point{dir (end_angle)};
66         (u, v) = before intersectiontimes after;
67
68         pat := start_point{dir (start_angle)}
69                .. outer_tangent_point{dir (-turning_dir * 90)}
70                ..tension 1.02.. z5'{dir (0)}
71                .. subpath (0, u) of before
72                .. subpath (v, infinity) of after;
73
74         if direction = 0:
75                 pat := reverse pat;
76         fi
77
78 pat
79 endgroup
80 enddef;
81
82
83 %
84 % [Wanske] says the bulbs should be positioned about 1/4 right of the
85 % `arrow'.
86 %
87 % TODO: The hair-curve at z6r looks a little awkward.
88 %
89
90 def draw_c_clef (expr reduction) =
91         save hair, norm, reduced_ss, right_edge;
92         save xoff;
93
94         reduced_ss# = staff_space# * reduction;
95         norm# := 2/3 reduced_ss#;
96         hair# := 0.06 reduced_ss# + 0.5 linethickness#;
97         right_edge# = 15/4 norm# + 2 hair#;
98         define_pixels (norm, reduced_ss, right_edge);
99         define_whole_vertical_blacker_pixels (hair);
100
101         set_char_box (0, right_edge#, 2 reduced_ss#, 2 reduced_ss#);
102
103         % make unreduced glyph fit exactly into five staff lines
104         if reduction = 1:
105                 h := d := 2 staff_space_rounded;
106         fi;
107
108         % assure that the gap between the left and right stem
109         % has the same number of pixels as the thickness of the right
110         % stem
111         draw_block ((0, -d + feta_shift),
112                     (3/4 norm + 1/2 hair, h));
113         draw_block ((3/4 norm + 1/2 hair + hround (3/2 hair), -d + feta_shift),
114                     (3/4 norm + 1/2 hair + 2 hround (3/2 hair), h));
115
116         % assure symmetry
117         h := h - feta_shift;
118
119         pickup feta_fillpen;
120
121         xoff = 3/4 norm + 1/2 hair + 2 hround (3/2 hair);
122         z5l = (xoff - 3/4 hair, 0);
123         z5r = (x4, 0);
124
125         penpos1 (hair - pen_top - pen_bot, -90);
126         top z1l = (xoff + norm + hair, h);
127
128         penpos2 (hround (norm - 3/2 hair) - pen_lft - pen_rt, 180);
129         rt z2l = (w, h / 2);
130
131         penpos3 (hair - pen_top - pen_bot, 90);
132         bot z3l = ((right_edge - xoff) / 2 + xoff,
133                    vround (.5 norm - 1.5 hair));
134
135         penpos4 (hair - pen_lft - pen_rt, 0);
136         top z4 = (xoff + 1/2 norm + 1/2 hair,
137                   vfloor (reduced_ss - linethickness - .2 hair));
138
139         bot z6 = (xoff + 3/4 norm, vround (.5 norm - .5 hair));
140
141         save t;
142         t = 0.833;
143
144         save pat;
145         path pat;
146
147         pat = z5l{curl 1}
148               .. z4l{up}
149               .. z4r{down}
150               .. z3r{right}
151               ..tension t.. z2r{up}
152               ..tension t.. flare_path (top z1l, 180, 90,
153                                         hair, hfloor (norm - 1/2 hair), -1)
154               ..tension t.. z2l{down}
155               .. z3l{left}
156               .. z6
157               .. z5r{down};
158
159         filldraw pat shifted (0, feta_shift)
160                  -- reverse pat yscaled -1 shifted (0, -feta_eps)
161                  -- cycle;
162
163         penlabels (1, 2, 3, 4, 5, 6);
164
165         % ugh, should be bulb, not flare?
166
167         draw_staff_if_debugging (-2, 2);
168 enddef;
169
170
171 fet_beginchar ("C clef", "C");
172         draw_c_clef (1.0);
173 fet_endchar;
174
175
176 fet_beginchar ("C clef", "C_change");
177         draw_c_clef (.8);
178 fet_endchar;
179
180 def draw_varc_clef (expr reduction) =
181         save hair, norm, reduced_ss;
182         save thick, thin, upper_stroke;
183
184         path upper_stroke;
185
186         reduced_ss# = staff_space# * reduction;
187         norm# := 2/3 reduced_ss#;
188         hair# := 0.06 reduced_ss# + 0.5 linethickness#;
189         define_pixels (norm, reduced_ss);
190         define_whole_vertical_blacker_pixels (hair);
191
192         set_char_box (0, 2.25 reduced_ss#, 2 reduced_ss#, 2 reduced_ss#);
193
194         % make unreduced glyph fit exactly into five staff lines
195         if reduction = 1:
196                 h := d := 2 staff_space_rounded;
197         fi;
198
199         % assure that the gap between the left and right stem
200         % has the same number of pixels as the thickness of the right
201         % stem
202         draw_block ((0, -d + feta_shift),
203                     (3/4 norm + 1/2 hair, h));
204         draw_block ((3/4 norm + 1/2 hair + hround (3/2 hair), -d + feta_shift),
205                     (3/4 norm + 1/2 hair + 2 hround (3/2 hair), h));
206
207         % assure symmetry
208         h := h - feta_shift;
209
210         thin := hround (3/2 hair);
211         thick := hround (3/4 norm);
212
213         x1'' = x8'' = x6'' - reduced_ss = 3/4 norm + 1/2 hair + 1.5 hround (3/2 hair);
214         x7'' = x6'' - 1/2 hair;
215         % the thick part of the c clef should be placed in the
216         % center of the forth staff space
217         y1'' = y2'' = 0.5 reduced_ss + thick/2;
218
219         y7'' = y8'' = y6'' - 1/2 hair = y1'' - thick;
220
221         x2'' = x3'' = x4'' = x6'' - thin;
222
223         y5'' = y3'' = y2'' + 0.6 reduced_ss;
224         x5'' = x6'';
225
226         y4'' = 2.25 reduced_ss;
227
228         upper_stroke := z1'' -- z2''
229                         -- new_bulb (z3'', 90, z4'', z5'', 270,
230                                      0.37 reduced_ss, 0.33 reduced_ss, thin, 1, -1)
231                         -- z6''{down} .. z7''{left}  -- z8'' -- cycle;
232
233         fill upper_stroke;
234         % the c clef parts should be symmetrical to the forth staff line
235         fill  upper_stroke yscaled -1;
236
237         penlabels (1'', 2'', 3'', 4'', 5'', 6'', 7'', 8'');
238
239         draw_staff_if_debugging (-2, 2);
240 enddef;
241
242
243 fet_beginchar ("Variant C clef", "varC");
244         draw_varc_clef (1.0);
245 fet_endchar;
246
247
248 fet_beginchar ("Variant C clef", "varC_change");
249         draw_varc_clef (0.8);
250 fet_endchar;
251
252
253 %
254 % There is some variation in the shape of bass clefs.
255 %
256 % * In some clefs the size of the swoosh tip almost reaches the
257 %   bottom staff line; in some it crosses the 2nd line from the bottom
258 %   with a small overshoot.
259 %
260 %   The most popular design is where the X part of the tip is aligned
261 %   with the left bulb boundary, and the Y part ends on the 2nd
262 %   staffline exactly.  This is what we do.
263 %
264 % * The diameter of the bulb is the width of the open space.
265 %
266 % * The vertical center of the bulb can be on or slightly above the
267 %   staff line.
268 %
269 % * The vertical position of the dots can be symmetrical around the
270 %   staffline, centered in the staff space.  The Baerenreiter SCS has
271 %   the bottom dot raised by approximately 0.1 staff space.
272 %
273 % * Uncarefully set music may have overshoots at the top.  We have none.
274 %
275 % * It is not exactly clear where the vertical tangent at the right
276 %   of the swoosh should be.
277 %
278
279 def draw_bass_clef (expr exact_center, reduction) =
280         save reduced_ss, swoosh_width;
281         save right_thickness, right_offset, tip_protrude;
282         save dot_diam, bulb_y_offset, bulb_flare;
283         pair tip_protrude;
284
285         reduced_ss# = staff_space# * reduction;
286         2.2 dot_diam# = reduction * (staff_space# - stafflinethickness#);
287         right_thickness# = 0.37 staff_space# + 1.2 linethickness#;
288         swoosh_width# = 2.1 reduced_ss#;
289         define_pixels (swoosh_width);
290         define_whole_pixels (reduced_ss);
291         define_whole_blacker_pixels (dot_diam, right_thickness);
292
293         right_offset = 0.05 staff_space;
294         bulb_y_offset := 0.075 staff_space;
295         bulb_flare := 2.5 linethickness;
296 %       tip_protrude := (-linethickness, -.2 staff_space);
297         tip_protrude := (0, 0);
298
299         set_char_box (-xpart exact_center,
300                       xpart exact_center + swoosh_width# + 7/12 reduced_ss#,
301                       -ypart exact_center + 2.5 reduced_ss#,
302                       ypart exact_center + reduced_ss#);
303
304         y1 = bulb_y_offset;
305         x1 = 0;
306
307         x2 = .5 [x1, x3];
308         x2l = x2r = x2;
309
310         y2l := vround_pixels (reduced_ss# + 0.5 linethickness#);
311         y2l - y2r = linethickness;
312
313         x3l - x1 = swoosh_width;
314         x3l - x3r = right_thickness;
315
316         % optical correction: the top dot seems farther away if y3l = 0.
317         y3l = right_offset;
318
319         z4 = -(0, 2.0 reduced_ss) + tip_protrude;
320
321         penpos3 (whatever, 185);
322         penpos4 (linethickness, 135);
323
324         fill new_bulb (z2l, 180, z1, z2r, 0,
325                        0.45 reduced_ss, 0.4 reduced_ss,
326                        bulb_flare, 1, 1)
327              .. z3r{down}
328              .. {curl 0}simple_serif (z4r, z4l, 90){curl 0}
329              .. z3l{up}
330              ..tension 0.9.. cycle;
331
332         pickup pencircle scaled dot_diam;
333
334         lft x5 = hround (x3l + 1/3 reduced_ss - dot_diam / 2);
335         bot y5 = vfloor (.5 reduced_ss - dot_diam / 2);
336         z6 = z5 yscaled -1;
337
338         % for symmetry
339         y5 := y5 + feta_shift;
340
341         drawdot z5;
342         drawdot z6;
343
344         penlabels (1, 2, 3, 4, 5, 6);
345
346         draw_staff_if_debugging (-3, 1);
347 enddef;
348
349
350 fet_beginchar ("F clef ", "F");
351         draw_bass_clef ((0, 0), 1.0);
352 fet_endchar;
353
354
355 fet_beginchar ("F clef (reduced)", "F_change");
356         draw_bass_clef ((0, 0), 0.8);
357 fet_endchar;
358
359
360
361 %
362 % Inspired by Baerenreiter
363 %
364 %
365 % Beste lezers, kijk,
366 %
367 % Een bolletje hebben we bij toeval allemaal wel eens getekend, maar begint u
368 % toch eenvoudig.  Eerst een eenvoudig kruis of herstellingsteken
369 % en via de dubbelslag naar een voorzichtig vlaggetje, en heb geduld!
370 % Ikzelf heb bijvoorbeeld over mijn eerste gave G-sleutel
371 % 35 kilobyte metafont, 12 patchlevels, 0 vriendinnen en 45 dagen gedaan
372 %
373 %  -- vrij naar Van Kooten & De Bie
374 %
375
376 def debugfill = fill enddef;
377
378 def draw_gclef (expr reduction, double_shift, extra_width) =
379         save reduced_ss, double_shift_ss, extra_width_ss;
380         save downstroke_dir, downstroke_angle, center;
381         save breapth_factor, inner_thick_end, thinness, thickness, thinnib;
382         save start_angle, inner_start_angle;
383         save upward_swoosh_angle, bot_angle;
384         save swirl, bulb, pat;
385         save corr_angle, corr, left_, right_, up_, down_, bot_angle_;
386         path swirl, bulb, pat;
387         pair downstroke_dir, center;
388         transform corr;
389         pair left_, right_, up_, down_;
390
391         reduced_ss# = staff_space# * reduction;
392         define_pixels (reduced_ss);
393
394         % G clef has now a smaller upper loop than it used to have.
395         % Too small loop in reduced clef (G_change) interacts badly
396         % with stafflines, so we make reduced clef's loop a bit bigger.
397         reduced_loop_correction := min (max (0.94, (0.6 + 0.46 * reduction)), 1);
398
399         thinness = 0.095 staff_space + 0.75 linethickness;
400         downstroke_dir = unitvector (14, -75);
401         downstroke_angle = angle downstroke_dir;
402         bot_angle = -180;               % downstroke_angle - 87
403
404         upward_swoosh_angle = 132;
405         start_angle = -97;
406
407         breapth_factor = 21/14;
408         inner_thick_end = 45;
409         inner_start_angle = downstroke_angle - 43;
410         thickness = .33 reduced_ss + 1.1 linethickness;
411
412         thinnib = thinness;
413
414         set_char_box (0, (1.71 * breapth_factor + double_shift + extra_width) * reduced_ss#,
415                       2.55 * reduced_ss#, 4.8 * reduced_ss# / reduced_loop_correction);
416
417         center := (breapth_factor * reduced_ss, 0);
418
419         z1 = center + whatever * dir (inner_start_angle);
420         x1 = xpart center - .28 reduced_ss;
421         penpos1 (thinnib, inner_start_angle);
422
423         x2r = xpart center;
424         y2r = vround_pixels (reduced_ss# + .5 stafflinethickness#);
425         penpos2 (thickness, 90);
426
427         z3 = (z4 - center) rotated inner_thick_end + center;
428         penpos3 (thinnib, -90 + inner_thick_end);
429
430         x4 = xpart center - .1 reduced_ss;
431         y4r = -y2r + feta_shift;
432         penpos4 (thinnib, -90);
433
434         x5r = -breapth_factor * reduced_ss + xpart center;
435         y5r = .37 reduced_ss + ypart center;
436         penpos5 (thickness, upward_swoosh_angle);
437
438         z6 = center + whatever * downstroke_dir + (-0.02, 0) * reduced_ss;
439         y6 = ypart center + 1.95 reduced_ss / reduced_loop_correction;
440         % penpos6 is computed later
441
442         z7l - z6 = whatever * (z5 - z6);
443         y7l = 3.38 reduced_ss / reduced_loop_correction;
444         penpos7 (thickness, upward_swoosh_angle);
445
446         x9 = .75 [x10, x7r];
447         top y9l = 4.78 reduced_ss / reduced_loop_correction;
448         penpos9 (1.45 thickness, -70);
449
450         x11 - x13r = 1.44 * reduced_ss + 0.5 thinnib;
451         y11 = ypart center - 45/28 reduced_ss;
452         y12 = ypart center - 69/28 reduced_ss;
453         y13 = .48 [y12, y4r];
454         x12r = xpart (.45 [z13r, z11] + .75 reduced_ss * downstroke_dir);
455
456 %       z10 = center + whatever * dir (downstroke_angle - 1.5);
457         x10 = x6 - 1.85 thinnib * reduction / reduced_loop_correction;
458         y10 = ypart center + 3.32 reduced_ss / reduced_loop_correction;
459         y10l - y10r = 1.0 thickness;
460         z10r - z10l = .7 thinnib * dir (downstroke_angle + 90)
461                       + whatever * downstroke_dir;
462         z10 = .5 [z10l, z10r];
463         z11 = center + whatever * downstroke_dir + (0.03 reduced_ss, 0);
464
465         penpos11 (thinnib, start_angle + 90);
466         penpos12 (thinnib, bot_angle + 90);
467         penpos13 (thinnib + 0.14 staff_space, 180);
468
469         % this auxiliary point ensures good contour overlapping
470         z8 = .5 [z9l, z9r] + .25 ((z9r - z9l) rotated -90);
471
472         z20 = z9l - (0, .25 blot_diameter);
473         penpos20 (blot_diameter, 0);
474
475         pat := z10{down}
476                .. z6
477                ..tension 1.1.. z11{dir (start_angle)};
478
479         penpos6 (thinnib, angle (direction 1 of pat) + 90);
480
481         % two auxiliary points to simulate `draw' with `penstroke'
482         z10' = point 0.3 of pat;
483         penpos10' (1.3 thinnib, angle (direction 0.3 of pat) + 50);
484
485         z11' = point 1.5 of pat + (0.033, -0.5) * reduced_ss;
486         penpos11' (thinnib, angle (direction 1.5 of pat) + 90);
487
488         z21l = z20l;
489         z21r = z9r;
490
491         % after computing all points, we want to rotate the clef
492         % rotating the whole picture won't work due to the complexity
493         % of the path and metafont's memory limitations, so we transform
494         % each point and draw the clef thereafter
495         corr_angle := 1.5;
496         corr := identity rotatedabout (center, -corr_angle);
497
498         bot_angle_ := bot_angle + corr_angle;
499
500         left_ := left rotated corr_angle;
501         right_ := right rotated corr_angle;
502         up_ := up rotated corr_angle;
503         down_ := down rotated corr_angle;
504
505         % transform points; we transform every point and save it
506         % to a shifted index range: z1 -> z101, z2 -> z102, etc.
507         for n := 1 upto 21:
508                 forsuffixes e := l,,r:
509                         z[n+100]e = z[n]e transformed corr;
510                 endfor
511         endfor
512
513         % transform helper points
514         for n := 10, 11:
515                 forsuffixes e := l,,r:
516                         z[n+100]'e = z[n]'e transformed corr;
517                 endfor
518         endfor
519
520         pat := z121l
521                .. z110l{down}
522                .. z110'l;
523
524         swirl := z102l{right}
525                  .. z103l
526                  .. z104l{left_}
527                  ..tension 1.07.. z105l{up_}% inside curve
528                  .. z107l{up_}
529                  ..tension 1.2.. z120r{curl 1}
530                  .. {direction 0 of pat}z120l
531                  -- z108
532                  -- z109r                       % {dir (downstroke_angle + 0)}
533                  ..tension 0.8.. z107r{down_}
534                  .. z105r{down_}
535                  .. z104r{right_}
536                  .. z103r
537                  .. z102r{left_}
538                  ..tension .95.. z101r
539                  -- simple_serif (z101r, z101l, 80)
540                  -- z101l
541                  ..tension 0.85.. cycle;
542         fill swirl;
543
544         penstroke z121e
545                   .. z110e{down_}
546                   .. z110'e
547                   .. z106e
548                   .. z111'e
549                   .. z111e{dir (-95 + corr_angle)}
550                   .. z112e{dir (bot_angle_)};
551
552         bulb := new_bulb (z112r, bot_angle_, z113r, z112l, bot_angle_ + 180,
553                           0.45 reduced_ss, 0.38 reduced_ss,
554                           thinnib + .05 staff_space, 1, -1)
555                 -- cycle;
556
557         fill bulb;
558
559         if double_shift <> 1:
560
561                 % transform helper points
562                 for n := 106, 110, 111, 112, 121:
563                         forsuffixes e := l,,r:
564                                 z[n+100]e = z[n]e shifted (double_shift * reduced_ss, 0);
565                         endfor
566                 endfor
567                 for n := 110, 111:
568                         forsuffixes e := l,,r:
569                                 z[n+100]'e = z[n]'e shifted (double_shift * reduced_ss, 0);
570                         endfor
571                 endfor
572
573                 fill swirl shifted (double_shift * reduced_ss, 0);
574                 penstroke z221e
575                           .. z210e{down_}
576                           .. z210'e
577                           .. z206e
578                           .. z211'e
579                           .. z211e{dir (-95 + corr_angle)}
580                           .. z212e{dir (bot_angle_)};
581                 fill bulb shifted (double_shift * reduced_ss, 0);
582         fi;
583
584         penlabels (range 101 thru 121);
585         penlabels (110', 111');
586
587         draw_staff_if_debugging (-1, 3);
588 enddef;
589
590
591 fet_beginchar ("G clef", "G");
592         draw_gclef (1.0, 0, 0);
593 fet_endchar;
594
595
596 fet_beginchar ("G clef", "G_change");
597         draw_gclef (0.8, 0, 0);
598 fet_endchar;
599
600
601 fet_beginchar ("double G clef", "GG");
602         draw_gclef (1.0, 1.5, 0);
603 fet_endchar;
604
605
606 fet_beginchar ("double G clef", "GG_change");
607         draw_gclef (0.8, 1.5, 0);
608 fet_endchar;
609
610 def draw_tenor_extension (expr reduction) =
611         save reduced_ss, thick, thin, upper_stroke, ne_beam_dir, nw_dist;
612         path upper_stroke;
613         pair ne_beam_dir, nw_dist;
614
615         reduced_ss# = staff_space# * reduction;
616         define_pixels (reduced_ss);
617
618         thin := hround (0.17 reduced_ss);
619         thick := hround (0.51 reduced_ss);
620
621         % the slanted left edge should protrude the g clef by a
622         % fixed amount relative to the width of the g clef:
623         x1'' = x6'' - 1.8 reduced_ss - 0.5 staff_space = 0.62 reduced_ss * reduction;
624         x8'' = x1'' - 2 thin;
625         x2'' = x3'' = x4'' = x6'' - thin;
626         x5'' = x6'';
627         x7'' = x6'' - 1/3 thin;
628         % the thick part of the c clef should be placed in the
629         % center of the forth staff space
630         y1'' = y2'' = 2.5 staff_space + thick/2;
631         y7'' =  y8'' = y6'' - 1/3 thin = y1'' - thick;
632         y5'' = y3'' = y2'' + reduced_ss;
633         y4'' = 4.5 reduced_ss;
634
635         upper_stroke := z2''
636                         -- new_bulb (z3'', 90, z4'', z5'', 270,
637                                      0.35 reduced_ss, 0.22 reduced_ss, thin, 1, -1)
638                         -- z6''{down} .. z7''{left};
639
640         % z1'' and z8'' are helper points that are responsible for
641         % hiding the lower left slant in the g clef's stroke
642         % z9'' and z10'' are computed to obtain nice rounded corners
643
644         pickup pencircle scaled 2/3 thin;
645         lft x9'' = x1'';
646         lft x10'' = x8'';
647
648         top y9'' = y1'';
649         bot y10'' = y8'';
650
651         ne_beam_dir = unitvector (z9'' - z10'');
652         nw_dist = (ne_beam_dir rotated 90) * 1/3 thin;
653
654         fill (z9''+nw_dist){ne_beam_dir}
655              ... top z9''{right}
656              -- upper_stroke
657              -- bot z10''{left}
658              ... (z10''+nw_dist){ne_beam_dir}
659              -- cycle;
660
661         % the slanted edge of the lower hook must not be visible, so it is
662         % shifted accordingly in x direction;
663         z1''' = z1'' shifted (staff_space - 0.9 reduced_ss, - staff_space);
664         z8''' = z8'' shifted (staff_space - 0.9 reduced_ss, - staff_space);
665
666         % the visible c clef parts should be symmetrical to the forth staff line
667         fill z1'''
668              -- reverse upper_stroke yscaled -1 shifted (0, 4 staff_space)
669              -- z8''' -- cycle;
670
671         penlabels (1''',2'',3'',4'',5'',6'',7'',8''',9'',10'');
672
673         draw_staff_if_debugging (-1, 3);
674 enddef;
675
676 fet_beginchar ("Tenor G clef", "tenorG");
677         draw_gclef (1.0, 0, 0.75);
678         draw_tenor_extension (1.0);
679 fet_endchar;
680
681
682 fet_beginchar ("Tenor G clef", "tenorG_change");
683         draw_gclef (0.8, 0, 0.75);
684         draw_tenor_extension (0.8);
685 fet_endchar;
686
687 %%%%
688 %
689 % PERCUSSION
690 %
691
692 %
693 % The percussion clef extent is not coincident with its bbox, since
694 % the percussion clef needs more space in front than a normal clef.
695 %
696
697 def draw_percussion_clef (expr reduction) =
698         save reduced_ss, razt;
699
700         reduced_ss# = staff_space# * reduction;
701         define_pixels (reduced_ss);
702
703         set_char_box (-.67 reduced_ss#, 2.0 reduced_ss#,
704                       reduced_ss#, reduced_ss#);
705
706         razt := hround (0.45 reduced_ss);
707
708         d := d - feta_shift;
709
710         draw_block ((-b, -d), (-b + razt, h));
711         draw_block ((w - razt, -d), (w, h));
712
713         draw_staff_if_debugging (-3, 1);
714 enddef;
715
716
717 fet_beginchar ("percussion clef", "percussion");
718         draw_percussion_clef (1.0);
719 fet_endchar;
720
721
722 fet_beginchar ("percussion clef (reduced)", "percussion_change");
723         draw_percussion_clef (.8);
724 fet_endchar;
725
726 def draw_varpercussion_clef (expr reduction) =
727         save reduced_ss, thin, thick;
728
729         reduced_ss# = staff_space# * reduction;
730         define_pixels (reduced_ss);
731
732         set_char_box (-.67 reduced_ss#, 1.75 reduced_ss#,
733                       1.675 reduced_ss#, 1.675 reduced_ss#);
734
735         thin := hround (0.175 reduced_ss);
736         thick := hround (0.35 reduced_ss);
737
738         d := d - feta_shift;
739
740         draw_block ((-b, -d), (-b + thin, h));
741         draw_block ((w - thin, -d), (w, h));
742
743         pickup penrazor scaled thick rotated 90;
744
745         top z1 = (-b + thin/2, h);
746         top z2 = (w - thin/2, h);
747
748         bot z3 = (-b + thin/2, -d);
749         bot z4 = (w - thin/2, -d);
750
751         draw z1 -- z2;
752         draw z3 -- z4;
753
754         penlabels (range 1 thru 4);
755
756         draw_staff_if_debugging (-3, 1);
757 enddef;
758
759
760 fet_beginchar ("variant percussion clef", "varpercussion");
761         draw_varpercussion_clef (1.0);
762 fet_endchar;
763
764
765 fet_beginchar ("variant percussion clef (reduced)", "varpercussion_change");
766         draw_varpercussion_clef (.8);
767 fet_endchar;
768
769
770 def draw_tab_T (expr pos, siz, slant) =
771 begingroup;
772         save vx, vy;
773         pair vx, vy;
774
775         clearxy;
776
777         vx = (xpart siz) * dir 0;
778         vy = (ypart siz) * dir 90;
779
780         penpos1 (.75 penh, 100);
781         z1 = z2 + (1/6 * vx - .15 * vy);
782         penpos2 (hround (.9 penw), 0);
783         x2l = hround xpart (pos + .75 vy);
784         y2l = ypart (pos + .75 vy);
785         penpos3 (penh, -100);
786         z3l = pos + .4 vx + vy;
787         penpos4 (penh, -90);
788         z4 = -.1 vy + .5 [z3, z5];
789         penpos5 (.8 penh, -30);
790         x5r = xpart (pos + siz);
791         y5l = ypart (pos + siz);
792
793         penpos10 (penw, 170);
794         z10 = pos + .55 vx + .9 vy;
795         penpos11 (.75 [penh, penw], 170);
796         z11 = z10 - .5 vy + .025 vx;
797         penpos12 (penh, 100);
798         z12l = (xpart .5 [z13, z11], ypart (pos - .025 * siz));
799         penpos13 (.75 penh, 60);
800         z13 = pos + .2 vx + .15 vy;
801
802         % penlabels (range 1 thru 13);
803
804         soft_penstroke (z1e
805                         ..tension 1.1.. z2e
806                         .. z3e{right}
807                         ..tension 1.5.. z4e
808                         ..z5e)
809           slanted slant shifted (slant * -ypart pos, 0);
810
811         soft_end_penstroke (z10e
812                             ..tension 1.5.. z11e
813                             .. z12e
814                             ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
815           slanted slant shifted (slant * -ypart pos, 0);
816 endgroup;
817 enddef;
818
819
820 def draw_tab_A (expr pos, siz, slant) =
821 begingroup;
822         save vx, vy, pat;
823         pair vx, vy;
824         path pat;
825
826         clearxy;
827
828         vx = (xpart siz) * dir 0;
829         vy = (ypart siz) * dir 90;
830
831         penpos1 (.75 penh, -110);
832         z1r = pos + .07 vy;
833         penpos2 (penh, -75);
834         z2r = (.5 [x1, x3], ypart pos);
835         penpos3 (.25 [penh, penw], -30);
836         z3 = (.45 [x2, x4], .15 [y2, y4]);
837         penpos4 (1 [penh, penw], 0);
838         z4 = pos + .5 vx + .975 vy;
839
840         penpos5 (1 [penh, penw], -180);
841         z5 = z4;
842         penpos6 (.2 [penh, penw], -150);
843         z6l = (.8 [x5l, x7l], .9 [y5l, y7l]);
844         penpos7 (penh,-90);
845         z7r = (.5 [x6, x8], ypart pos);
846         penpos8 (.75 penh, -70);
847         z8r = (xpart (pos + siz), y7r + .075 ypart (siz));
848
849         pat := z2
850                .. z3
851                .. z4;
852
853         penpos10 (penh, angle (direction 1.2 of pat) - 180);
854         z10 = point 1.2 of pat;
855         penpos11 (.9 penh, -90);
856         z11 = .4 [z10, z6] - 0.05 vy;
857         penpos12 (.75 penh, -75);
858         z12 = .3 [z11, z6] + 0.02 vy;
859
860         % penlabels (range 1 thru 12);
861
862         soft_penstroke (z1e{(z1r - z1l) rotated 90}
863                         .. z2e
864                         .. z3e
865                         .. z4e)
866           slanted slant shifted (slant * -ypart pos, 0);
867
868         soft_end_penstroke (z5e
869                             .. z6e
870                             .. z7e
871                             .. z8e{(z8r - z8l) rotated 90})
872           slanted slant shifted (slant * -ypart pos, 0);
873
874         soft_end_penstroke (z10e
875                             .. z11e
876                             .. z12e)
877           slanted slant shifted (slant * -ypart pos, 0);
878 endgroup;
879 enddef;
880
881
882 def draw_tab_B (expr pos, siz, slant) =
883 begingroup;
884         save vx, vy;
885         pair vx, vy;
886
887         clearxy;
888
889         vx = (xpart siz) * dir 0;
890         vy = (ypart siz) * dir 90;
891
892         penpos1 (.75 penh, 100);
893         z1 = z2 + (.15 * vx - .1 * vy);
894         penpos2 (hround (.9 penw), 0);
895         x2l = hround xpart (pos + .75 vy);
896         y2l = ypart (pos + .75 vy);
897         penpos3 (penh, -100);
898         z3l = pos + .4 vx + 1.05 vy;
899         penpos4 (.8 [penh, penw], -180);
900         z4 = (xpart (pos + .75 siz), .5 [y3, y5]);
901         penpos5 (.8 penh, 90);
902         z5 = (.5 [x10, x4], ypart (pos + .55 siz));
903
904         penpos6 (.8 penh, 270);
905         z6 = z5;
906         penpos7 (penw, 180);
907         z7l = (xpart (pos + siz), .5 [y6, y8]);
908         penpos8 (.8 penh, 45);
909         z8 = .5 [z12l, z11l] + .15 vx - .05 vy;
910
911         penpos10 (.75 [penh, penw], 170);
912         z10 = pos + .375 vx + vy;
913         penpos11 (.8 [penh, penw], 150);
914         z11 = z10 - .5 vy + .04 vx;
915         penpos12 (penh, 100);
916         z12l = (xpart .5 [z13, z11], ypart pos);
917         penpos13 (.75 penh, 60);
918         z13 = pos + .1 vx + .15 vy;
919
920         % penlabels (range 1 thru 13);
921
922         soft_penstroke (z1e
923                         ..tension 1.1.. z2e
924                         .. z3e
925                         .. z4e
926                         ..z5e {left})
927           slanted slant shifted (slant * -ypart pos, 0);
928
929         soft_end_penstroke (z6e{right}
930                             .. z7e
931                             .. z8e{(z8r - z8l) rotated 90})
932           slanted slant shifted (slant * -ypart pos, 0);
933
934         soft_end_penstroke (z10e
935                             ..tension 1.5.. z11e
936                             .. z12e
937                             ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
938           slanted slant shifted (slant * -ypart pos, 0);
939 endgroup;
940 enddef;
941
942
943 def draw_tab_clef (expr reduction) =
944         save reduced_ss, letterheight, penw, penh;
945
946         reduced_ss# = staff_space# * reduction;
947         letterheight# = 1.8 reduced_ss#;
948         define_pixels (reduced_ss, letterheight);
949
950         set_char_box (-.2 reduced_ss#, 2.8 reduced_ss#,
951                       1.6 letterheight#, 1.6 letterheight#);
952
953         penw = .45 reduced_ss;
954         penh = .2 reduced_ss;
955
956         draw_tab_T ((-b + .15 reduced_ss, h - letterheight),
957                     (2.1 reduced_ss, letterheight), 0.2);
958         draw_tab_A ((-b - .05 reduced_ss, -.5 letterheight +.15 reduced_ss),
959                     (2.2 reduced_ss, letterheight), 0.4);
960         draw_tab_B ((-b + .025 reduced_ss, -d),
961                     (2.1 reduced_ss, letterheight), 0.25);
962
963         draw_staff_if_debugging (-3, 2);
964 enddef;
965
966
967 fet_beginchar ("tab clef", "tab");
968         draw_tab_clef (1.0);
969 fet_endchar;
970
971
972 fet_beginchar ("tab clef (reduced)", "tab_change");
973         draw_tab_clef (.8);
974 fet_endchar;
975
976 fet_endgroup ("clefs");