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