]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-clefs.mf
Add '-dcrop' option to ps and svg backends
[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--2015 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 <> 0:
560                 addto currentpicture also
561                   currentpicture shifted (double_shift * reduced_ss, 0);
562         fi;
563
564         penlabels (range 101 thru 121);
565         penlabels (110', 111');
566
567         draw_staff_if_debugging (-1, 3);
568 enddef;
569
570
571 fet_beginchar ("G clef", "G");
572         draw_gclef (1.0, 0, 0);
573 fet_endchar;
574
575
576 fet_beginchar ("G clef", "G_change");
577         draw_gclef (0.8, 0, 0);
578 fet_endchar;
579
580
581 fet_beginchar ("double G clef", "GG");
582         draw_gclef (1.0, 1.5, 0);
583 fet_endchar;
584
585
586 fet_beginchar ("double G clef", "GG_change");
587         draw_gclef (0.8, 1.5, 0);
588 fet_endchar;
589
590 def draw_tenor_extension (expr reduction) =
591         save reduced_ss, thick, thin, upper_stroke, ne_beam_dir, nw_dist;
592         path upper_stroke;
593         pair ne_beam_dir, nw_dist;
594
595         reduced_ss# = staff_space# * reduction;
596         define_pixels (reduced_ss);
597
598         thin := hround (0.17 reduced_ss);
599         thick := hround (0.51 reduced_ss);
600
601         % the slanted left edge should protrude the g clef by a
602         % fixed amount relative to the width of the g clef:
603         x1'' = x6'' - 1.8 reduced_ss - 0.5 staff_space = 0.62 reduced_ss * reduction;
604         x8'' = x1'' - 2 thin;
605         x2'' = x3'' = x4'' = x6'' - thin;
606         x5'' = x6'';
607         x7'' = x6'' - 1/3 thin;
608         % the thick part of the c clef should be placed in the
609         % center of the forth staff space
610         y1'' = y2'' = 2.5 staff_space + thick/2;
611         y7'' =  y8'' = y6'' - 1/3 thin = y1'' - thick;
612         y5'' = y3'' = y2'' + reduced_ss;
613         y4'' = 4.5 reduced_ss;
614
615         upper_stroke := z2''
616                         -- new_bulb (z3'', 90, z4'', z5'', 270,
617                                      0.35 reduced_ss, 0.22 reduced_ss, thin, 1, -1)
618                         -- z6''{down} .. z7''{left};
619
620         % z1'' and z8'' are helper points that are responsible for
621         % hiding the lower left slant in the g clef's stroke
622         % z9'' and z10'' are computed to obtain nice rounded corners
623
624         pickup pencircle scaled 2/3 thin;
625         lft x9'' = x1'';
626         lft x10'' = x8'';
627
628         top y9'' = y1'';
629         bot y10'' = y8'';
630
631         ne_beam_dir = unitvector (z9'' - z10'');
632         nw_dist = (ne_beam_dir rotated 90) * 1/3 thin;
633
634         fill (z9''+nw_dist){ne_beam_dir}
635              ... top z9''{right}
636              -- upper_stroke
637              -- bot z10''{left}
638              ... (z10''+nw_dist){ne_beam_dir}
639              -- cycle;
640
641         % the slanted edge of the lower hook must not be visible, so it is
642         % shifted accordingly in x direction;
643         z1''' = z1'' shifted (staff_space - 0.9 reduced_ss, - staff_space);
644         z8''' = z8'' shifted (staff_space - 0.9 reduced_ss, - staff_space);
645
646         % the visible c clef parts should be symmetrical to the forth staff line
647         fill z1'''
648              -- reverse upper_stroke yscaled -1 shifted (0, 4 staff_space)
649              -- z8''' -- cycle;
650
651         penlabels (1''',2'',3'',4'',5'',6'',7'',8''',9'',10'');
652
653         draw_staff_if_debugging (-1, 3);
654 enddef;
655
656 fet_beginchar ("Tenor G clef", "tenorG");
657         draw_gclef (1.0, 0, 0.75);
658         draw_tenor_extension (1.0);
659 fet_endchar;
660
661
662 fet_beginchar ("Tenor G clef", "tenorG_change");
663         draw_gclef (0.8, 0, 0.75);
664         draw_tenor_extension (0.8);
665 fet_endchar;
666
667 %%%%
668 %
669 % PERCUSSION
670 %
671
672 %
673 % The percussion clef extent is not coincident with its bbox, since
674 % the percussion clef needs more space in front than a normal clef.
675 %
676
677 def draw_percussion_clef (expr reduction) =
678         save reduced_ss, razt;
679
680         reduced_ss# = staff_space# * reduction;
681         define_pixels (reduced_ss);
682
683         set_char_box (-.67 reduced_ss#, 2.0 reduced_ss#,
684                       reduced_ss#, reduced_ss#);
685
686         razt := hround (0.45 reduced_ss);
687
688         d := d - feta_shift;
689
690         draw_block ((-b, -d), (-b + razt, h));
691         draw_block ((w - razt, -d), (w, h));
692
693         draw_staff_if_debugging (-3, 1);
694 enddef;
695
696
697 fet_beginchar ("percussion clef", "percussion");
698         draw_percussion_clef (1.0);
699 fet_endchar;
700
701
702 fet_beginchar ("percussion clef (reduced)", "percussion_change");
703         draw_percussion_clef (.8);
704 fet_endchar;
705
706 def draw_varpercussion_clef (expr reduction) =
707         save reduced_ss, thin, thick;
708
709         reduced_ss# = staff_space# * reduction;
710         define_pixels (reduced_ss);
711
712         set_char_box (-.67 reduced_ss#, 1.75 reduced_ss#,
713                       1.675 reduced_ss#, 1.675 reduced_ss#);
714
715         thin := hround (0.175 reduced_ss);
716         thick := hround (0.35 reduced_ss);
717
718         d := d - feta_shift;
719
720         draw_block ((-b, -d), (-b + thin, h));
721         draw_block ((w - thin, -d), (w, h));
722
723         pickup penrazor scaled thick rotated 90;
724
725         top z1 = (-b + thin/2, h);
726         top z2 = (w - thin/2, h);
727
728         bot z3 = (-b + thin/2, -d);
729         bot z4 = (w - thin/2, -d);
730
731         draw z1 -- z2;
732         draw z3 -- z4;
733
734         penlabels (range 1 thru 4);
735
736         draw_staff_if_debugging (-3, 1);
737 enddef;
738
739
740 fet_beginchar ("variant percussion clef", "varpercussion");
741         draw_varpercussion_clef (1.0);
742 fet_endchar;
743
744
745 fet_beginchar ("variant percussion clef (reduced)", "varpercussion_change");
746         draw_varpercussion_clef (.8);
747 fet_endchar;
748
749
750 def draw_tab_T (expr pos, siz, slant) =
751 begingroup;
752         save vx, vy;
753         pair vx, vy;
754
755         clearxy;
756
757         vx = (xpart siz) * dir 0;
758         vy = (ypart siz) * dir 90;
759
760         penpos1 (.75 penh, 100);
761         z1 = z2 + (1/6 * vx - .15 * vy);
762         penpos2 (hround (.9 penw), 0);
763         x2l = hround xpart (pos + .75 vy);
764         y2l = ypart (pos + .75 vy);
765         penpos3 (penh, -100);
766         z3l = pos + .4 vx + vy;
767         penpos4 (penh, -90);
768         z4 = -.1 vy + .5 [z3, z5];
769         penpos5 (.8 penh, -30);
770         x5r = xpart (pos + siz);
771         y5l = ypart (pos + siz);
772
773         penpos10 (penw, 170);
774         z10 = pos + .55 vx + .9 vy;
775         penpos11 (.75 [penh, penw], 170);
776         z11 = z10 - .5 vy + .025 vx;
777         penpos12 (penh, 100);
778         z12l = (xpart .5 [z13, z11], ypart (pos - .025 * siz));
779         penpos13 (.75 penh, 60);
780         z13 = pos + .2 vx + .15 vy;
781
782         % penlabels (range 1 thru 13);
783
784         soft_penstroke (z1e
785                         ..tension 1.1.. z2e
786                         .. z3e{right}
787                         ..tension 1.5.. z4e
788                         ..z5e)
789           slanted slant shifted (slant * -ypart pos, 0);
790
791         soft_end_penstroke (z10e
792                             ..tension 1.5.. z11e
793                             .. z12e
794                             ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
795           slanted slant shifted (slant * -ypart pos, 0);
796 endgroup;
797 enddef;
798
799
800 def draw_tab_A (expr pos, siz, slant) =
801 begingroup;
802         save vx, vy, pat;
803         pair vx, vy;
804         path pat;
805
806         clearxy;
807
808         vx = (xpart siz) * dir 0;
809         vy = (ypart siz) * dir 90;
810
811         penpos1 (.75 penh, -110);
812         z1r = pos + .07 vy;
813         penpos2 (penh, -75);
814         z2r = (.5 [x1, x3], ypart pos);
815         penpos3 (.25 [penh, penw], -30);
816         z3 = (.45 [x2, x4], .15 [y2, y4]);
817         penpos4 (1 [penh, penw], 0);
818         z4 = pos + .5 vx + .975 vy;
819
820         penpos5 (1 [penh, penw], -180);
821         z5 = z4;
822         penpos6 (.2 [penh, penw], -150);
823         z6l = (.8 [x5l, x7l], .9 [y5l, y7l]);
824         penpos7 (penh,-90);
825         z7r = (.5 [x6, x8], ypart pos);
826         penpos8 (.75 penh, -70);
827         z8r = (xpart (pos + siz), y7r + .075 ypart (siz));
828
829         pat := z2
830                .. z3
831                .. z4;
832
833         penpos10 (penh, angle (direction 1.2 of pat) - 180);
834         z10 = point 1.2 of pat;
835         penpos11 (.9 penh, -90);
836         z11 = .4 [z10, z6] - 0.05 vy;
837         penpos12 (.75 penh, -75);
838         z12 = .3 [z11, z6] + 0.02 vy;
839
840         % penlabels (range 1 thru 12);
841
842         soft_penstroke (z1e{(z1r - z1l) rotated 90}
843                         .. z2e
844                         .. z3e
845                         .. z4e)
846           slanted slant shifted (slant * -ypart pos, 0);
847
848         soft_end_penstroke (z5e
849                             .. z6e
850                             .. z7e
851                             .. z8e{(z8r - z8l) rotated 90})
852           slanted slant shifted (slant * -ypart pos, 0);
853
854         soft_end_penstroke (z10e
855                             .. z11e
856                             .. z12e)
857           slanted slant shifted (slant * -ypart pos, 0);
858 endgroup;
859 enddef;
860
861
862 def draw_tab_B (expr pos, siz, slant) =
863 begingroup;
864         save vx, vy;
865         pair vx, vy;
866
867         clearxy;
868
869         vx = (xpart siz) * dir 0;
870         vy = (ypart siz) * dir 90;
871
872         penpos1 (.75 penh, 100);
873         z1 = z2 + (.15 * vx - .1 * vy);
874         penpos2 (hround (.9 penw), 0);
875         x2l = hround xpart (pos + .75 vy);
876         y2l = ypart (pos + .75 vy);
877         penpos3 (penh, -100);
878         z3l = pos + .4 vx + 1.05 vy;
879         penpos4 (.8 [penh, penw], -180);
880         z4 = (xpart (pos + .75 siz), .5 [y3, y5]);
881         penpos5 (.8 penh, 90);
882         z5 = (.5 [x10, x4], ypart (pos + .55 siz));
883
884         penpos6 (.8 penh, 270);
885         z6 = z5;
886         penpos7 (penw, 180);
887         z7l = (xpart (pos + siz), .5 [y6, y8]);
888         penpos8 (.8 penh, 45);
889         z8 = .5 [z12l, z11l] + .15 vx - .05 vy;
890
891         penpos10 (.75 [penh, penw], 170);
892         z10 = pos + .375 vx + vy;
893         penpos11 (.8 [penh, penw], 150);
894         z11 = z10 - .5 vy + .04 vx;
895         penpos12 (penh, 100);
896         z12l = (xpart .5 [z13, z11], ypart pos);
897         penpos13 (.75 penh, 60);
898         z13 = pos + .1 vx + .15 vy;
899
900         % penlabels (range 1 thru 13);
901
902         soft_penstroke (z1e
903                         ..tension 1.1.. z2e
904                         .. z3e
905                         .. z4e
906                         ..z5e {left})
907           slanted slant shifted (slant * -ypart pos, 0);
908
909         soft_end_penstroke (z6e{right}
910                             .. z7e
911                             .. z8e{(z8r - z8l) rotated 90})
912           slanted slant shifted (slant * -ypart pos, 0);
913
914         soft_end_penstroke (z10e
915                             ..tension 1.5.. z11e
916                             .. z12e
917                             ..tension 1.1.. z13e{(z13r - z13l) rotated 90})
918           slanted slant shifted (slant * -ypart pos, 0);
919 endgroup;
920 enddef;
921
922
923 def draw_tab_clef (expr reduction) =
924         save reduced_ss, letterheight, penw, penh;
925
926         reduced_ss# = staff_space# * reduction;
927         letterheight# = 1.8 reduced_ss#;
928         define_pixels (reduced_ss, letterheight);
929
930         set_char_box (-.2 reduced_ss#, 2.8 reduced_ss#,
931                       1.6 letterheight#, 1.6 letterheight#);
932
933         penw = .45 reduced_ss;
934         penh = .2 reduced_ss;
935
936         draw_tab_T ((-b + .15 reduced_ss, h - letterheight),
937                     (2.1 reduced_ss, letterheight), 0.2);
938         draw_tab_A ((-b - .05 reduced_ss, -.5 letterheight +.15 reduced_ss),
939                     (2.2 reduced_ss, letterheight), 0.4);
940         draw_tab_B ((-b + .025 reduced_ss, -d),
941                     (2.1 reduced_ss, letterheight), 0.25);
942
943         draw_staff_if_debugging (-3, 2);
944 enddef;
945
946
947 fet_beginchar ("tab clef", "tab");
948         draw_tab_clef (1.0);
949 fet_endchar;
950
951
952 fet_beginchar ("tab clef (reduced)", "tab_change");
953         draw_tab_clef (.8);
954 fet_endchar;
955
956 fet_endgroup ("clefs");