1 % Feta (not the Font-En-Tja) music font -- draw flags
2 % This file is part of LilyPond, the GNU music typesetter.
4 % Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
19 fet_begingroup ("flags");
25 % Flags pointing down overlap with the notehead (in x-direction), so
26 % the down-flag can be bigger.
29 upflag_width# = .65 black_notehead_width# + stemthickness# / 2;
30 downflag_width# = .833 black_notehead_width# + stemthickness# / 2;
32 right_upflag_space# = .0 upflag_width#;
33 right_downflag_space# = .0 downflag_width#;
36 % Flags pointing down cannot overlap with the notehead in y-direction,
37 % so they have less slant.
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.)
45 save hip_thickness, foot_thickness;
47 hip_thickness# = 1.0 linethickness# + 0.069 staff_space#;
48 foot_thickness# = 1.2055 linethickness# + 0.06 staff_space#;
50 define_pixels (hip_thickness, foot_thickness);
53 % Inspired by Adobe Sonata and [Wanske].
54 % For example, see POSTSCRIPT Language -- program design,
55 % page 119, and [Wanske], p 41, 42.
58 def draw_flag (expr center, flare, dims, hip_depth, foot_wid,
59 hip_thickness, foot_thickness, show_labels) =
67 penpos2 (whatever, 0);
69 x2r - x2l = hround (hip_thickness);
71 penpos3 (foot_thickness, -20.0);
74 z2r = center + (xpart (dims), -ypart (dims) * hip_depth);
75 z3r = center + (xpart (dims) * foot_wid, -ypart (dims));
80 outer_path := z3r{curl c}
89 ..tension 1.1.. z2l{down}
90 .. {curl c}simple_serif (z3l, z3r, 80)
97 % TODO: calculate intersectpoint (see TeX book, p. 137)
98 % TODO: calculate incision_depth
101 def add_flag (expr yoff, flare, hip_wid_multiplier, hip_dep_multiplier,
102 intersectpoint, hip_thickness, foot_thickness) =
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;
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;
120 wid = prev_hipwid * hip_wid_multiplier;
121 hip_dep = prev_hipdep * hip_dep_multiplier;
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;
129 draw_flag (center, flare, (wid, dep),
130 hip_dep_ratio, foot_wid_ratio,
131 hip_thickness, foot_thickness, 0);
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;
143 total_depth# = (3 - shortening) * staff_space# - blot_diameter# / 2;
145 flagspace# = staff_space#;
146 hip_depth_ratio = .72;
147 hip_width# = upflag_width# - hip_thickness# / 2;
148 foot_width_ratio = .8;
150 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
152 define_pixels (hip_width, foot_depth);
153 define_whole_vertical_pixels (flagspace);
155 set_char_box (0, hip_width# + stemthickness# / 2 + right_upflag_space#,
156 foot_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
163 draw_square_block ((-0.5 stemthickness_rounded, 0),
164 (0, (-flag_count * staff_space_rounded)));
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;
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;
180 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
182 define_pixels (hip_width, foot_depth);
183 define_whole_vertical_pixels (flagspace);
185 set_char_box (0, hip_width# + stemthickness# / 2 + right_upflag_space#,
186 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
193 add_flag (flagspace, flare, .97, 1.00, 1.25,
194 hip_thickness, foot_thickness);
196 draw_square_block ((-0.5 stemthickness_rounded, 0),
197 (0, (-flag_count * staff_space_rounded)));
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;
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;
213 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
215 define_pixels (hip_width, foot_depth);
216 define_whole_vertical_pixels (flagspace);
218 set_char_box (0, hip_width# + right_upflag_space#,
219 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
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);
231 draw_square_block ((-0.5 stemthickness_rounded, 0),
232 (0, (-flag_count * staff_space_rounded)));
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;
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;
248 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
250 define_pixels (hip_width, foot_depth);
251 define_whole_vertical_pixels (flagspace);
253 set_char_box (0, hip_width# + right_upflag_space#,
254 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
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);
268 draw_square_block ((-0.5 stemthickness_rounded, 0),
269 (0, (-flag_count * staff_space_rounded)));
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;
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;
285 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
287 define_pixels (hip_width, foot_depth);
288 define_whole_vertical_pixels (flagspace);
290 set_char_box (0, hip_width# + right_upflag_space#,
291 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
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);
307 draw_square_block ((-0.5 stemthickness_rounded, 0),
308 (0, (-flag_count * staff_space_rounded)));
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;
319 total_depth# = (2.75 - shortening) * 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;
326 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
328 define_pixels (hip_width, foot_depth);
329 define_whole_vertical_pixels (flagspace);
331 set_char_box (0, hip_width# + right_downflag_space#,
332 total_depth# + foot_thickness# / 2, stemthickness# / 2)
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);
339 draw_square_block ((-0.5 stemthickness_rounded, 0),
340 (0, (-flag_count * staff_space_rounded)));
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;
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;
358 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
360 define_pixels (hip_width, foot_depth);
361 define_whole_vertical_pixels (flagspace);
363 set_char_box (0, hip_width# + right_downflag_space#,
364 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
371 add_flag (flagspace, flare, .95, 1.00, 1.25,
372 hip_thickness, foot_thickness);
374 draw_square_block ((-0.5 stemthickness_rounded, 0),
375 (0, (-flag_count * staff_space_rounded)));
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;
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;
393 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
395 define_pixels (hip_width, foot_depth);
396 define_whole_vertical_pixels (flagspace);
398 set_char_box (0, hip_width# + right_downflag_space#,
399 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
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);
411 draw_square_block ((-0.5 stemthickness_rounded, 0),
412 (0, (-flag_count * staff_space_rounded)));
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;
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;
430 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
432 define_pixels (hip_width, foot_depth);
433 define_whole_vertical_pixels (flagspace);
435 set_char_box (0, hip_width# + right_downflag_space#,
436 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
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);
450 draw_square_block ((-0.5 stemthickness_rounded, 0),
451 (0, (-flag_count * staff_space_rounded)));
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;
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;
469 (flag_count - 1) * flagspace# + foot_depth# = total_depth#;
471 define_pixels (hip_width, foot_depth);
472 define_whole_vertical_pixels (flagspace);
474 set_char_box (0, hip_width# + right_downflag_space#,
475 total_depth# + foot_thickness# / 2, stemthickness# / 2);
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);
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);
491 draw_square_block ((-0.5 stemthickness_rounded, 0),
492 (0, (-flag_count * staff_space_rounded)));
500 fet_beginchar ("8th Flag (up)", "u3");
501 upstemsingleflag (0.0);
505 fet_beginchar ("16th Flag (up)", "u4");
506 upstemdoubleflag (0);
510 fet_beginchar ("32nd Flag (up)", "u5");
511 upstemtripleflag (0);
515 fet_beginchar ("64th Flag (up)", "u6");
516 upstemquadrupleflag (0);
520 fet_beginchar ("128th Flag (up)", "u7");
521 upstemquintupleflag (0);
528 fet_beginchar ("8th Flag (down)", "d3");
529 downstemsingleflag (0.0);
533 fet_beginchar ("16th Flag (down) 3", "d4");
534 downstemdoubleflag (0);
538 fet_beginchar ("32nd Flag (down)", "d5");
539 downstemtripleflag (0);
543 fet_beginchar ("64th Flag (down)", "d6");
544 downstemquadrupleflag (0);
548 fet_beginchar ("128th Flag (down)", "d7");
549 downstemquintupleflag (0);
557 % Single Stroke for Short Appoggiatura
560 fet_beginchar ("grace dash (up)", "ugrace");
561 save flare, hip_depth_ratio, hip_width, foot_depth;
563 hip_depth_ratio = .72;
564 flare# = staff_space#;
565 hip_width# = upflag_width# - hip_thickness# / 2;
566 foot_depth# = 3 staff_space#;
568 define_pixels (hip_width, foot_depth);
570 set_char_box (hip_width# * hip_depth_ratio,
571 hip_width# + right_upflag_space#,
572 foot_depth# * hip_depth_ratio, -flare#)
574 pickup pencircle scaled 1.5 stemthickness;
579 penpos1 (1.5 stemthickness, angle (z2 - z1) - 90);
580 penpos2 (1.5 stemthickness, angle (z2 - z1) - 90);
596 fet_beginchar ("grace dash (down)", "dgrace");
597 save flare, hip_depth_ratio, hip_width, foot_depth;
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;
607 define_pixels (hip_width, foot_depth);
609 set_char_box (hip_width# * hip_depth_ratio,
610 hip_width# + right_downflag_space#,
611 foot_depth# * hip_depth_ratio, -flare#)
613 pickup pencircle scaled 1.5 stemthickness;
618 penpos1 (1.5 stemthickness, angle (z2 - z1) - 90);
619 penpos2 (1.5 stemthickness, angle (z2 - z1) - 90);
635 fet_endgroup ("flags");