]> git.donarmstrong.com Git - lilypond.git/blobdiff - mf/parmesan-clefs.mf
Add '-dcrop' option to ps and svg backends
[lilypond.git] / mf / parmesan-clefs.mf
index ece1b5014c45a384551a5dedd6a8b845b56c9356..a291e3613afc8f8604291c115ecf986c36dd5170 100644 (file)
@@ -1,12 +1,22 @@
-% -%-Fundamental-%- -*-Metafont-*-
-% parmesan-clefs.mf -- implement ancient clefs
-% 
-% source file of LilyPond's pretty-but-neat music font
+% Feta (not the Font-En-Tja) music font --  ancient clefs
+% This file is part of LilyPond, the GNU music typesetter.
 %
-% (c) 2001--2006 Juergen Reuter <reuter@ipd.uka.de>
+% Copyright (C) 2001--2015 Juergen Reuter <reuter@ipd.uka.de>
 %
+% The LilyPond font is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version, or under the SIL Open Font License.
+%
+% LilyPond is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 
-fet_begingroup ("clefs")
+fet_begingroup ("clefs");
 
 %
 % character aligment:
@@ -16,10 +26,10 @@ fet_begingroup ("clefs")
 %   `f', etc.  The shape of each clef character defines a vertical
 %   position that is assumed to represent this pitch.  For the treble
 %   clef, it is the vertical position of the center of the spiral
-%   ending that represents the 'g' pitch.  For the bass clef, it is
+%   ending that represents the `g' pitch.  For the bass clef, it is
 %   the center between the two fat dots that define the vertical
-%   position of the 'f' pitch.  For the alto clef, it is the vertical
-%   center of the clef that is aligned with the 'c' pitch.  For each
+%   position of the `f' pitch.  For the alto clef, it is the vertical
+%   center of the clef that is aligned with the `c' pitch.  For each
 %   clef character, this center should be vertically aligned with the
 %   point (0, 0).  The horizontal alignment of each clef character
 %   should be such that the vertical line through the point (0, 0)
@@ -61,14 +71,14 @@ def draw_vaticana_do_clef (expr exact_center, reduction) =
 
        define_pixels (reduced_il);
 
-       save pat, ellipse, clef;
+       save pat, ellipse, clef, T;
        path pat, ellipse, clef;
+       transform T;
 
-       pickup pencircle xscaled 0.6 linethickness
-                        yscaled 0.6 reduced_il;
-
-       ellipse := reverse fullcircle xscaled 0.6 linethickness
-                                     yscaled 0.6 reduced_il;
+       T := identity xscaled 0.6 linethickness
+                     yscaled 0.6 reduced_il;
+       pickup pencircle transformed T;
+       ellipse := reverse fullcircle transformed T;
 
        save xoffs, yoffs;
 
@@ -115,9 +125,7 @@ enddef;
 
 
 fet_beginchar ("Ed. Vat. do clef", "vaticana.do");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_vaticana_do_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -137,14 +145,14 @@ def draw_vaticana_fa_clef (expr exact_center, reduction) =
        define_pixels (reduced_il, xoffs, yoffs);
 
        % left-handed punctum
-       pickup pencircle xscaled 0.6 linethickness
-                        yscaled 0.5 reduced_il;
-
-       save ellipse, pat;
+       save ellipse, pat, T;
        path ellipse, pat;
+       transform T;
 
-       ellipse := reverse fullcircle xscaled 0.6 linethickness
-                                     yscaled 0.5 reduced_il;
+       T := identity xscaled 0.6 linethickness
+                     yscaled 0.5 reduced_il;
+       pickup pencircle transformed T;
+       ellipse := reverse fullcircle transformed T;
 
        lft z21 = (xoffs + 0.00 reduced_il, yoffs + 0.00 reduced_il);
        z22 = (xoffs + 0.25 reduced_il, yoffs + 0.05 reduced_il);
@@ -184,9 +192,7 @@ enddef;
 
 
 fet_beginchar ("Ed. Vat. fa clef", "vaticana.fa");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_vaticana_fa_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -232,14 +238,14 @@ def draw_medicaea_do_clef (expr exact_center, reduction) =
        define_pixels (xoffs, yoffs);
 
        % flags
-       pickup pencircle xscaled reduced_slt
-                        yscaled flag_height;
-
-       save ellipse;
+       save ellipse, T;
        path ellipse;
+       transform T;
 
-       ellipse := reverse fullcircle xscaled reduced_slt
-                                     yscaled flag_height;
+       T := identity xscaled reduced_slt
+                     yscaled flag_height;
+       pickup pencircle transformed T;
+       ellipse := reverse fullcircle transformed T;
 
        xoffs = lft x1 = rt x2 - reduced_il;
        y1 = yoffs + 0.5 (reduced_il - flag_height - staff_space);
@@ -272,9 +278,7 @@ enddef;
 
 
 fet_beginchar ("Ed. Med. do clef", "medicaea.do");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_medicaea_do_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -304,26 +308,25 @@ def draw_medicaea_fa_clef (expr exact_center, reduction) =
        define_pixels (xoffs, yoffs);
 
        % stem
-       pickup pencircle scaled linethickness;
+       pickup pencircle scaled reduced_slt;
 
        x11 = x12 = xoffs + 0.4 reduced_il;
        y11 = yoffs = bot y12 + 1.5 reduced_il;
 
-       draw_rounded_block (bot lft z12, top rt z11, linethickness);
+       draw_rounded_block (bot lft z12, top rt z11, reduced_slt);
 
        % left-handed punctum
-
-       pickup pencircle xscaled reduced_slt
-                        yscaled reduced_il;
-
-       save ellipse;
+       save ellipse, T;
        path ellipse;
+       transform T;
 
-       ellipse := reverse fullcircle xscaled reduced_slt
-                                     yscaled reduced_il;
+       T := identity xscaled reduced_slt
+                     yscaled reduced_il;
+       pickup pencircle transformed T;
+       ellipse := reverse fullcircle transformed T;
 
        lft z13 = (xoffs, yoffs);
-       rt z14 = z11 + (linethickness / 2, 0);
+       rt z14 = z11 + (reduced_slt / 2, 0);
 
        fill get_subpath (ellipse, left, right, z13)
             -- get_subpath (ellipse, right, left, z14)
@@ -343,9 +346,7 @@ enddef;
 
 
 fet_beginchar ("Ed. Med. fa clef", "medicaea.fa");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_medicaea_fa_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -433,6 +434,7 @@ def draw_brevis (expr exact_center, bwidth, bheight, blinethickness) =
        penlabels (1, 2, 3);
 enddef;
 
+
 %
 % Draw two brevis notes; the second one shifted down by `shift'.
 % The other parameters are the same as with `draw_brevis'.
@@ -512,87 +514,6 @@ def draw_double_brevis (expr exact_center, bwidth, bheight,
 enddef;
 
 
-%
-% Draw three brevis notes; the second one shifted down by `shift',
-% the third one by `2 shift'.
-% The other parameters are the same as with `draw_brevis'.
-%
-def draw_triple_brevis (expr exact_center, bwidth, bheight,
-                            blinethickness, shift) =
-       save brevis_width, brevis_height, linethickness;
-
-       brevis_width# = bwidth;
-       brevis_height# = bheight;
-       linethickness# = blinethickness;
-
-       save beam_width, beam_height;
-       save serif_size, serif_protrude, hole_height;
-
-       beam_width# = 1.4 linethickness#;
-       hole_height# = 3 linethickness#;
-       2 beam_height# + hole_height# = brevis_height#;
-       serif_size# = (hole_height# - linethickness#) / 2;
-       serif_protrude# = 1.5 serif_size#;
-
-       save xoffs, yoffs;
-
-       xoffs# = xpart exact_center;
-       yoffs# = ypart exact_center;
-
-       define_pixels (xoffs, yoffs);
-       define_pixels (brevis_width, brevis_height, linethickness);
-       define_pixels (beam_width, beam_height, serif_size, serif_protrude);
-
-       z1l = (xoffs, yoffs - linethickness);
-       z2r = z1r + serif_size * (1, -1);
-       z3l = z2l + (-serif_size, -serif_protrude);
-
-       penpos1 (beam_width, 0);
-       penpos2 (beam_height, 90);
-       penpos3 (beam_width, 180);
-
-       z7 = z1 shifted (0, -2 shift);
-       z8 = z2 shifted (0, -2 shift);
-       z9 = z3 shifted (0, -2 shift);
-       
-       penpos7 (beam_width, 0);
-       penpos8 (beam_height, 90);
-       penpos9 (beam_width, 180);
-
-       save pat_in, pat_out;
-       path pat_in, pat_out;
-
-       pat_out := z9r{down}
-                  .. z9l{up}
-                  .. z8l{right};
-       pat_out := pat_out
-                  -- reverse pat_out xscaled -1
-                                     shifted (2 xoffs + brevis_width, 0);
-       pat_out := pat_out
-                  -- reverse pat_out yscaled -1
-                                     shifted (0, -2 yoffs)
-                  -- cycle;
-
-       fill pat_out;
-
-       pat_in := z1r{down}
-                 .. z2r{right};
-       pat_in := pat_in
-                 -- reverse pat_in xscaled -1
-                                   shifted (2 xoffs + brevis_width, 0);
-       pat_in := pat_in
-                 -- reverse pat_in yscaled -1
-                                   shifted (0, 2 yoffs)
-                 -- cycle;
-
-       unfill pat_in;
-       unfill pat_in shifted (0, -shift);
-       unfill pat_in shifted (0, -2 shift);
-
-       penlabels (1, 2, 3, 7, 8, 9);
-enddef;
-
-
 def draw_neomensural_c_clef (expr exact_center, reduction) = 
        save reduced_il, reduced_slt, stem_width;
 
@@ -617,14 +538,14 @@ def draw_neomensural_c_clef (expr exact_center, reduction) =
 
        define_pixels (xoffs, yoffs);
 
-       pickup pencircle xscaled stem_width
-                        yscaled blot_diameter;
-
-       save ellipse, pat;
+       save ellipse, pat, T;
        path ellipse, pat;
+       transform T;
 
-       ellipse := fullcircle xscaled stem_width
-                             yscaled blot_diameter;
+       T := identity xscaled stem_width
+                     yscaled blot_diameter;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
        lft x11 = lft x12 = xoffs;
        top y12 - bot y11 = 4 reduced_il;
@@ -660,9 +581,7 @@ enddef;
 
 
 fet_beginchar ("neo-mensural c clef", "neomensural.c");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_neomensural_c_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -710,14 +629,14 @@ def draw_petrucci_c_clef (expr exact_center, flare_align, reduction) =
 
        define_pixels (xoffs, yoffs);
 
-       pickup pencircle xscaled 1.4 linethickness
-                        yscaled blot_diameter;
-
-       save ellipse;
+       save ellipse, T;
        path ellipse;
+       transform T;
 
-       ellipse := fullcircle xscaled 1.4 linethickness
-                             yscaled blot_diameter;
+       T := identity xscaled 1.4 linethickness
+                     yscaled blot_diameter;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
        lft x11 = lft x13 = xoffs;
        top y11 = yoffs + left_height;
@@ -767,9 +686,7 @@ enddef;
 
 
 fet_beginchar ("petrucci c1 clef", "petrucci.c1");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_petrucci_c_clef ((0, 0), +2, 1.0);
 fet_endchar;
 
@@ -780,9 +697,7 @@ fet_endchar;
 
 
 fet_beginchar ("petrucci c2 clef", "petrucci.c2");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_petrucci_c_clef ((0, 0), +1, 1.0);
 fet_endchar;
 
@@ -793,9 +708,7 @@ fet_endchar;
 
 
 fet_beginchar ("petrucci c3 clef", "petrucci.c3");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_petrucci_c_clef ((0, 0), 0, 1.0);
 fet_endchar;
 
@@ -806,9 +719,7 @@ fet_endchar;
 
 
 fet_beginchar ("petrucci c4 clef", "petrucci.c4");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_petrucci_c_clef ((0, 0), -1, 1.0);
 fet_endchar;
 
@@ -819,9 +730,7 @@ fet_endchar;
 
 
 fet_beginchar ("petrucci c5 clef", "petrucci.c5");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_petrucci_c_clef ((0, 0), -2, 1.0);
 fet_endchar;
 
@@ -831,97 +740,104 @@ fet_beginchar ("petrucci c5 clef", "petrucci.c5_change");
 fet_endchar;
 
 
-def draw_mensural_c_clef (expr exact_center, reduction) =
-       % inspired by Ockeghem, "Missa Prolationum", in: MGG, volume
-       % 9, table 94.
-
-       save reduced_il;
+def draw_mensural_c_clef (expr exact_center, reduction, fill_char) =
+       save reduced_il, vert_thick, hor_thick, blot_rad;
 
        reduced_il# = staff_space# * reduction;
+       vert_thick# = linethickness# * 1.4;
+       hor_thick# = staff_space# * reduction * 0.25;
+
+       blot_rad = blot_diameter / 2;
+
+       define_pixels (reduced_il, vert_thick, hor_thick);
+
+       pickup pencircle scaled blot_diameter;
+
+       penpos1 (vert_thick, 0);
+       penpos2 (vert_thick, 0);
+       penpos3 (hor_thick, 90);
+       penpos4 (hor_thick, 90);
+       penpos5 (hor_thick, 90);
+       penpos6 (hor_thick, 90);
+       penpos7 (vert_thick, 0);
+       penpos8 (hor_thick, 90);
+
+       z1l = (0, 0);
+       x2l = 0;
+       top y2 = 2.2 reduced_il;
+       z3 = (vert_thick, 0.75 reduced_il);
+       z4 = z3 + (reduced_il - vert_thick, 0);
+       z5 = z4 + (vert_thick, -0.5 reduced_il);
+       z6 = z5 - (reduced_il, 0);
+       z7 = z4 + (0.5 vert_thick, 0.5 reduced_il);
+       z8 = z5 - (vert_thick, 0);
+
+       save pat, pat_mid;
+       path pat, pat_mid;
+
+       pat = z1l
+             -- z2l{up}
+             .. z2 + (0, blot_rad)
+             .. {down}z2r
+             -- top z3r{down}
+             .. {right}rt z3r
+             -- lft z4r{right}
+             .. {up}top z4r
+             -- z7l{up}
+             .. z7 + (0, blot_rad)
+             .. {down}z7r
+             -- top z5l{down}
+             .. {left}lft z5l
+             -- rt z6l{left}
+             .. {down}bot z6l
+             --z1r;
+       pat := pat
+              -- reverse pat yscaled -1
+              -- cycle;
+       fill pat;
 
-       define_pixels (reduced_il);
-
-       draw_triple_brevis (exact_center + (0, 0.5 staff_space#),
-                           2 reduced_il#, 0.8 staff_space#,
-                           0.8 linethickness#, staff_space);
-
-       save half_reduced_il;
-
-       half_reduced_il# = staff_space# * sqrt (reduction);
-
-       define_pixels (half_reduced_il);
-
-       set_char_box (0 - xpart exact_center,
-                     2 reduced_il# + xpart exact_center,
-                     2.2 half_reduced_il# + staff_space# -
-                       2 ypart exact_center,
-                     2.2 half_reduced_il# + 2 ypart exact_center);
-
-       save xoffs, yoffs;
-
-       xoffs# = xpart exact_center;
-       yoffs# = ypart exact_center;
-
-       define_pixels (xoffs, yoffs);
-
-       pickup pencircle xscaled 1.4 linethickness
-                        yscaled blot_diameter;
-
-       save ellipse;
-       path ellipse;
+       if fill_char:
+               pat_mid = bot z3l{up}
+                         .. {right}rt z3l
+                         -- lft z4l{right}
+                         .. {down}bot z4l
+                         -- top z8r{down}
+                         .. {left}lft z8r
+                         -- rt z6r{left}
+                         .. {up}top z6r
+                         --cycle;
+               unfill pat_mid;
+
+               pat_mid := pat_mid shifted (0, -reduced_il);
+               unfill pat_mid;
+       fi;
 
-       ellipse := fullcircle xscaled 1.4 linethickness
-                             yscaled blot_diameter;
+       set_char_box (0, reduced_il# + vert_thick#,
+                     2.2 reduced_il#, 2.2 reduced_il#);
 
-       lft x11 = lft x13 = xoffs;
-       top y11 = yoffs + 2.2 half_reduced_il;
-       bot y13 = yoffs - 2.2 half_reduced_il - staff_space;
-       rt x15 = rt x17 = xoffs + brevis_width;
-       y15 = yoffs + 1.4 half_reduced_il;
-       y17 = yoffs - 1.4 half_reduced_il - staff_space;
+       penlabels (1, 2, 3, 4, 5, 6, 7, 8);
+enddef;
 
-       z12 = z14 yscaled -1 shifted (0, -staff_space);
-       z14 = z9;
-       z16 = z18 yscaled -1 shifted (0, -staff_space);
-       rt z18 = lft z14 shifted (brevis_width, 0);
 
-       penpos12 (1.4 linethickness, 0);
-       penpos14 (1.4 linethickness, 0);
-       penpos16 (1.4 linethickness, 0);
-       penpos18 (1.4 linethickness, 0);
+fet_beginchar ("mensural c clef", "mensural.c");
+       draw_staff_if_debugging (-1, 3);
+       draw_mensural_c_clef ((0, 0), 1.0, true);
+fet_endchar;
 
-       fill get_subpath (ellipse, up, down, z11)
-            -- z12l
-            -- z12r
-            -- cycle;
-       fill get_subpath (ellipse, down, up, z13)
-            -- z14r
-            -- z14l
-            -- cycle;
-       fill get_subpath (ellipse, up, down, z15)
-            -- z16l
-            -- z16r
-            -- cycle;
-       fill get_subpath (ellipse, down, up, z17)
-            -- z18r
-            -- z18l
-            -- cycle;
 
-       labels (11, 13, 15, 17);
-       penlabels (12, 14, 16, 18);
-enddef;
+fet_beginchar ("mensural c clef", "mensural.c_change");
+       draw_mensural_c_clef ((0, 0), .8, true);
+fet_endchar;
 
 
-fet_beginchar ("mensural c clef", "mensural.c");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
-       draw_mensural_c_clef ((0, 0), 1.0);
+fet_beginchar ("black mensural c clef", "blackmensural.c");
+       draw_staff_if_debugging (-1, 3);
+       draw_mensural_c_clef ((0, 0), 1.0, false);
 fet_endchar;
 
 
-fet_beginchar ("mensural c clef", "mensural.c_change");
-       draw_mensural_c_clef ((0, 0), .8);
+fet_beginchar ("black mensural c clef", "blackmensural.c_change");
+       draw_mensural_c_clef ((0, 0), 0.8, false);
 fet_endchar;
 
 
@@ -947,16 +863,15 @@ def draw_diamond (expr exact_center, reduction) =
 
        define_pixels (xoffs, yoffs);
 
-       pickup pencircle xscaled beamheight
-                        yscaled stem_width
-                        rotated 45;
-
-       save ellipse;
+       save ellipse, T;
        path ellipse;
+       transform T;
 
-       ellipse := reverse fullcircle xscaled beamheight
-                                     yscaled stem_width
-                                     rotated 45;
+       T := identity xscaled beamheight
+                     yscaled stem_width
+                     rotated 45;
+       pickup pencircle transformed T;
+       ellipse := reverse fullcircle transformed T;
 
        x21 := xoffs - rh_width / 2;
        y21 := yoffs;
@@ -1033,16 +948,17 @@ def draw_petrucci_f_clef (expr exact_center, reduction) =
        define_pixels (xoffs, yoffs);
 
        % brevis stem
-       pickup pencircle xscaled stem_width
-                        yscaled blot_diameter;
-
-       save ellipse;
+       save ellipse, T;
        path ellipse;
+       transform T;
 
-       ellipse := fullcircle xscaled stem_width
-                             yscaled blot_diameter;
+       T := identity xscaled stem_width
+                     yscaled blot_diameter;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
-       rt z8 = (xoffs + reduced_il, yoffs - 4 reduced_slt);
+       rt x8 = xoffs + reduced_il;
+       y8 = y3;
        rt z9 = (xoffs + reduced_il, yoffs - 4 reduced_il);
 
        penpos8 (stem_width, 0);
@@ -1094,15 +1010,13 @@ enddef;
 
 
 fet_beginchar ("petrucci f clef", "petrucci.f");
-       if test = 1:
-               draw_staff (-1,3, 0.0);
-       fi;
-       draw_petrucci_f_clef ((0,0), 1.0);
+       draw_staff_if_debugging (-1, 3);
+       draw_petrucci_f_clef ((0, 0), 1.0);
 fet_endchar;
 
 
 fet_beginchar ("petrucci f clef", "petrucci.f_change");
-       draw_petrucci_f_clef ((0,0), .8);
+       draw_petrucci_f_clef ((0, 0), .8);
 fet_endchar;
 
 
@@ -1128,16 +1042,15 @@ def draw_mensural_f_clef (expr exact_center, reduction) =
 
        define_pixels (xoffs, yoffs);
 
-       pickup pencircle xscaled 0.2 width
-                        yscaled stem_width
-                        rotated 45;
-
-       save ellipse;
+       save ellipse, T;
        path ellipse;
+       transform T;
 
-       ellipse := fullcircle xscaled 0.2 width
-                             yscaled stem_width
-                             rotated 45;
+       T := identity xscaled 0.2 width
+                     yscaled stem_width
+                     rotated 45;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
        % half circle
        lft z10 = (0, 0);
@@ -1203,10 +1116,8 @@ enddef;
 
 
 fet_beginchar ("mensural f clef", "mensural.f");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
-       draw_mensural_f_clef ((0,0), 1.0);
+       draw_staff_if_debugging (-1, 3);
+       draw_mensural_f_clef ((0, 0), 1.0);
 fet_endchar;
 
 
@@ -1237,16 +1148,15 @@ def draw_petrucci_g_clef (expr exact_center, reduction) =
 
        define_pixels (xoffs, yoffs);
 
-       pickup pencircle xscaled 0.50 reduced_slt
-                        yscaled 0.22 reduced_il
-                        rotated -35;
-
-       save ellipse, paths, sub_path, outlines, sub_outlines;
+       save ellipse, paths, sub_path, outlines, sub_outlines, T;
        path ellipse, paths[], sub_path, outlines[], sub_outlines[];
+       transform T;
 
-       ellipse := fullcircle xscaled 0.5 reduced_slt
-                             yscaled 0.22 reduced_il
-                             rotated -35;
+       T := identity xscaled 0.5 reduced_slt
+                     yscaled 0.22 reduced_il
+                     rotated -35;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
        lft z1 = (xoffs + 0.80 reduced_il, yoffs + 0.00 reduced_il);
        lft z2 = (xoffs + 1.00 reduced_il, yoffs + 1.20 reduced_il);
@@ -1260,15 +1170,15 @@ def draw_petrucci_g_clef (expr exact_center, reduction) =
        lft z10 = (xoffs + 0.20 reduced_il, yoffs + 0.60 reduced_il);
 
        paths1 := z1{-1, 2}
-                   .. z2
-                   .. z3
-                   .. z4
-                   .. z5
-                   .. z6
-                   .. z7
-                   .. z8
-                   .. z9
-                   .. z10;
+                 .. z2
+                 .. z3
+                 .. z4
+                 .. z5
+                 .. z6
+                 .. z7
+                 .. z8
+                 .. z9
+                 .. z10;
 
        save dirs, s;
        pair dirs[];
@@ -1313,13 +1223,11 @@ def draw_petrucci_g_clef (expr exact_center, reduction) =
        (times42, times24) = sub_outlines4 intersectiontimes sub_outlines2;
        (times43, times34) = sub_outlines4 intersectiontimes sub_outlines3;
 
-       pickup pencircle xscaled 0.75 reduced_slt
-                        yscaled 0.33 reduced_il
-                        rotated -35;
-
-       ellipse := fullcircle xscaled 0.75 reduced_slt
-                             yscaled 0.33 reduced_il
-                             rotated -35;
+       T := identity xscaled 0.75 reduced_slt
+                     yscaled 0.33 reduced_il
+                     rotated -35;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
        lft z21 = (xoffs + 1.05 reduced_il, yoffs + 0.45 reduced_il);
        lft z22 = (xoffs + 0.55 reduced_il, yoffs + 0.45 reduced_il);
@@ -1385,40 +1293,51 @@ def draw_petrucci_g_clef (expr exact_center, reduction) =
             & subpath (0, times1 - s / 4) of sub_outlines1
             -- cycle;
 
+
        % we approximate `draw paths2'
        for i = 1 step s until (length paths2 - s):
                dirs[i + 20] := direction (i - 1) of paths2;
        endfor;
 
-       fill get_subpath (ellipse, -dirs21, dirs21, z21)
-            for i = (1 + s) step s until (length paths2 - s):
-                    .. get_subpoint (ellipse, dirs[i + 20],
-                                     point (i - 1) of paths2)
-            endfor
-            .. get_subpath (ellipse, up, z26 - z25, z25)
-            -- get_subpath (ellipse, z26 - z25, z25 - z26, z26)
-            -- get_subpoint (ellipse, z25 - z26, z25)
-            -- get_subpoint (ellipse, down, z25)
-            for i = (length paths2 - s) step -s until (t4 + 1):
-                    .. get_subpoint (ellipse, -dirs[i + 20],
-                                     point (i - 1) of paths2)
-            endfor
-            .. get_subpoint (ellipse, -direction t4 of paths2,
-                             point t4 of paths2)
-            -- get_subpoint (ellipse, -direction t3 of paths2,
-                             point t3 of paths2)
-            for i = (floor (t3 / s) * s + 1) step -s until (t2 + 1):
-                    .. get_subpoint (ellipse, -dirs[i + 20],
-                                     point (i - 1) of paths2)
-            endfor
-            .. get_subpoint (ellipse, -direction t2 of paths2,
-                             point t2 of paths2)
-            -- get_subpoint (ellipse, -direction t1 of paths2,
-                             point t1 of paths2)
-            for i = (floor (t1 / s) * s + 1) step -s until (1 + s):
-                    .. get_subpoint (ellipse, -dirs[i + 20],
-                                     point (i - 1) of paths2)
-            endfor
+       sub_outlines21 := get_subpath (ellipse, -dirs21, dirs21, z21)
+                         for i = (1 + s) step s until (length paths2 - s):
+                                 .. get_subpoint (ellipse, dirs[i + 20],
+                                                  point (i - 1) of paths2)
+                         endfor
+                         .. get_subpath (ellipse, up, z26 - z25, z25);
+       sub_outlines22 := get_subpath (ellipse, z26 - z25, z25 - z26, z26)
+                         -- get_subpoint (ellipse, z25 - z26, z25);
+       sub_outlines23 := get_subpoint (ellipse, down, z25)
+                         for i = (length paths2 - s) step -s until (t4 + 1):
+                                 .. get_subpoint (ellipse, -dirs[i + 20],
+                                                  point (i - 1) of paths2)
+                         endfor
+                         .. get_subpoint (ellipse, -direction t4 of paths2,
+                                          point t4 of paths2);
+       sub_outlines24 := get_subpoint (ellipse, -direction t3 of paths2,
+                                       point t3 of paths2)
+                         for i = (floor (t3 / s) * s + 1) step -s until (t2 + 1):
+                                 .. get_subpoint (ellipse, -dirs[i + 20],
+                                                  point (i - 1) of paths2)
+                         endfor
+                         .. get_subpoint (ellipse, -direction t2 of paths2,
+                                          point t2 of paths2);
+       sub_outlines25 := get_subpoint (ellipse, -direction t1 of paths2,
+                                       point t1 of paths2)
+                         for i = (floor (t1 / s) * s + 1) step -s until (1 + s):
+                                 .. get_subpoint (ellipse, -dirs[i + 20],
+                                                  point (i - 1) of paths2)
+                         endfor;
+
+       (times2223, times2322) = sub_outlines22 intersectiontimes sub_outlines23;
+       (times2324, times2423) = sub_outlines23 intersectiontimes sub_outlines24;
+       (times2425, times2524) = sub_outlines24 intersectiontimes sub_outlines25;
+
+       fill sub_outlines21
+            -- subpath (0, times2223) of sub_outlines22
+            -- subpath (times2322, times2324) of sub_outlines23
+            -- subpath (times2423, times2425) of sub_outlines24
+            -- subpath (times2524, infinity) of sub_outlines25
             .. cycle;
 
        labels (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
@@ -1427,9 +1346,7 @@ enddef;
 
 
 fet_beginchar ("petrucci g clef", "petrucci.g");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_petrucci_g_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -1461,9 +1378,7 @@ enddef;
 % until the code for the mensural g clef will be rewritten.
 %
 fet_beginchar ("mensural g clef", "mensural.g");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_petrucci_g_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -1504,16 +1419,15 @@ def draw_hufnagel_do_clef (expr exact_center, reduction) =
 
        define_pixels (xoffs, yoffs);
 
-       pickup pencircle xscaled (0.60 reduced_il)
-                        yscaled (0.10 reduced_il)
-                        rotated 40;
-
-       save ellipse, pat;
+       save ellipse, pat, T;
        path ellipse, pat;
+       transform T;
 
-       ellipse := fullcircle xscaled (0.60 reduced_il)
-                             yscaled (0.10 reduced_il)
-                             rotated 40;
+       T := identity xscaled 0.6 reduced_il
+                     yscaled 0.1 reduced_il
+                     rotated 40;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
        z1 = (xoffs + 0.90 reduced_il, yoffs + .45 reduced_il);
        z2 = (xoffs + 0.80 reduced_il, yoffs + .45 reduced_il);
@@ -1553,9 +1467,7 @@ enddef;
 
 
 fet_beginchar ("Hufnagel do clef", "hufnagel.do");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_hufnagel_do_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -1580,10 +1492,6 @@ def draw_hufnagel_fa_clef (expr exact_center, reduction) =
                      1.15 reduced_il# - ypart exact_center,
                      1.00 reduced_il# + ypart exact_center);
 
-       pickup pencircle xscaled (0.60 reduced_il)
-                        yscaled (0.10 reduced_il)
-                        rotated 40;
-
        save xoffs, yoffs;
 
        xoffs# = xpart exact_center;
@@ -1591,12 +1499,15 @@ def draw_hufnagel_fa_clef (expr exact_center, reduction) =
 
        define_pixels (xoffs, yoffs);
 
-       save ellipse, pat;
+       save ellipse, pat, T;
        path ellipse, pat;
+       transform T;
 
-       ellipse := fullcircle xscaled (0.60 reduced_il)
-                             yscaled (0.10 reduced_il)
-                             rotated 40;
+       T := identity xscaled 0.6 reduced_il
+                     yscaled 0.1 reduced_il
+                     rotated 40;
+       pickup pencircle transformed T;
+       ellipse := fullcircle transformed T;
 
        z11 = (xoffs + 0.90 reduced_il, yoffs + 0.70 reduced_il);
        z12 = (xoffs + 0.80 reduced_il, yoffs + 0.70 reduced_il);
@@ -1650,9 +1561,7 @@ enddef;
 
 
 fet_beginchar ("Hufnagel fa clef", "hufnagel.fa");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_hufnagel_fa_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -1674,9 +1583,7 @@ enddef;
 
 
 fet_beginchar ("Hufnagel do/fa clef", "hufnagel.do.fa");
-       if test = 1:
-               draw_staff (-1, 3, 0.0);
-       fi;
+       draw_staff_if_debugging (-1, 3);
        draw_hufnagel_do_fa_clef ((0, 0), 1.0);
 fet_endchar;
 
@@ -1686,4 +1593,61 @@ fet_beginchar ("Hufnagel do/fa clef", "hufnagel.do.fa_change");
 fet_endchar;
 
 
-fet_endgroup ("clefs")
+%%%%%%%%
+%%
+%% Medieval East-Slavic (Kievan) Notation clefs
+%% Code by Aleksandr Andreev <aleksandr.andreev@gmail.com>
+%%
+%%%%%%%%
+
+def draw_kievan_do_clef =
+       z1 = (1.108 staff_space, 0.554 staff_space);
+       z2 = (1.063 staff_space, -0.122 staff_space);
+       z3 = (1.467 staff_space, -1.621 staff_space);
+       z4 = (1.002 staff_space, -2.253 staff_space);
+
+       y5 = y3;
+       x4 - x5 = x3 - x4;
+
+       z6 = (0.917 staff_space, -0.383 staff_space);
+       z7 = (0.012 staff_space, -0.448 staff_space);
+       z8 = (0, -0.167 staff_space);
+       z9 = (0.057 staff_space, 0.464 staff_space);
+       z10 = (0.994 staff_space, 0.387 staff_space);
+       z11 = (1.023 staff_space, 0.554 staff_space);
+
+       fill z1
+            .. z2{down}
+            .. z3
+            -- z4
+            -- z5
+            .. {up}z6
+            & z6{left}
+            .. z7
+            & z7
+            .. z8{up}
+            .. z9
+            & z9
+            .. {right}z10
+            & z10
+            .. z11
+            -- cycle;
+
+       set_char_box (0, 1.5 staff_space#,
+                     2.25 staff_space#, 0.55 staff_space#);
+enddef;
+
+
+fet_beginchar ("Kievan tsefaut clef", "kievan.do");
+       % This draws the Tse-Fa-Ut clef; it is a variant alto clef that
+       % always occurs on the third line of the staff.
+       draw_kievan_do_clef;
+fet_endchar;
+
+
+fet_beginchar ("Kievan tsefaut clef", "kievan.do_change");
+       % This is the same thing as a do clef?
+       draw_kievan_do_clef;
+fet_endchar;
+
+fet_endgroup ("clefs");