4 \header { texidoc=" You can write stencil callbacks in Scheme, thus
5 providing custom glyphs for notation elements. A simple example is
6 adding parentheses to existing stencil callbacks.
8 The parenthesized beam is less successful due to implementation of the
9 Beam. The note head is also rather naive, since the extent of the
10 parens are also not seen by accidentals.
15 #(define (parenthesize-callback callback)
16 "Construct a function that will do CALLBACK and add parentheses.
19 \\property NoteHead \\override #'print-function
21 #(parenthesize-callback ly:note-head::print)
26 (define (parenthesize-stencil grob)
27 "This function adds parentheses to the original callback for
28 GROB. The dimensions of the stencil is not affected.
31 (let* ((fn (ly:grob-default-font grob))
32 (pclose (ly:font-get-glyph fn "accidentals.rightparen"))
33 (popen (ly:font-get-glyph fn "accidentals.leftparen"))
34 (subject (callback grob))
37 (subject-dim-x (ly:stencil-extent subject 0))
38 (subject-dim-y (ly:stencil-extent subject 1)))
42 (ly:stencil-combine-at-edge
43 (ly:stencil-combine-at-edge subject 0 1 pclose 0.2)
48 (ly:stencil-expr subject) subject-dim-x subject-dim-y)))
52 \layout { ragged-right = ##t }
56 \override NoteHead #'stencil
58 #(parenthesize-callback ly:note-head::print)
60 \revert NoteHead #'stencil
62 \override Beam #'stencil
64 #(parenthesize-callback ly:beam::print)