]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-toevallig.mf
* mf/feta-slag.mf (draw_trillelement): Fix shape to get clean
[lilypond.git] / mf / feta-toevallig.mf
1 %
2 % feta-toevallig.mf -- implement Accidentals
3 %
4 % source file of the Feta (Font-En-Tja) music font
5 %
6 % (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 %
8
9
10 %
11 % Accidentals from various sources, notably
12 %
13 %   Baerenreiter edition of Schuberts `Auf dem Strom' (sharp, natural)
14 %   F Hofmeister edition of Muellers `Etueden fuer Horn' (double sharp, flat)
15 %
16
17
18 fet_begingroup ("accidentals");
19
20
21 save remember_pic;
22 picture remember_pic;
23
24
25 %
26 % The beams of most sharps have horizontal endings (as if drawn with
27 % a square pen).  [Wanske] does not mention this, so we'll just ignore
28 % this fact.
29 %
30
31 def draw_meta_sharp (expr width, offset) =
32         save beamheight, beamwidth, beamslope;
33         save ne, nw_dist;
34         pair ne, nw_dist;
35
36         beamwidth := width;
37
38         beamheight# := 0.3 staff_space# + stafflinethickness#;
39         define_whole_vertical_blacker_pixels (beamheight);
40
41         clearxy;
42
43         beamslope = beamheight / beamwidth;
44
45         pickup pencircle scaled 2 blot_diameter;
46
47         rt x2 - lft x1 = beamwidth;
48         y2 - y1 = beamheight;
49         .5 [z1, z3] = (.5 w, offset);
50         x3 = x2;
51         top y2 - bot y3 = beamheight;
52         x4 = x1;
53         top y1 - bot y4 = beamheight;
54
55         ne = unitvector (z2 - z1);
56         nw_dist = (ne rotated 90) * blot_diameter;
57
58         fill lft z1{up}
59              ... (z1 + nw_dist){ne}
60              -- (z2 + nw_dist){ne}
61              ... rt z2{down}
62              -- rt z3{down}
63              ... (z3 - nw_dist){-ne}
64              -- (z4 - nw_dist){-ne}
65              ... lft z4{up}
66              -- cycle;
67
68         labels (1, 2, 3, 4);
69 enddef;
70
71
72 fet_beginchar ("Sharp", "2");
73         save stem, stemx, stemwidth;
74         save outer_space, interbeam;
75
76         stemwidth# := stafflinethickness# + .05 staff_space#;
77         define_whole_blacker_pixels (stemwidth);
78
79         interbeam := 1.05 staff_space_rounded;
80
81         set_char_box (0, 1.1 staff_space#,
82                       1.5 staff_space#, 1.5 staff_space#);
83
84         stem := 7 / 16 * w;
85         stemx := hround stem;
86         outer_space := hround ((w - stemx - stemwidth) / 2);
87
88         w := 2 outer_space + stemx + stemwidth;
89         d := d - feta_space_shift;
90
91         draw_meta_sharp (w, -.5 interbeam);
92         draw_meta_sharp (w, -.5 interbeam + vround interbeam);
93
94         pickup pencircle scaled stemwidth;
95
96         lft x5 = lft x6 = outer_space;
97         lft x7 = lft x8 = outer_space + stemx;
98         bot y5 = -d;
99         top y6 = vround (1.5 staff_space - stem * beamslope);
100         bot y7 = -top y6 + feta_space_shift;
101         top y8 = h;
102
103         labels (5, 6, 7, 8);    
104
105         draw_gridline (z5, z6, stemwidth);
106         draw_gridline (z7, z8, stemwidth);
107
108         remember_pic := currentpicture;
109
110         draw_staff (-2, 2, 0);
111 fet_endchar;
112
113
114 if test > 0:
115         fet_beginchar ("Sharp", "2");
116
117                 set_char_box (0, 1.1 staff_space#,
118                               1.5 staff_space#, 1.5 staff_space#);
119
120                 currentpicture := remember_pic;
121
122                 draw_staff (-2, 2, 0.5);
123         fet_endchar;
124 fi;
125
126
127 fet_beginchar ("1/2 Sharp", "1");
128         save stem, stemwidth;
129         save outer_space, interbeam;
130
131         stemwidth# := stafflinethickness# + .05 staff_space#;
132         define_whole_blacker_pixels (stemwidth);
133
134         interbeam := 1.05 staff_space_rounded;
135
136         set_char_box (0, 0.7 staff_space#,
137                       1.5 staff_space#, 1.5 staff_space#);
138
139         stem := 7 / 16 * w;
140         outer_space := hround ((w - stemwidth) / 2);
141
142         w := 2 outer_space + stemwidth;
143         d := d - feta_space_shift;
144
145         draw_meta_sharp (w, -.5 interbeam);
146         draw_meta_sharp (w, -.5 interbeam + vround interbeam);
147
148         pickup pencircle scaled stemwidth;
149
150         lft x5 = lft x6 = outer_space;
151         top y6 = vround (1.5 staff_space - .5 stem);
152         bot y5 = -top y6 + feta_space_shift;
153
154         labels (5, 6);
155
156         draw_gridline (z5, z6, stemwidth);
157
158         remember_pic := currentpicture;
159
160         draw_staff (-2, 2, 0);
161 fet_endchar;
162
163
164 if test > 0:
165         fet_beginchar ("1/2 Sharp", "1");
166
167                 set_char_box (0, 0.7 staff_space#,
168                               1.5 staff_space#, 1.5 staff_space#);
169
170                 currentpicture := remember_pic;
171
172                 draw_staff (-2, 2, 0.5);
173         fet_endchar;
174 fi;
175
176
177 fet_beginchar ("3/4 Sharp", "3");
178         save stem, stemx, stemwidth;
179         save outer_space, interbeam;
180
181         stemwidth# := stafflinethickness# + .05 staff_space#;
182         define_whole_blacker_pixels (stemwidth);
183
184         interbeam := 1.05 staff_space_rounded;
185
186         set_char_box (0, 1.6 staff_space#,
187                       1.5 staff_space#, 1.5 staff_space#);
188
189         stem := 9 / 32 * w;
190         stemx := hround stem;
191         outer_space := hround ((w - 2 stemx - stemwidth) / 2);
192
193         w := 2 outer_space + 2 stemx + stemwidth;
194         d := d - feta_space_shift;
195
196         draw_meta_sharp (w, -.5 interbeam);
197         draw_meta_sharp (w, -.5 interbeam + vround interbeam);
198
199         pickup pencircle scaled stemwidth;
200
201         lft x5 = lft x6 = outer_space;
202         lft x7 = lft x8 = outer_space + stemx;
203         lft x9 = lft x10 = outer_space + 2 stemx;
204         bot y5 = -d;
205         top y6 = vround (1.5 staff_space - 2 stem * beamslope);
206         bot y9 = -top y6 + feta_space_shift;
207         top y10 = h;
208         y7 = .5 [y5, y9];
209         y8 = .5 [y6, y10];
210
211         labels (5, 6, 7, 8, 9, 10);
212
213         draw_gridline (z5, z6, stemwidth);
214         draw_gridline (z7, z8, stemwidth);
215         draw_gridline (z9, z10, stemwidth);
216
217         remember_pic := currentpicture;
218
219         draw_staff (-2, 2, 0);
220 fet_endchar;
221
222
223 if test > 0:
224         fet_beginchar ("3/4 Sharp", "3");
225
226                 set_char_box (0, 1.6 staff_space#,
227                               1.5 staff_space#, 1.5 staff_space#);
228
229                 currentpicture := remember_pic;
230
231                 draw_staff (-2, 2, 0.5);
232         fet_endchar;
233 fi;
234
235
236 %
237 % The stems of the natural are brushed (at least, in Barenreiter SCS)
238 %
239
240 fet_beginchar ("Natural", "0");
241         save beam_shift;
242         save interbeam, interstem;
243         save beamheight, beamwidth;
244         save stemwidth, top_stem_thick;
245
246         beamheight# = 0.35 staff_space# + .5 stafflinethickness#;
247         top_stem_thick# = stafflinethickness# + .09 staff_space#;
248         stemwidth# = 0.08 staff_space# + .5 stafflinethickness#;
249         define_whole_vertical_blacker_pixels (beamheight);
250         define_whole_blacker_pixels (top_stem_thick, stemwidth);
251
252         set_char_box (0, 2/3 staff_space#,
253                       1.5 staff_space#, 1.5 staff_space#);
254
255         interstem + stemwidth = w;
256
257         z2 - z1 = (interstem, slope * interstem);
258         xpart .5 [z2, z1] = w / 2;
259
260         d := d - feta_space_shift;
261
262         pickup penrazor scaled beamheight rotated 90;
263         top y2 = vround (staff_space - 3/2 stafflinethickness);
264         slope = stafflinethickness / interstem;
265
266         x1 := round x1;
267         y1 := round y1;
268         x2 := round x2;
269         y2 := round y2;
270
271         x1' = x1;
272         bot y1' = -d + (h - top y2);
273         z1 - z1' = z2 - z2';
274
275         draw z1
276              -- z2;
277         draw z1'
278              -- z2';
279
280         beamtop = top y2;
281
282         pickup pencircle scaled stemwidth;
283         x3 = x1;
284         x4 = x2;
285
286         penpos3 (top_stem_thick, 0);
287         penpos5 (top_stem_thick, 0);
288         penpos4 (stemwidth, 0);
289         penpos6 (stemwidth, 0);
290
291         y3 = h;
292         top y4 = beamtop;
293         x5 = x4;
294         x6 = x3;
295         y6 = -y4 + feta_space_shift;
296         y5 = -d;
297
298         fill simple_serif (z3l, z3r, -30)
299              -- z6r
300              .. bot z6
301              .. z6l
302              -- cycle;
303         fill simple_serif (z5l, z5r, 30)
304              -- z4r
305              .. top z4
306              .. z4l
307              -- cycle;
308
309         penlabels (3, 4, 5, 6);
310         labels (1, 1', 2, 2');
311
312         remember_pic := currentpicture;
313
314         draw_staff (-2, 2, 0);
315 fet_endchar;
316
317
318 if test > 0:
319         fet_beginchar ("Natural", "0");
320                 set_char_box (0, 2/3 staff_space#,
321                               1.5 staff_space#, 1.5 staff_space#);
322
323                 currentpicture := remember_pic;
324
325                 draw_staff (-2, 2, 0.5);
326         fet_endchar;
327 fi;
328
329
330 %
331 % Dedicated to my mom.    (3/10/97)
332 %
333 % Mamma, ik hou van je; kom je alsjeblieft terug?
334 %    -- HW
335 %
336 %
337 % TODO: remove crook_fatness
338 % TODO: document, simplify!
339 %
340
341 def draw_meta_flat (expr xcenter, w, crook_fatness) =
342         save crook_thinness;
343         save bottom_overshoot, bot_crook_dir;
344         save top_stem_thick, bottom_stem_thick, hair, smaller_hole;
345         save top_crook_thinness;
346         save zwiep;
347         save center;
348         pair center, bot_crook_dir;
349         save clearing;
350
351         clearxy;
352
353         % the stem shouldn't reach the top staff line.
354         %% TODO: should take from height.
355         %
356         % TODO: parameterize this
357         %
358         if w >= 0.75 staff_space:
359                 smaller_hole = 0.35 stafflinethickness;
360         else:
361                 smaller_hole = 0;
362         fi
363         clearing = 1.7 stafflinethickness;
364         crook_thinness = .7 stafflinethickness + .06 staff_space;
365         top_crook_thinness = 1 stafflinethickness + .065 staff_space;
366         bottom_overshoot = stafflinethickness;
367
368         bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
369         top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
370         define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick);
371
372         if odd (top_stem_thick - bottom_stem_thick):
373                 top_stem_thick := top_stem_thick - 1;
374         fi;
375
376         center = (xcenter, 0);
377
378         x1l = hround (xcenter - .5 top_stem_thick);
379         y1 = vround (2 staff_space - clearing);
380         x2l = hround (xcenter - .5 bottom_stem_thick);
381         y2 = -.5 staff_space - .5 stafflinethickness;
382
383         penpos1 (top_stem_thick, 0);
384         penpos2 (bottom_stem_thick, 0);
385
386         y3l = vfloor ((staff_space - stafflinethickness) / 2);
387         z3l = whatever [z2r, z1r];
388         z3r = .3 [z2r, z1r] + (smaller_hole, 0);
389         x3r := hceiling x3r;
390
391         % we insert z3l to get better conversion with mf2pt1
392         fill simple_serif (z1r, z1l, 30)
393              -- z2l
394              -- z2r
395              -- z3l
396              -- cycle;
397
398         z10 = whatever [z2r, z1r] + (smaller_hole, 0);
399         y10 = -1/10 staff_space;
400         x10 := hceiling x10;
401
402         x11 = xcenter + bottom_overshoot / 3;
403         y11 = -vround (.5 (staff_space + stafflinethickness)
404                        + bottom_overshoot);
405
406         penpos4 (whatever, 53);
407
408         y4l - y4r = top_crook_thinness;
409         y5r = .15 staff_space;
410         x5l = hround (w + xcenter);
411         y4 = staff_space / 2;
412         x4r = .45 [x5r, x3r];
413         y4l := vround y4l;
414
415         penpos5 (crook_fatness, -175);
416
417         bot_crook_dir = unitvector ((x5l, 0) - z11);
418         z8 = z11 + whatever * bot_crook_dir;
419         y8 = -staff_space / 2;
420
421         z7 = z8
422              + whatever * bot_crook_dir
423              + crook_thinness * (bot_crook_dir rotated 90);
424         x7 = .1 [x3r, x8];
425
426         unfill z3r{z3r - z10}
427                .. z4r{right}
428                .. z5r{down}
429                .. z7{-bot_crook_dir}
430                & z7
431                .. z10{z3r - z10}
432                -- cycle;
433
434         fill z2l{down}
435              .. z11{right}
436              .. z8{bot_crook_dir}
437              .. z5l{up}
438              .. z4l{left}
439              .. z3l
440              -- cycle;
441 enddef;
442
443
444 %
445 % unfortunately, 600dpi is not enough to show the brush of the stem.
446 %
447
448 fet_beginchar ("Flat", "-2");
449         set_char_box (1.2 stafflinethickness#, .8 staff_space#,
450                       0.6 staff_space#, 1.9 staff_space#);
451
452         draw_meta_flat (0, w, 0.31 staff_space);
453         penlabels (range 0 thru 11);
454
455         remember_pic := currentpicture;
456
457         draw_staff (-2, 2, 0);
458 fet_endchar;
459
460
461 if test > 0:
462         fet_beginchar ("Flat", "-2");
463                 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
464                               0.6 staff_space#, 1.9 staff_space#);
465
466                 currentpicture := remember_pic;
467
468                 draw_staff (-2, 2, 0.5);
469         fet_endchar;
470 fi;
471
472
473 fet_beginchar ("Semi flat", "-1");
474         set_char_box (1.2 stafflinethickness#, .8 staff_space#,
475                       0.6 staff_space#, 1.9 staff_space#);
476
477         draw_meta_flat (0, w, 0.31 staff_space);
478         currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
479 fet_endchar;
480
481
482 fet_beginchar ("Double Flat", "-4");
483         save left_wid, overlap, right_wid;
484
485         left_wid = .7;
486         right_wid = .8;
487         overlap = .05;
488
489         set_char_box (1.2 stafflinethickness#,
490                       (left_wid + right_wid - overlap) * staff_space#,
491                       .6 staff_space#, 1.9 staff_space#);
492         draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
493         draw_meta_flat (round ((left_wid - overlap) * staff_space),
494                         right_wid * staff_space, 0.33 staff_space);
495 fet_endchar;
496
497
498 fet_beginchar ("3/4 Flat", "-3");
499         save left_wid, overlap, right_wid;
500
501         left_wid = .7;
502         right_wid = .8;
503         overlap = .05;
504
505         set_char_box (1.2 stafflinethickness#,
506                       (left_wid + right_wid - overlap) * staff_space#,
507                       .6 staff_space#, 1.9 staff_space#);
508         draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
509         draw_meta_flat (round ((left_wid - overlap) * staff_space),
510                         right_wid * staff_space, 0.33 staff_space);
511
512         %% maybe we should clip part of the stems?
513         %% or make the 1st flat smaller?
514         %% or reverse it?
515         pickup pencircle scaled 2 stafflinethickness;
516
517         z12 = round (-.25 w - b, .55 staff_space) + feta_offset;
518         z13 = round (.75 w, 1.45 staff_space) + feta_offset;
519         penpos12 (2 stafflinethickness, angle (z13 - z12) - 90);
520         penpos13 (2 stafflinethickness, angle (z13 - z12) - 90);
521
522         z14 = z12 - stafflinethickness * unitvector (z13 - z12);
523         z15 = z13 + stafflinethickness * unitvector (z13 - z12);
524
525         fill z13r
526              .. z15
527              .. z13l
528              -- z12l
529              .. z14
530              .. z12 r
531              -- z13r
532              .. cycle;
533
534         penlabels (12, 13);
535         labels (14, 15);
536
537         remember_pic := currentpicture;
538
539         draw_staff (-2, 2, 0);
540 fet_endchar;
541
542
543 if test > 0:
544         fet_beginchar ("3/4 Flat", "-3");
545                 save left_wid, overlap, right_wid;
546
547                 left_wid = .7;
548                 right_wid = .8;
549                 overlap = .05;
550
551                 set_char_box (1.2 stafflinethickness#,
552                               (left_wid + right_wid - overlap) * staff_space#,
553                               .6 staff_space#, 1.9 staff_space#);
554
555                 currentpicture := remember_pic;
556
557                 draw_staff (-2, 2, 0.5);
558         fet_endchar;
559 fi;
560
561
562 fet_beginchar ("Double Sharp", "4");
563         save klaverblad, klaversteel;
564         save pat;
565         path pat;
566
567         klaversteel = 1/15 staff_space;
568         klaverblad = .4 staff_space - .5 stafflinethickness;
569
570         set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
571
572         z1 = (klaversteel, 0);
573         z2 = (w / 2 - klaverblad / 10, h - klaverblad);
574         z3 = (w / 2, h);
575         z4 = z2 reflectedabout ((0, 0), (1, 1));
576         z5 = z1 reflectedabout ((0, 0), (1, 1));
577
578         labels (1, 2, 3, 4, 5);
579
580         pickup pencircle scaled blot_diameter;
581
582         x2 := hfloor (rt x2) - blot_diameter / 2;
583         x3 := hfloor (rt x3) - blot_diameter / 2;
584         y3 := vfloor (top y3) - blot_diameter / 2;
585         y4 := vfloor (top y4) - blot_diameter / 2;
586
587         pat = (rt z1){dir45}
588               .. {right}(bot z2)
589               .. rt z2
590               -- rt z3{z3 - z2}
591               .. top z3{z4 - z3}
592               -- top z4{z4 - z3}
593               .. (lft z4){down}
594               .. {dir 225}(top z5);
595         pat := pat
596                -- reverse pat xscaled -1 shifted (-feta_eps, 0);
597
598         % assure symmetry -- it's more important to center the glyph on the
599         % staff line than centering it between staff lines, so we use
600         % feta_shift, not feta_space_shift.
601         h := h + feta_shift;
602
603         fill pat shifted (0, feta_shift)
604              -- reverse pat yscaled -1 shifted (0, -feta_eps)
605              -- cycle;
606
607         % ugh
608         currentpicture := currentpicture shifted (hround (w / 2), 0);
609
610         remember_pic := currentpicture;
611
612         draw_staff (-2, 2, 0);
613 fet_endchar;
614
615
616 if test > 0:
617         fet_beginchar ("Double Sharp", "4");
618                 set_char_box (0, staff_space#,
619                               .5 staff_space#, .5 staff_space#);
620
621                 currentpicture := remember_pic;
622
623                 draw_staff (-2, 2, 0.5);
624         fet_endchar;
625 fi;
626
627
628 def draw_paren =
629         save leftindent;
630
631         leftindent := .2 staff_space;
632
633         set_char_box (0, .5 staff_space# + stafflinethickness#,
634                       staff_space#, staff_space#);
635
636         d := d - feta_shift;
637
638         z1 = (leftindent, h);
639         z2 = (w - stafflinethickness, .5 (h - d));
640         z3 = (leftindent, -d);
641
642         penpos1 (stafflinethickness, 35);
643         penpos2 (.1 staff_space + stafflinethickness, 0);
644         penpos3 (stafflinethickness, -35);
645
646         fill z2l{down}
647              .. simple_serif (z3l, z3r, 90)
648              .. z2r{up}
649              .. simple_serif (z1r, z1l, 90)
650              .. z2l{down}
651              -- cycle;
652 enddef;
653
654
655 fet_beginchar ("Right Parenthesis", "rightparen");
656         draw_paren;
657         penlabels (1, 2, 3);
658
659         remember_pic := currentpicture;
660
661         draw_staff (-2, 2, 0);
662 fet_endchar;
663
664
665 if test > 0:
666         fet_beginchar ("Right Parenthesis", "rightparen");
667                 draw_paren;
668                 penlabels (1, 2, 3);
669
670                 remember_pic := currentpicture;
671
672                 draw_staff (-2, 2, 0.5);
673         fet_endchar;
674 fi;
675
676
677 fet_beginchar ("Left Parenthesis", "leftparen");
678         draw_paren;
679
680         currentpicture := currentpicture xscaled -1;
681
682         set_char_box (charwd, charbp, chardp, charht);
683 fet_endchar;
684
685
686 fet_endgroup ("accidentals");