]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-toevallig.mf
b6ee76e3ac4b28e5b733dd24499ee653e1aa1d0a
[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--2005 Han-Wen Nienhuys <hanwen@xs4all.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 stemwidth, top_stem_thick;
242         save ne, pat_top, pat_bottom;
243         pair ne;
244         path pat_top, pat_bottom;
245
246         top_stem_thick# = stafflinethickness# + .10 staff_space#;
247         stemwidth# = 0.09 staff_space# + .5 stafflinethickness#;
248         define_whole_blacker_pixels (top_stem_thick, stemwidth);
249
250         set_char_box (0, 2/3 staff_space#,
251                       1.5 staff_space#, 1.5 staff_space#);
252
253         d := d - feta_space_shift;
254
255         pickup pencircle scaled stemwidth;
256
257         penpos1 (top_stem_thick, 0);
258         penpos3 (top_stem_thick, 0);
259         penpos2 (stemwidth, 0);
260         penpos4 (stemwidth, 0);
261
262         x2r = w;
263         x4l = 0;
264         x3 = x2;
265         x1 = x4;
266
267         y1 = h;
268         y3 = -d;
269         top y2 = vround (staff_space - 3/2 stafflinethickness);
270         y4 = -y2 + feta_space_shift;
271
272         pat_bottom := z4r{z4r - z1r}
273                       .. bot z4
274                       .. z4l{z1l - z4l};
275         fill simple_serif (z1l, z1r, -30)
276              -- pat_bottom
277              -- cycle;
278
279         pat_top := z2r{z2r - z3r}
280                    .. top z2
281                    .. z2l{z3l - z2l};
282         fill simple_serif (z3l, z3r, 30)
283              -- pat_top
284              -- cycle;
285
286         ne = (x2 - x4, stafflinethickness);
287
288         z11' = z3l + whatever * (z2l - z3l);
289         y11' = vround (.5 (staff_space - stafflinethickness));
290         z11 = z11' + whatever * ne;
291         x11 = x12;
292         z12 = directionpoint -ne of pat_top;
293         z13 = z12 + whatever * ne;
294         x13 = x1;
295         z14 = z11 + whatever * ne;
296         x14 = x1;
297
298         z21' = z4r + whatever * (z1r - z4r);
299         y21' = -y11' + feta_space_shift;
300         z21 = z21' + whatever * ne;
301         x21 = x22;
302         z22 = directionpoint -ne of pat_bottom;
303         z23 = z22 + whatever * ne;
304         x23 = x3;
305         z24 = z21 + whatever * ne;
306         x24 = x3;
307
308         fill z11
309              -- z12
310              -- z13
311              -- z14
312              -- cycle;
313         fill z21
314              -- z22
315              -- z23
316              -- z24
317              -- cycle;
318
319         penlabels (1, 2, 3, 4);
320         labels (11, 11', 12, 13, 14, 21, 21', 22, 23, 24);
321
322         remember_pic := currentpicture;
323
324         draw_staff (-2, 2, 0);
325 fet_endchar;
326
327
328 if test > 0:
329         fet_beginchar ("Natural", "0");
330                 set_char_box (0, 2/3 staff_space#,
331                               1.5 staff_space#, 1.5 staff_space#);
332
333                 currentpicture := remember_pic;
334
335                 draw_staff (-2, 2, 0.5);
336         fet_endchar;
337 fi;
338
339
340 %
341 % Dedicated to my mom.    (3/10/97)
342 %
343 % Mamma, ik hou van je; kom je alsjeblieft terug?
344 %    -- HW
345 %
346 %
347 % TODO: remove crook_fatness
348 % TODO: document, simplify!
349 %
350
351 def draw_meta_flat (expr xcenter, w, crook_fatness) =
352         save crook_thinness;
353         save bottom_overshoot, bot_crook_dir;
354         save top_stem_thick, bottom_stem_thick, hair, smaller_hole;
355         save top_crook_thinness;
356         save zwiep;
357         save center;
358         pair center, bot_crook_dir;
359         save clearing;
360
361         clearxy;
362
363         % the stem shouldn't reach the top staff line.
364         %% TODO: should take from height.
365         %
366         % TODO: parameterize this
367         %
368         if w >= 0.75 staff_space:
369                 smaller_hole = 0.35 stafflinethickness;
370         else:
371                 smaller_hole = 0;
372         fi
373         clearing = 1.7 stafflinethickness;
374         crook_thinness = .7 stafflinethickness + .06 staff_space;
375         top_crook_thinness = 1 stafflinethickness + .065 staff_space;
376         bottom_overshoot = stafflinethickness;
377
378         bottom_stem_thick# = 0.06 staff_space# + 0.6 stafflinethickness#;
379         top_stem_thick# = 0.1 staff_space# + 1.2 stafflinethickness#;
380         define_whole_blacker_pixels (bottom_stem_thick, top_stem_thick);
381
382         if odd (top_stem_thick - bottom_stem_thick):
383                 top_stem_thick := top_stem_thick - 1;
384         fi;
385
386         center = (xcenter, 0);
387
388         x1l = hround (xcenter - .5 top_stem_thick);
389         y1 = vround (2 staff_space - clearing);
390         x2l = hround (xcenter - .5 bottom_stem_thick);
391         y2 = -.5 staff_space - .5 stafflinethickness;
392
393         penpos1 (top_stem_thick, 0);
394         penpos2 (bottom_stem_thick, 0);
395
396         y3l = vfloor ((staff_space - stafflinethickness) / 2);
397         z3l = whatever [z2r, z1r];
398         z3r = .3 [z2r, z1r] + (smaller_hole, 0);
399         x3r := hceiling x3r;
400
401         % we insert z3l to get better conversion with mf2pt1
402         fill simple_serif (z1r, z1l, 30)
403              -- z2l
404              -- z2r
405              -- z3l
406              -- cycle;
407
408         z10 = whatever [z2r, z1r] + (smaller_hole, 0);
409         y10 = -1/10 staff_space;
410         x10 := hceiling x10;
411
412         x11 = xcenter + bottom_overshoot / 3;
413         y11 = -vround (.5 (staff_space + stafflinethickness)
414                        + bottom_overshoot);
415
416         penpos4 (whatever, 53);
417
418         y4l - y4r = top_crook_thinness;
419         y5r = .15 staff_space;
420         x5l = hround (w + xcenter);
421         y4 = staff_space / 2;
422         x4r = .45 [x5r, x3r];
423         y4l := vround y4l;
424
425         penpos5 (crook_fatness, -175);
426
427         bot_crook_dir = unitvector ((x5l, 0) - z11);
428         z8 = z11 + whatever * bot_crook_dir;
429         y8 = -staff_space / 2;
430
431         z7 = z8
432              + whatever * bot_crook_dir
433              + crook_thinness * (bot_crook_dir rotated 90);
434         x7 = .1 [x3r, x8];
435
436         unfill z3r{z3r - z10}
437                .. z4r{right}
438                .. z5r{down}
439                .. z7{-bot_crook_dir}
440                & z7
441                .. z10{z3r - z10}
442                -- cycle;
443
444         fill z2l{down}
445              .. z11{right}
446              .. z8{bot_crook_dir}
447              .. z5l{up}
448              .. z4l{left}
449              .. z3l
450              -- cycle;
451 enddef;
452
453
454 %
455 % unfortunately, 600dpi is not enough to show the brush of the stem.
456 %
457
458 fet_beginchar ("Flat", "-2");
459         set_char_box (1.2 stafflinethickness#, .8 staff_space#,
460                       0.6 staff_space#, 1.9 staff_space#);
461
462         draw_meta_flat (0, w, 0.31 staff_space);
463         penlabels (range 0 thru 11);
464
465         remember_pic := currentpicture;
466
467         draw_staff (-2, 2, 0);
468 fet_endchar;
469
470
471 if test > 0:
472         fet_beginchar ("Flat", "-2");
473                 set_char_box (1.2 stafflinethickness#, .8 staff_space#,
474                               0.6 staff_space#, 1.9 staff_space#);
475
476                 currentpicture := remember_pic;
477
478                 draw_staff (-2, 2, 0.5);
479         fet_endchar;
480 fi;
481
482
483 fet_beginchar ("Semi flat", "-1");
484         set_char_box (1.2 stafflinethickness#, .8 staff_space#,
485                       0.6 staff_space#, 1.9 staff_space#);
486
487         draw_meta_flat (0, w, 0.31 staff_space);
488         currentpicture := currentpicture xscaled -1 shifted (w - b, 0);
489 fet_endchar;
490
491
492 fet_beginchar ("Double Flat", "-4");
493         save left_wid, overlap, right_wid;
494
495         left_wid = .7;
496         right_wid = .8;
497         overlap = .05;
498
499         set_char_box (1.2 stafflinethickness#,
500                       (left_wid + right_wid - overlap) * staff_space#,
501                       .6 staff_space#, 1.9 staff_space#);
502         draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
503         draw_meta_flat (round ((left_wid - overlap) * staff_space),
504                         right_wid * staff_space, 0.33 staff_space);
505 fet_endchar;
506
507
508 fet_beginchar ("3/4 Flat", "-3");
509         save left_wid, overlap, right_wid;
510
511         left_wid = .7;
512         right_wid = .8;
513         overlap = .05;
514
515         set_char_box (1.2 stafflinethickness#,
516                       (left_wid + right_wid - overlap) * staff_space#,
517                       .6 staff_space#, 1.9 staff_space#);
518         draw_meta_flat (0, left_wid * staff_space, 1/3 staff_space);
519         draw_meta_flat (round ((left_wid - overlap) * staff_space),
520                         right_wid * staff_space, 0.33 staff_space);
521
522         %% maybe we should clip part of the stems?
523         %% or make the 1st flat smaller?
524         %% or reverse it?
525         pickup pencircle scaled 2 stafflinethickness;
526
527         z12 = round (-.25 w - b, .55 staff_space) + feta_offset;
528         z13 = round (.75 w, 1.45 staff_space) + feta_offset;
529         penpos12 (2 stafflinethickness, angle (z13 - z12) - 90);
530         penpos13 (2 stafflinethickness, angle (z13 - z12) - 90);
531
532         z14 = z12 - stafflinethickness * unitvector (z13 - z12);
533         z15 = z13 + stafflinethickness * unitvector (z13 - z12);
534
535         fill z13r
536              .. z15
537              .. z13l
538              -- z12l
539              .. z14
540              .. z12 r
541              -- z13r
542              .. cycle;
543
544         penlabels (12, 13);
545         labels (14, 15);
546
547         remember_pic := currentpicture;
548
549         draw_staff (-2, 2, 0);
550 fet_endchar;
551
552
553 if test > 0:
554         fet_beginchar ("3/4 Flat", "-3");
555                 save left_wid, overlap, right_wid;
556
557                 left_wid = .7;
558                 right_wid = .8;
559                 overlap = .05;
560
561                 set_char_box (1.2 stafflinethickness#,
562                               (left_wid + right_wid - overlap) * staff_space#,
563                               .6 staff_space#, 1.9 staff_space#);
564
565                 currentpicture := remember_pic;
566
567                 draw_staff (-2, 2, 0.5);
568         fet_endchar;
569 fi;
570
571
572 fet_beginchar ("Double Sharp", "4");
573         save klaverblad, klaversteel;
574         save pat;
575         path pat;
576
577         klaversteel = 1/15 staff_space;
578         klaverblad = .4 staff_space - .5 stafflinethickness;
579
580         set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
581
582         z1 = (klaversteel, 0);
583         z2 = (w / 2 - klaverblad / 10, h - klaverblad);
584         z3 = (w / 2, h);
585         z4 = z2 reflectedabout ((0, 0), (1, 1));
586         z5 = z1 reflectedabout ((0, 0), (1, 1));
587
588         labels (1, 2, 3, 4, 5);
589
590         pickup pencircle scaled blot_diameter;
591
592         x2 := hfloor (rt x2) - blot_diameter / 2;
593         x3 := hfloor (rt x3) - blot_diameter / 2;
594         y3 := vfloor (top y3) - blot_diameter / 2;
595         y4 := vfloor (top y4) - blot_diameter / 2;
596
597         pat = (rt z1){dir45}
598               .. {right}(bot z2)
599               .. rt z2
600               -- rt z3{z3 - z2}
601               .. top z3{z4 - z3}
602               -- top z4{z4 - z3}
603               .. (lft z4){down}
604               .. {dir 225}(top z5);
605         pat := pat
606                -- reverse pat xscaled -1 shifted (-feta_eps, 0);
607
608         % assure symmetry -- it's more important to center the glyph on the
609         % staff line than centering it between staff lines, so we use
610         % feta_shift, not feta_space_shift.
611         h := h + feta_shift;
612
613         fill pat shifted (0, feta_shift)
614              -- reverse pat yscaled -1 shifted (0, -feta_eps)
615              -- cycle;
616
617         % ugh
618         currentpicture := currentpicture shifted (hround (w / 2), 0);
619
620         remember_pic := currentpicture;
621
622         draw_staff (-2, 2, 0);
623 fet_endchar;
624
625
626 if test > 0:
627         fet_beginchar ("Double Sharp", "4");
628                 set_char_box (0, staff_space#,
629                               .5 staff_space#, .5 staff_space#);
630
631                 currentpicture := remember_pic;
632
633                 draw_staff (-2, 2, 0.5);
634         fet_endchar;
635 fi;
636
637
638 def draw_paren =
639         save leftindent;
640
641         leftindent := .2 staff_space;
642
643         set_char_box (0, .5 staff_space# + stafflinethickness#,
644                       staff_space#, staff_space#);
645
646         d := d - feta_shift;
647
648         z1 = (leftindent, h);
649         z2 = (w - stafflinethickness, .5 (h - d));
650         z3 = (leftindent, -d);
651
652         penpos1 (stafflinethickness, 35);
653         penpos2 (.1 staff_space + stafflinethickness, 0);
654         penpos3 (stafflinethickness, -35);
655
656         fill z2l{down}
657              .. simple_serif (z3l, z3r, 90)
658              .. z2r{up}
659              .. simple_serif (z1r, z1l, 90)
660              .. z2l{down}
661              -- cycle;
662 enddef;
663
664
665 fet_beginchar ("Right Parenthesis", "rightparen");
666         draw_paren;
667         penlabels (1, 2, 3);
668
669         remember_pic := currentpicture;
670
671         draw_staff (-2, 2, 0);
672 fet_endchar;
673
674
675 if test > 0:
676         fet_beginchar ("Right Parenthesis", "rightparen");
677                 draw_paren;
678                 penlabels (1, 2, 3);
679
680                 remember_pic := currentpicture;
681
682                 draw_staff (-2, 2, 0.5);
683         fet_endchar;
684 fi;
685
686
687 fet_beginchar ("Left Parenthesis", "leftparen");
688         draw_paren;
689
690         currentpicture := currentpicture xscaled -1;
691
692         set_char_box (charwd, charbp, chardp, charht);
693 fet_endchar;
694
695
696 fet_endgroup ("accidentals");