]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-flags.mf
Add '-dcrop' option to ps and svg backends
[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--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 %
6 % The LilyPond font 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, or under the SIL Open Font License.
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
137
138 def upstemsingleflag (expr shortening) =
139         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
140         save flagspace, total_depth, flag_count;
141
142         flag_count = 1;
143         total_depth# = (3 - shortening) * staff_space# - blot_diameter# / 2;
144         flare = staff_space;
145         flagspace# = staff_space#;
146         hip_depth_ratio = .72;
147         hip_width# = upflag_width# - hip_thickness# / 2;
148         foot_width_ratio = .8;
149
150         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
151
152         define_pixels (hip_width, foot_depth);
153         define_whole_vertical_pixels (flagspace);
154
155         set_char_box (0, hip_width# + stemthickness# / 2 + right_upflag_space#,
156                       foot_depth# + foot_thickness# / 2, stemthickness# / 2);
157
158         draw_flag ((0, -(flag_count - 1) * flagspace),
159                    flare, (hip_width, foot_depth),
160                    hip_depth_ratio, foot_width_ratio,
161                    hip_thickness, foot_thickness, 1);
162
163         draw_square_block ((-0.5 stemthickness_rounded, 0),
164                            (0, (-flag_count * staff_space_rounded)));
165 enddef;
166
167
168 def upstemdoubleflag (expr shortening) =
169         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
170         save flagspace, total_depth, flag_count;
171
172         flag_count = 2;
173         total_depth# = (3.5 - shortening) * staff_space# - blot_diameter# / 2;
174         flare = .85 staff_space;
175         flagspace# = .85 staff_space#;
176         hip_depth_ratio = .72;
177         hip_width# = upflag_width# - hip_thickness# / 2;
178         foot_width_ratio = .8;
179
180         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
181
182         define_pixels (hip_width, foot_depth);
183         define_whole_vertical_pixels (flagspace);
184
185         set_char_box (0, hip_width# + stemthickness# / 2 + right_upflag_space#,
186                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
187
188         draw_flag ((0, -(flag_count - 1) * flagspace),
189                    flare, (hip_width, foot_depth),
190                    hip_depth_ratio, foot_width_ratio,
191                    hip_thickness, foot_thickness, 1);
192
193         add_flag (flagspace, flare, .97, 1.00, 1.25,
194                   hip_thickness, foot_thickness);
195
196         draw_square_block ((-0.5 stemthickness_rounded, 0),
197                            (0, (-flag_count * staff_space_rounded)));
198 enddef;
199
200
201 def upstemtripleflag (expr shortening) =
202         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
203         save flagspace, total_depth, flag_count;
204
205         flag_count = 3;
206         total_depth# = (4.25 - shortening) * staff_space# - blot_diameter# / 2;
207         flare = .85 staff_space;
208         flagspace# = .87 staff_space#;
209         hip_depth_ratio = .72;
210         hip_width# = upflag_width# - hip_thickness# / 2;
211         foot_width_ratio = .8;
212
213         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
214
215         define_pixels (hip_width, foot_depth);
216         define_whole_vertical_pixels (flagspace);
217
218         set_char_box (0, hip_width# + right_upflag_space#,
219                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
220
221         draw_flag ((0, -(flag_count - 1) * flagspace),
222                    flare, (hip_width, foot_depth),
223                    hip_depth_ratio, foot_width_ratio,
224                    hip_thickness, foot_thickness, 1);
225
226         add_flag (flagspace, flare, .97, 1.00, 1.25,
227                   hip_thickness, foot_thickness);
228         add_flag (flagspace, flare, .95, 1.05, 1.25,
229                   hip_thickness, foot_thickness);
230
231         draw_square_block ((-0.5 stemthickness_rounded, 0),
232                            (0, (-flag_count * staff_space_rounded)));
233 enddef;
234
235
236 def upstemquadrupleflag (expr shortening) =
237         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
238         save flagspace, total_depth, flag_count;
239
240         flag_count = 4;
241         total_depth# = (5.25 - shortening) *  staff_space# - blot_diameter# / 2;
242         flare = .85 staff_space;
243         flagspace# = .9 staff_space#;
244         hip_depth_ratio = .72;
245         hip_width# = upflag_width# - hip_thickness# / 2;
246         foot_width_ratio = .8;
247
248         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
249
250         define_pixels (hip_width, foot_depth);
251         define_whole_vertical_pixels (flagspace);
252
253         set_char_box (0, hip_width# + right_upflag_space#,
254                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
255
256         draw_flag ((0, -(flag_count - 1) * flagspace),
257                    flare, (hip_width, foot_depth),
258                    hip_depth_ratio, foot_width_ratio,
259                    hip_thickness, foot_thickness, 1);
260
261         add_flag (flagspace, flare, .97, 1.00, 1.3,
262                   hip_thickness, foot_thickness);
263         add_flag (flagspace, flare, 1.00, 1.00, 1.25,
264                   hip_thickness, foot_thickness);
265         add_flag (flagspace, flare, .95, 1.05, 1.25,
266                   hip_thickness, foot_thickness);
267
268         draw_square_block ((-0.5 stemthickness_rounded, 0),
269                            (0, (-flag_count * staff_space_rounded)));
270 enddef;
271
272
273 def upstemquintupleflag (expr shortening) =
274         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
275         save flagspace, total_depth, flag_count;
276
277         flag_count = 5;
278         total_depth# = (6.25 - shortening) *  staff_space# - blot_diameter# / 2;
279         flare = .85 staff_space;
280         flagspace# = .93 staff_space#;
281         hip_depth_ratio = .72;
282         hip_width# = upflag_width# - hip_thickness# / 2;
283         foot_width_ratio = .8;
284
285         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
286
287         define_pixels (hip_width, foot_depth);
288         define_whole_vertical_pixels (flagspace);
289
290         set_char_box (0, hip_width# + right_upflag_space#,
291                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
292
293         draw_flag ((0, -(flag_count - 1) * flagspace),
294                    flare, (hip_width, foot_depth),
295                    hip_depth_ratio, foot_width_ratio,
296                    hip_thickness, foot_thickness, 1);
297
298         add_flag (flagspace, flare, .97, 1.00, 1.3,
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, 1.00, 1.00, 1.25,
303                   hip_thickness, foot_thickness);
304         add_flag (flagspace, flare, 0.95, 1.05, 1.25,
305                   hip_thickness, foot_thickness);
306
307         draw_square_block ((-0.5 stemthickness_rounded, 0),
308                            (0, (-flag_count * staff_space_rounded)));
309 enddef;
310
311
312
313
314 def downstemsingleflag (expr shortening) =
315         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
316         save flagspace, total_depth, flag_count;
317
318         flag_count = 1;
319         total_depth# = (2.75 - shortening) * staff_space#;
320         flare = staff_space;
321         flagspace# = .9 staff_space#;
322         hip_depth_ratio = .74;
323         hip_width# = downflag_width# - hip_thickness# / 2;
324         foot_width_ratio = .85;
325
326         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
327
328         define_pixels (hip_width, foot_depth);
329         define_whole_vertical_pixels (flagspace);
330
331         set_char_box (0, hip_width# + right_downflag_space#,
332                       total_depth# + foot_thickness# / 2, stemthickness# / 2)
333
334         draw_flag ((0, -(flag_count - 1) * flagspace),
335                    flare, (hip_width, foot_depth),
336                    hip_depth_ratio, foot_width_ratio,
337                    hip_thickness, foot_thickness, 0);
338
339         draw_square_block ((-0.5 stemthickness_rounded, 0),
340                            (0, (-flag_count * staff_space_rounded)));
341
342         y_mirror_char;
343 enddef;
344
345
346 def downstemdoubleflag (expr shortening) =
347         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
348         save flagspace, total_depth, flag_count;
349
350         flag_count = 2;
351         total_depth# = (3.0 - shortening) * staff_space# - blot_diameter# / 2;
352         flare = .82 staff_space;
353         flagspace# = .9 staff_space#;
354         hip_depth_ratio = .85;
355         hip_width# = downflag_width# - hip_thickness# / 2;
356         foot_width_ratio = .95;
357
358         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
359
360         define_pixels (hip_width, foot_depth);
361         define_whole_vertical_pixels (flagspace);
362
363         set_char_box (0, hip_width# + right_downflag_space#,
364                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
365
366         draw_flag ((0, -(flag_count - 1) * flagspace),
367                    flare, (hip_width, foot_depth),
368                    hip_depth_ratio, foot_width_ratio,
369                    hip_thickness, foot_thickness, 0);
370
371         add_flag (flagspace, flare, .95, 1.00, 1.25,
372                   hip_thickness, foot_thickness);
373
374         draw_square_block ((-0.5 stemthickness_rounded, 0),
375                            (0, (-flag_count * staff_space_rounded)));
376
377         y_mirror_char;
378 enddef;
379
380
381 def downstemtripleflag (expr shortening) =
382         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
383         save flagspace, total_depth, flag_count;
384
385         flag_count = 3;
386         total_depth# = (3.75 - shortening) * staff_space# - blot_diameter# / 2;
387         flare = .82 staff_space;
388         flagspace# = .88 staff_space#;
389         hip_depth_ratio = .87;
390         hip_width# = downflag_width# - hip_thickness# / 2;
391         foot_width_ratio = .965;
392
393         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
394
395         define_pixels (hip_width, foot_depth);
396         define_whole_vertical_pixels (flagspace);
397
398         set_char_box (0, hip_width# + right_downflag_space#,
399                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
400
401         draw_flag ((0, -(flag_count - 1) * flagspace),
402                    flare, (hip_width, foot_depth),
403                    hip_depth_ratio, foot_width_ratio,
404                    hip_thickness, foot_thickness, 0);
405
406         add_flag (flagspace, flare, .98, 1.00, 1.22,
407                   hip_thickness, foot_thickness);
408         add_flag (flagspace, flare, .95, 1.02, 1.22,
409                   hip_thickness, foot_thickness);
410
411         draw_square_block ((-0.5 stemthickness_rounded, 0),
412                            (0, (-flag_count * staff_space_rounded)));
413
414         y_mirror_char;
415 enddef;
416
417
418 def downstemquadrupleflag (expr shortening) =
419         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
420         save flagspace, total_depth, flag_count;
421
422         flag_count = 4;
423         total_depth# = (4.5 - shortening) * staff_space# - blot_diameter# / 2;
424         flare = .8 staff_space;
425         flagspace# = .9 staff_space#;
426         hip_depth_ratio = .83;
427         hip_width# = downflag_width# - hip_thickness# / 2;
428         foot_width_ratio = .975;
429
430         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
431
432         define_pixels (hip_width, foot_depth);
433         define_whole_vertical_pixels (flagspace);
434
435         set_char_box (0, hip_width# + right_downflag_space#,
436                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
437
438         draw_flag ((0, -(flag_count - 1) * flagspace),
439                    flare, (hip_width, foot_depth),
440                    hip_depth_ratio, foot_width_ratio,
441                    hip_thickness, foot_thickness, 0);
442
443         add_flag (flagspace, flare, .98, 1.10, 1.19,
444                   hip_thickness, foot_thickness);
445         add_flag (flagspace, flare, .98, 1.08, 1.19,
446                   hip_thickness, foot_thickness);
447         add_flag (.98 flagspace, flare, .94, 1.04, 1.21,
448                   hip_thickness, foot_thickness);
449
450         draw_square_block ((-0.5 stemthickness_rounded, 0),
451                            (0, (-flag_count * staff_space_rounded)));
452
453         y_mirror_char;
454 enddef;
455
456
457 def downstemquintupleflag (expr shortening) =
458         save flare, hip_depth_ratio, hip_width, foot_depth, foot_width_ratio;
459         save flagspace, total_depth, flag_count;
460
461         flag_count = 5;
462         total_depth# = (5.5 - shortening) * staff_space# - blot_diameter# / 2;
463         flare = .8 staff_space;
464         flagspace# = .92 staff_space#;
465         hip_depth_ratio = .85;
466         hip_width# = downflag_width# - hip_thickness# / 2;
467         foot_width_ratio = .98;
468
469         (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
470
471         define_pixels (hip_width, foot_depth);
472         define_whole_vertical_pixels (flagspace);
473
474         set_char_box (0, hip_width# + right_downflag_space#,
475                       total_depth# + foot_thickness# / 2, stemthickness# / 2);
476
477         draw_flag ((0, -(flag_count - 1) * flagspace),
478                    flare, (hip_width, foot_depth),
479                    hip_depth_ratio, foot_width_ratio,
480                    hip_thickness, foot_thickness, 0);
481
482         add_flag (flagspace, flare, .98, 1.10, 1.185,
483                   hip_thickness, foot_thickness);
484         add_flag (flagspace, flare, .98, 1.08, 1.185,
485                   hip_thickness, foot_thickness);
486         add_flag (.98 flagspace, flare, .97, 1.06, 1.2,
487                   hip_thickness, foot_thickness);
488         add_flag (.98 flagspace, flare, .93, 1.04, 1.22,
489                   hip_thickness, foot_thickness);
490
491         draw_square_block ((-0.5 stemthickness_rounded, 0),
492                            (0, (-flag_count * staff_space_rounded)));
493
494         y_mirror_char;
495 enddef;
496
497
498
499
500 fet_beginchar ("8th Flag (up)", "u3");
501         upstemsingleflag (0.0);
502 fet_endchar;
503
504
505 fet_beginchar ("16th Flag (up)", "u4");
506         upstemdoubleflag (0);
507 fet_endchar;
508
509
510 fet_beginchar ("32nd Flag (up)", "u5");
511         upstemtripleflag (0);
512 fet_endchar;
513
514
515 fet_beginchar ("64th Flag (up)", "u6");
516         upstemquadrupleflag (0);
517 fet_endchar;
518
519
520 fet_beginchar ("128th Flag (up)", "u7");
521         upstemquintupleflag (0);
522 fet_endchar;
523
524
525
526
527
528 fet_beginchar ("8th Flag (down)", "d3");
529         downstemsingleflag (0.0);
530 fet_endchar;
531
532
533 fet_beginchar ("16th Flag (down) 3", "d4");
534         downstemdoubleflag (0);
535 fet_endchar;
536
537
538 fet_beginchar ("32nd Flag (down)", "d5");
539         downstemtripleflag (0);
540 fet_endchar;
541
542
543 fet_beginchar ("64th Flag (down)", "d6");
544         downstemquadrupleflag (0);
545 fet_endchar;
546
547
548 fet_beginchar ("128th Flag (down)", "d7");
549         downstemquintupleflag (0);
550 fet_endchar;
551
552
553
554
555 %%%%%%%%
556 %
557 % Single Stroke for Short Appoggiatura
558 %
559
560 fet_beginchar ("grace dash (up)", "ugrace");
561         save flare, hip_depth_ratio, hip_width, foot_depth;
562
563         hip_depth_ratio = .72;
564         flare# = staff_space#;
565         hip_width# = upflag_width# - hip_thickness# / 2;
566         foot_depth# = 3 staff_space#;
567
568         define_pixels (hip_width, foot_depth);
569
570         set_char_box (hip_width# * hip_depth_ratio,
571                       hip_width# + right_upflag_space#,
572                       foot_depth# * hip_depth_ratio, -flare#)
573
574         pickup pencircle scaled 1.5 stemthickness;
575
576         z1 = (-b, -d);
577         z2 = (w, h);
578
579         penpos1 (1.5 stemthickness, angle (z2 - z1) - 90);
580         penpos2 (1.5 stemthickness, angle (z2 - z1) - 90);
581
582         fill z1l
583              -- z2l
584              .. top z2
585              .. rt z2
586              .. z2r
587              -- z1r
588              .. bot z1
589              .. lft z1
590              .. cycle;
591
592         penlabels (1, 2);
593 fet_endchar;
594
595
596 fet_beginchar ("grace dash (down)", "dgrace");
597         save flare, hip_depth_ratio, hip_width, foot_depth;
598         save total_depth;
599
600         hip_depth_ratio = .72 ;
601         flare# = .99 staff_space#;
602         hip_width# = downflag_width# - hip_thickness# / 2;
603         total_depth# = 2.85 staff_space#;
604         foot_depth# = total_depth#;
605         foot_width_ratio = .8;
606
607         define_pixels (hip_width, foot_depth);
608
609         set_char_box (hip_width# * hip_depth_ratio,
610                       hip_width# + right_downflag_space#,
611                       foot_depth# * hip_depth_ratio, -flare#)
612
613         pickup pencircle scaled 1.5 stemthickness;
614
615         z1 = (-b, -d);
616         z2 = (w, h);
617
618         penpos1 (1.5 stemthickness, angle (z2 - z1) - 90);
619         penpos2 (1.5 stemthickness, angle (z2 - z1) - 90);
620
621         fill z1l
622              -- z2l
623              .. top z2
624              .. rt z2
625              .. z2r
626              -- z1r
627              .. bot z1
628              .. lft z1
629              .. cycle;
630
631         y_mirror_char;
632 fet_endchar;
633
634
635 fet_endgroup ("flags");