]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-flags.mf
Whitespace.
[lilypond.git] / mf / feta-flags.mf
1 % Feta (not the Font-En-Tja) music font -- draw flags
2 % This file is part of LilyPond, the GNU music typesetter.
3 %
4 % Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 %
6 % LilyPond is free software: you can redistribute it and/or modify
7 % it under the terms of the GNU General Public License as published by
8 % the Free Software Foundation, either version 3 of the License, or
9 % (at your option) any later version.
10 %
11 % LilyPond is distributed in the hope that it will be useful,
12 % but WITHOUT ANY WARRANTY; without even the implied warranty of
13 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 % GNU General Public License for more details.
15 %
16 % You should have received a copy of the GNU General Public License
17 % along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18
19 fet_begingroup ("flags");
20
21 save outer_path;
22 path outer_path;
23
24 %
25 % Flags pointing down overlap with the notehead (in x-direction), so
26 % the down-flag can be bigger.
27 %
28
29 upflag_width# = .65 black_notehead_width# + stemthickness# / 2;
30 downflag_width# = .833 black_notehead_width# + stemthickness# / 2;
31
32 right_upflag_space# = .0 upflag_width#;
33 right_downflag_space# = .0 downflag_width#;
34
35 %
36 % Flags pointing down cannot overlap with the notehead in y-direction,
37 % so they have less slant.
38 %
39 % Because of optical illusion, the utmost flag (bottom for
40 % down-pointing, top for up-pointing) should be smaller than the other
41 % flags.  Adobe Sonata doesn't do this correctly.  (Instead they have
42 % an extension flag, which looks less elegant.)
43 %
44
45 save hip_thickness, foot_thickness;
46
47 hip_thickness# = 1.0 linethickness# + 0.069 staff_space#;
48 foot_thickness# = 1.2055 linethickness# + 0.06 staff_space#;
49
50 define_pixels (hip_thickness, foot_thickness);
51
52 %
53 % Inspired by Adobe Sonata and [Wanske].
54 % For example, see POSTSCRIPT Language -- program design,
55 % page 119, and [Wanske], p 41, 42.
56 %
57
58 def draw_flag (expr center, flare, dims, hip_depth, foot_wid,
59                hip_thickness, foot_thickness, show_labels) =
60         save c;
61
62         clearxy;
63
64         c = 0.7;
65
66         penpos1 (flare, 90);
67         penpos2 (whatever, 0);
68
69         x2r - x2l = hround (hip_thickness);
70
71         penpos3 (foot_thickness, -20.0);
72
73         z1r = center;
74         z2r = center + (xpart (dims), -ypart (dims) * hip_depth);
75         z3r = center + (xpart (dims) * foot_wid, -ypart (dims));
76
77         x2r := hround x2r;
78         y2r := vround y2r;
79
80         outer_path := z3r{curl c}
81                       .. z2r{up}
82                       .. {up}z1r;
83
84         if show_labels = 1:
85                 penlabels (1, 2, 3);
86         fi;
87
88         fill z1l{curl 0}
89              ..tension 1.1.. z2l{down}
90              .. {curl c}simple_serif (z3l, z3r, 80)
91              & outer_path
92              & z1r
93              -- cycle;
94 enddef;
95
96 %
97 % TODO: calculate intersectpoint (see TeX book, p. 137)
98 % TODO: calculate incision_depth
99 %
100
101 def add_flag (expr yoff, flare, hip_wid_multiplier, hip_dep_multiplier,
102               intersectpoint, hip_thickness, foot_thickness) =
103 begingroup
104         save prev_center, prev_xextreme, prev_yextreme;
105         save rel_foot, ip, center, incision_depth;
106         save prev_hipwid, prev_footdep, prev_hipdep, wid, dep, hip_dep;
107         save hip_dep_ratio, foot_wid_ratio;
108         pair prev_center, center, foot, prev_xextreme, prev_yextreme;
109         pair ip, rel_foot;
110
111         incision_depth = 1.013;
112         prev_center = point 2 of outer_path;
113         prev_xextreme = point 1 of outer_path;
114         prev_yextreme = point 0 of outer_path;
115         prev_hipwid = xpart (prev_xextreme - prev_center);
116         prev_footdep = -ypart (prev_yextreme - prev_center);
117         prev_hipdep = -ypart (prev_xextreme - prev_center);
118         ip = point intersectpoint of outer_path;
119
120         wid = prev_hipwid * hip_wid_multiplier;
121         hip_dep = prev_hipdep * hip_dep_multiplier;
122
123         center = prev_center + (0, yoff);
124         rel_foot = incision_depth [(wid, hip_dep), ip - center];
125         dep = -ypart (rel_foot);
126         foot_wid_ratio = xpart (rel_foot) / wid;
127         hip_dep_ratio = hip_dep / dep;
128
129         draw_flag (center, flare, (wid, dep),
130                    hip_dep_ratio, foot_wid_ratio,
131                    hip_thickness, foot_thickness, 0);
132 endgroup
133 enddef;
134
135
136 fet_beginchar ("8th Flag (up)", "u3");
137         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
138         save flagspace, total_depth, flag_count;
139
140         flag_count = 1;
141         total_depth# = 3 staff_space# - blot_diameter# / 2;
142         flare = staff_space;
143         flagspace# = staff_space#;
144         hip_depth_ratio = .72;
145         hip_width# = upflag_width# - hip_thickness# / 2;
146         foot_width_ratio = .8;
147
148         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
149
150         define_pixels (hip_width, foot_depth);
151         define_whole_vertical_pixels (flagspace);
152
153         set_char_box (0, hip_width# + stemthickness# / 2 + right_upflag_space#,
154                       foot_depth# + foot_thickness# / 2, stemthickness# / 2);
155
156         draw_flag ((0, -(flag_count - 1) * flagspace),
157                    flare, (hip_width, foot_depth),
158                    hip_depth_ratio, foot_width_ratio,
159                    hip_thickness, foot_thickness, 1);
160
161         draw_square_block ((-0.5 stemthickness_rounded, 0),
162                            (0, (-flag_count * staff_space_rounded)));
163 fet_endchar;
164
165
166 fet_beginchar ("16th Flag (up)", "u4");
167         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
168         save flagspace, total_depth, flag_count;
169
170         flag_count = 2;
171         total_depth# = 3.5 staff_space# - blot_diameter# / 2;
172         flare = .85 staff_space;
173         flagspace# = .85 staff_space#;
174         hip_depth_ratio = .72;
175         hip_width# = upflag_width# - hip_thickness# / 2;
176         foot_width_ratio = .8;
177
178         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
179
180         define_pixels (hip_width, foot_depth);
181         define_whole_vertical_pixels (flagspace);
182
183         set_char_box (0, hip_width# + stemthickness# / 2 + right_upflag_space#,
184                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
185
186         draw_flag ((0, -(flag_count - 1) * flagspace),
187                    flare, (hip_width, foot_depth),
188                    hip_depth_ratio, foot_width_ratio,
189                    hip_thickness, foot_thickness, 1);
190
191         add_flag (flagspace, flare, .97, 1.00, 1.25,
192                   hip_thickness, foot_thickness);
193
194         draw_square_block ((-0.5 stemthickness_rounded, 0),
195                            (0, (-flag_count * staff_space_rounded)));
196 fet_endchar;
197
198
199 fet_beginchar ("32nd Flag (up)", "u5");
200         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
201         save flagspace, total_depth, flag_count;
202
203         flag_count = 3;
204         total_depth# = 4.25 staff_space# - blot_diameter# / 2;
205         flare = .85 staff_space;
206         flagspace# = .87 staff_space#;
207         hip_depth_ratio = .72;
208         hip_width# = upflag_width# - hip_thickness# / 2;
209         foot_width_ratio = .8;
210
211         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
212
213         define_pixels (hip_width, foot_depth);
214         define_whole_vertical_pixels (flagspace);
215
216         set_char_box (0, hip_width# + right_upflag_space#,
217                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
218
219         draw_flag ((0, -(flag_count - 1) * flagspace),
220                    flare, (hip_width, foot_depth),
221                    hip_depth_ratio, foot_width_ratio,
222                    hip_thickness, foot_thickness, 1);
223
224         add_flag (flagspace, flare, .97, 1.00, 1.25,
225                   hip_thickness, foot_thickness);
226         add_flag (flagspace, flare, .95, 1.05, 1.25,
227                   hip_thickness, foot_thickness);
228
229         draw_square_block ((-0.5 stemthickness_rounded, 0),
230                            (0, (-flag_count * staff_space_rounded)));
231 fet_endchar;
232
233
234 fet_beginchar ("64th Flag (up)", "u6");
235         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
236         save flagspace, total_depth, flag_count;
237
238         flag_count = 4;
239         total_depth# = 5.25 staff_space# - blot_diameter# / 2;
240         flare = .85 staff_space;
241         flagspace# = .9 staff_space#;
242         hip_depth_ratio = .72;
243         hip_width# = upflag_width# - hip_thickness# / 2;
244         foot_width_ratio = .8;
245
246         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
247
248         define_pixels (hip_width, foot_depth);
249         define_whole_vertical_pixels (flagspace);
250
251         set_char_box (0, hip_width# + right_upflag_space#,
252                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
253
254         draw_flag ((0, -(flag_count - 1) * flagspace),
255                    flare, (hip_width, foot_depth),
256                    hip_depth_ratio, foot_width_ratio,
257                    hip_thickness, foot_thickness, 1);
258
259         add_flag (flagspace, flare, .97, 1.00, 1.3,
260                   hip_thickness, foot_thickness);
261         add_flag (flagspace, flare, 1.00, 1.00, 1.25,
262                   hip_thickness, foot_thickness);
263         add_flag (flagspace, flare, .95, 1.05, 1.25,
264                   hip_thickness, foot_thickness);
265
266         draw_square_block ((-0.5 stemthickness_rounded, 0),
267                            (0, (-flag_count * staff_space_rounded)));
268 fet_endchar;
269
270
271 fet_beginchar ("128th Flag (up)", "u7");
272         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
273         save flagspace, total_depth, flag_count;
274
275         flag_count = 5;
276         total_depth# = 6.25 staff_space# - blot_diameter# / 2;
277         flare = .85 staff_space;
278         flagspace# = .93 staff_space#;
279         hip_depth_ratio = .72;
280         hip_width# = upflag_width# - hip_thickness# / 2;
281         foot_width_ratio = .8;
282
283         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
284
285         define_pixels (hip_width, foot_depth);
286         define_whole_vertical_pixels (flagspace);
287
288         set_char_box (0, hip_width# + right_upflag_space#,
289                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
290
291         draw_flag ((0, -(flag_count - 1) * flagspace),
292                    flare, (hip_width, foot_depth),
293                    hip_depth_ratio, foot_width_ratio,
294                    hip_thickness, foot_thickness, 1);
295
296         add_flag (flagspace, flare, .97, 1.00, 1.3,
297                   hip_thickness, foot_thickness);
298         add_flag (flagspace, flare, 1.00, 1.00, 1.25,
299                   hip_thickness, foot_thickness);
300         add_flag (flagspace, flare, 1.00, 1.00, 1.25,
301                   hip_thickness, foot_thickness);
302         add_flag (flagspace, flare, 0.95, 1.05, 1.25,
303                   hip_thickness, foot_thickness);
304
305         draw_square_block ((-0.5 stemthickness_rounded, 0),
306                            (0, (-flag_count * staff_space_rounded)));
307 fet_endchar;
308
309
310 fet_beginchar ("8th (down)", "d3");
311         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
312         save flagspace, total_depth, flag_count;
313
314         flag_count = 1;
315         total_depth# = 2.75 staff_space#;
316         flare = staff_space;
317         flagspace# = .9 staff_space#;
318         hip_depth_ratio = .74;
319         hip_width# = downflag_width# - hip_thickness# / 2;
320         foot_width_ratio = .85;
321
322         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
323
324         define_pixels (hip_width, foot_depth);
325         define_whole_vertical_pixels (flagspace);
326
327         set_char_box (0, hip_width# + right_downflag_space#,
328                       total_depth# + foot_thickness# / 2, stemthickness# / 2)
329
330         draw_flag ((0, -(flag_count - 1) * flagspace),
331                    flare, (hip_width, foot_depth),
332                    hip_depth_ratio, foot_width_ratio,
333                    hip_thickness, foot_thickness, 0);
334
335         draw_square_block ((-0.5 stemthickness_rounded, 0),
336                            (0, (-flag_count * staff_space_rounded)));
337
338         y_mirror_char;
339 fet_endchar;
340
341
342 fet_beginchar ("16th (down)", "d4");
343         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
344         save flagspace, total_depth, flag_count;
345
346         flag_count = 2;
347         total_depth# = 3.0 staff_space# - blot_diameter# / 2;
348         flare = .82 staff_space;
349         flagspace# = .9 staff_space#;
350         hip_depth_ratio = .85;
351         hip_width# = downflag_width# - hip_thickness# / 2;
352         foot_width_ratio = .95;
353
354         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
355
356         define_pixels (hip_width, foot_depth);
357         define_whole_vertical_pixels (flagspace);
358
359         set_char_box (0, hip_width# + right_downflag_space#,
360                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
361
362         draw_flag ((0, -(flag_count - 1) * flagspace),
363                    flare, (hip_width, foot_depth),
364                    hip_depth_ratio, foot_width_ratio,
365                    hip_thickness, foot_thickness, 0);
366
367         add_flag (flagspace, flare, .95, 1.00, 1.25,
368                   hip_thickness, foot_thickness);
369
370         draw_square_block ((-0.5 stemthickness_rounded, 0),
371                            (0, (-flag_count * staff_space_rounded)));
372
373         y_mirror_char;
374 fet_endchar;
375
376
377 fet_beginchar ("32nd (down)", "d5");
378         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
379         save flagspace, total_depth, flag_count;
380
381         flag_count = 3;
382         total_depth# = 3.75 * staff_space# - blot_diameter# / 2;
383         flare = .82 staff_space;
384         flagspace# = .88 staff_space#;
385         hip_depth_ratio = .87;
386         hip_width# = downflag_width# - hip_thickness# / 2;
387         foot_width_ratio = .965;
388
389         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
390
391         define_pixels (hip_width, foot_depth);
392         define_whole_vertical_pixels (flagspace);
393
394         set_char_box (0, hip_width# + right_downflag_space#,
395                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
396
397         draw_flag ((0, -(flag_count - 1) * flagspace),
398                    flare, (hip_width, foot_depth),
399                    hip_depth_ratio, foot_width_ratio,
400                    hip_thickness, foot_thickness, 0);
401
402         add_flag (flagspace, flare, .98, 1.00, 1.22,
403                   hip_thickness, foot_thickness);
404         add_flag (flagspace, flare, .95, 1.02, 1.22,
405                   hip_thickness, foot_thickness);
406
407         draw_square_block ((-0.5 stemthickness_rounded, 0),
408                            (0, (-flag_count * staff_space_rounded)));
409
410         y_mirror_char;
411 fet_endchar;
412
413
414 fet_beginchar ("64th (down)", "d6");
415         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
416         save flagspace, total_depth, flag_count;
417
418         flag_count = 4;
419         total_depth# = 4.5 staff_space# - blot_diameter# / 2;
420         flare = .8 staff_space;
421         flagspace# = .9 staff_space#;
422         hip_depth_ratio = .83;
423         hip_width# = downflag_width# - hip_thickness# / 2;
424         foot_width_ratio = .975;
425
426         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
427
428         define_pixels (hip_width, foot_depth);
429         define_whole_vertical_pixels (flagspace);
430
431         set_char_box (0, hip_width# + right_downflag_space#,
432                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
433
434         draw_flag ((0, -(flag_count - 1) * flagspace),
435                    flare, (hip_width, foot_depth),
436                    hip_depth_ratio, foot_width_ratio,
437                    hip_thickness, foot_thickness, 0);
438
439         add_flag (flagspace, flare, .98, 1.10, 1.19,
440                   hip_thickness, foot_thickness);
441         add_flag (flagspace, flare, .98, 1.08, 1.19,
442                   hip_thickness, foot_thickness);
443         add_flag (.98 flagspace, flare, .94, 1.04, 1.21,
444                   hip_thickness, foot_thickness);
445
446         draw_square_block ((-0.5 stemthickness_rounded, 0),
447                            (0, (-flag_count * staff_space_rounded)));
448
449         y_mirror_char;
450 fet_endchar;
451
452
453 fet_beginchar ("128th (down)", "d7");
454         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
455         save flagspace, total_depth, flag_count;
456
457         flag_count = 5;
458         total_depth# = 5.5 staff_space# - blot_diameter# / 2;
459         flare = .8 staff_space;
460         flagspace# = .92 staff_space#;
461         hip_depth_ratio = .85;
462         hip_width# = downflag_width# - hip_thickness# / 2;
463         foot_width_ratio = .98;
464
465         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
466
467         define_pixels (hip_width, foot_depth);
468         define_whole_vertical_pixels (flagspace);
469
470         set_char_box (0, hip_width# + right_downflag_space#,
471                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
472
473         draw_flag ((0, -(flag_count - 1) * flagspace),
474                    flare, (hip_width, foot_depth),
475                    hip_depth_ratio, foot_width_ratio,
476                    hip_thickness, foot_thickness, 0);
477
478         add_flag (flagspace, flare, .98, 1.10, 1.185,
479                   hip_thickness, foot_thickness);
480         add_flag (flagspace, flare, .98, 1.08, 1.185,
481                   hip_thickness, foot_thickness);
482         add_flag (.98 flagspace, flare, .97, 1.06, 1.2,
483                   hip_thickness, foot_thickness);
484         add_flag (.98 flagspace, flare, .93, 1.04, 1.22,
485                   hip_thickness, foot_thickness);
486
487         draw_square_block ((-0.5 stemthickness_rounded, 0),
488                            (0, (-flag_count * staff_space_rounded)));
489
490         y_mirror_char;
491 fet_endchar;
492
493
494 %%%%%%%%
495 %
496 % Single Stroke for Short Appogiatura
497 %
498
499 fet_beginchar ("grace dash (up)", "ugrace");
500         save flare, hip_depth_ratio, hip_width, foot_depth;
501
502         hip_depth_ratio = .72;
503         flare# = staff_space#;
504         hip_width# = upflag_width# - hip_thickness# / 2;
505         foot_depth# = 3 staff_space#;
506
507         define_pixels (hip_width, foot_depth);
508
509         set_char_box (hip_width# * hip_depth_ratio,
510                       hip_width# + right_upflag_space#,
511                       foot_depth# * hip_depth_ratio, -flare#)
512
513         pickup pencircle scaled 1.5 stemthickness;
514
515         z1 = (-b, -d);
516         z2 = (w, h);
517
518         penpos1 (1.5 stemthickness, angle (z2 - z1) - 90);
519         penpos2 (1.5 stemthickness, angle (z2 - z1) - 90);
520
521         fill z1l
522              -- z2l
523              .. top z2
524              .. rt z2
525              .. z2r
526              -- z1r
527              .. bot z1
528              .. lft z1
529              .. cycle;
530
531         penlabels (1, 2);
532 fet_endchar;
533
534
535 fet_beginchar ("grace dash (down)", "dgrace");
536         save flare, hip_depth_ratio, hip_width, foot_depth;
537         save total_depth;
538
539         hip_depth_ratio = .72 ;
540         flare# = .99 staff_space#;
541         hip_width# = downflag_width# - hip_thickness# / 2;
542         total_depth# = 2.85 staff_space#;
543         foot_depth# = total_depth#;
544         foot_width_ratio = .8;
545
546         define_pixels (hip_width, foot_depth);
547
548         set_char_box (hip_width# * hip_depth_ratio,
549                       hip_width# + right_downflag_space#,
550                       foot_depth# * hip_depth_ratio, -flare#)
551
552         pickup pencircle scaled 1.5 stemthickness;
553
554         z1 = (-b, -d);
555         z2 = (w, h);
556
557         penpos1 (1.5 stemthickness, angle (z2 - z1) - 90);
558         penpos2 (1.5 stemthickness, angle (z2 - z1) - 90);
559
560         fill z1l
561              -- z2l
562              .. top z2
563              .. rt z2
564              .. z2r
565              -- z1r
566              .. bot z1
567              .. lft z1
568              .. cycle;
569
570         y_mirror_char;
571 fet_endchar;
572
573
574 fet_endgroup ("flags");