3 \header { texidoc=" You can write stencil callbacks in Scheme, thus
4 providing custom glyphs for notation elements. A simple example is
5 adding parentheses to existing stencil callbacks.
7 The parenthesized beam is less successful due to implementation of the
8 Beam. The note head is also rather naive, since the extent of the
9 parens are also not seen by accidentals.
14 #(define (parenthesize-callback callback)
15 "Construct a function that will do CALLBACK and add parentheses.
18 \\override NoteHead.stencil
20 #(parenthesize-callback ly:note-head::print)"
22 (define (parenthesize-stencil grob)
23 "This function adds parentheses to the original callback for
24 GROB. It does not affect the dimensions of the stencil.
27 (let* ((fn (ly:grob-default-font grob))
28 (pclose (ly:font-get-glyph fn "accidentals.rightparen"))
29 (popen (ly:font-get-glyph fn "accidentals.leftparen"))
30 (subject (callback grob))
33 (subject-dim-x (ly:stencil-extent subject X))
34 (subject-dim-y (ly:stencil-extent subject Y)))
38 (ly:stencil-combine-at-edge
39 (ly:stencil-combine-at-edge subject X RIGHT pclose 0.2)
44 (ly:stencil-expr subject) subject-dim-x subject-dim-y)))
48 \layout { ragged-right = ##t }
52 \override NoteHead.stencil
54 #(parenthesize-callback ly:note-head::print)
56 \revert NoteHead.stencil
58 \override Beam.stencil
60 #(parenthesize-callback ly:beam::print)